]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.16.2-201409141907.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.16.2-201409141907.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 9de9813..1462492 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -51,14 +54,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -72,9 +78,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -83,6 +91,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -95,32 +104,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -128,12 +145,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -148,14 +168,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -165,14 +185,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -188,6 +209,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index b7fa2f5..90cd9f8 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1138,6 +1138,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246 + ignore grsecurity's /proc restrictions
247 +
248 +
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252 @@ -2141,6 +2145,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256 + nopcid [X86-64]
257 + Disable PCID (Process-Context IDentifier) even if it
258 + is supported by the processor.
259 +
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263 @@ -2418,6 +2426,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268 + virtualization environments that don't cope well with the
269 + expand down segment used by UDEREF on X86-32 or the frequent
270 + page table updates on X86-64.
271 +
272 + pax_sanitize_slab=
273 + 0/1 to disable/enable slab object sanitization (enabled by
274 + default).
275 +
276 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277 +
278 + pax_extra_latent_entropy
279 + Enable a very simple form of latent entropy extraction
280 + from the first 4GB of memory as the bootmem allocator
281 + passes the memory pages to the buddy allocator.
282 +
283 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284 + when the processor supports PCID.
285 +
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289 diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt
290 index ee78eba..a06b48d 100644
291 --- a/Documentation/networking/filter.txt
292 +++ b/Documentation/networking/filter.txt
293 @@ -277,11 +277,10 @@ Possible BPF extensions are shown in the following table:
294 mark skb->mark
295 queue skb->queue_mapping
296 hatype skb->dev->type
297 - rxhash skb->hash
298 + rxhash skb->rxhash
299 cpu raw_smp_processor_id()
300 vlan_tci vlan_tx_tag_get(skb)
301 vlan_pr vlan_tx_tag_present(skb)
302 - rand prandom_u32()
303
304 These extensions can also be prefixed with '#'.
305 Examples for low-level BPF:
306 @@ -309,18 +308,6 @@ Examples for low-level BPF:
307 ret #-1
308 drop: ret #0
309
310 -** icmp random packet sampling, 1 in 4
311 - ldh [12]
312 - jne #0x800, drop
313 - ldb [23]
314 - jneq #1, drop
315 - # get a random uint32 number
316 - ld rand
317 - mod #4
318 - jneq #1, drop
319 - ret #-1
320 - drop: ret #0
321 -
322 ** SECCOMP filter example:
323
324 ld [4] /* offsetof(struct seccomp_data, arch) */
325 @@ -559,456 +546,6 @@ ffffffffa0069c8f + <x>:
326 For BPF JIT developers, bpf_jit_disasm, bpf_asm and bpf_dbg provides a useful
327 toolchain for developing and testing the kernel's JIT compiler.
328
329 -BPF kernel internals
330 ---------------------
331 -Internally, for the kernel interpreter, a different instruction set
332 -format with similar underlying principles from BPF described in previous
333 -paragraphs is being used. However, the instruction set format is modelled
334 -closer to the underlying architecture to mimic native instruction sets, so
335 -that a better performance can be achieved (more details later). This new
336 -ISA is called 'eBPF' or 'internal BPF' interchangeably. (Note: eBPF which
337 -originates from [e]xtended BPF is not the same as BPF extensions! While
338 -eBPF is an ISA, BPF extensions date back to classic BPF's 'overloading'
339 -of BPF_LD | BPF_{B,H,W} | BPF_ABS instruction.)
340 -
341 -It is designed to be JITed with one to one mapping, which can also open up
342 -the possibility for GCC/LLVM compilers to generate optimized eBPF code through
343 -an eBPF backend that performs almost as fast as natively compiled code.
344 -
345 -The new instruction set was originally designed with the possible goal in
346 -mind to write programs in "restricted C" and compile into eBPF with a optional
347 -GCC/LLVM backend, so that it can just-in-time map to modern 64-bit CPUs with
348 -minimal performance overhead over two steps, that is, C -> eBPF -> native code.
349 -
350 -Currently, the new format is being used for running user BPF programs, which
351 -includes seccomp BPF, classic socket filters, cls_bpf traffic classifier,
352 -team driver's classifier for its load-balancing mode, netfilter's xt_bpf
353 -extension, PTP dissector/classifier, and much more. They are all internally
354 -converted by the kernel into the new instruction set representation and run
355 -in the eBPF interpreter. For in-kernel handlers, this all works transparently
356 -by using sk_unattached_filter_create() for setting up the filter, resp.
357 -sk_unattached_filter_destroy() for destroying it. The macro
358 -SK_RUN_FILTER(filter, ctx) transparently invokes eBPF interpreter or JITed
359 -code to run the filter. 'filter' is a pointer to struct sk_filter that we
360 -got from sk_unattached_filter_create(), and 'ctx' the given context (e.g.
361 -skb pointer). All constraints and restrictions from sk_chk_filter() apply
362 -before a conversion to the new layout is being done behind the scenes!
363 -
364 -Currently, the classic BPF format is being used for JITing on most of the
365 -architectures. Only x86-64 performs JIT compilation from eBPF instruction set,
366 -however, future work will migrate other JIT compilers as well, so that they
367 -will profit from the very same benefits.
368 -
369 -Some core changes of the new internal format:
370 -
371 -- Number of registers increase from 2 to 10:
372 -
373 - The old format had two registers A and X, and a hidden frame pointer. The
374 - new layout extends this to be 10 internal registers and a read-only frame
375 - pointer. Since 64-bit CPUs are passing arguments to functions via registers
376 - the number of args from eBPF program to in-kernel function is restricted
377 - to 5 and one register is used to accept return value from an in-kernel
378 - function. Natively, x86_64 passes first 6 arguments in registers, aarch64/
379 - sparcv9/mips64 have 7 - 8 registers for arguments; x86_64 has 6 callee saved
380 - registers, and aarch64/sparcv9/mips64 have 11 or more callee saved registers.
381 -
382 - Therefore, eBPF calling convention is defined as:
383 -
384 - * R0 - return value from in-kernel function, and exit value for eBPF program
385 - * R1 - R5 - arguments from eBPF program to in-kernel function
386 - * R6 - R9 - callee saved registers that in-kernel function will preserve
387 - * R10 - read-only frame pointer to access stack
388 -
389 - Thus, all eBPF registers map one to one to HW registers on x86_64, aarch64,
390 - etc, and eBPF calling convention maps directly to ABIs used by the kernel on
391 - 64-bit architectures.
392 -
393 - On 32-bit architectures JIT may map programs that use only 32-bit arithmetic
394 - and may let more complex programs to be interpreted.
395 -
396 - R0 - R5 are scratch registers and eBPF program needs spill/fill them if
397 - necessary across calls. Note that there is only one eBPF program (== one
398 - eBPF main routine) and it cannot call other eBPF functions, it can only
399 - call predefined in-kernel functions, though.
400 -
401 -- Register width increases from 32-bit to 64-bit:
402 -
403 - Still, the semantics of the original 32-bit ALU operations are preserved
404 - via 32-bit subregisters. All eBPF registers are 64-bit with 32-bit lower
405 - subregisters that zero-extend into 64-bit if they are being written to.
406 - That behavior maps directly to x86_64 and arm64 subregister definition, but
407 - makes other JITs more difficult.
408 -
409 - 32-bit architectures run 64-bit internal BPF programs via interpreter.
410 - Their JITs may convert BPF programs that only use 32-bit subregisters into
411 - native instruction set and let the rest being interpreted.
412 -
413 - Operation is 64-bit, because on 64-bit architectures, pointers are also
414 - 64-bit wide, and we want to pass 64-bit values in/out of kernel functions,
415 - so 32-bit eBPF registers would otherwise require to define register-pair
416 - ABI, thus, there won't be able to use a direct eBPF register to HW register
417 - mapping and JIT would need to do combine/split/move operations for every
418 - register in and out of the function, which is complex, bug prone and slow.
419 - Another reason is the use of atomic 64-bit counters.
420 -
421 -- Conditional jt/jf targets replaced with jt/fall-through:
422 -
423 - While the original design has constructs such as "if (cond) jump_true;
424 - else jump_false;", they are being replaced into alternative constructs like
425 - "if (cond) jump_true; /* else fall-through */".
426 -
427 -- Introduces bpf_call insn and register passing convention for zero overhead
428 - calls from/to other kernel functions:
429 -
430 - Before an in-kernel function call, the internal BPF program needs to
431 - place function arguments into R1 to R5 registers to satisfy calling
432 - convention, then the interpreter will take them from registers and pass
433 - to in-kernel function. If R1 - R5 registers are mapped to CPU registers
434 - that are used for argument passing on given architecture, the JIT compiler
435 - doesn't need to emit extra moves. Function arguments will be in the correct
436 - registers and BPF_CALL instruction will be JITed as single 'call' HW
437 - instruction. This calling convention was picked to cover common call
438 - situations without performance penalty.
439 -
440 - After an in-kernel function call, R1 - R5 are reset to unreadable and R0 has
441 - a return value of the function. Since R6 - R9 are callee saved, their state
442 - is preserved across the call.
443 -
444 - For example, consider three C functions:
445 -
446 - u64 f1() { return (*_f2)(1); }
447 - u64 f2(u64 a) { return f3(a + 1, a); }
448 - u64 f3(u64 a, u64 b) { return a - b; }
449 -
450 - GCC can compile f1, f3 into x86_64:
451 -
452 - f1:
453 - movl $1, %edi
454 - movq _f2(%rip), %rax
455 - jmp *%rax
456 - f3:
457 - movq %rdi, %rax
458 - subq %rsi, %rax
459 - ret
460 -
461 - Function f2 in eBPF may look like:
462 -
463 - f2:
464 - bpf_mov R2, R1
465 - bpf_add R1, 1
466 - bpf_call f3
467 - bpf_exit
468 -
469 - If f2 is JITed and the pointer stored to '_f2'. The calls f1 -> f2 -> f3 and
470 - returns will be seamless. Without JIT, __sk_run_filter() interpreter needs to
471 - be used to call into f2.
472 -
473 - For practical reasons all eBPF programs have only one argument 'ctx' which is
474 - already placed into R1 (e.g. on __sk_run_filter() startup) and the programs
475 - can call kernel functions with up to 5 arguments. Calls with 6 or more arguments
476 - are currently not supported, but these restrictions can be lifted if necessary
477 - in the future.
478 -
479 - On 64-bit architectures all register map to HW registers one to one. For
480 - example, x86_64 JIT compiler can map them as ...
481 -
482 - R0 - rax
483 - R1 - rdi
484 - R2 - rsi
485 - R3 - rdx
486 - R4 - rcx
487 - R5 - r8
488 - R6 - rbx
489 - R7 - r13
490 - R8 - r14
491 - R9 - r15
492 - R10 - rbp
493 -
494 - ... since x86_64 ABI mandates rdi, rsi, rdx, rcx, r8, r9 for argument passing
495 - and rbx, r12 - r15 are callee saved.
496 -
497 - Then the following internal BPF pseudo-program:
498 -
499 - bpf_mov R6, R1 /* save ctx */
500 - bpf_mov R2, 2
501 - bpf_mov R3, 3
502 - bpf_mov R4, 4
503 - bpf_mov R5, 5
504 - bpf_call foo
505 - bpf_mov R7, R0 /* save foo() return value */
506 - bpf_mov R1, R6 /* restore ctx for next call */
507 - bpf_mov R2, 6
508 - bpf_mov R3, 7
509 - bpf_mov R4, 8
510 - bpf_mov R5, 9
511 - bpf_call bar
512 - bpf_add R0, R7
513 - bpf_exit
514 -
515 - After JIT to x86_64 may look like:
516 -
517 - push %rbp
518 - mov %rsp,%rbp
519 - sub $0x228,%rsp
520 - mov %rbx,-0x228(%rbp)
521 - mov %r13,-0x220(%rbp)
522 - mov %rdi,%rbx
523 - mov $0x2,%esi
524 - mov $0x3,%edx
525 - mov $0x4,%ecx
526 - mov $0x5,%r8d
527 - callq foo
528 - mov %rax,%r13
529 - mov %rbx,%rdi
530 - mov $0x2,%esi
531 - mov $0x3,%edx
532 - mov $0x4,%ecx
533 - mov $0x5,%r8d
534 - callq bar
535 - add %r13,%rax
536 - mov -0x228(%rbp),%rbx
537 - mov -0x220(%rbp),%r13
538 - leaveq
539 - retq
540 -
541 - Which is in this example equivalent in C to:
542 -
543 - u64 bpf_filter(u64 ctx)
544 - {
545 - return foo(ctx, 2, 3, 4, 5) + bar(ctx, 6, 7, 8, 9);
546 - }
547 -
548 - In-kernel functions foo() and bar() with prototype: u64 (*)(u64 arg1, u64
549 - arg2, u64 arg3, u64 arg4, u64 arg5); will receive arguments in proper
550 - registers and place their return value into '%rax' which is R0 in eBPF.
551 - Prologue and epilogue are emitted by JIT and are implicit in the
552 - interpreter. R0-R5 are scratch registers, so eBPF program needs to preserve
553 - them across the calls as defined by calling convention.
554 -
555 - For example the following program is invalid:
556 -
557 - bpf_mov R1, 1
558 - bpf_call foo
559 - bpf_mov R0, R1
560 - bpf_exit
561 -
562 - After the call the registers R1-R5 contain junk values and cannot be read.
563 - In the future an eBPF verifier can be used to validate internal BPF programs.
564 -
565 -Also in the new design, eBPF is limited to 4096 insns, which means that any
566 -program will terminate quickly and will only call a fixed number of kernel
567 -functions. Original BPF and the new format are two operand instructions,
568 -which helps to do one-to-one mapping between eBPF insn and x86 insn during JIT.
569 -
570 -The input context pointer for invoking the interpreter function is generic,
571 -its content is defined by a specific use case. For seccomp register R1 points
572 -to seccomp_data, for converted BPF filters R1 points to a skb.
573 -
574 -A program, that is translated internally consists of the following elements:
575 -
576 - op:16, jt:8, jf:8, k:32 ==> op:8, dst_reg:4, src_reg:4, off:16, imm:32
577 -
578 -So far 87 internal BPF instructions were implemented. 8-bit 'op' opcode field
579 -has room for new instructions. Some of them may use 16/24/32 byte encoding. New
580 -instructions must be multiple of 8 bytes to preserve backward compatibility.
581 -
582 -Internal BPF is a general purpose RISC instruction set. Not every register and
583 -every instruction are used during translation from original BPF to new format.
584 -For example, socket filters are not using 'exclusive add' instruction, but
585 -tracing filters may do to maintain counters of events, for example. Register R9
586 -is not used by socket filters either, but more complex filters may be running
587 -out of registers and would have to resort to spill/fill to stack.
588 -
589 -Internal BPF can used as generic assembler for last step performance
590 -optimizations, socket filters and seccomp are using it as assembler. Tracing
591 -filters may use it as assembler to generate code from kernel. In kernel usage
592 -may not be bounded by security considerations, since generated internal BPF code
593 -may be optimizing internal code path and not being exposed to the user space.
594 -Safety of internal BPF can come from a verifier (TBD). In such use cases as
595 -described, it may be used as safe instruction set.
596 -
597 -Just like the original BPF, the new format runs within a controlled environment,
598 -is deterministic and the kernel can easily prove that. The safety of the program
599 -can be determined in two steps: first step does depth-first-search to disallow
600 -loops and other CFG validation; second step starts from the first insn and
601 -descends all possible paths. It simulates execution of every insn and observes
602 -the state change of registers and stack.
603 -
604 -eBPF opcode encoding
605 ---------------------
606 -
607 -eBPF is reusing most of the opcode encoding from classic to simplify conversion
608 -of classic BPF to eBPF. For arithmetic and jump instructions the 8-bit 'code'
609 -field is divided into three parts:
610 -
611 - +----------------+--------+--------------------+
612 - | 4 bits | 1 bit | 3 bits |
613 - | operation code | source | instruction class |
614 - +----------------+--------+--------------------+
615 - (MSB) (LSB)
616 -
617 -Three LSB bits store instruction class which is one of:
618 -
619 - Classic BPF classes: eBPF classes:
620 -
621 - BPF_LD 0x00 BPF_LD 0x00
622 - BPF_LDX 0x01 BPF_LDX 0x01
623 - BPF_ST 0x02 BPF_ST 0x02
624 - BPF_STX 0x03 BPF_STX 0x03
625 - BPF_ALU 0x04 BPF_ALU 0x04
626 - BPF_JMP 0x05 BPF_JMP 0x05
627 - BPF_RET 0x06 [ class 6 unused, for future if needed ]
628 - BPF_MISC 0x07 BPF_ALU64 0x07
629 -
630 -When BPF_CLASS(code) == BPF_ALU or BPF_JMP, 4th bit encodes source operand ...
631 -
632 - BPF_K 0x00
633 - BPF_X 0x08
634 -
635 - * in classic BPF, this means:
636 -
637 - BPF_SRC(code) == BPF_X - use register X as source operand
638 - BPF_SRC(code) == BPF_K - use 32-bit immediate as source operand
639 -
640 - * in eBPF, this means:
641 -
642 - BPF_SRC(code) == BPF_X - use 'src_reg' register as source operand
643 - BPF_SRC(code) == BPF_K - use 32-bit immediate as source operand
644 -
645 -... and four MSB bits store operation code.
646 -
647 -If BPF_CLASS(code) == BPF_ALU or BPF_ALU64 [ in eBPF ], BPF_OP(code) is one of:
648 -
649 - BPF_ADD 0x00
650 - BPF_SUB 0x10
651 - BPF_MUL 0x20
652 - BPF_DIV 0x30
653 - BPF_OR 0x40
654 - BPF_AND 0x50
655 - BPF_LSH 0x60
656 - BPF_RSH 0x70
657 - BPF_NEG 0x80
658 - BPF_MOD 0x90
659 - BPF_XOR 0xa0
660 - BPF_MOV 0xb0 /* eBPF only: mov reg to reg */
661 - BPF_ARSH 0xc0 /* eBPF only: sign extending shift right */
662 - BPF_END 0xd0 /* eBPF only: endianness conversion */
663 -
664 -If BPF_CLASS(code) == BPF_JMP, BPF_OP(code) is one of:
665 -
666 - BPF_JA 0x00
667 - BPF_JEQ 0x10
668 - BPF_JGT 0x20
669 - BPF_JGE 0x30
670 - BPF_JSET 0x40
671 - BPF_JNE 0x50 /* eBPF only: jump != */
672 - BPF_JSGT 0x60 /* eBPF only: signed '>' */
673 - BPF_JSGE 0x70 /* eBPF only: signed '>=' */
674 - BPF_CALL 0x80 /* eBPF only: function call */
675 - BPF_EXIT 0x90 /* eBPF only: function return */
676 -
677 -So BPF_ADD | BPF_X | BPF_ALU means 32-bit addition in both classic BPF
678 -and eBPF. There are only two registers in classic BPF, so it means A += X.
679 -In eBPF it means dst_reg = (u32) dst_reg + (u32) src_reg; similarly,
680 -BPF_XOR | BPF_K | BPF_ALU means A ^= imm32 in classic BPF and analogous
681 -src_reg = (u32) src_reg ^ (u32) imm32 in eBPF.
682 -
683 -Classic BPF is using BPF_MISC class to represent A = X and X = A moves.
684 -eBPF is using BPF_MOV | BPF_X | BPF_ALU code instead. Since there are no
685 -BPF_MISC operations in eBPF, the class 7 is used as BPF_ALU64 to mean
686 -exactly the same operations as BPF_ALU, but with 64-bit wide operands
687 -instead. So BPF_ADD | BPF_X | BPF_ALU64 means 64-bit addition, i.e.:
688 -dst_reg = dst_reg + src_reg
689 -
690 -Classic BPF wastes the whole BPF_RET class to represent a single 'ret'
691 -operation. Classic BPF_RET | BPF_K means copy imm32 into return register
692 -and perform function exit. eBPF is modeled to match CPU, so BPF_JMP | BPF_EXIT
693 -in eBPF means function exit only. The eBPF program needs to store return
694 -value into register R0 before doing a BPF_EXIT. Class 6 in eBPF is currently
695 -unused and reserved for future use.
696 -
697 -For load and store instructions the 8-bit 'code' field is divided as:
698 -
699 - +--------+--------+-------------------+
700 - | 3 bits | 2 bits | 3 bits |
701 - | mode | size | instruction class |
702 - +--------+--------+-------------------+
703 - (MSB) (LSB)
704 -
705 -Size modifier is one of ...
706 -
707 - BPF_W 0x00 /* word */
708 - BPF_H 0x08 /* half word */
709 - BPF_B 0x10 /* byte */
710 - BPF_DW 0x18 /* eBPF only, double word */
711 -
712 -... which encodes size of load/store operation:
713 -
714 - B - 1 byte
715 - H - 2 byte
716 - W - 4 byte
717 - DW - 8 byte (eBPF only)
718 -
719 -Mode modifier is one of:
720 -
721 - BPF_IMM 0x00 /* classic BPF only, reserved in eBPF */
722 - BPF_ABS 0x20
723 - BPF_IND 0x40
724 - BPF_MEM 0x60
725 - BPF_LEN 0x80 /* classic BPF only, reserved in eBPF */
726 - BPF_MSH 0xa0 /* classic BPF only, reserved in eBPF */
727 - BPF_XADD 0xc0 /* eBPF only, exclusive add */
728 -
729 -eBPF has two non-generic instructions: (BPF_ABS | <size> | BPF_LD) and
730 -(BPF_IND | <size> | BPF_LD) which are used to access packet data.
731 -
732 -They had to be carried over from classic to have strong performance of
733 -socket filters running in eBPF interpreter. These instructions can only
734 -be used when interpreter context is a pointer to 'struct sk_buff' and
735 -have seven implicit operands. Register R6 is an implicit input that must
736 -contain pointer to sk_buff. Register R0 is an implicit output which contains
737 -the data fetched from the packet. Registers R1-R5 are scratch registers
738 -and must not be used to store the data across BPF_ABS | BPF_LD or
739 -BPF_IND | BPF_LD instructions.
740 -
741 -These instructions have implicit program exit condition as well. When
742 -eBPF program is trying to access the data beyond the packet boundary,
743 -the interpreter will abort the execution of the program. JIT compilers
744 -therefore must preserve this property. src_reg and imm32 fields are
745 -explicit inputs to these instructions.
746 -
747 -For example:
748 -
749 - BPF_IND | BPF_W | BPF_LD means:
750 -
751 - R0 = ntohl(*(u32 *) (((struct sk_buff *) R6)->data + src_reg + imm32))
752 - and R1 - R5 were scratched.
753 -
754 -Unlike classic BPF instruction set, eBPF has generic load/store operations:
755 -
756 -BPF_MEM | <size> | BPF_STX: *(size *) (dst_reg + off) = src_reg
757 -BPF_MEM | <size> | BPF_ST: *(size *) (dst_reg + off) = imm32
758 -BPF_MEM | <size> | BPF_LDX: dst_reg = *(size *) (src_reg + off)
759 -BPF_XADD | BPF_W | BPF_STX: lock xadd *(u32 *)(dst_reg + off16) += src_reg
760 -BPF_XADD | BPF_DW | BPF_STX: lock xadd *(u64 *)(dst_reg + off16) += src_reg
761 -
762 -Where size is one of: BPF_B or BPF_H or BPF_W or BPF_DW. Note that 1 and
763 -2 byte atomic increments are not supported.
764 -
765 -Testing
766 --------
767 -
768 -Next to the BPF toolchain, the kernel also ships a test module that contains
769 -various test cases for classic and internal BPF that can be executed against
770 -the BPF interpreter and JIT compiler. It can be found in lib/test_bpf.c and
771 -enabled via Kconfig:
772 -
773 - CONFIG_TEST_BPF=m
774 -
775 -After the module has been built and installed, the test suite can be executed
776 -via insmod or modprobe against 'test_bpf' module. Results of the test cases
777 -including timings in nsec can be found in the kernel log (dmesg).
778 -
779 Misc
780 ----
781
782 @@ -1024,4 +561,3 @@ the underlying architecture.
783
784 Jay Schulist <jschlst@samba.org>
785 Daniel Borkmann <dborkman@redhat.com>
786 -Alexei Starovoitov <ast@plumgrid.com>
787 diff --git a/Makefile b/Makefile
788 index c261752..e1d82656 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 @@ -692,7 +762,7 @@ KBUILD_CFLAGS += $(call cc-option, -fno-var-tracking-assignments)
891
892 ifdef CONFIG_DEBUG_INFO
893 KBUILD_CFLAGS += -g
894 -KBUILD_AFLAGS += -Wa,-gdwarf-2
895 +KBUILD_AFLAGS += -Wa,--gdwarf-2
896 endif
897
898 ifdef CONFIG_DEBUG_INFO_REDUCED
899 @@ -839,7 +909,7 @@ export mod_sign_cmd
900
901
902 ifeq ($(KBUILD_EXTMOD),)
903 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
904 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
905
906 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
907 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
908 @@ -888,6 +958,8 @@ endif
909
910 # The actual objects are generated when descending,
911 # make sure no implicit rule kicks in
912 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
913 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
914 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
915
916 # Handle descending into subdirectories listed in $(vmlinux-dirs)
917 @@ -897,7 +969,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
918 # Error messages still appears in the original language
919
920 PHONY += $(vmlinux-dirs)
921 -$(vmlinux-dirs): prepare scripts
922 +$(vmlinux-dirs): gcc-plugins prepare scripts
923 $(Q)$(MAKE) $(build)=$@
924
925 define filechk_kernel.release
926 @@ -940,10 +1012,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
927
928 archprepare: archheaders archscripts prepare1 scripts_basic
929
930 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
931 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
932 prepare0: archprepare FORCE
933 $(Q)$(MAKE) $(build)=.
934
935 # All the preparing..
936 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
937 prepare: prepare0
938
939 # Generate some files
940 @@ -1051,6 +1126,8 @@ all: modules
941 # using awk while concatenating to the final file.
942
943 PHONY += modules
944 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
945 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
946 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
947 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
948 @$(kecho) ' Building modules, stage 2.';
949 @@ -1066,7 +1143,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
950
951 # Target to prepare building external modules
952 PHONY += modules_prepare
953 -modules_prepare: prepare scripts
954 +modules_prepare: gcc-plugins prepare scripts
955
956 # Target to install modules
957 PHONY += modules_install
958 @@ -1132,7 +1209,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
959 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
960 signing_key.priv signing_key.x509 x509.genkey \
961 extra_certificates signing_key.x509.keyid \
962 - signing_key.x509.signer include/linux/version.h
963 + signing_key.x509.signer include/linux/version.h \
964 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
965 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
966 + tools/gcc/randomize_layout_seed.h
967
968 # clean - Delete most, but leave enough to build external modules
969 #
970 @@ -1171,7 +1251,7 @@ distclean: mrproper
971 @find $(srctree) $(RCS_FIND_IGNORE) \
972 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
973 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
974 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
975 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
976 -type f -print | xargs rm -f
977
978
979 @@ -1332,6 +1412,8 @@ PHONY += $(module-dirs) modules
980 $(module-dirs): crmodverdir $(objtree)/Module.symvers
981 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
982
983 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
984 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
985 modules: $(module-dirs)
986 @$(kecho) ' Building modules, stage 2.';
987 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
988 @@ -1471,17 +1553,21 @@ else
989 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
990 endif
991
992 -%.s: %.c prepare scripts FORCE
993 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
994 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
995 +%.s: %.c gcc-plugins prepare scripts FORCE
996 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
997 %.i: %.c prepare scripts FORCE
998 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
999 -%.o: %.c prepare scripts FORCE
1000 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1001 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1002 +%.o: %.c gcc-plugins prepare scripts FORCE
1003 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1004 %.lst: %.c prepare scripts FORCE
1005 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1006 -%.s: %.S prepare scripts FORCE
1007 +%.s: %.S gcc-plugins prepare scripts FORCE
1008 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1009 -%.o: %.S prepare scripts FORCE
1010 +%.o: %.S gcc-plugins prepare scripts FORCE
1011 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1012 %.symtypes: %.c prepare scripts FORCE
1013 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1014 @@ -1491,11 +1577,15 @@ endif
1015 $(cmd_crmodverdir)
1016 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1017 $(build)=$(build-dir)
1018 -%/: prepare scripts FORCE
1019 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1020 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1021 +%/: gcc-plugins prepare scripts FORCE
1022 $(cmd_crmodverdir)
1023 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1024 $(build)=$(build-dir)
1025 -%.ko: prepare scripts FORCE
1026 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
1027 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
1028 +%.ko: gcc-plugins prepare scripts FORCE
1029 $(cmd_crmodverdir)
1030 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1031 $(build)=$(build-dir) $(@:.ko=.o)
1032 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
1033 index ed60a1e..47f1a55 100644
1034 --- a/arch/alpha/include/asm/atomic.h
1035 +++ b/arch/alpha/include/asm/atomic.h
1036 @@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
1037 #define atomic_dec(v) atomic_sub(1,(v))
1038 #define atomic64_dec(v) atomic64_sub(1,(v))
1039
1040 +#define atomic64_read_unchecked(v) atomic64_read(v)
1041 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1042 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1043 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1044 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1045 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1046 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1047 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1048 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1049 +
1050 #endif /* _ALPHA_ATOMIC_H */
1051 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
1052 index ad368a9..fbe0f25 100644
1053 --- a/arch/alpha/include/asm/cache.h
1054 +++ b/arch/alpha/include/asm/cache.h
1055 @@ -4,19 +4,19 @@
1056 #ifndef __ARCH_ALPHA_CACHE_H
1057 #define __ARCH_ALPHA_CACHE_H
1058
1059 +#include <linux/const.h>
1060
1061 /* Bytes per L1 (data) cache line. */
1062 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
1063 -# define L1_CACHE_BYTES 64
1064 # define L1_CACHE_SHIFT 6
1065 #else
1066 /* Both EV4 and EV5 are write-through, read-allocate,
1067 direct-mapped, physical.
1068 */
1069 -# define L1_CACHE_BYTES 32
1070 # define L1_CACHE_SHIFT 5
1071 #endif
1072
1073 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1074 #define SMP_CACHE_BYTES L1_CACHE_BYTES
1075
1076 #endif
1077 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
1078 index 968d999..d36b2df 100644
1079 --- a/arch/alpha/include/asm/elf.h
1080 +++ b/arch/alpha/include/asm/elf.h
1081 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1082
1083 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
1084
1085 +#ifdef CONFIG_PAX_ASLR
1086 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
1087 +
1088 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
1089 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
1090 +#endif
1091 +
1092 /* $0 is set by ld.so to a pointer to a function which might be
1093 registered using atexit. This provides a mean for the dynamic
1094 linker to call DT_FINI functions for shared libraries that have
1095 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
1096 index aab14a0..b4fa3e7 100644
1097 --- a/arch/alpha/include/asm/pgalloc.h
1098 +++ b/arch/alpha/include/asm/pgalloc.h
1099 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
1100 pgd_set(pgd, pmd);
1101 }
1102
1103 +static inline void
1104 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
1105 +{
1106 + pgd_populate(mm, pgd, pmd);
1107 +}
1108 +
1109 extern pgd_t *pgd_alloc(struct mm_struct *mm);
1110
1111 static inline void
1112 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
1113 index d8f9b7e..f6222fa 100644
1114 --- a/arch/alpha/include/asm/pgtable.h
1115 +++ b/arch/alpha/include/asm/pgtable.h
1116 @@ -102,6 +102,17 @@ struct vm_area_struct;
1117 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
1118 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1119 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1120 +
1121 +#ifdef CONFIG_PAX_PAGEEXEC
1122 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
1123 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1124 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1125 +#else
1126 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1127 +# define PAGE_COPY_NOEXEC PAGE_COPY
1128 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1129 +#endif
1130 +
1131 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
1132
1133 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
1134 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
1135 index 2fd00b7..cfd5069 100644
1136 --- a/arch/alpha/kernel/module.c
1137 +++ b/arch/alpha/kernel/module.c
1138 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
1139
1140 /* The small sections were sorted to the end of the segment.
1141 The following should definitely cover them. */
1142 - gp = (u64)me->module_core + me->core_size - 0x8000;
1143 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
1144 got = sechdrs[me->arch.gotsecindex].sh_addr;
1145
1146 for (i = 0; i < n; i++) {
1147 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
1148 index 1402fcc..0b1abd2 100644
1149 --- a/arch/alpha/kernel/osf_sys.c
1150 +++ b/arch/alpha/kernel/osf_sys.c
1151 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
1152 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
1153
1154 static unsigned long
1155 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1156 - unsigned long limit)
1157 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
1158 + unsigned long limit, unsigned long flags)
1159 {
1160 struct vm_unmapped_area_info info;
1161 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
1162
1163 info.flags = 0;
1164 info.length = len;
1165 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
1166 info.high_limit = limit;
1167 info.align_mask = 0;
1168 info.align_offset = 0;
1169 + info.threadstack_offset = offset;
1170 return vm_unmapped_area(&info);
1171 }
1172
1173 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1174 merely specific addresses, but regions of memory -- perhaps
1175 this feature should be incorporated into all ports? */
1176
1177 +#ifdef CONFIG_PAX_RANDMMAP
1178 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1179 +#endif
1180 +
1181 if (addr) {
1182 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1183 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
1184 if (addr != (unsigned long) -ENOMEM)
1185 return addr;
1186 }
1187
1188 /* Next, try allocating at TASK_UNMAPPED_BASE. */
1189 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1190 - len, limit);
1191 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
1192 +
1193 if (addr != (unsigned long) -ENOMEM)
1194 return addr;
1195
1196 /* Finally, try allocating in low memory. */
1197 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
1198 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
1199
1200 return addr;
1201 }
1202 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
1203 index 98838a0..b304fb4 100644
1204 --- a/arch/alpha/mm/fault.c
1205 +++ b/arch/alpha/mm/fault.c
1206 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
1207 __reload_thread(pcb);
1208 }
1209
1210 +#ifdef CONFIG_PAX_PAGEEXEC
1211 +/*
1212 + * PaX: decide what to do with offenders (regs->pc = fault address)
1213 + *
1214 + * returns 1 when task should be killed
1215 + * 2 when patched PLT trampoline was detected
1216 + * 3 when unpatched PLT trampoline was detected
1217 + */
1218 +static int pax_handle_fetch_fault(struct pt_regs *regs)
1219 +{
1220 +
1221 +#ifdef CONFIG_PAX_EMUPLT
1222 + int err;
1223 +
1224 + do { /* PaX: patched PLT emulation #1 */
1225 + unsigned int ldah, ldq, jmp;
1226 +
1227 + err = get_user(ldah, (unsigned int *)regs->pc);
1228 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
1229 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
1230 +
1231 + if (err)
1232 + break;
1233 +
1234 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1235 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
1236 + jmp == 0x6BFB0000U)
1237 + {
1238 + unsigned long r27, addr;
1239 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1240 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
1241 +
1242 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1243 + err = get_user(r27, (unsigned long *)addr);
1244 + if (err)
1245 + break;
1246 +
1247 + regs->r27 = r27;
1248 + regs->pc = r27;
1249 + return 2;
1250 + }
1251 + } while (0);
1252 +
1253 + do { /* PaX: patched PLT emulation #2 */
1254 + unsigned int ldah, lda, br;
1255 +
1256 + err = get_user(ldah, (unsigned int *)regs->pc);
1257 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
1258 + err |= get_user(br, (unsigned int *)(regs->pc+8));
1259 +
1260 + if (err)
1261 + break;
1262 +
1263 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1264 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
1265 + (br & 0xFFE00000U) == 0xC3E00000U)
1266 + {
1267 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
1268 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1269 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
1270 +
1271 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1272 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
1273 + return 2;
1274 + }
1275 + } while (0);
1276 +
1277 + do { /* PaX: unpatched PLT emulation */
1278 + unsigned int br;
1279 +
1280 + err = get_user(br, (unsigned int *)regs->pc);
1281 +
1282 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
1283 + unsigned int br2, ldq, nop, jmp;
1284 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
1285 +
1286 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
1287 + err = get_user(br2, (unsigned int *)addr);
1288 + err |= get_user(ldq, (unsigned int *)(addr+4));
1289 + err |= get_user(nop, (unsigned int *)(addr+8));
1290 + err |= get_user(jmp, (unsigned int *)(addr+12));
1291 + err |= get_user(resolver, (unsigned long *)(addr+16));
1292 +
1293 + if (err)
1294 + break;
1295 +
1296 + if (br2 == 0xC3600000U &&
1297 + ldq == 0xA77B000CU &&
1298 + nop == 0x47FF041FU &&
1299 + jmp == 0x6B7B0000U)
1300 + {
1301 + regs->r28 = regs->pc+4;
1302 + regs->r27 = addr+16;
1303 + regs->pc = resolver;
1304 + return 3;
1305 + }
1306 + }
1307 + } while (0);
1308 +#endif
1309 +
1310 + return 1;
1311 +}
1312 +
1313 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1314 +{
1315 + unsigned long i;
1316 +
1317 + printk(KERN_ERR "PAX: bytes at PC: ");
1318 + for (i = 0; i < 5; i++) {
1319 + unsigned int c;
1320 + if (get_user(c, (unsigned int *)pc+i))
1321 + printk(KERN_CONT "???????? ");
1322 + else
1323 + printk(KERN_CONT "%08x ", c);
1324 + }
1325 + printk("\n");
1326 +}
1327 +#endif
1328
1329 /*
1330 * This routine handles page faults. It determines the address,
1331 @@ -133,8 +251,29 @@ retry:
1332 good_area:
1333 si_code = SEGV_ACCERR;
1334 if (cause < 0) {
1335 - if (!(vma->vm_flags & VM_EXEC))
1336 + if (!(vma->vm_flags & VM_EXEC)) {
1337 +
1338 +#ifdef CONFIG_PAX_PAGEEXEC
1339 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
1340 + goto bad_area;
1341 +
1342 + up_read(&mm->mmap_sem);
1343 + switch (pax_handle_fetch_fault(regs)) {
1344 +
1345 +#ifdef CONFIG_PAX_EMUPLT
1346 + case 2:
1347 + case 3:
1348 + return;
1349 +#endif
1350 +
1351 + }
1352 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
1353 + do_group_exit(SIGKILL);
1354 +#else
1355 goto bad_area;
1356 +#endif
1357 +
1358 + }
1359 } else if (!cause) {
1360 /* Allow reads even for write-only mappings */
1361 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
1362 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
1363 index 290f02ee..a639059 100644
1364 --- a/arch/arm/Kconfig
1365 +++ b/arch/arm/Kconfig
1366 @@ -1787,7 +1787,7 @@ config ALIGNMENT_TRAP
1367
1368 config UACCESS_WITH_MEMCPY
1369 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
1370 - depends on MMU
1371 + depends on MMU && !PAX_MEMORY_UDEREF
1372 default y if CPU_FEROCEON
1373 help
1374 Implement faster copy_to_user and clear_user methods for CPU
1375 @@ -2051,6 +2051,7 @@ config XIP_PHYS_ADDR
1376 config KEXEC
1377 bool "Kexec system call (EXPERIMENTAL)"
1378 depends on (!SMP || PM_SLEEP_SMP)
1379 + depends on !GRKERNSEC_KMEM
1380 help
1381 kexec is a system call that implements the ability to shutdown your
1382 current kernel, and to start another kernel. It is like a reboot
1383 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
1384 index 3040359..cf3bab0 100644
1385 --- a/arch/arm/include/asm/atomic.h
1386 +++ b/arch/arm/include/asm/atomic.h
1387 @@ -18,17 +18,35 @@
1388 #include <asm/barrier.h>
1389 #include <asm/cmpxchg.h>
1390
1391 +#ifdef CONFIG_GENERIC_ATOMIC64
1392 +#include <asm-generic/atomic64.h>
1393 +#endif
1394 +
1395 #define ATOMIC_INIT(i) { (i) }
1396
1397 #ifdef __KERNEL__
1398
1399 +#define _ASM_EXTABLE(from, to) \
1400 +" .pushsection __ex_table,\"a\"\n"\
1401 +" .align 3\n" \
1402 +" .long " #from ", " #to"\n" \
1403 +" .popsection"
1404 +
1405 /*
1406 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1407 * strex/ldrex monitor on some implementations. The reason we can use it for
1408 * atomic_set() is the clrex or dummy strex done on every exception return.
1409 */
1410 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1411 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1412 +{
1413 + return v->counter;
1414 +}
1415 #define atomic_set(v,i) (((v)->counter) = (i))
1416 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1417 +{
1418 + v->counter = i;
1419 +}
1420
1421 #if __LINUX_ARM_ARCH__ >= 6
1422
1423 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
1424
1425 prefetchw(&v->counter);
1426 __asm__ __volatile__("@ atomic_add\n"
1427 +"1: ldrex %1, [%3]\n"
1428 +" adds %0, %1, %4\n"
1429 +
1430 +#ifdef CONFIG_PAX_REFCOUNT
1431 +" bvc 3f\n"
1432 +"2: bkpt 0xf103\n"
1433 +"3:\n"
1434 +#endif
1435 +
1436 +" strex %1, %0, [%3]\n"
1437 +" teq %1, #0\n"
1438 +" bne 1b"
1439 +
1440 +#ifdef CONFIG_PAX_REFCOUNT
1441 +"\n4:\n"
1442 + _ASM_EXTABLE(2b, 4b)
1443 +#endif
1444 +
1445 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1446 + : "r" (&v->counter), "Ir" (i)
1447 + : "cc");
1448 +}
1449 +
1450 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1451 +{
1452 + unsigned long tmp;
1453 + int result;
1454 +
1455 + prefetchw(&v->counter);
1456 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1457 "1: ldrex %0, [%3]\n"
1458 " add %0, %0, %4\n"
1459 " strex %1, %0, [%3]\n"
1460 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1461 prefetchw(&v->counter);
1462
1463 __asm__ __volatile__("@ atomic_add_return\n"
1464 +"1: ldrex %1, [%3]\n"
1465 +" adds %0, %1, %4\n"
1466 +
1467 +#ifdef CONFIG_PAX_REFCOUNT
1468 +" bvc 3f\n"
1469 +" mov %0, %1\n"
1470 +"2: bkpt 0xf103\n"
1471 +"3:\n"
1472 +#endif
1473 +
1474 +" strex %1, %0, [%3]\n"
1475 +" teq %1, #0\n"
1476 +" bne 1b"
1477 +
1478 +#ifdef CONFIG_PAX_REFCOUNT
1479 +"\n4:\n"
1480 + _ASM_EXTABLE(2b, 4b)
1481 +#endif
1482 +
1483 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 + : "r" (&v->counter), "Ir" (i)
1485 + : "cc");
1486 +
1487 + smp_mb();
1488 +
1489 + return result;
1490 +}
1491 +
1492 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1493 +{
1494 + unsigned long tmp;
1495 + int result;
1496 +
1497 + smp_mb();
1498 + prefetchw(&v->counter);
1499 +
1500 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1501 "1: ldrex %0, [%3]\n"
1502 " add %0, %0, %4\n"
1503 " strex %1, %0, [%3]\n"
1504 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1505
1506 prefetchw(&v->counter);
1507 __asm__ __volatile__("@ atomic_sub\n"
1508 +"1: ldrex %1, [%3]\n"
1509 +" subs %0, %1, %4\n"
1510 +
1511 +#ifdef CONFIG_PAX_REFCOUNT
1512 +" bvc 3f\n"
1513 +"2: bkpt 0xf103\n"
1514 +"3:\n"
1515 +#endif
1516 +
1517 +" strex %1, %0, [%3]\n"
1518 +" teq %1, #0\n"
1519 +" bne 1b"
1520 +
1521 +#ifdef CONFIG_PAX_REFCOUNT
1522 +"\n4:\n"
1523 + _ASM_EXTABLE(2b, 4b)
1524 +#endif
1525 +
1526 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1527 + : "r" (&v->counter), "Ir" (i)
1528 + : "cc");
1529 +}
1530 +
1531 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1532 +{
1533 + unsigned long tmp;
1534 + int result;
1535 +
1536 + prefetchw(&v->counter);
1537 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1538 "1: ldrex %0, [%3]\n"
1539 " sub %0, %0, %4\n"
1540 " strex %1, %0, [%3]\n"
1541 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1542 prefetchw(&v->counter);
1543
1544 __asm__ __volatile__("@ atomic_sub_return\n"
1545 -"1: ldrex %0, [%3]\n"
1546 -" sub %0, %0, %4\n"
1547 +"1: ldrex %1, [%3]\n"
1548 +" subs %0, %1, %4\n"
1549 +
1550 +#ifdef CONFIG_PAX_REFCOUNT
1551 +" bvc 3f\n"
1552 +" mov %0, %1\n"
1553 +"2: bkpt 0xf103\n"
1554 +"3:\n"
1555 +#endif
1556 +
1557 " strex %1, %0, [%3]\n"
1558 " teq %1, #0\n"
1559 " bne 1b"
1560 +
1561 +#ifdef CONFIG_PAX_REFCOUNT
1562 +"\n4:\n"
1563 + _ASM_EXTABLE(2b, 4b)
1564 +#endif
1565 +
1566 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1567 : "r" (&v->counter), "Ir" (i)
1568 : "cc");
1569 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1570 __asm__ __volatile__ ("@ atomic_add_unless\n"
1571 "1: ldrex %0, [%4]\n"
1572 " teq %0, %5\n"
1573 -" beq 2f\n"
1574 -" add %1, %0, %6\n"
1575 +" beq 4f\n"
1576 +" adds %1, %0, %6\n"
1577 +
1578 +#ifdef CONFIG_PAX_REFCOUNT
1579 +" bvc 3f\n"
1580 +"2: bkpt 0xf103\n"
1581 +"3:\n"
1582 +#endif
1583 +
1584 " strex %2, %1, [%4]\n"
1585 " teq %2, #0\n"
1586 " bne 1b\n"
1587 -"2:"
1588 +"4:"
1589 +
1590 +#ifdef CONFIG_PAX_REFCOUNT
1591 + _ASM_EXTABLE(2b, 4b)
1592 +#endif
1593 +
1594 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1595 : "r" (&v->counter), "r" (u), "r" (a)
1596 : "cc");
1597 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1598 return oldval;
1599 }
1600
1601 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1602 +{
1603 + unsigned long oldval, res;
1604 +
1605 + smp_mb();
1606 +
1607 + do {
1608 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1609 + "ldrex %1, [%3]\n"
1610 + "mov %0, #0\n"
1611 + "teq %1, %4\n"
1612 + "strexeq %0, %5, [%3]\n"
1613 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1614 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1615 + : "cc");
1616 + } while (res);
1617 +
1618 + smp_mb();
1619 +
1620 + return oldval;
1621 +}
1622 +
1623 #else /* ARM_ARCH_6 */
1624
1625 #ifdef CONFIG_SMP
1626 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1627
1628 return val;
1629 }
1630 +
1631 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1632 +{
1633 + return atomic_add_return(i, v);
1634 +}
1635 +
1636 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1637 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1638 +{
1639 + (void) atomic_add_return(i, v);
1640 +}
1641
1642 static inline int atomic_sub_return(int i, atomic_t *v)
1643 {
1644 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1645 return val;
1646 }
1647 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1648 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1649 +{
1650 + (void) atomic_sub_return(i, v);
1651 +}
1652
1653 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1654 {
1655 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1656 return ret;
1657 }
1658
1659 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1660 +{
1661 + return atomic_cmpxchg(v, old, new);
1662 +}
1663 +
1664 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1665 {
1666 int c, old;
1667 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1668 #endif /* __LINUX_ARM_ARCH__ */
1669
1670 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1671 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1672 +{
1673 + return xchg(&v->counter, new);
1674 +}
1675
1676 #define atomic_inc(v) atomic_add(1, v)
1677 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1678 +{
1679 + atomic_add_unchecked(1, v);
1680 +}
1681 #define atomic_dec(v) atomic_sub(1, v)
1682 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1683 +{
1684 + atomic_sub_unchecked(1, v);
1685 +}
1686
1687 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1688 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1689 +{
1690 + return atomic_add_return_unchecked(1, v) == 0;
1691 +}
1692 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1693 #define atomic_inc_return(v) (atomic_add_return(1, v))
1694 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1695 +{
1696 + return atomic_add_return_unchecked(1, v);
1697 +}
1698 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1699 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1700
1701 @@ -246,6 +448,14 @@ typedef struct {
1702 long long counter;
1703 } atomic64_t;
1704
1705 +#ifdef CONFIG_PAX_REFCOUNT
1706 +typedef struct {
1707 + long long counter;
1708 +} atomic64_unchecked_t;
1709 +#else
1710 +typedef atomic64_t atomic64_unchecked_t;
1711 +#endif
1712 +
1713 #define ATOMIC64_INIT(i) { (i) }
1714
1715 #ifdef CONFIG_ARM_LPAE
1716 @@ -262,6 +472,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1717 return result;
1718 }
1719
1720 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1721 +{
1722 + long long result;
1723 +
1724 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1725 +" ldrd %0, %H0, [%1]"
1726 + : "=&r" (result)
1727 + : "r" (&v->counter), "Qo" (v->counter)
1728 + );
1729 +
1730 + return result;
1731 +}
1732 +
1733 static inline void atomic64_set(atomic64_t *v, long long i)
1734 {
1735 __asm__ __volatile__("@ atomic64_set\n"
1736 @@ -270,6 +493,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1737 : "r" (&v->counter), "r" (i)
1738 );
1739 }
1740 +
1741 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1742 +{
1743 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1744 +" strd %2, %H2, [%1]"
1745 + : "=Qo" (v->counter)
1746 + : "r" (&v->counter), "r" (i)
1747 + );
1748 +}
1749 #else
1750 static inline long long atomic64_read(const atomic64_t *v)
1751 {
1752 @@ -284,6 +516,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1753 return result;
1754 }
1755
1756 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1757 +{
1758 + long long result;
1759 +
1760 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1761 +" ldrexd %0, %H0, [%1]"
1762 + : "=&r" (result)
1763 + : "r" (&v->counter), "Qo" (v->counter)
1764 + );
1765 +
1766 + return result;
1767 +}
1768 +
1769 static inline void atomic64_set(atomic64_t *v, long long i)
1770 {
1771 long long tmp;
1772 @@ -298,6 +543,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1773 : "r" (&v->counter), "r" (i)
1774 : "cc");
1775 }
1776 +
1777 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1778 +{
1779 + long long tmp;
1780 +
1781 + prefetchw(&v->counter);
1782 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1783 +"1: ldrexd %0, %H0, [%2]\n"
1784 +" strexd %0, %3, %H3, [%2]\n"
1785 +" teq %0, #0\n"
1786 +" bne 1b"
1787 + : "=&r" (tmp), "=Qo" (v->counter)
1788 + : "r" (&v->counter), "r" (i)
1789 + : "cc");
1790 +}
1791 #endif
1792
1793 static inline void atomic64_add(long long i, atomic64_t *v)
1794 @@ -309,6 +569,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1795 __asm__ __volatile__("@ atomic64_add\n"
1796 "1: ldrexd %0, %H0, [%3]\n"
1797 " adds %Q0, %Q0, %Q4\n"
1798 +" adcs %R0, %R0, %R4\n"
1799 +
1800 +#ifdef CONFIG_PAX_REFCOUNT
1801 +" bvc 3f\n"
1802 +"2: bkpt 0xf103\n"
1803 +"3:\n"
1804 +#endif
1805 +
1806 +" strexd %1, %0, %H0, [%3]\n"
1807 +" teq %1, #0\n"
1808 +" bne 1b"
1809 +
1810 +#ifdef CONFIG_PAX_REFCOUNT
1811 +"\n4:\n"
1812 + _ASM_EXTABLE(2b, 4b)
1813 +#endif
1814 +
1815 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1816 + : "r" (&v->counter), "r" (i)
1817 + : "cc");
1818 +}
1819 +
1820 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1821 +{
1822 + long long result;
1823 + unsigned long tmp;
1824 +
1825 + prefetchw(&v->counter);
1826 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1827 +"1: ldrexd %0, %H0, [%3]\n"
1828 +" adds %Q0, %Q0, %Q4\n"
1829 " adc %R0, %R0, %R4\n"
1830 " strexd %1, %0, %H0, [%3]\n"
1831 " teq %1, #0\n"
1832 @@ -329,6 +620,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1833 __asm__ __volatile__("@ atomic64_add_return\n"
1834 "1: ldrexd %0, %H0, [%3]\n"
1835 " adds %Q0, %Q0, %Q4\n"
1836 +" adcs %R0, %R0, %R4\n"
1837 +
1838 +#ifdef CONFIG_PAX_REFCOUNT
1839 +" bvc 3f\n"
1840 +" mov %0, %1\n"
1841 +" mov %H0, %H1\n"
1842 +"2: bkpt 0xf103\n"
1843 +"3:\n"
1844 +#endif
1845 +
1846 +" strexd %1, %0, %H0, [%3]\n"
1847 +" teq %1, #0\n"
1848 +" bne 1b"
1849 +
1850 +#ifdef CONFIG_PAX_REFCOUNT
1851 +"\n4:\n"
1852 + _ASM_EXTABLE(2b, 4b)
1853 +#endif
1854 +
1855 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1856 + : "r" (&v->counter), "r" (i)
1857 + : "cc");
1858 +
1859 + smp_mb();
1860 +
1861 + return result;
1862 +}
1863 +
1864 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1865 +{
1866 + long long result;
1867 + unsigned long tmp;
1868 +
1869 + smp_mb();
1870 +
1871 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1872 +"1: ldrexd %0, %H0, [%3]\n"
1873 +" adds %Q0, %Q0, %Q4\n"
1874 " adc %R0, %R0, %R4\n"
1875 " strexd %1, %0, %H0, [%3]\n"
1876 " teq %1, #0\n"
1877 @@ -351,6 +680,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1878 __asm__ __volatile__("@ atomic64_sub\n"
1879 "1: ldrexd %0, %H0, [%3]\n"
1880 " subs %Q0, %Q0, %Q4\n"
1881 +" sbcs %R0, %R0, %R4\n"
1882 +
1883 +#ifdef CONFIG_PAX_REFCOUNT
1884 +" bvc 3f\n"
1885 +"2: bkpt 0xf103\n"
1886 +"3:\n"
1887 +#endif
1888 +
1889 +" strexd %1, %0, %H0, [%3]\n"
1890 +" teq %1, #0\n"
1891 +" bne 1b"
1892 +
1893 +#ifdef CONFIG_PAX_REFCOUNT
1894 +"\n4:\n"
1895 + _ASM_EXTABLE(2b, 4b)
1896 +#endif
1897 +
1898 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1899 + : "r" (&v->counter), "r" (i)
1900 + : "cc");
1901 +}
1902 +
1903 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1904 +{
1905 + long long result;
1906 + unsigned long tmp;
1907 +
1908 + prefetchw(&v->counter);
1909 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1910 +"1: ldrexd %0, %H0, [%3]\n"
1911 +" subs %Q0, %Q0, %Q4\n"
1912 " sbc %R0, %R0, %R4\n"
1913 " strexd %1, %0, %H0, [%3]\n"
1914 " teq %1, #0\n"
1915 @@ -371,10 +731,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1916 __asm__ __volatile__("@ atomic64_sub_return\n"
1917 "1: ldrexd %0, %H0, [%3]\n"
1918 " subs %Q0, %Q0, %Q4\n"
1919 -" sbc %R0, %R0, %R4\n"
1920 +" sbcs %R0, %R0, %R4\n"
1921 +
1922 +#ifdef CONFIG_PAX_REFCOUNT
1923 +" bvc 3f\n"
1924 +" mov %0, %1\n"
1925 +" mov %H0, %H1\n"
1926 +"2: bkpt 0xf103\n"
1927 +"3:\n"
1928 +#endif
1929 +
1930 " strexd %1, %0, %H0, [%3]\n"
1931 " teq %1, #0\n"
1932 " bne 1b"
1933 +
1934 +#ifdef CONFIG_PAX_REFCOUNT
1935 +"\n4:\n"
1936 + _ASM_EXTABLE(2b, 4b)
1937 +#endif
1938 +
1939 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1940 : "r" (&v->counter), "r" (i)
1941 : "cc");
1942 @@ -410,6 +785,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1943 return oldval;
1944 }
1945
1946 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1947 + long long new)
1948 +{
1949 + long long oldval;
1950 + unsigned long res;
1951 +
1952 + smp_mb();
1953 +
1954 + do {
1955 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1956 + "ldrexd %1, %H1, [%3]\n"
1957 + "mov %0, #0\n"
1958 + "teq %1, %4\n"
1959 + "teqeq %H1, %H4\n"
1960 + "strexdeq %0, %5, %H5, [%3]"
1961 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1962 + : "r" (&ptr->counter), "r" (old), "r" (new)
1963 + : "cc");
1964 + } while (res);
1965 +
1966 + smp_mb();
1967 +
1968 + return oldval;
1969 +}
1970 +
1971 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1972 {
1973 long long result;
1974 @@ -435,21 +835,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1975 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1976 {
1977 long long result;
1978 - unsigned long tmp;
1979 + u64 tmp;
1980
1981 smp_mb();
1982 prefetchw(&v->counter);
1983
1984 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1985 -"1: ldrexd %0, %H0, [%3]\n"
1986 -" subs %Q0, %Q0, #1\n"
1987 -" sbc %R0, %R0, #0\n"
1988 +"1: ldrexd %1, %H1, [%3]\n"
1989 +" subs %Q0, %Q1, #1\n"
1990 +" sbcs %R0, %R1, #0\n"
1991 +
1992 +#ifdef CONFIG_PAX_REFCOUNT
1993 +" bvc 3f\n"
1994 +" mov %Q0, %Q1\n"
1995 +" mov %R0, %R1\n"
1996 +"2: bkpt 0xf103\n"
1997 +"3:\n"
1998 +#endif
1999 +
2000 " teq %R0, #0\n"
2001 -" bmi 2f\n"
2002 +" bmi 4f\n"
2003 " strexd %1, %0, %H0, [%3]\n"
2004 " teq %1, #0\n"
2005 " bne 1b\n"
2006 -"2:"
2007 +"4:\n"
2008 +
2009 +#ifdef CONFIG_PAX_REFCOUNT
2010 + _ASM_EXTABLE(2b, 4b)
2011 +#endif
2012 +
2013 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
2014 : "r" (&v->counter)
2015 : "cc");
2016 @@ -473,13 +887,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
2017 " teq %0, %5\n"
2018 " teqeq %H0, %H5\n"
2019 " moveq %1, #0\n"
2020 -" beq 2f\n"
2021 +" beq 4f\n"
2022 " adds %Q0, %Q0, %Q6\n"
2023 -" adc %R0, %R0, %R6\n"
2024 +" adcs %R0, %R0, %R6\n"
2025 +
2026 +#ifdef CONFIG_PAX_REFCOUNT
2027 +" bvc 3f\n"
2028 +"2: bkpt 0xf103\n"
2029 +"3:\n"
2030 +#endif
2031 +
2032 " strexd %2, %0, %H0, [%4]\n"
2033 " teq %2, #0\n"
2034 " bne 1b\n"
2035 -"2:"
2036 +"4:\n"
2037 +
2038 +#ifdef CONFIG_PAX_REFCOUNT
2039 + _ASM_EXTABLE(2b, 4b)
2040 +#endif
2041 +
2042 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
2043 : "r" (&v->counter), "r" (u), "r" (a)
2044 : "cc");
2045 @@ -492,10 +918,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
2046
2047 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
2048 #define atomic64_inc(v) atomic64_add(1LL, (v))
2049 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
2050 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
2051 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
2052 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
2053 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
2054 #define atomic64_dec(v) atomic64_sub(1LL, (v))
2055 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
2056 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
2057 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
2058 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
2059 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
2060 index c6a3e73..35cca85 100644
2061 --- a/arch/arm/include/asm/barrier.h
2062 +++ b/arch/arm/include/asm/barrier.h
2063 @@ -63,7 +63,7 @@
2064 do { \
2065 compiletime_assert_atomic_type(*p); \
2066 smp_mb(); \
2067 - ACCESS_ONCE(*p) = (v); \
2068 + ACCESS_ONCE_RW(*p) = (v); \
2069 } while (0)
2070
2071 #define smp_load_acquire(p) \
2072 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
2073 index 75fe66b..ba3dee4 100644
2074 --- a/arch/arm/include/asm/cache.h
2075 +++ b/arch/arm/include/asm/cache.h
2076 @@ -4,8 +4,10 @@
2077 #ifndef __ASMARM_CACHE_H
2078 #define __ASMARM_CACHE_H
2079
2080 +#include <linux/const.h>
2081 +
2082 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
2083 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2084 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2085
2086 /*
2087 * Memory returned by kmalloc() may be used for DMA, so we must make
2088 @@ -24,5 +26,6 @@
2089 #endif
2090
2091 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2092 +#define __read_only __attribute__ ((__section__(".data..read_only")))
2093
2094 #endif
2095 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
2096 index fd43f7f..a817f5a 100644
2097 --- a/arch/arm/include/asm/cacheflush.h
2098 +++ b/arch/arm/include/asm/cacheflush.h
2099 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
2100 void (*dma_unmap_area)(const void *, size_t, int);
2101
2102 void (*dma_flush_range)(const void *, const void *);
2103 -};
2104 +} __no_const;
2105
2106 /*
2107 * Select the calling method
2108 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
2109 index 5233151..87a71fa 100644
2110 --- a/arch/arm/include/asm/checksum.h
2111 +++ b/arch/arm/include/asm/checksum.h
2112 @@ -37,7 +37,19 @@ __wsum
2113 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
2114
2115 __wsum
2116 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
2117 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
2118 +
2119 +static inline __wsum
2120 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
2121 +{
2122 + __wsum ret;
2123 + pax_open_userland();
2124 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
2125 + pax_close_userland();
2126 + return ret;
2127 +}
2128 +
2129 +
2130
2131 /*
2132 * Fold a partial checksum without adding pseudo headers
2133 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
2134 index abb2c37..96db950 100644
2135 --- a/arch/arm/include/asm/cmpxchg.h
2136 +++ b/arch/arm/include/asm/cmpxchg.h
2137 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
2138
2139 #define xchg(ptr,x) \
2140 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
2141 +#define xchg_unchecked(ptr,x) \
2142 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
2143
2144 #include <asm-generic/cmpxchg-local.h>
2145
2146 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
2147 index 6ddbe44..b5e38b1 100644
2148 --- a/arch/arm/include/asm/domain.h
2149 +++ b/arch/arm/include/asm/domain.h
2150 @@ -48,18 +48,37 @@
2151 * Domain types
2152 */
2153 #define DOMAIN_NOACCESS 0
2154 -#define DOMAIN_CLIENT 1
2155 #ifdef CONFIG_CPU_USE_DOMAINS
2156 +#define DOMAIN_USERCLIENT 1
2157 +#define DOMAIN_KERNELCLIENT 1
2158 #define DOMAIN_MANAGER 3
2159 +#define DOMAIN_VECTORS DOMAIN_USER
2160 #else
2161 +
2162 +#ifdef CONFIG_PAX_KERNEXEC
2163 #define DOMAIN_MANAGER 1
2164 +#define DOMAIN_KERNEXEC 3
2165 +#else
2166 +#define DOMAIN_MANAGER 1
2167 +#endif
2168 +
2169 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2170 +#define DOMAIN_USERCLIENT 0
2171 +#define DOMAIN_UDEREF 1
2172 +#define DOMAIN_VECTORS DOMAIN_KERNEL
2173 +#else
2174 +#define DOMAIN_USERCLIENT 1
2175 +#define DOMAIN_VECTORS DOMAIN_USER
2176 +#endif
2177 +#define DOMAIN_KERNELCLIENT 1
2178 +
2179 #endif
2180
2181 #define domain_val(dom,type) ((type) << (2*(dom)))
2182
2183 #ifndef __ASSEMBLY__
2184
2185 -#ifdef CONFIG_CPU_USE_DOMAINS
2186 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2187 static inline void set_domain(unsigned val)
2188 {
2189 asm volatile(
2190 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
2191 isb();
2192 }
2193
2194 -#define modify_domain(dom,type) \
2195 - do { \
2196 - struct thread_info *thread = current_thread_info(); \
2197 - unsigned int domain = thread->cpu_domain; \
2198 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
2199 - thread->cpu_domain = domain | domain_val(dom, type); \
2200 - set_domain(thread->cpu_domain); \
2201 - } while (0)
2202 -
2203 +extern void modify_domain(unsigned int dom, unsigned int type);
2204 #else
2205 static inline void set_domain(unsigned val) { }
2206 static inline void modify_domain(unsigned dom, unsigned type) { }
2207 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
2208 index f4b46d3..abc9b2b 100644
2209 --- a/arch/arm/include/asm/elf.h
2210 +++ b/arch/arm/include/asm/elf.h
2211 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
2212 the loader. We need to make sure that it is out of the way of the program
2213 that it will "exec", and that there is sufficient room for the brk. */
2214
2215 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2216 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2217 +
2218 +#ifdef CONFIG_PAX_ASLR
2219 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
2220 +
2221 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2222 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2223 +#endif
2224
2225 /* When the program starts, a1 contains a pointer to a function to be
2226 registered with atexit, as per the SVR4 ABI. A value of 0 means we
2227 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
2228 extern void elf_set_personality(const struct elf32_hdr *);
2229 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
2230
2231 -struct mm_struct;
2232 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2233 -#define arch_randomize_brk arch_randomize_brk
2234 -
2235 #ifdef CONFIG_MMU
2236 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2237 struct linux_binprm;
2238 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
2239 index de53547..52b9a28 100644
2240 --- a/arch/arm/include/asm/fncpy.h
2241 +++ b/arch/arm/include/asm/fncpy.h
2242 @@ -81,7 +81,9 @@
2243 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
2244 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
2245 \
2246 + pax_open_kernel(); \
2247 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
2248 + pax_close_kernel(); \
2249 flush_icache_range((unsigned long)(dest_buf), \
2250 (unsigned long)(dest_buf) + (size)); \
2251 \
2252 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
2253 index 53e69da..3fdc896 100644
2254 --- a/arch/arm/include/asm/futex.h
2255 +++ b/arch/arm/include/asm/futex.h
2256 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2257 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
2258 return -EFAULT;
2259
2260 + pax_open_userland();
2261 +
2262 smp_mb();
2263 /* Prefetching cannot fault */
2264 prefetchw(uaddr);
2265 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2266 : "cc", "memory");
2267 smp_mb();
2268
2269 + pax_close_userland();
2270 +
2271 *uval = val;
2272 return ret;
2273 }
2274 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2275 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
2276 return -EFAULT;
2277
2278 + pax_open_userland();
2279 +
2280 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
2281 "1: " TUSER(ldr) " %1, [%4]\n"
2282 " teq %1, %2\n"
2283 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
2284 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
2285 : "cc", "memory");
2286
2287 + pax_close_userland();
2288 +
2289 *uval = val;
2290 return ret;
2291 }
2292 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
2293 return -EFAULT;
2294
2295 pagefault_disable(); /* implies preempt_disable() */
2296 + pax_open_userland();
2297
2298 switch (op) {
2299 case FUTEX_OP_SET:
2300 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
2301 ret = -ENOSYS;
2302 }
2303
2304 + pax_close_userland();
2305 pagefault_enable(); /* subsumes preempt_enable() */
2306
2307 if (!ret) {
2308 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
2309 index 83eb2f7..ed77159 100644
2310 --- a/arch/arm/include/asm/kmap_types.h
2311 +++ b/arch/arm/include/asm/kmap_types.h
2312 @@ -4,6 +4,6 @@
2313 /*
2314 * This is the "bare minimum". AIO seems to require this.
2315 */
2316 -#define KM_TYPE_NR 16
2317 +#define KM_TYPE_NR 17
2318
2319 #endif
2320 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
2321 index 9e614a1..3302cca 100644
2322 --- a/arch/arm/include/asm/mach/dma.h
2323 +++ b/arch/arm/include/asm/mach/dma.h
2324 @@ -22,7 +22,7 @@ struct dma_ops {
2325 int (*residue)(unsigned int, dma_t *); /* optional */
2326 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
2327 const char *type;
2328 -};
2329 +} __do_const;
2330
2331 struct dma_struct {
2332 void *addr; /* single DMA address */
2333 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
2334 index f98c7f3..e5c626d 100644
2335 --- a/arch/arm/include/asm/mach/map.h
2336 +++ b/arch/arm/include/asm/mach/map.h
2337 @@ -23,17 +23,19 @@ struct map_desc {
2338
2339 /* types 0-3 are defined in asm/io.h */
2340 enum {
2341 - MT_UNCACHED = 4,
2342 - MT_CACHECLEAN,
2343 - MT_MINICLEAN,
2344 + MT_UNCACHED_RW = 4,
2345 + MT_CACHECLEAN_RO,
2346 + MT_MINICLEAN_RO,
2347 MT_LOW_VECTORS,
2348 MT_HIGH_VECTORS,
2349 - MT_MEMORY_RWX,
2350 + __MT_MEMORY_RWX,
2351 MT_MEMORY_RW,
2352 - MT_ROM,
2353 - MT_MEMORY_RWX_NONCACHED,
2354 + MT_MEMORY_RX,
2355 + MT_ROM_RX,
2356 + MT_MEMORY_RW_NONCACHED,
2357 + MT_MEMORY_RX_NONCACHED,
2358 MT_MEMORY_RW_DTCM,
2359 - MT_MEMORY_RWX_ITCM,
2360 + MT_MEMORY_RX_ITCM,
2361 MT_MEMORY_RW_SO,
2362 MT_MEMORY_DMA_READY,
2363 };
2364 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
2365 index 891a56b..48f337e 100644
2366 --- a/arch/arm/include/asm/outercache.h
2367 +++ b/arch/arm/include/asm/outercache.h
2368 @@ -36,7 +36,7 @@ struct outer_cache_fns {
2369
2370 /* This is an ARM L2C thing */
2371 void (*write_sec)(unsigned long, unsigned);
2372 -};
2373 +} __no_const;
2374
2375 extern struct outer_cache_fns outer_cache;
2376
2377 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
2378 index 4355f0e..cd9168e 100644
2379 --- a/arch/arm/include/asm/page.h
2380 +++ b/arch/arm/include/asm/page.h
2381 @@ -23,6 +23,7 @@
2382
2383 #else
2384
2385 +#include <linux/compiler.h>
2386 #include <asm/glue.h>
2387
2388 /*
2389 @@ -114,7 +115,7 @@ struct cpu_user_fns {
2390 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
2391 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
2392 unsigned long vaddr, struct vm_area_struct *vma);
2393 -};
2394 +} __no_const;
2395
2396 #ifdef MULTI_USER
2397 extern struct cpu_user_fns cpu_user;
2398 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2399 index 78a7793..e3dc06c 100644
2400 --- a/arch/arm/include/asm/pgalloc.h
2401 +++ b/arch/arm/include/asm/pgalloc.h
2402 @@ -17,6 +17,7 @@
2403 #include <asm/processor.h>
2404 #include <asm/cacheflush.h>
2405 #include <asm/tlbflush.h>
2406 +#include <asm/system_info.h>
2407
2408 #define check_pgt_cache() do { } while (0)
2409
2410 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2411 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2412 }
2413
2414 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2415 +{
2416 + pud_populate(mm, pud, pmd);
2417 +}
2418 +
2419 #else /* !CONFIG_ARM_LPAE */
2420
2421 /*
2422 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2423 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2424 #define pmd_free(mm, pmd) do { } while (0)
2425 #define pud_populate(mm,pmd,pte) BUG()
2426 +#define pud_populate_kernel(mm,pmd,pte) BUG()
2427
2428 #endif /* CONFIG_ARM_LPAE */
2429
2430 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2431 __free_page(pte);
2432 }
2433
2434 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2435 +{
2436 +#ifdef CONFIG_ARM_LPAE
2437 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2438 +#else
2439 + if (addr & SECTION_SIZE)
2440 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2441 + else
2442 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2443 +#endif
2444 + flush_pmd_entry(pmdp);
2445 +}
2446 +
2447 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2448 pmdval_t prot)
2449 {
2450 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2451 static inline void
2452 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2453 {
2454 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2455 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2456 }
2457 #define pmd_pgtable(pmd) pmd_page(pmd)
2458
2459 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2460 index 5cfba15..f415e1a 100644
2461 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2462 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2463 @@ -20,12 +20,15 @@
2464 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2465 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2466 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2467 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2468 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2469 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2470 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2471 +
2472 /*
2473 * - section
2474 */
2475 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2476 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2477 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2478 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2479 @@ -37,6 +40,7 @@
2480 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2481 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2482 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2483 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2484
2485 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2486 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2487 @@ -66,6 +70,7 @@
2488 * - extended small page/tiny page
2489 */
2490 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2491 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2492 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2493 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2494 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2495 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2496 index 219ac88..73ec32a 100644
2497 --- a/arch/arm/include/asm/pgtable-2level.h
2498 +++ b/arch/arm/include/asm/pgtable-2level.h
2499 @@ -126,6 +126,9 @@
2500 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2501 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2502
2503 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2504 +#define L_PTE_PXN (_AT(pteval_t, 0))
2505 +
2506 /*
2507 * These are the memory types, defined to be compatible with
2508 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2509 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2510 index 626989f..9d67a33 100644
2511 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2512 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2513 @@ -75,6 +75,7 @@
2514 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2515 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2516 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2517 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2518 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2519
2520 /*
2521 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2522 index 85c60ad..b0bbd7e 100644
2523 --- a/arch/arm/include/asm/pgtable-3level.h
2524 +++ b/arch/arm/include/asm/pgtable-3level.h
2525 @@ -82,6 +82,7 @@
2526 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2527 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2528 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2529 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2530 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2531 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2532 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2533 @@ -95,6 +96,7 @@
2534 /*
2535 * To be used in assembly code with the upper page attributes.
2536 */
2537 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2538 #define L_PTE_XN_HIGH (1 << (54 - 32))
2539 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2540
2541 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2542 index 5478e5d..f5b5cb3 100644
2543 --- a/arch/arm/include/asm/pgtable.h
2544 +++ b/arch/arm/include/asm/pgtable.h
2545 @@ -33,6 +33,9 @@
2546 #include <asm/pgtable-2level.h>
2547 #endif
2548
2549 +#define ktla_ktva(addr) (addr)
2550 +#define ktva_ktla(addr) (addr)
2551 +
2552 /*
2553 * Just any arbitrary offset to the start of the vmalloc VM area: the
2554 * current 8MB value just means that there will be a 8MB "hole" after the
2555 @@ -48,6 +51,9 @@
2556 #define LIBRARY_TEXT_START 0x0c000000
2557
2558 #ifndef __ASSEMBLY__
2559 +extern pteval_t __supported_pte_mask;
2560 +extern pmdval_t __supported_pmd_mask;
2561 +
2562 extern void __pte_error(const char *file, int line, pte_t);
2563 extern void __pmd_error(const char *file, int line, pmd_t);
2564 extern void __pgd_error(const char *file, int line, pgd_t);
2565 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2566 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2567 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2568
2569 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2570 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2571 +
2572 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2573 +#include <asm/domain.h>
2574 +#include <linux/thread_info.h>
2575 +#include <linux/preempt.h>
2576 +
2577 +static inline int test_domain(int domain, int domaintype)
2578 +{
2579 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2580 +}
2581 +#endif
2582 +
2583 +#ifdef CONFIG_PAX_KERNEXEC
2584 +static inline unsigned long pax_open_kernel(void) {
2585 +#ifdef CONFIG_ARM_LPAE
2586 + /* TODO */
2587 +#else
2588 + preempt_disable();
2589 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2590 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2591 +#endif
2592 + return 0;
2593 +}
2594 +
2595 +static inline unsigned long pax_close_kernel(void) {
2596 +#ifdef CONFIG_ARM_LPAE
2597 + /* TODO */
2598 +#else
2599 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2600 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2601 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2602 + preempt_enable_no_resched();
2603 +#endif
2604 + return 0;
2605 +}
2606 +#else
2607 +static inline unsigned long pax_open_kernel(void) { return 0; }
2608 +static inline unsigned long pax_close_kernel(void) { return 0; }
2609 +#endif
2610 +
2611 /*
2612 * This is the lowest virtual address we can permit any user space
2613 * mapping to be mapped at. This is particularly important for
2614 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2615 /*
2616 * The pgprot_* and protection_map entries will be fixed up in runtime
2617 * to include the cachable and bufferable bits based on memory policy,
2618 - * as well as any architecture dependent bits like global/ASID and SMP
2619 - * shared mapping bits.
2620 + * as well as any architecture dependent bits like global/ASID, PXN,
2621 + * and SMP shared mapping bits.
2622 */
2623 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2624
2625 @@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2626 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2627 {
2628 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2629 - L_PTE_NONE | L_PTE_VALID;
2630 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2631 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2632 return pte;
2633 }
2634 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2635 index c25ef3e..735f14b 100644
2636 --- a/arch/arm/include/asm/psci.h
2637 +++ b/arch/arm/include/asm/psci.h
2638 @@ -32,7 +32,7 @@ struct psci_operations {
2639 int (*affinity_info)(unsigned long target_affinity,
2640 unsigned long lowest_affinity_level);
2641 int (*migrate_info_type)(void);
2642 -};
2643 +} __no_const;
2644
2645 extern struct psci_operations psci_ops;
2646 extern struct smp_operations psci_smp_ops;
2647 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2648 index 2ec765c..beb1fe16 100644
2649 --- a/arch/arm/include/asm/smp.h
2650 +++ b/arch/arm/include/asm/smp.h
2651 @@ -113,7 +113,7 @@ struct smp_operations {
2652 int (*cpu_disable)(unsigned int cpu);
2653 #endif
2654 #endif
2655 -};
2656 +} __no_const;
2657
2658 struct of_cpu_method {
2659 const char *method;
2660 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2661 index e4e4208..086684a 100644
2662 --- a/arch/arm/include/asm/thread_info.h
2663 +++ b/arch/arm/include/asm/thread_info.h
2664 @@ -88,9 +88,9 @@ struct thread_info {
2665 .flags = 0, \
2666 .preempt_count = INIT_PREEMPT_COUNT, \
2667 .addr_limit = KERNEL_DS, \
2668 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2669 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2670 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2671 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2672 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2673 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2674 .restart_block = { \
2675 .fn = do_no_restart_syscall, \
2676 }, \
2677 @@ -164,7 +164,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2678 #define TIF_SYSCALL_AUDIT 9
2679 #define TIF_SYSCALL_TRACEPOINT 10
2680 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2681 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2682 +/* within 8 bits of TIF_SYSCALL_TRACE
2683 + * to meet flexible second operand requirements
2684 + */
2685 +#define TIF_GRSEC_SETXID 12
2686 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2687 #define TIF_USING_IWMMXT 17
2688 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2689 #define TIF_RESTORE_SIGMASK 20
2690 @@ -178,10 +182,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2691 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2692 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2693 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2694 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2695
2696 /* Checks for any syscall work in entry-common.S */
2697 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2698 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2699 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2700
2701 /*
2702 * Change these and you break ASM code in entry-common.S
2703 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2704 index 75d9579..b5b40e4 100644
2705 --- a/arch/arm/include/asm/uaccess.h
2706 +++ b/arch/arm/include/asm/uaccess.h
2707 @@ -18,6 +18,7 @@
2708 #include <asm/domain.h>
2709 #include <asm/unified.h>
2710 #include <asm/compiler.h>
2711 +#include <asm/pgtable.h>
2712
2713 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2714 #include <asm-generic/uaccess-unaligned.h>
2715 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2716 static inline void set_fs(mm_segment_t fs)
2717 {
2718 current_thread_info()->addr_limit = fs;
2719 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2720 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2721 }
2722
2723 #define segment_eq(a,b) ((a) == (b))
2724
2725 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2726 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2727 +
2728 +static inline void pax_open_userland(void)
2729 +{
2730 +
2731 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2732 + if (segment_eq(get_fs(), USER_DS)) {
2733 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2734 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2735 + }
2736 +#endif
2737 +
2738 +}
2739 +
2740 +static inline void pax_close_userland(void)
2741 +{
2742 +
2743 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2744 + if (segment_eq(get_fs(), USER_DS)) {
2745 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2746 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2747 + }
2748 +#endif
2749 +
2750 +}
2751 +
2752 #define __addr_ok(addr) ({ \
2753 unsigned long flag; \
2754 __asm__("cmp %2, %0; movlo %0, #0" \
2755 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2756
2757 #define get_user(x,p) \
2758 ({ \
2759 + int __e; \
2760 might_fault(); \
2761 - __get_user_check(x,p); \
2762 + pax_open_userland(); \
2763 + __e = __get_user_check(x,p); \
2764 + pax_close_userland(); \
2765 + __e; \
2766 })
2767
2768 extern int __put_user_1(void *, unsigned int);
2769 @@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2770
2771 #define put_user(x,p) \
2772 ({ \
2773 + int __e; \
2774 might_fault(); \
2775 - __put_user_check(x,p); \
2776 + pax_open_userland(); \
2777 + __e = __put_user_check(x,p); \
2778 + pax_close_userland(); \
2779 + __e; \
2780 })
2781
2782 #else /* CONFIG_MMU */
2783 @@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2784
2785 #endif /* CONFIG_MMU */
2786
2787 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2788 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2789
2790 #define user_addr_max() \
2791 @@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2792 #define __get_user(x,ptr) \
2793 ({ \
2794 long __gu_err = 0; \
2795 + pax_open_userland(); \
2796 __get_user_err((x),(ptr),__gu_err); \
2797 + pax_close_userland(); \
2798 __gu_err; \
2799 })
2800
2801 #define __get_user_error(x,ptr,err) \
2802 ({ \
2803 + pax_open_userland(); \
2804 __get_user_err((x),(ptr),err); \
2805 + pax_close_userland(); \
2806 (void) 0; \
2807 })
2808
2809 @@ -320,13 +361,17 @@ do { \
2810 #define __put_user(x,ptr) \
2811 ({ \
2812 long __pu_err = 0; \
2813 + pax_open_userland(); \
2814 __put_user_err((x),(ptr),__pu_err); \
2815 + pax_close_userland(); \
2816 __pu_err; \
2817 })
2818
2819 #define __put_user_error(x,ptr,err) \
2820 ({ \
2821 + pax_open_userland(); \
2822 __put_user_err((x),(ptr),err); \
2823 + pax_close_userland(); \
2824 (void) 0; \
2825 })
2826
2827 @@ -426,11 +471,44 @@ do { \
2828
2829
2830 #ifdef CONFIG_MMU
2831 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2832 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2833 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2834 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2835 +
2836 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2837 +{
2838 + unsigned long ret;
2839 +
2840 + check_object_size(to, n, false);
2841 + pax_open_userland();
2842 + ret = ___copy_from_user(to, from, n);
2843 + pax_close_userland();
2844 + return ret;
2845 +}
2846 +
2847 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2848 +{
2849 + unsigned long ret;
2850 +
2851 + check_object_size(from, n, true);
2852 + pax_open_userland();
2853 + ret = ___copy_to_user(to, from, n);
2854 + pax_close_userland();
2855 + return ret;
2856 +}
2857 +
2858 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2859 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2860 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2861 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2862 +
2863 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2864 +{
2865 + unsigned long ret;
2866 + pax_open_userland();
2867 + ret = ___clear_user(addr, n);
2868 + pax_close_userland();
2869 + return ret;
2870 +}
2871 +
2872 #else
2873 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2874 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2875 @@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2876
2877 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2878 {
2879 + if ((long)n < 0)
2880 + return n;
2881 +
2882 if (access_ok(VERIFY_READ, from, n))
2883 n = __copy_from_user(to, from, n);
2884 else /* security hole - plug it */
2885 @@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2886
2887 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2888 {
2889 + if ((long)n < 0)
2890 + return n;
2891 +
2892 if (access_ok(VERIFY_WRITE, to, n))
2893 n = __copy_to_user(to, from, n);
2894 return n;
2895 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2896 index 5af0ed1..cea83883 100644
2897 --- a/arch/arm/include/uapi/asm/ptrace.h
2898 +++ b/arch/arm/include/uapi/asm/ptrace.h
2899 @@ -92,7 +92,7 @@
2900 * ARMv7 groups of PSR bits
2901 */
2902 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2903 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2904 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2905 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2906 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2907
2908 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2909 index f7b450f..f5364c5 100644
2910 --- a/arch/arm/kernel/armksyms.c
2911 +++ b/arch/arm/kernel/armksyms.c
2912 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2913
2914 /* networking */
2915 EXPORT_SYMBOL(csum_partial);
2916 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2917 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2918 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2919 EXPORT_SYMBOL(__csum_ipv6_magic);
2920
2921 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2922 #ifdef CONFIG_MMU
2923 EXPORT_SYMBOL(copy_page);
2924
2925 -EXPORT_SYMBOL(__copy_from_user);
2926 -EXPORT_SYMBOL(__copy_to_user);
2927 -EXPORT_SYMBOL(__clear_user);
2928 +EXPORT_SYMBOL(___copy_from_user);
2929 +EXPORT_SYMBOL(___copy_to_user);
2930 +EXPORT_SYMBOL(___clear_user);
2931
2932 EXPORT_SYMBOL(__get_user_1);
2933 EXPORT_SYMBOL(__get_user_2);
2934 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2935 index 52a949a..d8bbcab 100644
2936 --- a/arch/arm/kernel/entry-armv.S
2937 +++ b/arch/arm/kernel/entry-armv.S
2938 @@ -47,6 +47,87 @@
2939 9997:
2940 .endm
2941
2942 + .macro pax_enter_kernel
2943 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2944 + @ make aligned space for saved DACR
2945 + sub sp, sp, #8
2946 + @ save regs
2947 + stmdb sp!, {r1, r2}
2948 + @ read DACR from cpu_domain into r1
2949 + mov r2, sp
2950 + @ assume 8K pages, since we have to split the immediate in two
2951 + bic r2, r2, #(0x1fc0)
2952 + bic r2, r2, #(0x3f)
2953 + ldr r1, [r2, #TI_CPU_DOMAIN]
2954 + @ store old DACR on stack
2955 + str r1, [sp, #8]
2956 +#ifdef CONFIG_PAX_KERNEXEC
2957 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2958 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2959 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2960 +#endif
2961 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2962 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2963 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2964 +#endif
2965 + @ write r1 to current_thread_info()->cpu_domain
2966 + str r1, [r2, #TI_CPU_DOMAIN]
2967 + @ write r1 to DACR
2968 + mcr p15, 0, r1, c3, c0, 0
2969 + @ instruction sync
2970 + instr_sync
2971 + @ restore regs
2972 + ldmia sp!, {r1, r2}
2973 +#endif
2974 + .endm
2975 +
2976 + .macro pax_open_userland
2977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2978 + @ save regs
2979 + stmdb sp!, {r0, r1}
2980 + @ read DACR from cpu_domain into r1
2981 + mov r0, sp
2982 + @ assume 8K pages, since we have to split the immediate in two
2983 + bic r0, r0, #(0x1fc0)
2984 + bic r0, r0, #(0x3f)
2985 + ldr r1, [r0, #TI_CPU_DOMAIN]
2986 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2987 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2988 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2989 + @ write r1 to current_thread_info()->cpu_domain
2990 + str r1, [r0, #TI_CPU_DOMAIN]
2991 + @ write r1 to DACR
2992 + mcr p15, 0, r1, c3, c0, 0
2993 + @ instruction sync
2994 + instr_sync
2995 + @ restore regs
2996 + ldmia sp!, {r0, r1}
2997 +#endif
2998 + .endm
2999 +
3000 + .macro pax_close_userland
3001 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3002 + @ save regs
3003 + stmdb sp!, {r0, r1}
3004 + @ read DACR from cpu_domain into r1
3005 + mov r0, sp
3006 + @ assume 8K pages, since we have to split the immediate in two
3007 + bic r0, r0, #(0x1fc0)
3008 + bic r0, r0, #(0x3f)
3009 + ldr r1, [r0, #TI_CPU_DOMAIN]
3010 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
3011 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3012 + @ write r1 to current_thread_info()->cpu_domain
3013 + str r1, [r0, #TI_CPU_DOMAIN]
3014 + @ write r1 to DACR
3015 + mcr p15, 0, r1, c3, c0, 0
3016 + @ instruction sync
3017 + instr_sync
3018 + @ restore regs
3019 + ldmia sp!, {r0, r1}
3020 +#endif
3021 + .endm
3022 +
3023 .macro pabt_helper
3024 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
3025 #ifdef MULTI_PABORT
3026 @@ -89,11 +170,15 @@
3027 * Invalid mode handlers
3028 */
3029 .macro inv_entry, reason
3030 +
3031 + pax_enter_kernel
3032 +
3033 sub sp, sp, #S_FRAME_SIZE
3034 ARM( stmib sp, {r1 - lr} )
3035 THUMB( stmia sp, {r0 - r12} )
3036 THUMB( str sp, [sp, #S_SP] )
3037 THUMB( str lr, [sp, #S_LR] )
3038 +
3039 mov r1, #\reason
3040 .endm
3041
3042 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
3043 .macro svc_entry, stack_hole=0
3044 UNWIND(.fnstart )
3045 UNWIND(.save {r0 - pc} )
3046 +
3047 + pax_enter_kernel
3048 +
3049 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
3050 +
3051 #ifdef CONFIG_THUMB2_KERNEL
3052 SPFIX( str r0, [sp] ) @ temporarily saved
3053 SPFIX( mov r0, sp )
3054 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
3055 ldmia r0, {r3 - r5}
3056 add r7, sp, #S_SP - 4 @ here for interlock avoidance
3057 mov r6, #-1 @ "" "" "" ""
3058 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3059 + @ offset sp by 8 as done in pax_enter_kernel
3060 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
3061 +#else
3062 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
3063 +#endif
3064 SPFIX( addeq r2, r2, #4 )
3065 str r3, [sp, #-4]! @ save the "real" r0 copied
3066 @ from the exception stack
3067 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
3068 .macro usr_entry
3069 UNWIND(.fnstart )
3070 UNWIND(.cantunwind ) @ don't unwind the user space
3071 +
3072 + pax_enter_kernel_user
3073 +
3074 sub sp, sp, #S_FRAME_SIZE
3075 ARM( stmib sp, {r1 - r12} )
3076 THUMB( stmia sp, {r0 - r12} )
3077 @@ -421,7 +518,9 @@ __und_usr:
3078 tst r3, #PSR_T_BIT @ Thumb mode?
3079 bne __und_usr_thumb
3080 sub r4, r2, #4 @ ARM instr at LR - 4
3081 + pax_open_userland
3082 1: ldrt r0, [r4]
3083 + pax_close_userland
3084 ARM_BE8(rev r0, r0) @ little endian instruction
3085
3086 @ r0 = 32-bit ARM instruction which caused the exception
3087 @@ -455,11 +554,15 @@ __und_usr_thumb:
3088 */
3089 .arch armv6t2
3090 #endif
3091 + pax_open_userland
3092 2: ldrht r5, [r4]
3093 + pax_close_userland
3094 ARM_BE8(rev16 r5, r5) @ little endian instruction
3095 cmp r5, #0xe800 @ 32bit instruction if xx != 0
3096 blo __und_usr_fault_16 @ 16bit undefined instruction
3097 + pax_open_userland
3098 3: ldrht r0, [r2]
3099 + pax_close_userland
3100 ARM_BE8(rev16 r0, r0) @ little endian instruction
3101 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
3102 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
3103 @@ -489,7 +592,8 @@ ENDPROC(__und_usr)
3104 */
3105 .pushsection .fixup, "ax"
3106 .align 2
3107 -4: str r4, [sp, #S_PC] @ retry current instruction
3108 +4: pax_close_userland
3109 + str r4, [sp, #S_PC] @ retry current instruction
3110 mov pc, r9
3111 .popsection
3112 .pushsection __ex_table,"a"
3113 @@ -698,7 +802,7 @@ ENTRY(__switch_to)
3114 THUMB( str lr, [ip], #4 )
3115 ldr r4, [r2, #TI_TP_VALUE]
3116 ldr r5, [r2, #TI_TP_VALUE + 4]
3117 -#ifdef CONFIG_CPU_USE_DOMAINS
3118 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3119 ldr r6, [r2, #TI_CPU_DOMAIN]
3120 #endif
3121 switch_tls r1, r4, r5, r3, r7
3122 @@ -707,7 +811,7 @@ ENTRY(__switch_to)
3123 ldr r8, =__stack_chk_guard
3124 ldr r7, [r7, #TSK_STACK_CANARY]
3125 #endif
3126 -#ifdef CONFIG_CPU_USE_DOMAINS
3127 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3128 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
3129 #endif
3130 mov r5, r0
3131 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
3132 index 7139d4a..feaf37f 100644
3133 --- a/arch/arm/kernel/entry-common.S
3134 +++ b/arch/arm/kernel/entry-common.S
3135 @@ -10,18 +10,46 @@
3136
3137 #include <asm/unistd.h>
3138 #include <asm/ftrace.h>
3139 +#include <asm/domain.h>
3140 #include <asm/unwind.h>
3141
3142 +#include "entry-header.S"
3143 +
3144 #ifdef CONFIG_NEED_RET_TO_USER
3145 #include <mach/entry-macro.S>
3146 #else
3147 .macro arch_ret_to_user, tmp1, tmp2
3148 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3149 + @ save regs
3150 + stmdb sp!, {r1, r2}
3151 + @ read DACR from cpu_domain into r1
3152 + mov r2, sp
3153 + @ assume 8K pages, since we have to split the immediate in two
3154 + bic r2, r2, #(0x1fc0)
3155 + bic r2, r2, #(0x3f)
3156 + ldr r1, [r2, #TI_CPU_DOMAIN]
3157 +#ifdef CONFIG_PAX_KERNEXEC
3158 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
3159 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
3160 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
3161 +#endif
3162 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3163 + @ set current DOMAIN_USER to DOMAIN_UDEREF
3164 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3165 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
3166 +#endif
3167 + @ write r1 to current_thread_info()->cpu_domain
3168 + str r1, [r2, #TI_CPU_DOMAIN]
3169 + @ write r1 to DACR
3170 + mcr p15, 0, r1, c3, c0, 0
3171 + @ instruction sync
3172 + instr_sync
3173 + @ restore regs
3174 + ldmia sp!, {r1, r2}
3175 +#endif
3176 .endm
3177 #endif
3178
3179 -#include "entry-header.S"
3180 -
3181 -
3182 .align 5
3183 /*
3184 * This is the fast syscall return path. We do as little as
3185 @@ -405,6 +433,12 @@ ENTRY(vector_swi)
3186 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
3187 #endif
3188
3189 + /*
3190 + * do this here to avoid a performance hit of wrapping the code above
3191 + * that directly dereferences userland to parse the SWI instruction
3192 + */
3193 + pax_enter_kernel_user
3194 +
3195 adr tbl, sys_call_table @ load syscall table pointer
3196
3197 #if defined(CONFIG_OABI_COMPAT)
3198 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
3199 index 5d702f8..f5fc51a 100644
3200 --- a/arch/arm/kernel/entry-header.S
3201 +++ b/arch/arm/kernel/entry-header.S
3202 @@ -188,6 +188,60 @@
3203 msr cpsr_c, \rtemp @ switch back to the SVC mode
3204 .endm
3205
3206 + .macro pax_enter_kernel_user
3207 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3208 + @ save regs
3209 + stmdb sp!, {r0, r1}
3210 + @ read DACR from cpu_domain into r1
3211 + mov r0, sp
3212 + @ assume 8K pages, since we have to split the immediate in two
3213 + bic r0, r0, #(0x1fc0)
3214 + bic r0, r0, #(0x3f)
3215 + ldr r1, [r0, #TI_CPU_DOMAIN]
3216 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3217 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
3218 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
3219 +#endif
3220 +#ifdef CONFIG_PAX_KERNEXEC
3221 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
3222 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
3223 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
3224 +#endif
3225 + @ write r1 to current_thread_info()->cpu_domain
3226 + str r1, [r0, #TI_CPU_DOMAIN]
3227 + @ write r1 to DACR
3228 + mcr p15, 0, r1, c3, c0, 0
3229 + @ instruction sync
3230 + instr_sync
3231 + @ restore regs
3232 + ldmia sp!, {r0, r1}
3233 +#endif
3234 + .endm
3235 +
3236 + .macro pax_exit_kernel
3237 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3238 + @ save regs
3239 + stmdb sp!, {r0, r1}
3240 + @ read old DACR from stack into r1
3241 + ldr r1, [sp, #(8 + S_SP)]
3242 + sub r1, r1, #8
3243 + ldr r1, [r1]
3244 +
3245 + @ write r1 to current_thread_info()->cpu_domain
3246 + mov r0, sp
3247 + @ assume 8K pages, since we have to split the immediate in two
3248 + bic r0, r0, #(0x1fc0)
3249 + bic r0, r0, #(0x3f)
3250 + str r1, [r0, #TI_CPU_DOMAIN]
3251 + @ write r1 to DACR
3252 + mcr p15, 0, r1, c3, c0, 0
3253 + @ instruction sync
3254 + instr_sync
3255 + @ restore regs
3256 + ldmia sp!, {r0, r1}
3257 +#endif
3258 + .endm
3259 +
3260 #ifndef CONFIG_THUMB2_KERNEL
3261 .macro svc_exit, rpsr, irq = 0
3262 .if \irq != 0
3263 @@ -207,6 +261,9 @@
3264 blne trace_hardirqs_off
3265 #endif
3266 .endif
3267 +
3268 + pax_exit_kernel
3269 +
3270 msr spsr_cxsf, \rpsr
3271 #if defined(CONFIG_CPU_V6)
3272 ldr r0, [sp]
3273 @@ -265,6 +322,9 @@
3274 blne trace_hardirqs_off
3275 #endif
3276 .endif
3277 +
3278 + pax_exit_kernel
3279 +
3280 ldr lr, [sp, #S_SP] @ top of the stack
3281 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
3282 clrex @ clear the exclusive monitor
3283 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
3284 index 918875d..cd5fa27 100644
3285 --- a/arch/arm/kernel/fiq.c
3286 +++ b/arch/arm/kernel/fiq.c
3287 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
3288 void *base = vectors_page;
3289 unsigned offset = FIQ_OFFSET;
3290
3291 + pax_open_kernel();
3292 memcpy(base + offset, start, length);
3293 + pax_close_kernel();
3294 +
3295 if (!cache_is_vipt_nonaliasing())
3296 flush_icache_range((unsigned long)base + offset, offset +
3297 length);
3298 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
3299 index 2c35f0f..7747ee6 100644
3300 --- a/arch/arm/kernel/head.S
3301 +++ b/arch/arm/kernel/head.S
3302 @@ -437,7 +437,7 @@ __enable_mmu:
3303 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
3304 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
3305 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
3306 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
3307 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
3308 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
3309 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
3310 #endif
3311 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
3312 index 45e4781..8eac93d 100644
3313 --- a/arch/arm/kernel/module.c
3314 +++ b/arch/arm/kernel/module.c
3315 @@ -38,12 +38,39 @@
3316 #endif
3317
3318 #ifdef CONFIG_MMU
3319 -void *module_alloc(unsigned long size)
3320 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
3321 {
3322 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
3323 + return NULL;
3324 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
3325 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
3326 + GFP_KERNEL, prot, NUMA_NO_NODE,
3327 __builtin_return_address(0));
3328 }
3329 +
3330 +void *module_alloc(unsigned long size)
3331 +{
3332 +
3333 +#ifdef CONFIG_PAX_KERNEXEC
3334 + return __module_alloc(size, PAGE_KERNEL);
3335 +#else
3336 + return __module_alloc(size, PAGE_KERNEL_EXEC);
3337 +#endif
3338 +
3339 +}
3340 +
3341 +#ifdef CONFIG_PAX_KERNEXEC
3342 +void module_free_exec(struct module *mod, void *module_region)
3343 +{
3344 + module_free(mod, module_region);
3345 +}
3346 +EXPORT_SYMBOL(module_free_exec);
3347 +
3348 +void *module_alloc_exec(unsigned long size)
3349 +{
3350 + return __module_alloc(size, PAGE_KERNEL_EXEC);
3351 +}
3352 +EXPORT_SYMBOL(module_alloc_exec);
3353 +#endif
3354 #endif
3355
3356 int
3357 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
3358 index 07314af..c46655c 100644
3359 --- a/arch/arm/kernel/patch.c
3360 +++ b/arch/arm/kernel/patch.c
3361 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3362 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
3363 int size;
3364
3365 + pax_open_kernel();
3366 if (thumb2 && __opcode_is_thumb16(insn)) {
3367 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
3368 size = sizeof(u16);
3369 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3370 *(u32 *)addr = insn;
3371 size = sizeof(u32);
3372 }
3373 + pax_close_kernel();
3374
3375 flush_icache_range((uintptr_t)(addr),
3376 (uintptr_t)(addr) + size);
3377 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3378 index 81ef686..f4130b8 100644
3379 --- a/arch/arm/kernel/process.c
3380 +++ b/arch/arm/kernel/process.c
3381 @@ -212,6 +212,7 @@ void machine_power_off(void)
3382
3383 if (pm_power_off)
3384 pm_power_off();
3385 + BUG();
3386 }
3387
3388 /*
3389 @@ -225,7 +226,7 @@ void machine_power_off(void)
3390 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3391 * to use. Implementing such co-ordination would be essentially impossible.
3392 */
3393 -void machine_restart(char *cmd)
3394 +__noreturn void machine_restart(char *cmd)
3395 {
3396 local_irq_disable();
3397 smp_send_stop();
3398 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3399
3400 show_regs_print_info(KERN_DEFAULT);
3401
3402 - print_symbol("PC is at %s\n", instruction_pointer(regs));
3403 - print_symbol("LR is at %s\n", regs->ARM_lr);
3404 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3405 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
3406 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3407 "sp : %08lx ip : %08lx fp : %08lx\n",
3408 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3409 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
3410 return 0;
3411 }
3412
3413 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3414 -{
3415 - unsigned long range_end = mm->brk + 0x02000000;
3416 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3417 -}
3418 -
3419 #ifdef CONFIG_MMU
3420 #ifdef CONFIG_KUSER_HELPERS
3421 /*
3422 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
3423
3424 static int __init gate_vma_init(void)
3425 {
3426 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3427 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3428 return 0;
3429 }
3430 arch_initcall(gate_vma_init);
3431 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
3432
3433 const char *arch_vma_name(struct vm_area_struct *vma)
3434 {
3435 - return is_gate_vma(vma) ? "[vectors]" :
3436 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3437 - "[sigpage]" : NULL;
3438 + return is_gate_vma(vma) ? "[vectors]" : NULL;
3439 }
3440
3441 -static struct page *signal_page;
3442 -extern struct page *get_signal_page(void);
3443 -
3444 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3445 {
3446 struct mm_struct *mm = current->mm;
3447 - unsigned long addr;
3448 - int ret;
3449 -
3450 - if (!signal_page)
3451 - signal_page = get_signal_page();
3452 - if (!signal_page)
3453 - return -ENOMEM;
3454
3455 down_write(&mm->mmap_sem);
3456 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3457 - if (IS_ERR_VALUE(addr)) {
3458 - ret = addr;
3459 - goto up_fail;
3460 - }
3461 -
3462 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
3463 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3464 - &signal_page);
3465 -
3466 - if (ret == 0)
3467 - mm->context.sigpage = addr;
3468 -
3469 - up_fail:
3470 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3471 up_write(&mm->mmap_sem);
3472 - return ret;
3473 + return 0;
3474 }
3475 #endif
3476 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3477 index f73891b..cf3004e 100644
3478 --- a/arch/arm/kernel/psci.c
3479 +++ b/arch/arm/kernel/psci.c
3480 @@ -28,7 +28,7 @@
3481 #include <asm/psci.h>
3482 #include <asm/system_misc.h>
3483
3484 -struct psci_operations psci_ops;
3485 +struct psci_operations psci_ops __read_only;
3486
3487 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3488 typedef int (*psci_initcall_t)(const struct device_node *);
3489 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3490 index 0c27ed6..b67388e 100644
3491 --- a/arch/arm/kernel/ptrace.c
3492 +++ b/arch/arm/kernel/ptrace.c
3493 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3494 regs->ARM_ip = ip;
3495 }
3496
3497 +#ifdef CONFIG_GRKERNSEC_SETXID
3498 +extern void gr_delayed_cred_worker(void);
3499 +#endif
3500 +
3501 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3502 {
3503 current_thread_info()->syscall = scno;
3504
3505 +#ifdef CONFIG_GRKERNSEC_SETXID
3506 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3507 + gr_delayed_cred_worker();
3508 +#endif
3509 +
3510 /* Do the secure computing check first; failures should be fast. */
3511 if (secure_computing(scno) == -1)
3512 return -1;
3513 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3514 index 8a16ee5..4f560e5 100644
3515 --- a/arch/arm/kernel/setup.c
3516 +++ b/arch/arm/kernel/setup.c
3517 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3518 unsigned int elf_hwcap2 __read_mostly;
3519 EXPORT_SYMBOL(elf_hwcap2);
3520
3521 +pteval_t __supported_pte_mask __read_only;
3522 +pmdval_t __supported_pmd_mask __read_only;
3523
3524 #ifdef MULTI_CPU
3525 -struct processor processor __read_mostly;
3526 +struct processor processor __read_only;
3527 #endif
3528 #ifdef MULTI_TLB
3529 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3530 +struct cpu_tlb_fns cpu_tlb __read_only;
3531 #endif
3532 #ifdef MULTI_USER
3533 -struct cpu_user_fns cpu_user __read_mostly;
3534 +struct cpu_user_fns cpu_user __read_only;
3535 #endif
3536 #ifdef MULTI_CACHE
3537 -struct cpu_cache_fns cpu_cache __read_mostly;
3538 +struct cpu_cache_fns cpu_cache __read_only;
3539 #endif
3540 #ifdef CONFIG_OUTER_CACHE
3541 -struct outer_cache_fns outer_cache __read_mostly;
3542 +struct outer_cache_fns outer_cache __read_only;
3543 EXPORT_SYMBOL(outer_cache);
3544 #endif
3545
3546 @@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3547 asm("mrc p15, 0, %0, c0, c1, 4"
3548 : "=r" (mmfr0));
3549 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3550 - (mmfr0 & 0x000000f0) >= 0x00000030)
3551 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3552 cpu_arch = CPU_ARCH_ARMv7;
3553 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3554 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3555 + __supported_pte_mask |= L_PTE_PXN;
3556 + __supported_pmd_mask |= PMD_PXNTABLE;
3557 + }
3558 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3559 (mmfr0 & 0x000000f0) == 0x00000020)
3560 cpu_arch = CPU_ARCH_ARMv6;
3561 else
3562 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3563 index bd19834..e4d8c66 100644
3564 --- a/arch/arm/kernel/signal.c
3565 +++ b/arch/arm/kernel/signal.c
3566 @@ -24,8 +24,6 @@
3567
3568 extern const unsigned long sigreturn_codes[7];
3569
3570 -static unsigned long signal_return_offset;
3571 -
3572 #ifdef CONFIG_CRUNCH
3573 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3574 {
3575 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3576 * except when the MPU has protected the vectors
3577 * page from PL0
3578 */
3579 - retcode = mm->context.sigpage + signal_return_offset +
3580 - (idx << 2) + thumb;
3581 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3582 } else
3583 #endif
3584 {
3585 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3586 } while (thread_flags & _TIF_WORK_MASK);
3587 return 0;
3588 }
3589 -
3590 -struct page *get_signal_page(void)
3591 -{
3592 - unsigned long ptr;
3593 - unsigned offset;
3594 - struct page *page;
3595 - void *addr;
3596 -
3597 - page = alloc_pages(GFP_KERNEL, 0);
3598 -
3599 - if (!page)
3600 - return NULL;
3601 -
3602 - addr = page_address(page);
3603 -
3604 - /* Give the signal return code some randomness */
3605 - offset = 0x200 + (get_random_int() & 0x7fc);
3606 - signal_return_offset = offset;
3607 -
3608 - /*
3609 - * Copy signal return handlers into the vector page, and
3610 - * set sigreturn to be a pointer to these.
3611 - */
3612 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3613 -
3614 - ptr = (unsigned long)addr + offset;
3615 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3616 -
3617 - return page;
3618 -}
3619 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3620 index 7c4fada..8581286 100644
3621 --- a/arch/arm/kernel/smp.c
3622 +++ b/arch/arm/kernel/smp.c
3623 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3624
3625 static DECLARE_COMPLETION(cpu_running);
3626
3627 -static struct smp_operations smp_ops;
3628 +static struct smp_operations smp_ops __read_only;
3629
3630 void __init smp_set_ops(struct smp_operations *ops)
3631 {
3632 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3633 index 7a3be1d..b00c7de 100644
3634 --- a/arch/arm/kernel/tcm.c
3635 +++ b/arch/arm/kernel/tcm.c
3636 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3637 .virtual = ITCM_OFFSET,
3638 .pfn = __phys_to_pfn(ITCM_OFFSET),
3639 .length = 0,
3640 - .type = MT_MEMORY_RWX_ITCM,
3641 + .type = MT_MEMORY_RX_ITCM,
3642 }
3643 };
3644
3645 @@ -267,7 +267,9 @@ no_dtcm:
3646 start = &__sitcm_text;
3647 end = &__eitcm_text;
3648 ram = &__itcm_start;
3649 + pax_open_kernel();
3650 memcpy(start, ram, itcm_code_sz);
3651 + pax_close_kernel();
3652 pr_debug("CPU ITCM: copied code from %p - %p\n",
3653 start, end);
3654 itcm_present = true;
3655 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3656 index abd2fc0..895dbb6 100644
3657 --- a/arch/arm/kernel/traps.c
3658 +++ b/arch/arm/kernel/traps.c
3659 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3660 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3661 {
3662 #ifdef CONFIG_KALLSYMS
3663 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3664 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3665 #else
3666 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3667 #endif
3668 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3669 static int die_owner = -1;
3670 static unsigned int die_nest_count;
3671
3672 +extern void gr_handle_kernel_exploit(void);
3673 +
3674 static unsigned long oops_begin(void)
3675 {
3676 int cpu;
3677 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3678 panic("Fatal exception in interrupt");
3679 if (panic_on_oops)
3680 panic("Fatal exception");
3681 +
3682 + gr_handle_kernel_exploit();
3683 +
3684 if (signr)
3685 do_exit(signr);
3686 }
3687 @@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3688 * The user helper at 0xffff0fe0 must be used instead.
3689 * (see entry-armv.S for details)
3690 */
3691 + pax_open_kernel();
3692 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3693 + pax_close_kernel();
3694 }
3695 return 0;
3696
3697 @@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3698 kuser_init(vectors_base);
3699
3700 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3701 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3702 +
3703 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3704 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3705 +#endif
3706 +
3707 #else /* ifndef CONFIG_CPU_V7M */
3708 /*
3709 * on V7-M there is no need to copy the vector table to a dedicated
3710 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3711 index 7bcee5c..e2f3249 100644
3712 --- a/arch/arm/kernel/vmlinux.lds.S
3713 +++ b/arch/arm/kernel/vmlinux.lds.S
3714 @@ -8,7 +8,11 @@
3715 #include <asm/thread_info.h>
3716 #include <asm/memory.h>
3717 #include <asm/page.h>
3718 -
3719 +
3720 +#ifdef CONFIG_PAX_KERNEXEC
3721 +#include <asm/pgtable.h>
3722 +#endif
3723 +
3724 #define PROC_INFO \
3725 . = ALIGN(4); \
3726 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3727 @@ -34,7 +38,7 @@
3728 #endif
3729
3730 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3731 - defined(CONFIG_GENERIC_BUG)
3732 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3733 #define ARM_EXIT_KEEP(x) x
3734 #define ARM_EXIT_DISCARD(x)
3735 #else
3736 @@ -90,6 +94,11 @@ SECTIONS
3737 _text = .;
3738 HEAD_TEXT
3739 }
3740 +
3741 +#ifdef CONFIG_PAX_KERNEXEC
3742 + . = ALIGN(1<<SECTION_SHIFT);
3743 +#endif
3744 +
3745 .text : { /* Real text segment */
3746 _stext = .; /* Text and read-only data */
3747 __exception_text_start = .;
3748 @@ -112,6 +121,8 @@ SECTIONS
3749 ARM_CPU_KEEP(PROC_INFO)
3750 }
3751
3752 + _etext = .; /* End of text section */
3753 +
3754 RO_DATA(PAGE_SIZE)
3755
3756 . = ALIGN(4);
3757 @@ -142,7 +153,9 @@ SECTIONS
3758
3759 NOTES
3760
3761 - _etext = .; /* End of text and rodata section */
3762 +#ifdef CONFIG_PAX_KERNEXEC
3763 + . = ALIGN(1<<SECTION_SHIFT);
3764 +#endif
3765
3766 #ifndef CONFIG_XIP_KERNEL
3767 . = ALIGN(PAGE_SIZE);
3768 @@ -220,6 +233,11 @@ SECTIONS
3769 . = PAGE_OFFSET + TEXT_OFFSET;
3770 #else
3771 __init_end = .;
3772 +
3773 +#ifdef CONFIG_PAX_KERNEXEC
3774 + . = ALIGN(1<<SECTION_SHIFT);
3775 +#endif
3776 +
3777 . = ALIGN(THREAD_SIZE);
3778 __data_loc = .;
3779 #endif
3780 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3781 index 3c82b37..69fa3d2 100644
3782 --- a/arch/arm/kvm/arm.c
3783 +++ b/arch/arm/kvm/arm.c
3784 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3785 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3786
3787 /* The VMID used in the VTTBR */
3788 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3789 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3790 static u8 kvm_next_vmid;
3791 static DEFINE_SPINLOCK(kvm_vmid_lock);
3792
3793 @@ -409,7 +409,7 @@ void force_vm_exit(const cpumask_t *mask)
3794 */
3795 static bool need_new_vmid_gen(struct kvm *kvm)
3796 {
3797 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3798 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3799 }
3800
3801 /**
3802 @@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3803
3804 /* First user of a new VMID generation? */
3805 if (unlikely(kvm_next_vmid == 0)) {
3806 - atomic64_inc(&kvm_vmid_gen);
3807 + atomic64_inc_unchecked(&kvm_vmid_gen);
3808 kvm_next_vmid = 1;
3809
3810 /*
3811 @@ -459,7 +459,7 @@ static void update_vttbr(struct kvm *kvm)
3812 kvm_call_hyp(__kvm_flush_vm_context);
3813 }
3814
3815 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3816 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3817 kvm->arch.vmid = kvm_next_vmid;
3818 kvm_next_vmid++;
3819
3820 @@ -1034,7 +1034,7 @@ static void check_kvm_target_cpu(void *ret)
3821 /**
3822 * Initialize Hyp-mode and memory mappings on all CPUs.
3823 */
3824 -int kvm_arch_init(void *opaque)
3825 +int kvm_arch_init(const void *opaque)
3826 {
3827 int err;
3828 int ret, cpu;
3829 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3830 index 14a0d98..7771a7d 100644
3831 --- a/arch/arm/lib/clear_user.S
3832 +++ b/arch/arm/lib/clear_user.S
3833 @@ -12,14 +12,14 @@
3834
3835 .text
3836
3837 -/* Prototype: int __clear_user(void *addr, size_t sz)
3838 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3839 * Purpose : clear some user memory
3840 * Params : addr - user memory address to clear
3841 * : sz - number of bytes to clear
3842 * Returns : number of bytes NOT cleared
3843 */
3844 ENTRY(__clear_user_std)
3845 -WEAK(__clear_user)
3846 +WEAK(___clear_user)
3847 stmfd sp!, {r1, lr}
3848 mov r2, #0
3849 cmp r1, #4
3850 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3851 USER( strnebt r2, [r0])
3852 mov r0, #0
3853 ldmfd sp!, {r1, pc}
3854 -ENDPROC(__clear_user)
3855 +ENDPROC(___clear_user)
3856 ENDPROC(__clear_user_std)
3857
3858 .pushsection .fixup,"ax"
3859 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3860 index 66a477a..bee61d3 100644
3861 --- a/arch/arm/lib/copy_from_user.S
3862 +++ b/arch/arm/lib/copy_from_user.S
3863 @@ -16,7 +16,7 @@
3864 /*
3865 * Prototype:
3866 *
3867 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3868 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3869 *
3870 * Purpose:
3871 *
3872 @@ -84,11 +84,11 @@
3873
3874 .text
3875
3876 -ENTRY(__copy_from_user)
3877 +ENTRY(___copy_from_user)
3878
3879 #include "copy_template.S"
3880
3881 -ENDPROC(__copy_from_user)
3882 +ENDPROC(___copy_from_user)
3883
3884 .pushsection .fixup,"ax"
3885 .align 0
3886 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3887 index 6ee2f67..d1cce76 100644
3888 --- a/arch/arm/lib/copy_page.S
3889 +++ b/arch/arm/lib/copy_page.S
3890 @@ -10,6 +10,7 @@
3891 * ASM optimised string functions
3892 */
3893 #include <linux/linkage.h>
3894 +#include <linux/const.h>
3895 #include <asm/assembler.h>
3896 #include <asm/asm-offsets.h>
3897 #include <asm/cache.h>
3898 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3899 index d066df6..df28194 100644
3900 --- a/arch/arm/lib/copy_to_user.S
3901 +++ b/arch/arm/lib/copy_to_user.S
3902 @@ -16,7 +16,7 @@
3903 /*
3904 * Prototype:
3905 *
3906 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3907 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3908 *
3909 * Purpose:
3910 *
3911 @@ -88,11 +88,11 @@
3912 .text
3913
3914 ENTRY(__copy_to_user_std)
3915 -WEAK(__copy_to_user)
3916 +WEAK(___copy_to_user)
3917
3918 #include "copy_template.S"
3919
3920 -ENDPROC(__copy_to_user)
3921 +ENDPROC(___copy_to_user)
3922 ENDPROC(__copy_to_user_std)
3923
3924 .pushsection .fixup,"ax"
3925 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3926 index 7d08b43..f7ca7ea 100644
3927 --- a/arch/arm/lib/csumpartialcopyuser.S
3928 +++ b/arch/arm/lib/csumpartialcopyuser.S
3929 @@ -57,8 +57,8 @@
3930 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3931 */
3932
3933 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3934 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3935 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3936 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3937
3938 #include "csumpartialcopygeneric.S"
3939
3940 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3941 index 5306de3..aed6d03 100644
3942 --- a/arch/arm/lib/delay.c
3943 +++ b/arch/arm/lib/delay.c
3944 @@ -28,7 +28,7 @@
3945 /*
3946 * Default to the loop-based delay implementation.
3947 */
3948 -struct arm_delay_ops arm_delay_ops = {
3949 +struct arm_delay_ops arm_delay_ops __read_only = {
3950 .delay = __loop_delay,
3951 .const_udelay = __loop_const_udelay,
3952 .udelay = __loop_udelay,
3953 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3954 index 3e58d71..029817c 100644
3955 --- a/arch/arm/lib/uaccess_with_memcpy.c
3956 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3957 @@ -136,7 +136,7 @@ out:
3958 }
3959
3960 unsigned long
3961 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3962 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3963 {
3964 /*
3965 * This test is stubbed out of the main function above to keep
3966 @@ -190,7 +190,7 @@ out:
3967 return n;
3968 }
3969
3970 -unsigned long __clear_user(void __user *addr, unsigned long n)
3971 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3972 {
3973 /* See rational for this in __copy_to_user() above. */
3974 if (n < 64)
3975 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3976 index f7a07a5..258e1f7 100644
3977 --- a/arch/arm/mach-at91/setup.c
3978 +++ b/arch/arm/mach-at91/setup.c
3979 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3980
3981 desc->pfn = __phys_to_pfn(base);
3982 desc->length = length;
3983 - desc->type = MT_MEMORY_RWX_NONCACHED;
3984 + desc->type = MT_MEMORY_RW_NONCACHED;
3985
3986 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3987 base, length, desc->virtual);
3988 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3989 index 255f33a..507b157 100644
3990 --- a/arch/arm/mach-kirkwood/common.c
3991 +++ b/arch/arm/mach-kirkwood/common.c
3992 @@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3993 clk_gate_ops.disable(hw);
3994 }
3995
3996 -static struct clk_ops clk_gate_fn_ops;
3997 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3998 +{
3999 + return clk_gate_ops.is_enabled(hw);
4000 +}
4001 +
4002 +static struct clk_ops clk_gate_fn_ops = {
4003 + .enable = clk_gate_fn_enable,
4004 + .disable = clk_gate_fn_disable,
4005 + .is_enabled = clk_gate_fn_is_enabled,
4006 +};
4007
4008 static struct clk __init *clk_register_gate_fn(struct device *dev,
4009 const char *name,
4010 @@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
4011 gate_fn->fn_en = fn_en;
4012 gate_fn->fn_dis = fn_dis;
4013
4014 - /* ops is the gate ops, but with our enable/disable functions */
4015 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
4016 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
4017 - clk_gate_fn_ops = clk_gate_ops;
4018 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
4019 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
4020 - }
4021 -
4022 clk = clk_register(dev, &gate_fn->gate.hw);
4023
4024 if (IS_ERR(clk))
4025 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
4026 index 2bdc323..cf1c607 100644
4027 --- a/arch/arm/mach-mvebu/coherency.c
4028 +++ b/arch/arm/mach-mvebu/coherency.c
4029 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
4030
4031 /*
4032 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
4033 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
4034 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
4035 * is needed as a workaround for a deadlock issue between the PCIe
4036 * interface and the cache controller.
4037 */
4038 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
4039 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
4040
4041 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
4042 - mtype = MT_UNCACHED;
4043 + mtype = MT_UNCACHED_RW;
4044
4045 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
4046 }
4047 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
4048 index aead77a..a2253fa 100644
4049 --- a/arch/arm/mach-omap2/board-n8x0.c
4050 +++ b/arch/arm/mach-omap2/board-n8x0.c
4051 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
4052 }
4053 #endif
4054
4055 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
4056 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
4057 .late_init = n8x0_menelaus_late_init,
4058 };
4059
4060 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
4061 index 8bc1338..8b28b69 100644
4062 --- a/arch/arm/mach-omap2/gpmc.c
4063 +++ b/arch/arm/mach-omap2/gpmc.c
4064 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
4065 };
4066
4067 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
4068 -static struct irq_chip gpmc_irq_chip;
4069 static int gpmc_irq_start;
4070
4071 static struct resource gpmc_mem_root;
4072 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
4073
4074 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
4075
4076 +static struct irq_chip gpmc_irq_chip = {
4077 + .name = "gpmc",
4078 + .irq_startup = gpmc_irq_noop_ret,
4079 + .irq_enable = gpmc_irq_enable,
4080 + .irq_disable = gpmc_irq_disable,
4081 + .irq_shutdown = gpmc_irq_noop,
4082 + .irq_ack = gpmc_irq_noop,
4083 + .irq_mask = gpmc_irq_noop,
4084 + .irq_unmask = gpmc_irq_noop,
4085 +
4086 +};
4087 +
4088 static int gpmc_setup_irq(void)
4089 {
4090 int i;
4091 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
4092 return gpmc_irq_start;
4093 }
4094
4095 - gpmc_irq_chip.name = "gpmc";
4096 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
4097 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
4098 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
4099 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
4100 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
4101 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
4102 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
4103 -
4104 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
4105 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
4106
4107 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4108 index 4001325..b14e2a0 100644
4109 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4110 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
4111 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
4112 int (*finish_suspend)(unsigned long cpu_state);
4113 void (*resume)(void);
4114 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
4115 -};
4116 +} __no_const;
4117
4118 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
4119 static struct powerdomain *mpuss_pd;
4120 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
4121 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
4122 {}
4123
4124 -struct cpu_pm_ops omap_pm_ops = {
4125 +static struct cpu_pm_ops omap_pm_ops __read_only = {
4126 .finish_suspend = default_finish_suspend,
4127 .resume = dummy_cpu_resume,
4128 .scu_prepare = dummy_scu_prepare,
4129 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
4130 index 37843a7..a98df13 100644
4131 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
4132 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
4133 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
4134 return NOTIFY_OK;
4135 }
4136
4137 -static struct notifier_block __refdata irq_hotplug_notifier = {
4138 +static struct notifier_block irq_hotplug_notifier = {
4139 .notifier_call = irq_cpu_hotplug_notify,
4140 };
4141
4142 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
4143 index 01ef59d..32ae28a8 100644
4144 --- a/arch/arm/mach-omap2/omap_device.c
4145 +++ b/arch/arm/mach-omap2/omap_device.c
4146 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
4147 struct platform_device __init *omap_device_build(const char *pdev_name,
4148 int pdev_id,
4149 struct omap_hwmod *oh,
4150 - void *pdata, int pdata_len)
4151 + const void *pdata, int pdata_len)
4152 {
4153 struct omap_hwmod *ohs[] = { oh };
4154
4155 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
4156 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
4157 int pdev_id,
4158 struct omap_hwmod **ohs,
4159 - int oh_cnt, void *pdata,
4160 + int oh_cnt, const void *pdata,
4161 int pdata_len)
4162 {
4163 int ret = -ENOMEM;
4164 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
4165 index 78c02b3..c94109a 100644
4166 --- a/arch/arm/mach-omap2/omap_device.h
4167 +++ b/arch/arm/mach-omap2/omap_device.h
4168 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
4169 /* Core code interface */
4170
4171 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
4172 - struct omap_hwmod *oh, void *pdata,
4173 + struct omap_hwmod *oh, const void *pdata,
4174 int pdata_len);
4175
4176 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
4177 struct omap_hwmod **oh, int oh_cnt,
4178 - void *pdata, int pdata_len);
4179 + const void *pdata, int pdata_len);
4180
4181 struct omap_device *omap_device_alloc(struct platform_device *pdev,
4182 struct omap_hwmod **ohs, int oh_cnt);
4183 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
4184 index da1b256..ab2a327 100644
4185 --- a/arch/arm/mach-omap2/omap_hwmod.c
4186 +++ b/arch/arm/mach-omap2/omap_hwmod.c
4187 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
4188 int (*init_clkdm)(struct omap_hwmod *oh);
4189 void (*update_context_lost)(struct omap_hwmod *oh);
4190 int (*get_context_lost)(struct omap_hwmod *oh);
4191 -};
4192 +} __no_const;
4193
4194 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
4195 -static struct omap_hwmod_soc_ops soc_ops;
4196 +static struct omap_hwmod_soc_ops soc_ops __read_only;
4197
4198 /* omap_hwmod_list contains all registered struct omap_hwmods */
4199 static LIST_HEAD(omap_hwmod_list);
4200 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
4201 index 95fee54..cfa9cf1 100644
4202 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
4203 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
4204 @@ -10,6 +10,7 @@
4205
4206 #include <linux/kernel.h>
4207 #include <linux/init.h>
4208 +#include <asm/pgtable.h>
4209
4210 #include "powerdomain.h"
4211
4212 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
4213
4214 void __init am43xx_powerdomains_init(void)
4215 {
4216 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4217 + pax_open_kernel();
4218 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
4219 + pax_close_kernel();
4220 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
4221 pwrdm_register_pwrdms(powerdomains_am43xx);
4222 pwrdm_complete_init();
4223 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
4224 index 97d6607..8429d14 100644
4225 --- a/arch/arm/mach-omap2/wd_timer.c
4226 +++ b/arch/arm/mach-omap2/wd_timer.c
4227 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
4228 struct omap_hwmod *oh;
4229 char *oh_name = "wd_timer2";
4230 char *dev_name = "omap_wdt";
4231 - struct omap_wd_timer_platform_data pdata;
4232 + static struct omap_wd_timer_platform_data pdata = {
4233 + .read_reset_sources = prm_read_reset_sources
4234 + };
4235
4236 if (!cpu_class_is_omap2() || of_have_populated_dt())
4237 return 0;
4238 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
4239 return -EINVAL;
4240 }
4241
4242 - pdata.read_reset_sources = prm_read_reset_sources;
4243 -
4244 pdev = omap_device_build(dev_name, id, oh, &pdata,
4245 sizeof(struct omap_wd_timer_platform_data));
4246 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
4247 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
4248 index b82dcae..44ee5b6 100644
4249 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
4250 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
4251 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
4252 bool entered_lp2 = false;
4253
4254 if (tegra_pending_sgi())
4255 - ACCESS_ONCE(abort_flag) = true;
4256 + ACCESS_ONCE_RW(abort_flag) = true;
4257
4258 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
4259
4260 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
4261 index 2dea8b5..6499da2 100644
4262 --- a/arch/arm/mach-ux500/setup.h
4263 +++ b/arch/arm/mach-ux500/setup.h
4264 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
4265 .type = MT_DEVICE, \
4266 }
4267
4268 -#define __MEM_DEV_DESC(x, sz) { \
4269 - .virtual = IO_ADDRESS(x), \
4270 - .pfn = __phys_to_pfn(x), \
4271 - .length = sz, \
4272 - .type = MT_MEMORY_RWX, \
4273 -}
4274 -
4275 extern struct smp_operations ux500_smp_ops;
4276 extern void ux500_cpu_die(unsigned int cpu);
4277
4278 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
4279 index c348eae..456a1a4 100644
4280 --- a/arch/arm/mm/Kconfig
4281 +++ b/arch/arm/mm/Kconfig
4282 @@ -446,6 +446,7 @@ config CPU_32v5
4283
4284 config CPU_32v6
4285 bool
4286 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4287 select TLS_REG_EMUL if !CPU_32v6K && !MMU
4288
4289 config CPU_32v6K
4290 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
4291
4292 config CPU_USE_DOMAINS
4293 bool
4294 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
4295 help
4296 This option enables or disables the use of domain switching
4297 via the set_fs() function.
4298 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
4299 config KUSER_HELPERS
4300 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
4301 default y
4302 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
4303 help
4304 Warning: disabling this option may break user programs.
4305
4306 @@ -811,7 +814,7 @@ config KUSER_HELPERS
4307 See Documentation/arm/kernel_user_helpers.txt for details.
4308
4309 However, the fixed address nature of these helpers can be used
4310 - by ROP (return orientated programming) authors when creating
4311 + by ROP (Return Oriented Programming) authors when creating
4312 exploits.
4313
4314 If all of the binaries and libraries which run on your platform
4315 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
4316 index b8cb1a2..6a5624a 100644
4317 --- a/arch/arm/mm/alignment.c
4318 +++ b/arch/arm/mm/alignment.c
4319 @@ -214,10 +214,12 @@ union offset_union {
4320 #define __get16_unaligned_check(ins,val,addr) \
4321 do { \
4322 unsigned int err = 0, v, a = addr; \
4323 + pax_open_userland(); \
4324 __get8_unaligned_check(ins,v,a,err); \
4325 val = v << ((BE) ? 8 : 0); \
4326 __get8_unaligned_check(ins,v,a,err); \
4327 val |= v << ((BE) ? 0 : 8); \
4328 + pax_close_userland(); \
4329 if (err) \
4330 goto fault; \
4331 } while (0)
4332 @@ -231,6 +233,7 @@ union offset_union {
4333 #define __get32_unaligned_check(ins,val,addr) \
4334 do { \
4335 unsigned int err = 0, v, a = addr; \
4336 + pax_open_userland(); \
4337 __get8_unaligned_check(ins,v,a,err); \
4338 val = v << ((BE) ? 24 : 0); \
4339 __get8_unaligned_check(ins,v,a,err); \
4340 @@ -239,6 +242,7 @@ union offset_union {
4341 val |= v << ((BE) ? 8 : 16); \
4342 __get8_unaligned_check(ins,v,a,err); \
4343 val |= v << ((BE) ? 0 : 24); \
4344 + pax_close_userland(); \
4345 if (err) \
4346 goto fault; \
4347 } while (0)
4348 @@ -252,6 +256,7 @@ union offset_union {
4349 #define __put16_unaligned_check(ins,val,addr) \
4350 do { \
4351 unsigned int err = 0, v = val, a = addr; \
4352 + pax_open_userland(); \
4353 __asm__( FIRST_BYTE_16 \
4354 ARM( "1: "ins" %1, [%2], #1\n" ) \
4355 THUMB( "1: "ins" %1, [%2]\n" ) \
4356 @@ -271,6 +276,7 @@ union offset_union {
4357 " .popsection\n" \
4358 : "=r" (err), "=&r" (v), "=&r" (a) \
4359 : "0" (err), "1" (v), "2" (a)); \
4360 + pax_close_userland(); \
4361 if (err) \
4362 goto fault; \
4363 } while (0)
4364 @@ -284,6 +290,7 @@ union offset_union {
4365 #define __put32_unaligned_check(ins,val,addr) \
4366 do { \
4367 unsigned int err = 0, v = val, a = addr; \
4368 + pax_open_userland(); \
4369 __asm__( FIRST_BYTE_32 \
4370 ARM( "1: "ins" %1, [%2], #1\n" ) \
4371 THUMB( "1: "ins" %1, [%2]\n" ) \
4372 @@ -313,6 +320,7 @@ union offset_union {
4373 " .popsection\n" \
4374 : "=r" (err), "=&r" (v), "=&r" (a) \
4375 : "0" (err), "1" (v), "2" (a)); \
4376 + pax_close_userland(); \
4377 if (err) \
4378 goto fault; \
4379 } while (0)
4380 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
4381 index 7c3fb41..bfb87d8 100644
4382 --- a/arch/arm/mm/cache-l2x0.c
4383 +++ b/arch/arm/mm/cache-l2x0.c
4384 @@ -41,7 +41,7 @@ struct l2c_init_data {
4385 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
4386 void (*save)(void __iomem *);
4387 struct outer_cache_fns outer_cache;
4388 -};
4389 +} __do_const;
4390
4391 #define CACHE_LINE_SIZE 32
4392
4393 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
4394 index 6eb97b3..ac509f6 100644
4395 --- a/arch/arm/mm/context.c
4396 +++ b/arch/arm/mm/context.c
4397 @@ -43,7 +43,7 @@
4398 #define NUM_USER_ASIDS ASID_FIRST_VERSION
4399
4400 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
4401 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4402 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4403 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4404
4405 static DEFINE_PER_CPU(atomic64_t, active_asids);
4406 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4407 {
4408 static u32 cur_idx = 1;
4409 u64 asid = atomic64_read(&mm->context.id);
4410 - u64 generation = atomic64_read(&asid_generation);
4411 + u64 generation = atomic64_read_unchecked(&asid_generation);
4412
4413 if (asid != 0 && is_reserved_asid(asid)) {
4414 /*
4415 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4416 */
4417 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4418 if (asid == NUM_USER_ASIDS) {
4419 - generation = atomic64_add_return(ASID_FIRST_VERSION,
4420 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4421 &asid_generation);
4422 flush_context(cpu);
4423 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4424 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4425 cpu_set_reserved_ttbr0();
4426
4427 asid = atomic64_read(&mm->context.id);
4428 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4429 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4430 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4431 goto switch_mm_fastpath;
4432
4433 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4434 /* Check that our ASID belongs to the current generation. */
4435 asid = atomic64_read(&mm->context.id);
4436 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4437 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4438 asid = new_context(mm, cpu);
4439 atomic64_set(&mm->context.id, asid);
4440 }
4441 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4442 index eb8830a..5360ce7 100644
4443 --- a/arch/arm/mm/fault.c
4444 +++ b/arch/arm/mm/fault.c
4445 @@ -25,6 +25,7 @@
4446 #include <asm/system_misc.h>
4447 #include <asm/system_info.h>
4448 #include <asm/tlbflush.h>
4449 +#include <asm/sections.h>
4450
4451 #include "fault.h"
4452
4453 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4454 if (fixup_exception(regs))
4455 return;
4456
4457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4458 + if (addr < TASK_SIZE) {
4459 + if (current->signal->curr_ip)
4460 + 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),
4461 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4462 + else
4463 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4464 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4465 + }
4466 +#endif
4467 +
4468 +#ifdef CONFIG_PAX_KERNEXEC
4469 + if ((fsr & FSR_WRITE) &&
4470 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4471 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4472 + {
4473 + if (current->signal->curr_ip)
4474 + 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),
4475 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4476 + else
4477 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4478 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4479 + }
4480 +#endif
4481 +
4482 /*
4483 * No handler, we'll have to terminate things with extreme prejudice.
4484 */
4485 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4486 }
4487 #endif
4488
4489 +#ifdef CONFIG_PAX_PAGEEXEC
4490 + if (fsr & FSR_LNX_PF) {
4491 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4492 + do_group_exit(SIGKILL);
4493 + }
4494 +#endif
4495 +
4496 tsk->thread.address = addr;
4497 tsk->thread.error_code = fsr;
4498 tsk->thread.trap_no = 14;
4499 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4500 }
4501 #endif /* CONFIG_MMU */
4502
4503 +#ifdef CONFIG_PAX_PAGEEXEC
4504 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4505 +{
4506 + long i;
4507 +
4508 + printk(KERN_ERR "PAX: bytes at PC: ");
4509 + for (i = 0; i < 20; i++) {
4510 + unsigned char c;
4511 + if (get_user(c, (__force unsigned char __user *)pc+i))
4512 + printk(KERN_CONT "?? ");
4513 + else
4514 + printk(KERN_CONT "%02x ", c);
4515 + }
4516 + printk("\n");
4517 +
4518 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4519 + for (i = -1; i < 20; i++) {
4520 + unsigned long c;
4521 + if (get_user(c, (__force unsigned long __user *)sp+i))
4522 + printk(KERN_CONT "???????? ");
4523 + else
4524 + printk(KERN_CONT "%08lx ", c);
4525 + }
4526 + printk("\n");
4527 +}
4528 +#endif
4529 +
4530 /*
4531 * First Level Translation Fault Handler
4532 *
4533 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4534 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4535 struct siginfo info;
4536
4537 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4538 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4539 + if (current->signal->curr_ip)
4540 + 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),
4541 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4542 + else
4543 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4544 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4545 + goto die;
4546 + }
4547 +#endif
4548 +
4549 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4550 return;
4551
4552 +die:
4553 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4554 inf->name, fsr, addr);
4555
4556 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4557 ifsr_info[nr].name = name;
4558 }
4559
4560 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4561 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4562 +
4563 asmlinkage void __exception
4564 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4565 {
4566 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4567 struct siginfo info;
4568 + unsigned long pc = instruction_pointer(regs);
4569 +
4570 + if (user_mode(regs)) {
4571 + unsigned long sigpage = current->mm->context.sigpage;
4572 +
4573 + if (sigpage <= pc && pc < sigpage + 7*4) {
4574 + if (pc < sigpage + 3*4)
4575 + sys_sigreturn(regs);
4576 + else
4577 + sys_rt_sigreturn(regs);
4578 + return;
4579 + }
4580 + if (pc == 0xffff0f60UL) {
4581 + /*
4582 + * PaX: __kuser_cmpxchg64 emulation
4583 + */
4584 + // TODO
4585 + //regs->ARM_pc = regs->ARM_lr;
4586 + //return;
4587 + }
4588 + if (pc == 0xffff0fa0UL) {
4589 + /*
4590 + * PaX: __kuser_memory_barrier emulation
4591 + */
4592 + // dmb(); implied by the exception
4593 + regs->ARM_pc = regs->ARM_lr;
4594 + return;
4595 + }
4596 + if (pc == 0xffff0fc0UL) {
4597 + /*
4598 + * PaX: __kuser_cmpxchg emulation
4599 + */
4600 + // TODO
4601 + //long new;
4602 + //int op;
4603 +
4604 + //op = FUTEX_OP_SET << 28;
4605 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4606 + //regs->ARM_r0 = old != new;
4607 + //regs->ARM_pc = regs->ARM_lr;
4608 + //return;
4609 + }
4610 + if (pc == 0xffff0fe0UL) {
4611 + /*
4612 + * PaX: __kuser_get_tls emulation
4613 + */
4614 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4615 + regs->ARM_pc = regs->ARM_lr;
4616 + return;
4617 + }
4618 + }
4619 +
4620 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4621 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4622 + if (current->signal->curr_ip)
4623 + 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),
4624 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4625 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4626 + else
4627 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4628 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4629 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4630 + goto die;
4631 + }
4632 +#endif
4633 +
4634 +#ifdef CONFIG_PAX_REFCOUNT
4635 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4636 + unsigned int bkpt;
4637 +
4638 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4639 + current->thread.error_code = ifsr;
4640 + current->thread.trap_no = 0;
4641 + pax_report_refcount_overflow(regs);
4642 + fixup_exception(regs);
4643 + return;
4644 + }
4645 + }
4646 +#endif
4647
4648 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4649 return;
4650
4651 +die:
4652 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4653 inf->name, ifsr, addr);
4654
4655 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4656 index cf08bdf..772656c 100644
4657 --- a/arch/arm/mm/fault.h
4658 +++ b/arch/arm/mm/fault.h
4659 @@ -3,6 +3,7 @@
4660
4661 /*
4662 * Fault status register encodings. We steal bit 31 for our own purposes.
4663 + * Set when the FSR value is from an instruction fault.
4664 */
4665 #define FSR_LNX_PF (1 << 31)
4666 #define FSR_WRITE (1 << 11)
4667 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4668 }
4669 #endif
4670
4671 +/* valid for LPAE and !LPAE */
4672 +static inline int is_xn_fault(unsigned int fsr)
4673 +{
4674 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4675 +}
4676 +
4677 +static inline int is_domain_fault(unsigned int fsr)
4678 +{
4679 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4680 +}
4681 +
4682 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4683 unsigned long search_exception_table(unsigned long addr);
4684
4685 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4686 index 659c75d..6f8c029 100644
4687 --- a/arch/arm/mm/init.c
4688 +++ b/arch/arm/mm/init.c
4689 @@ -31,6 +31,8 @@
4690 #include <asm/setup.h>
4691 #include <asm/tlb.h>
4692 #include <asm/fixmap.h>
4693 +#include <asm/system_info.h>
4694 +#include <asm/cp15.h>
4695
4696 #include <asm/mach/arch.h>
4697 #include <asm/mach/map.h>
4698 @@ -619,7 +621,46 @@ void free_initmem(void)
4699 {
4700 #ifdef CONFIG_HAVE_TCM
4701 extern char __tcm_start, __tcm_end;
4702 +#endif
4703
4704 +#ifdef CONFIG_PAX_KERNEXEC
4705 + unsigned long addr;
4706 + pgd_t *pgd;
4707 + pud_t *pud;
4708 + pmd_t *pmd;
4709 + int cpu_arch = cpu_architecture();
4710 + unsigned int cr = get_cr();
4711 +
4712 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4713 + /* make pages tables, etc before .text NX */
4714 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4715 + pgd = pgd_offset_k(addr);
4716 + pud = pud_offset(pgd, addr);
4717 + pmd = pmd_offset(pud, addr);
4718 + __section_update(pmd, addr, PMD_SECT_XN);
4719 + }
4720 + /* make init NX */
4721 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4722 + pgd = pgd_offset_k(addr);
4723 + pud = pud_offset(pgd, addr);
4724 + pmd = pmd_offset(pud, addr);
4725 + __section_update(pmd, addr, PMD_SECT_XN);
4726 + }
4727 + /* make kernel code/rodata RX */
4728 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4729 + pgd = pgd_offset_k(addr);
4730 + pud = pud_offset(pgd, addr);
4731 + pmd = pmd_offset(pud, addr);
4732 +#ifdef CONFIG_ARM_LPAE
4733 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4734 +#else
4735 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4736 +#endif
4737 + }
4738 + }
4739 +#endif
4740 +
4741 +#ifdef CONFIG_HAVE_TCM
4742 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4743 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4744 #endif
4745 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4746 index d1e5ad7..84dcbf2 100644
4747 --- a/arch/arm/mm/ioremap.c
4748 +++ b/arch/arm/mm/ioremap.c
4749 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4750 unsigned int mtype;
4751
4752 if (cached)
4753 - mtype = MT_MEMORY_RWX;
4754 + mtype = MT_MEMORY_RX;
4755 else
4756 - mtype = MT_MEMORY_RWX_NONCACHED;
4757 + mtype = MT_MEMORY_RX_NONCACHED;
4758
4759 return __arm_ioremap_caller(phys_addr, size, mtype,
4760 __builtin_return_address(0));
4761 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4762 index 5e85ed3..b10a7ed 100644
4763 --- a/arch/arm/mm/mmap.c
4764 +++ b/arch/arm/mm/mmap.c
4765 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4766 struct vm_area_struct *vma;
4767 int do_align = 0;
4768 int aliasing = cache_is_vipt_aliasing();
4769 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4770 struct vm_unmapped_area_info info;
4771
4772 /*
4773 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4774 if (len > TASK_SIZE)
4775 return -ENOMEM;
4776
4777 +#ifdef CONFIG_PAX_RANDMMAP
4778 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4779 +#endif
4780 +
4781 if (addr) {
4782 if (do_align)
4783 addr = COLOUR_ALIGN(addr, pgoff);
4784 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4785 addr = PAGE_ALIGN(addr);
4786
4787 vma = find_vma(mm, addr);
4788 - if (TASK_SIZE - len >= addr &&
4789 - (!vma || addr + len <= vma->vm_start))
4790 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4791 return addr;
4792 }
4793
4794 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4795 info.high_limit = TASK_SIZE;
4796 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4797 info.align_offset = pgoff << PAGE_SHIFT;
4798 + info.threadstack_offset = offset;
4799 return vm_unmapped_area(&info);
4800 }
4801
4802 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4803 unsigned long addr = addr0;
4804 int do_align = 0;
4805 int aliasing = cache_is_vipt_aliasing();
4806 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4807 struct vm_unmapped_area_info info;
4808
4809 /*
4810 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4811 return addr;
4812 }
4813
4814 +#ifdef CONFIG_PAX_RANDMMAP
4815 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4816 +#endif
4817 +
4818 /* requesting a specific address */
4819 if (addr) {
4820 if (do_align)
4821 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4822 else
4823 addr = PAGE_ALIGN(addr);
4824 vma = find_vma(mm, addr);
4825 - if (TASK_SIZE - len >= addr &&
4826 - (!vma || addr + len <= vma->vm_start))
4827 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4828 return addr;
4829 }
4830
4831 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4832 info.high_limit = mm->mmap_base;
4833 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4834 info.align_offset = pgoff << PAGE_SHIFT;
4835 + info.threadstack_offset = offset;
4836 addr = vm_unmapped_area(&info);
4837
4838 /*
4839 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4840 {
4841 unsigned long random_factor = 0UL;
4842
4843 +#ifdef CONFIG_PAX_RANDMMAP
4844 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4845 +#endif
4846 +
4847 /* 8 bits of randomness in 20 address space bits */
4848 if ((current->flags & PF_RANDOMIZE) &&
4849 !(current->personality & ADDR_NO_RANDOMIZE))
4850 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4851
4852 if (mmap_is_legacy()) {
4853 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4854 +
4855 +#ifdef CONFIG_PAX_RANDMMAP
4856 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4857 + mm->mmap_base += mm->delta_mmap;
4858 +#endif
4859 +
4860 mm->get_unmapped_area = arch_get_unmapped_area;
4861 } else {
4862 mm->mmap_base = mmap_base(random_factor);
4863 +
4864 +#ifdef CONFIG_PAX_RANDMMAP
4865 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4866 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4867 +#endif
4868 +
4869 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4870 }
4871 }
4872 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4873 index 6e3ba8d..9cbb4d7 100644
4874 --- a/arch/arm/mm/mmu.c
4875 +++ b/arch/arm/mm/mmu.c
4876 @@ -40,6 +40,22 @@
4877 #include "mm.h"
4878 #include "tcm.h"
4879
4880 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4881 +void modify_domain(unsigned int dom, unsigned int type)
4882 +{
4883 + struct thread_info *thread = current_thread_info();
4884 + unsigned int domain = thread->cpu_domain;
4885 + /*
4886 + * DOMAIN_MANAGER might be defined to some other value,
4887 + * use the arch-defined constant
4888 + */
4889 + domain &= ~domain_val(dom, 3);
4890 + thread->cpu_domain = domain | domain_val(dom, type);
4891 + set_domain(thread->cpu_domain);
4892 +}
4893 +EXPORT_SYMBOL(modify_domain);
4894 +#endif
4895 +
4896 /*
4897 * empty_zero_page is a special page that is used for
4898 * zero-initialized data and COW.
4899 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4900 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4901 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4902
4903 -static struct mem_type mem_types[] = {
4904 +#ifdef CONFIG_PAX_KERNEXEC
4905 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4906 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4907 +#else
4908 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4909 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4910 +#endif
4911 +
4912 +static struct mem_type mem_types[] __read_only = {
4913 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4914 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4915 L_PTE_SHARED,
4916 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4917 .prot_sect = PROT_SECT_DEVICE,
4918 .domain = DOMAIN_IO,
4919 },
4920 - [MT_UNCACHED] = {
4921 + [MT_UNCACHED_RW] = {
4922 .prot_pte = PROT_PTE_DEVICE,
4923 .prot_l1 = PMD_TYPE_TABLE,
4924 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4925 .domain = DOMAIN_IO,
4926 },
4927 - [MT_CACHECLEAN] = {
4928 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4929 + [MT_CACHECLEAN_RO] = {
4930 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4931 .domain = DOMAIN_KERNEL,
4932 },
4933 #ifndef CONFIG_ARM_LPAE
4934 - [MT_MINICLEAN] = {
4935 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4936 + [MT_MINICLEAN_RO] = {
4937 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4938 .domain = DOMAIN_KERNEL,
4939 },
4940 #endif
4941 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4942 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4943 L_PTE_RDONLY,
4944 .prot_l1 = PMD_TYPE_TABLE,
4945 - .domain = DOMAIN_USER,
4946 + .domain = DOMAIN_VECTORS,
4947 },
4948 [MT_HIGH_VECTORS] = {
4949 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4950 L_PTE_USER | L_PTE_RDONLY,
4951 .prot_l1 = PMD_TYPE_TABLE,
4952 - .domain = DOMAIN_USER,
4953 + .domain = DOMAIN_VECTORS,
4954 },
4955 - [MT_MEMORY_RWX] = {
4956 + [__MT_MEMORY_RWX] = {
4957 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4958 .prot_l1 = PMD_TYPE_TABLE,
4959 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4960 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4961 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4962 .domain = DOMAIN_KERNEL,
4963 },
4964 - [MT_ROM] = {
4965 - .prot_sect = PMD_TYPE_SECT,
4966 + [MT_MEMORY_RX] = {
4967 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4968 + .prot_l1 = PMD_TYPE_TABLE,
4969 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4970 + .domain = DOMAIN_KERNEL,
4971 + },
4972 + [MT_ROM_RX] = {
4973 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4974 .domain = DOMAIN_KERNEL,
4975 },
4976 - [MT_MEMORY_RWX_NONCACHED] = {
4977 + [MT_MEMORY_RW_NONCACHED] = {
4978 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4979 L_PTE_MT_BUFFERABLE,
4980 .prot_l1 = PMD_TYPE_TABLE,
4981 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4982 .domain = DOMAIN_KERNEL,
4983 },
4984 + [MT_MEMORY_RX_NONCACHED] = {
4985 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4986 + L_PTE_MT_BUFFERABLE,
4987 + .prot_l1 = PMD_TYPE_TABLE,
4988 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4989 + .domain = DOMAIN_KERNEL,
4990 + },
4991 [MT_MEMORY_RW_DTCM] = {
4992 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4993 L_PTE_XN,
4994 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4995 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4996 .domain = DOMAIN_KERNEL,
4997 },
4998 - [MT_MEMORY_RWX_ITCM] = {
4999 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
5000 + [MT_MEMORY_RX_ITCM] = {
5001 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
5002 .prot_l1 = PMD_TYPE_TABLE,
5003 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
5004 .domain = DOMAIN_KERNEL,
5005 },
5006 [MT_MEMORY_RW_SO] = {
5007 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
5008 * Mark cache clean areas and XIP ROM read only
5009 * from SVC mode and no access from userspace.
5010 */
5011 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5012 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5013 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5014 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5015 +#ifdef CONFIG_PAX_KERNEXEC
5016 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5017 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5018 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5019 +#endif
5020 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5021 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
5022 #endif
5023
5024 /*
5025 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
5026 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
5027 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
5028 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
5029 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5030 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5031 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
5032 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
5033 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
5034 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
5035 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
5036 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
5037 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
5038 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
5039 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
5040 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
5041 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
5042 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
5043 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
5044 }
5045 }
5046
5047 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
5048 if (cpu_arch >= CPU_ARCH_ARMv6) {
5049 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
5050 /* Non-cacheable Normal is XCB = 001 */
5051 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5052 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5053 + PMD_SECT_BUFFERED;
5054 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5055 PMD_SECT_BUFFERED;
5056 } else {
5057 /* For both ARMv6 and non-TEX-remapping ARMv7 */
5058 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
5059 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
5060 + PMD_SECT_TEX(1);
5061 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
5062 PMD_SECT_TEX(1);
5063 }
5064 } else {
5065 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5066 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5067 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
5068 }
5069
5070 #ifdef CONFIG_ARM_LPAE
5071 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
5072 vecs_pgprot |= PTE_EXT_AF;
5073 #endif
5074
5075 + user_pgprot |= __supported_pte_mask;
5076 +
5077 for (i = 0; i < 16; i++) {
5078 pteval_t v = pgprot_val(protection_map[i]);
5079 protection_map[i] = __pgprot(v | user_pgprot);
5080 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
5081
5082 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
5083 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
5084 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5085 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5086 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
5087 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
5088 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
5089 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
5090 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
5091 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
5092 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
5093 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
5094 - mem_types[MT_ROM].prot_sect |= cp->pmd;
5095 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
5096 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
5097 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
5098
5099 switch (cp->pmd) {
5100 case PMD_SECT_WT:
5101 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
5102 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
5103 break;
5104 case PMD_SECT_WB:
5105 case PMD_SECT_WBWA:
5106 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
5107 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
5108 break;
5109 }
5110 pr_info("Memory policy: %sData cache %s\n",
5111 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
5112 return;
5113 }
5114
5115 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
5116 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
5117 md->virtual >= PAGE_OFFSET &&
5118 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
5119 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
5120 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
5121 * called function. This means you can't use any function or debugging
5122 * method which may touch any device, otherwise the kernel _will_ crash.
5123 */
5124 +
5125 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
5126 +
5127 static void __init devicemaps_init(const struct machine_desc *mdesc)
5128 {
5129 struct map_desc map;
5130 unsigned long addr;
5131 - void *vectors;
5132
5133 - /*
5134 - * Allocate the vector page early.
5135 - */
5136 - vectors = early_alloc(PAGE_SIZE * 2);
5137 -
5138 - early_trap_init(vectors);
5139 + early_trap_init(&vectors);
5140
5141 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
5142 pmd_clear(pmd_off_k(addr));
5143 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5144 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
5145 map.virtual = MODULES_VADDR;
5146 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
5147 - map.type = MT_ROM;
5148 + map.type = MT_ROM_RX;
5149 create_mapping(&map);
5150 #endif
5151
5152 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5153 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
5154 map.virtual = FLUSH_BASE;
5155 map.length = SZ_1M;
5156 - map.type = MT_CACHECLEAN;
5157 + map.type = MT_CACHECLEAN_RO;
5158 create_mapping(&map);
5159 #endif
5160 #ifdef FLUSH_BASE_MINICACHE
5161 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
5162 map.virtual = FLUSH_BASE_MINICACHE;
5163 map.length = SZ_1M;
5164 - map.type = MT_MINICLEAN;
5165 + map.type = MT_MINICLEAN_RO;
5166 create_mapping(&map);
5167 #endif
5168
5169 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
5170 * location (0xffff0000). If we aren't using high-vectors, also
5171 * create a mapping at the low-vectors virtual address.
5172 */
5173 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
5174 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
5175 map.virtual = 0xffff0000;
5176 map.length = PAGE_SIZE;
5177 #ifdef CONFIG_KUSER_HELPERS
5178 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
5179 static void __init map_lowmem(void)
5180 {
5181 struct memblock_region *reg;
5182 +#ifndef CONFIG_PAX_KERNEXEC
5183 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
5184 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
5185 +#endif
5186
5187 /* Map all the lowmem memory banks. */
5188 for_each_memblock(memory, reg) {
5189 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
5190 if (start >= end)
5191 break;
5192
5193 +#ifdef CONFIG_PAX_KERNEXEC
5194 + map.pfn = __phys_to_pfn(start);
5195 + map.virtual = __phys_to_virt(start);
5196 + map.length = end - start;
5197 +
5198 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
5199 + struct map_desc kernel;
5200 + struct map_desc initmap;
5201 +
5202 + /* when freeing initmem we will make this RW */
5203 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
5204 + initmap.virtual = (unsigned long)__init_begin;
5205 + initmap.length = _sdata - __init_begin;
5206 + initmap.type = __MT_MEMORY_RWX;
5207 + create_mapping(&initmap);
5208 +
5209 + /* when freeing initmem we will make this RX */
5210 + kernel.pfn = __phys_to_pfn(__pa(_stext));
5211 + kernel.virtual = (unsigned long)_stext;
5212 + kernel.length = __init_begin - _stext;
5213 + kernel.type = __MT_MEMORY_RWX;
5214 + create_mapping(&kernel);
5215 +
5216 + if (map.virtual < (unsigned long)_stext) {
5217 + map.length = (unsigned long)_stext - map.virtual;
5218 + map.type = __MT_MEMORY_RWX;
5219 + create_mapping(&map);
5220 + }
5221 +
5222 + map.pfn = __phys_to_pfn(__pa(_sdata));
5223 + map.virtual = (unsigned long)_sdata;
5224 + map.length = end - __pa(_sdata);
5225 + }
5226 +
5227 + map.type = MT_MEMORY_RW;
5228 + create_mapping(&map);
5229 +#else
5230 if (end < kernel_x_start || start >= kernel_x_end) {
5231 map.pfn = __phys_to_pfn(start);
5232 map.virtual = __phys_to_virt(start);
5233 map.length = end - start;
5234 - map.type = MT_MEMORY_RWX;
5235 + map.type = __MT_MEMORY_RWX;
5236
5237 create_mapping(&map);
5238 } else {
5239 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
5240 map.pfn = __phys_to_pfn(kernel_x_start);
5241 map.virtual = __phys_to_virt(kernel_x_start);
5242 map.length = kernel_x_end - kernel_x_start;
5243 - map.type = MT_MEMORY_RWX;
5244 + map.type = __MT_MEMORY_RWX;
5245
5246 create_mapping(&map);
5247
5248 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
5249 create_mapping(&map);
5250 }
5251 }
5252 +#endif
5253 }
5254 }
5255
5256 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
5257 index 5b217f4..c23f40e 100644
5258 --- a/arch/arm/plat-iop/setup.c
5259 +++ b/arch/arm/plat-iop/setup.c
5260 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
5261 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
5262 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
5263 .length = IOP3XX_PERIPHERAL_SIZE,
5264 - .type = MT_UNCACHED,
5265 + .type = MT_UNCACHED_RW,
5266 },
5267 };
5268
5269 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
5270 index a5bc92d..0bb4730 100644
5271 --- a/arch/arm/plat-omap/sram.c
5272 +++ b/arch/arm/plat-omap/sram.c
5273 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
5274 * Looks like we need to preserve some bootloader code at the
5275 * beginning of SRAM for jumping to flash for reboot to work...
5276 */
5277 + pax_open_kernel();
5278 memset_io(omap_sram_base + omap_sram_skip, 0,
5279 omap_sram_size - omap_sram_skip);
5280 + pax_close_kernel();
5281 }
5282 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
5283 index ce6d763..cfea917 100644
5284 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
5285 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
5286 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
5287 int (*started)(unsigned ch);
5288 int (*flush)(unsigned ch);
5289 int (*stop)(unsigned ch);
5290 -};
5291 +} __no_const;
5292
5293 extern void *samsung_dmadev_get_ops(void);
5294 extern void *s3c_dma_get_ops(void);
5295 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
5296 index 6389d60..b5d3bdd 100644
5297 --- a/arch/arm64/include/asm/barrier.h
5298 +++ b/arch/arm64/include/asm/barrier.h
5299 @@ -41,7 +41,7 @@
5300 do { \
5301 compiletime_assert_atomic_type(*p); \
5302 barrier(); \
5303 - ACCESS_ONCE(*p) = (v); \
5304 + ACCESS_ONCE_RW(*p) = (v); \
5305 } while (0)
5306
5307 #define smp_load_acquire(p) \
5308 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
5309 index 3bf8f4e..5dd5491 100644
5310 --- a/arch/arm64/include/asm/uaccess.h
5311 +++ b/arch/arm64/include/asm/uaccess.h
5312 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
5313 flag; \
5314 })
5315
5316 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5317 #define access_ok(type, addr, size) __range_ok(addr, size)
5318 #define user_addr_max get_fs
5319
5320 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
5321 index c3a58a1..78fbf54 100644
5322 --- a/arch/avr32/include/asm/cache.h
5323 +++ b/arch/avr32/include/asm/cache.h
5324 @@ -1,8 +1,10 @@
5325 #ifndef __ASM_AVR32_CACHE_H
5326 #define __ASM_AVR32_CACHE_H
5327
5328 +#include <linux/const.h>
5329 +
5330 #define L1_CACHE_SHIFT 5
5331 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5332 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5333
5334 /*
5335 * Memory returned by kmalloc() may be used for DMA, so we must make
5336 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
5337 index d232888..87c8df1 100644
5338 --- a/arch/avr32/include/asm/elf.h
5339 +++ b/arch/avr32/include/asm/elf.h
5340 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
5341 the loader. We need to make sure that it is out of the way of the program
5342 that it will "exec", and that there is sufficient room for the brk. */
5343
5344 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
5345 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5346
5347 +#ifdef CONFIG_PAX_ASLR
5348 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
5349 +
5350 +#define PAX_DELTA_MMAP_LEN 15
5351 +#define PAX_DELTA_STACK_LEN 15
5352 +#endif
5353
5354 /* This yields a mask that user programs can use to figure out what
5355 instruction set this CPU supports. This could be done in user space,
5356 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
5357 index 479330b..53717a8 100644
5358 --- a/arch/avr32/include/asm/kmap_types.h
5359 +++ b/arch/avr32/include/asm/kmap_types.h
5360 @@ -2,9 +2,9 @@
5361 #define __ASM_AVR32_KMAP_TYPES_H
5362
5363 #ifdef CONFIG_DEBUG_HIGHMEM
5364 -# define KM_TYPE_NR 29
5365 +# define KM_TYPE_NR 30
5366 #else
5367 -# define KM_TYPE_NR 14
5368 +# define KM_TYPE_NR 15
5369 #endif
5370
5371 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5372 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5373 index 0eca933..eb78c7b 100644
5374 --- a/arch/avr32/mm/fault.c
5375 +++ b/arch/avr32/mm/fault.c
5376 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5377
5378 int exception_trace = 1;
5379
5380 +#ifdef CONFIG_PAX_PAGEEXEC
5381 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5382 +{
5383 + unsigned long i;
5384 +
5385 + printk(KERN_ERR "PAX: bytes at PC: ");
5386 + for (i = 0; i < 20; i++) {
5387 + unsigned char c;
5388 + if (get_user(c, (unsigned char *)pc+i))
5389 + printk(KERN_CONT "???????? ");
5390 + else
5391 + printk(KERN_CONT "%02x ", c);
5392 + }
5393 + printk("\n");
5394 +}
5395 +#endif
5396 +
5397 /*
5398 * This routine handles page faults. It determines the address and the
5399 * problem, and then passes it off to one of the appropriate routines.
5400 @@ -176,6 +193,16 @@ bad_area:
5401 up_read(&mm->mmap_sem);
5402
5403 if (user_mode(regs)) {
5404 +
5405 +#ifdef CONFIG_PAX_PAGEEXEC
5406 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5407 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5408 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5409 + do_group_exit(SIGKILL);
5410 + }
5411 + }
5412 +#endif
5413 +
5414 if (exception_trace && printk_ratelimit())
5415 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5416 "sp %08lx ecr %lu\n",
5417 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5418 index 568885a..f8008df 100644
5419 --- a/arch/blackfin/include/asm/cache.h
5420 +++ b/arch/blackfin/include/asm/cache.h
5421 @@ -7,6 +7,7 @@
5422 #ifndef __ARCH_BLACKFIN_CACHE_H
5423 #define __ARCH_BLACKFIN_CACHE_H
5424
5425 +#include <linux/const.h>
5426 #include <linux/linkage.h> /* for asmlinkage */
5427
5428 /*
5429 @@ -14,7 +15,7 @@
5430 * Blackfin loads 32 bytes for cache
5431 */
5432 #define L1_CACHE_SHIFT 5
5433 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5434 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5435 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5436
5437 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5438 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5439 index aea2718..3639a60 100644
5440 --- a/arch/cris/include/arch-v10/arch/cache.h
5441 +++ b/arch/cris/include/arch-v10/arch/cache.h
5442 @@ -1,8 +1,9 @@
5443 #ifndef _ASM_ARCH_CACHE_H
5444 #define _ASM_ARCH_CACHE_H
5445
5446 +#include <linux/const.h>
5447 /* Etrax 100LX have 32-byte cache-lines. */
5448 -#define L1_CACHE_BYTES 32
5449 #define L1_CACHE_SHIFT 5
5450 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5451
5452 #endif /* _ASM_ARCH_CACHE_H */
5453 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5454 index 7caf25d..ee65ac5 100644
5455 --- a/arch/cris/include/arch-v32/arch/cache.h
5456 +++ b/arch/cris/include/arch-v32/arch/cache.h
5457 @@ -1,11 +1,12 @@
5458 #ifndef _ASM_CRIS_ARCH_CACHE_H
5459 #define _ASM_CRIS_ARCH_CACHE_H
5460
5461 +#include <linux/const.h>
5462 #include <arch/hwregs/dma.h>
5463
5464 /* A cache-line is 32 bytes. */
5465 -#define L1_CACHE_BYTES 32
5466 #define L1_CACHE_SHIFT 5
5467 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5468
5469 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5470
5471 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5472 index f6c3a16..cd422a4 100644
5473 --- a/arch/frv/include/asm/atomic.h
5474 +++ b/arch/frv/include/asm/atomic.h
5475 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5476 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5477 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5478
5479 +#define atomic64_read_unchecked(v) atomic64_read(v)
5480 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5481 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5482 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5483 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5484 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5485 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5486 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5487 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5488 +
5489 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5490 {
5491 int c, old;
5492 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5493 index 2797163..c2a401d 100644
5494 --- a/arch/frv/include/asm/cache.h
5495 +++ b/arch/frv/include/asm/cache.h
5496 @@ -12,10 +12,11 @@
5497 #ifndef __ASM_CACHE_H
5498 #define __ASM_CACHE_H
5499
5500 +#include <linux/const.h>
5501
5502 /* bytes per L1 cache line */
5503 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5504 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5505 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5506
5507 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5508 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5509 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5510 index 43901f2..0d8b865 100644
5511 --- a/arch/frv/include/asm/kmap_types.h
5512 +++ b/arch/frv/include/asm/kmap_types.h
5513 @@ -2,6 +2,6 @@
5514 #ifndef _ASM_KMAP_TYPES_H
5515 #define _ASM_KMAP_TYPES_H
5516
5517 -#define KM_TYPE_NR 17
5518 +#define KM_TYPE_NR 18
5519
5520 #endif
5521 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5522 index 836f147..4cf23f5 100644
5523 --- a/arch/frv/mm/elf-fdpic.c
5524 +++ b/arch/frv/mm/elf-fdpic.c
5525 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5526 {
5527 struct vm_area_struct *vma;
5528 struct vm_unmapped_area_info info;
5529 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5530
5531 if (len > TASK_SIZE)
5532 return -ENOMEM;
5533 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5534 if (addr) {
5535 addr = PAGE_ALIGN(addr);
5536 vma = find_vma(current->mm, addr);
5537 - if (TASK_SIZE - len >= addr &&
5538 - (!vma || addr + len <= vma->vm_start))
5539 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5540 goto success;
5541 }
5542
5543 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5544 info.high_limit = (current->mm->start_stack - 0x00200000);
5545 info.align_mask = 0;
5546 info.align_offset = 0;
5547 + info.threadstack_offset = offset;
5548 addr = vm_unmapped_area(&info);
5549 if (!(addr & ~PAGE_MASK))
5550 goto success;
5551 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5552 index f4ca594..adc72fd6 100644
5553 --- a/arch/hexagon/include/asm/cache.h
5554 +++ b/arch/hexagon/include/asm/cache.h
5555 @@ -21,9 +21,11 @@
5556 #ifndef __ASM_CACHE_H
5557 #define __ASM_CACHE_H
5558
5559 +#include <linux/const.h>
5560 +
5561 /* Bytes per L1 cache line */
5562 -#define L1_CACHE_SHIFT (5)
5563 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5564 +#define L1_CACHE_SHIFT 5
5565 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5566
5567 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5568 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5569 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5570 index 2f3abcf..e63c7fa 100644
5571 --- a/arch/ia64/Kconfig
5572 +++ b/arch/ia64/Kconfig
5573 @@ -547,6 +547,7 @@ source "drivers/sn/Kconfig"
5574 config KEXEC
5575 bool "kexec system call"
5576 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5577 + depends on !GRKERNSEC_KMEM
5578 help
5579 kexec is a system call that implements the ability to shutdown your
5580 current kernel, and to start another kernel. It is like a reboot
5581 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5582 index f37238f..810b95f 100644
5583 --- a/arch/ia64/Makefile
5584 +++ b/arch/ia64/Makefile
5585 @@ -99,5 +99,6 @@ endef
5586 archprepare: make_nr_irqs_h FORCE
5587 PHONY += make_nr_irqs_h FORCE
5588
5589 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5590 make_nr_irqs_h: FORCE
5591 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5592 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5593 index 0f8bf48..40ea950 100644
5594 --- a/arch/ia64/include/asm/atomic.h
5595 +++ b/arch/ia64/include/asm/atomic.h
5596 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5597 #define atomic64_inc(v) atomic64_add(1, (v))
5598 #define atomic64_dec(v) atomic64_sub(1, (v))
5599
5600 +#define atomic64_read_unchecked(v) atomic64_read(v)
5601 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5602 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5603 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5604 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5605 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5606 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5607 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5608 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5609 +
5610 #endif /* _ASM_IA64_ATOMIC_H */
5611 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5612 index a48957c..e097b56 100644
5613 --- a/arch/ia64/include/asm/barrier.h
5614 +++ b/arch/ia64/include/asm/barrier.h
5615 @@ -67,7 +67,7 @@
5616 do { \
5617 compiletime_assert_atomic_type(*p); \
5618 barrier(); \
5619 - ACCESS_ONCE(*p) = (v); \
5620 + ACCESS_ONCE_RW(*p) = (v); \
5621 } while (0)
5622
5623 #define smp_load_acquire(p) \
5624 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5625 index 988254a..e1ee885 100644
5626 --- a/arch/ia64/include/asm/cache.h
5627 +++ b/arch/ia64/include/asm/cache.h
5628 @@ -1,6 +1,7 @@
5629 #ifndef _ASM_IA64_CACHE_H
5630 #define _ASM_IA64_CACHE_H
5631
5632 +#include <linux/const.h>
5633
5634 /*
5635 * Copyright (C) 1998-2000 Hewlett-Packard Co
5636 @@ -9,7 +10,7 @@
5637
5638 /* Bytes per L1 (data) cache line. */
5639 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5640 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5641 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5642
5643 #ifdef CONFIG_SMP
5644 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5645 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5646 index 5a83c5c..4d7f553 100644
5647 --- a/arch/ia64/include/asm/elf.h
5648 +++ b/arch/ia64/include/asm/elf.h
5649 @@ -42,6 +42,13 @@
5650 */
5651 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5652
5653 +#ifdef CONFIG_PAX_ASLR
5654 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5655 +
5656 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5657 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5658 +#endif
5659 +
5660 #define PT_IA_64_UNWIND 0x70000001
5661
5662 /* IA-64 relocations: */
5663 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5664 index 5767cdf..7462574 100644
5665 --- a/arch/ia64/include/asm/pgalloc.h
5666 +++ b/arch/ia64/include/asm/pgalloc.h
5667 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5668 pgd_val(*pgd_entry) = __pa(pud);
5669 }
5670
5671 +static inline void
5672 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5673 +{
5674 + pgd_populate(mm, pgd_entry, pud);
5675 +}
5676 +
5677 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5678 {
5679 return quicklist_alloc(0, GFP_KERNEL, NULL);
5680 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5681 pud_val(*pud_entry) = __pa(pmd);
5682 }
5683
5684 +static inline void
5685 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5686 +{
5687 + pud_populate(mm, pud_entry, pmd);
5688 +}
5689 +
5690 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5691 {
5692 return quicklist_alloc(0, GFP_KERNEL, NULL);
5693 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5694 index 7935115..c0eca6a 100644
5695 --- a/arch/ia64/include/asm/pgtable.h
5696 +++ b/arch/ia64/include/asm/pgtable.h
5697 @@ -12,7 +12,7 @@
5698 * David Mosberger-Tang <davidm@hpl.hp.com>
5699 */
5700
5701 -
5702 +#include <linux/const.h>
5703 #include <asm/mman.h>
5704 #include <asm/page.h>
5705 #include <asm/processor.h>
5706 @@ -142,6 +142,17 @@
5707 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5708 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5709 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5710 +
5711 +#ifdef CONFIG_PAX_PAGEEXEC
5712 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5713 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5714 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5715 +#else
5716 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5717 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5718 +# define PAGE_COPY_NOEXEC PAGE_COPY
5719 +#endif
5720 +
5721 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5722 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5723 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5724 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5725 index 45698cd..e8e2dbc 100644
5726 --- a/arch/ia64/include/asm/spinlock.h
5727 +++ b/arch/ia64/include/asm/spinlock.h
5728 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5729 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5730
5731 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5732 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5733 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5734 }
5735
5736 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5737 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5738 index 449c8c0..3d4b1e9 100644
5739 --- a/arch/ia64/include/asm/uaccess.h
5740 +++ b/arch/ia64/include/asm/uaccess.h
5741 @@ -70,6 +70,7 @@
5742 && ((segment).seg == KERNEL_DS.seg \
5743 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5744 })
5745 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5746 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5747
5748 /*
5749 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5750 static inline unsigned long
5751 __copy_to_user (void __user *to, const void *from, unsigned long count)
5752 {
5753 + if (count > INT_MAX)
5754 + return count;
5755 +
5756 + if (!__builtin_constant_p(count))
5757 + check_object_size(from, count, true);
5758 +
5759 return __copy_user(to, (__force void __user *) from, count);
5760 }
5761
5762 static inline unsigned long
5763 __copy_from_user (void *to, const void __user *from, unsigned long count)
5764 {
5765 + if (count > INT_MAX)
5766 + return count;
5767 +
5768 + if (!__builtin_constant_p(count))
5769 + check_object_size(to, count, false);
5770 +
5771 return __copy_user((__force void __user *) to, from, count);
5772 }
5773
5774 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5775 ({ \
5776 void __user *__cu_to = (to); \
5777 const void *__cu_from = (from); \
5778 - long __cu_len = (n); \
5779 + unsigned long __cu_len = (n); \
5780 \
5781 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5782 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5783 + if (!__builtin_constant_p(n)) \
5784 + check_object_size(__cu_from, __cu_len, true); \
5785 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5786 + } \
5787 __cu_len; \
5788 })
5789
5790 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5791 ({ \
5792 void *__cu_to = (to); \
5793 const void __user *__cu_from = (from); \
5794 - long __cu_len = (n); \
5795 + unsigned long __cu_len = (n); \
5796 \
5797 __chk_user_ptr(__cu_from); \
5798 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5799 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5800 + if (!__builtin_constant_p(n)) \
5801 + check_object_size(__cu_to, __cu_len, false); \
5802 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5803 + } \
5804 __cu_len; \
5805 })
5806
5807 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5808 index 24603be..948052d 100644
5809 --- a/arch/ia64/kernel/module.c
5810 +++ b/arch/ia64/kernel/module.c
5811 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5812 void
5813 module_free (struct module *mod, void *module_region)
5814 {
5815 - if (mod && mod->arch.init_unw_table &&
5816 - module_region == mod->module_init) {
5817 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5818 unw_remove_unwind_table(mod->arch.init_unw_table);
5819 mod->arch.init_unw_table = NULL;
5820 }
5821 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5822 }
5823
5824 static inline int
5825 +in_init_rx (const struct module *mod, uint64_t addr)
5826 +{
5827 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5828 +}
5829 +
5830 +static inline int
5831 +in_init_rw (const struct module *mod, uint64_t addr)
5832 +{
5833 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5834 +}
5835 +
5836 +static inline int
5837 in_init (const struct module *mod, uint64_t addr)
5838 {
5839 - return addr - (uint64_t) mod->module_init < mod->init_size;
5840 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5841 +}
5842 +
5843 +static inline int
5844 +in_core_rx (const struct module *mod, uint64_t addr)
5845 +{
5846 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5847 +}
5848 +
5849 +static inline int
5850 +in_core_rw (const struct module *mod, uint64_t addr)
5851 +{
5852 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5853 }
5854
5855 static inline int
5856 in_core (const struct module *mod, uint64_t addr)
5857 {
5858 - return addr - (uint64_t) mod->module_core < mod->core_size;
5859 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5860 }
5861
5862 static inline int
5863 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5864 break;
5865
5866 case RV_BDREL:
5867 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5868 + if (in_init_rx(mod, val))
5869 + val -= (uint64_t) mod->module_init_rx;
5870 + else if (in_init_rw(mod, val))
5871 + val -= (uint64_t) mod->module_init_rw;
5872 + else if (in_core_rx(mod, val))
5873 + val -= (uint64_t) mod->module_core_rx;
5874 + else if (in_core_rw(mod, val))
5875 + val -= (uint64_t) mod->module_core_rw;
5876 break;
5877
5878 case RV_LTV:
5879 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5880 * addresses have been selected...
5881 */
5882 uint64_t gp;
5883 - if (mod->core_size > MAX_LTOFF)
5884 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5885 /*
5886 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5887 * at the end of the module.
5888 */
5889 - gp = mod->core_size - MAX_LTOFF / 2;
5890 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5891 else
5892 - gp = mod->core_size / 2;
5893 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5894 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5895 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5896 mod->arch.gp = gp;
5897 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5898 }
5899 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5900 index c39c3cd..3c77738 100644
5901 --- a/arch/ia64/kernel/palinfo.c
5902 +++ b/arch/ia64/kernel/palinfo.c
5903 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5904 return NOTIFY_OK;
5905 }
5906
5907 -static struct notifier_block __refdata palinfo_cpu_notifier =
5908 +static struct notifier_block palinfo_cpu_notifier =
5909 {
5910 .notifier_call = palinfo_cpu_callback,
5911 .priority = 0,
5912 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5913 index 41e33f8..65180b2a 100644
5914 --- a/arch/ia64/kernel/sys_ia64.c
5915 +++ b/arch/ia64/kernel/sys_ia64.c
5916 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5917 unsigned long align_mask = 0;
5918 struct mm_struct *mm = current->mm;
5919 struct vm_unmapped_area_info info;
5920 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5921
5922 if (len > RGN_MAP_LIMIT)
5923 return -ENOMEM;
5924 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5925 if (REGION_NUMBER(addr) == RGN_HPAGE)
5926 addr = 0;
5927 #endif
5928 +
5929 +#ifdef CONFIG_PAX_RANDMMAP
5930 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5931 + addr = mm->free_area_cache;
5932 + else
5933 +#endif
5934 +
5935 if (!addr)
5936 addr = TASK_UNMAPPED_BASE;
5937
5938 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5939 info.high_limit = TASK_SIZE;
5940 info.align_mask = align_mask;
5941 info.align_offset = 0;
5942 + info.threadstack_offset = offset;
5943 return vm_unmapped_area(&info);
5944 }
5945
5946 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5947 index 84f8a52..7c76178 100644
5948 --- a/arch/ia64/kernel/vmlinux.lds.S
5949 +++ b/arch/ia64/kernel/vmlinux.lds.S
5950 @@ -192,7 +192,7 @@ SECTIONS {
5951 /* Per-cpu data: */
5952 . = ALIGN(PERCPU_PAGE_SIZE);
5953 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5954 - __phys_per_cpu_start = __per_cpu_load;
5955 + __phys_per_cpu_start = per_cpu_load;
5956 /*
5957 * ensure percpu data fits
5958 * into percpu page size
5959 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5960 index 7225dad..2a7c8256 100644
5961 --- a/arch/ia64/mm/fault.c
5962 +++ b/arch/ia64/mm/fault.c
5963 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5964 return pte_present(pte);
5965 }
5966
5967 +#ifdef CONFIG_PAX_PAGEEXEC
5968 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5969 +{
5970 + unsigned long i;
5971 +
5972 + printk(KERN_ERR "PAX: bytes at PC: ");
5973 + for (i = 0; i < 8; i++) {
5974 + unsigned int c;
5975 + if (get_user(c, (unsigned int *)pc+i))
5976 + printk(KERN_CONT "???????? ");
5977 + else
5978 + printk(KERN_CONT "%08x ", c);
5979 + }
5980 + printk("\n");
5981 +}
5982 +#endif
5983 +
5984 # define VM_READ_BIT 0
5985 # define VM_WRITE_BIT 1
5986 # define VM_EXEC_BIT 2
5987 @@ -151,8 +168,21 @@ retry:
5988 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5989 goto bad_area;
5990
5991 - if ((vma->vm_flags & mask) != mask)
5992 + if ((vma->vm_flags & mask) != mask) {
5993 +
5994 +#ifdef CONFIG_PAX_PAGEEXEC
5995 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5996 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5997 + goto bad_area;
5998 +
5999 + up_read(&mm->mmap_sem);
6000 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
6001 + do_group_exit(SIGKILL);
6002 + }
6003 +#endif
6004 +
6005 goto bad_area;
6006 + }
6007
6008 /*
6009 * If for any reason at all we couldn't handle the fault, make
6010 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
6011 index 76069c1..c2aa816 100644
6012 --- a/arch/ia64/mm/hugetlbpage.c
6013 +++ b/arch/ia64/mm/hugetlbpage.c
6014 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
6015 unsigned long pgoff, unsigned long flags)
6016 {
6017 struct vm_unmapped_area_info info;
6018 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
6019
6020 if (len > RGN_MAP_LIMIT)
6021 return -ENOMEM;
6022 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
6023 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
6024 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
6025 info.align_offset = 0;
6026 + info.threadstack_offset = offset;
6027 return vm_unmapped_area(&info);
6028 }
6029
6030 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
6031 index 25c3502..560dae7 100644
6032 --- a/arch/ia64/mm/init.c
6033 +++ b/arch/ia64/mm/init.c
6034 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
6035 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
6036 vma->vm_end = vma->vm_start + PAGE_SIZE;
6037 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
6038 +
6039 +#ifdef CONFIG_PAX_PAGEEXEC
6040 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
6041 + vma->vm_flags &= ~VM_EXEC;
6042 +
6043 +#ifdef CONFIG_PAX_MPROTECT
6044 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
6045 + vma->vm_flags &= ~VM_MAYEXEC;
6046 +#endif
6047 +
6048 + }
6049 +#endif
6050 +
6051 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6052 down_write(&current->mm->mmap_sem);
6053 if (insert_vm_struct(current->mm, vma)) {
6054 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
6055 index 40b3ee9..8c2c112 100644
6056 --- a/arch/m32r/include/asm/cache.h
6057 +++ b/arch/m32r/include/asm/cache.h
6058 @@ -1,8 +1,10 @@
6059 #ifndef _ASM_M32R_CACHE_H
6060 #define _ASM_M32R_CACHE_H
6061
6062 +#include <linux/const.h>
6063 +
6064 /* L1 cache line size */
6065 #define L1_CACHE_SHIFT 4
6066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6067 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6068
6069 #endif /* _ASM_M32R_CACHE_H */
6070 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
6071 index 82abd15..d95ae5d 100644
6072 --- a/arch/m32r/lib/usercopy.c
6073 +++ b/arch/m32r/lib/usercopy.c
6074 @@ -14,6 +14,9 @@
6075 unsigned long
6076 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6077 {
6078 + if ((long)n < 0)
6079 + return n;
6080 +
6081 prefetch(from);
6082 if (access_ok(VERIFY_WRITE, to, n))
6083 __copy_user(to,from,n);
6084 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
6085 unsigned long
6086 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
6087 {
6088 + if ((long)n < 0)
6089 + return n;
6090 +
6091 prefetchw(to);
6092 if (access_ok(VERIFY_READ, from, n))
6093 __copy_user_zeroing(to,from,n);
6094 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
6095 index 0395c51..5f26031 100644
6096 --- a/arch/m68k/include/asm/cache.h
6097 +++ b/arch/m68k/include/asm/cache.h
6098 @@ -4,9 +4,11 @@
6099 #ifndef __ARCH_M68K_CACHE_H
6100 #define __ARCH_M68K_CACHE_H
6101
6102 +#include <linux/const.h>
6103 +
6104 /* bytes per L1 cache line */
6105 #define L1_CACHE_SHIFT 4
6106 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
6107 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6108
6109 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
6110
6111 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
6112 index c7591e8..ecef036 100644
6113 --- a/arch/metag/include/asm/barrier.h
6114 +++ b/arch/metag/include/asm/barrier.h
6115 @@ -89,7 +89,7 @@ static inline void fence(void)
6116 do { \
6117 compiletime_assert_atomic_type(*p); \
6118 smp_mb(); \
6119 - ACCESS_ONCE(*p) = (v); \
6120 + ACCESS_ONCE_RW(*p) = (v); \
6121 } while (0)
6122
6123 #define smp_load_acquire(p) \
6124 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
6125 index 3c52fa6..11b2ad8 100644
6126 --- a/arch/metag/mm/hugetlbpage.c
6127 +++ b/arch/metag/mm/hugetlbpage.c
6128 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
6129 info.high_limit = TASK_SIZE;
6130 info.align_mask = PAGE_MASK & HUGEPT_MASK;
6131 info.align_offset = 0;
6132 + info.threadstack_offset = 0;
6133 return vm_unmapped_area(&info);
6134 }
6135
6136 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
6137 index 4efe96a..60e8699 100644
6138 --- a/arch/microblaze/include/asm/cache.h
6139 +++ b/arch/microblaze/include/asm/cache.h
6140 @@ -13,11 +13,12 @@
6141 #ifndef _ASM_MICROBLAZE_CACHE_H
6142 #define _ASM_MICROBLAZE_CACHE_H
6143
6144 +#include <linux/const.h>
6145 #include <asm/registers.h>
6146
6147 #define L1_CACHE_SHIFT 5
6148 /* word-granular cache in microblaze */
6149 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6150 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6151
6152 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6153
6154 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
6155 index 4e238e6..7c9ed92 100644
6156 --- a/arch/mips/Kconfig
6157 +++ b/arch/mips/Kconfig
6158 @@ -2392,6 +2392,7 @@ source "kernel/Kconfig.preempt"
6159
6160 config KEXEC
6161 bool "Kexec system call"
6162 + depends on !GRKERNSEC_KMEM
6163 help
6164 kexec is a system call that implements the ability to shutdown your
6165 current kernel, and to start another kernel. It is like a reboot
6166 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
6167 index 02f2444..506969c 100644
6168 --- a/arch/mips/cavium-octeon/dma-octeon.c
6169 +++ b/arch/mips/cavium-octeon/dma-octeon.c
6170 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
6171 if (dma_release_from_coherent(dev, order, vaddr))
6172 return;
6173
6174 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
6175 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
6176 }
6177
6178 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
6179 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
6180 index 37b2bef..02122b8 100644
6181 --- a/arch/mips/include/asm/atomic.h
6182 +++ b/arch/mips/include/asm/atomic.h
6183 @@ -21,15 +21,39 @@
6184 #include <asm/cmpxchg.h>
6185 #include <asm/war.h>
6186
6187 +#ifdef CONFIG_GENERIC_ATOMIC64
6188 +#include <asm-generic/atomic64.h>
6189 +#endif
6190 +
6191 #define ATOMIC_INIT(i) { (i) }
6192
6193 +#ifdef CONFIG_64BIT
6194 +#define _ASM_EXTABLE(from, to) \
6195 +" .section __ex_table,\"a\"\n" \
6196 +" .dword " #from ", " #to"\n" \
6197 +" .previous\n"
6198 +#else
6199 +#define _ASM_EXTABLE(from, to) \
6200 +" .section __ex_table,\"a\"\n" \
6201 +" .word " #from ", " #to"\n" \
6202 +" .previous\n"
6203 +#endif
6204 +
6205 /*
6206 * atomic_read - read atomic variable
6207 * @v: pointer of type atomic_t
6208 *
6209 * Atomically reads the value of @v.
6210 */
6211 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
6212 +static inline int atomic_read(const atomic_t *v)
6213 +{
6214 + return (*(volatile const int *) &v->counter);
6215 +}
6216 +
6217 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6218 +{
6219 + return (*(volatile const int *) &v->counter);
6220 +}
6221
6222 /*
6223 * atomic_set - set atomic variable
6224 @@ -38,7 +62,15 @@
6225 *
6226 * Atomically sets the value of @v to @i.
6227 */
6228 -#define atomic_set(v, i) ((v)->counter = (i))
6229 +static inline void atomic_set(atomic_t *v, int i)
6230 +{
6231 + v->counter = i;
6232 +}
6233 +
6234 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6235 +{
6236 + v->counter = i;
6237 +}
6238
6239 /*
6240 * atomic_add - add integer to atomic variable
6241 @@ -47,7 +79,67 @@
6242 *
6243 * Atomically adds @i to @v.
6244 */
6245 -static __inline__ void atomic_add(int i, atomic_t * v)
6246 +static __inline__ void atomic_add(int i, atomic_t *v)
6247 +{
6248 + int temp;
6249 +
6250 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6251 + __asm__ __volatile__(
6252 + " .set mips3 \n"
6253 + "1: ll %0, %1 # atomic_add \n"
6254 +#ifdef CONFIG_PAX_REFCOUNT
6255 + /* Exception on overflow. */
6256 + "2: add %0, %2 \n"
6257 +#else
6258 + " addu %0, %2 \n"
6259 +#endif
6260 + " sc %0, %1 \n"
6261 + " beqzl %0, 1b \n"
6262 +#ifdef CONFIG_PAX_REFCOUNT
6263 + "3: \n"
6264 + _ASM_EXTABLE(2b, 3b)
6265 +#endif
6266 + " .set mips0 \n"
6267 + : "=&r" (temp), "+m" (v->counter)
6268 + : "Ir" (i));
6269 + } else if (kernel_uses_llsc) {
6270 + __asm__ __volatile__(
6271 + " .set mips3 \n"
6272 + "1: ll %0, %1 # atomic_add \n"
6273 +#ifdef CONFIG_PAX_REFCOUNT
6274 + /* Exception on overflow. */
6275 + "2: add %0, %2 \n"
6276 +#else
6277 + " addu %0, %2 \n"
6278 +#endif
6279 + " sc %0, %1 \n"
6280 + " beqz %0, 1b \n"
6281 +#ifdef CONFIG_PAX_REFCOUNT
6282 + "3: \n"
6283 + _ASM_EXTABLE(2b, 3b)
6284 +#endif
6285 + " .set mips0 \n"
6286 + : "=&r" (temp), "+m" (v->counter)
6287 + : "Ir" (i));
6288 + } else {
6289 + unsigned long flags;
6290 +
6291 + raw_local_irq_save(flags);
6292 + __asm__ __volatile__(
6293 +#ifdef CONFIG_PAX_REFCOUNT
6294 + /* Exception on overflow. */
6295 + "1: add %0, %1 \n"
6296 + "2: \n"
6297 + _ASM_EXTABLE(1b, 2b)
6298 +#else
6299 + " addu %0, %1 \n"
6300 +#endif
6301 + : "+r" (v->counter) : "Ir" (i));
6302 + raw_local_irq_restore(flags);
6303 + }
6304 +}
6305 +
6306 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6307 {
6308 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6309 int temp;
6310 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
6311 *
6312 * Atomically subtracts @i from @v.
6313 */
6314 -static __inline__ void atomic_sub(int i, atomic_t * v)
6315 +static __inline__ void atomic_sub(int i, atomic_t *v)
6316 +{
6317 + int temp;
6318 +
6319 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6320 + __asm__ __volatile__(
6321 + " .set mips3 \n"
6322 + "1: ll %0, %1 # atomic64_sub \n"
6323 +#ifdef CONFIG_PAX_REFCOUNT
6324 + /* Exception on overflow. */
6325 + "2: sub %0, %2 \n"
6326 +#else
6327 + " subu %0, %2 \n"
6328 +#endif
6329 + " sc %0, %1 \n"
6330 + " beqzl %0, 1b \n"
6331 +#ifdef CONFIG_PAX_REFCOUNT
6332 + "3: \n"
6333 + _ASM_EXTABLE(2b, 3b)
6334 +#endif
6335 + " .set mips0 \n"
6336 + : "=&r" (temp), "+m" (v->counter)
6337 + : "Ir" (i));
6338 + } else if (kernel_uses_llsc) {
6339 + __asm__ __volatile__(
6340 + " .set mips3 \n"
6341 + "1: ll %0, %1 # atomic64_sub \n"
6342 +#ifdef CONFIG_PAX_REFCOUNT
6343 + /* Exception on overflow. */
6344 + "2: sub %0, %2 \n"
6345 +#else
6346 + " subu %0, %2 \n"
6347 +#endif
6348 + " sc %0, %1 \n"
6349 + " beqz %0, 1b \n"
6350 +#ifdef CONFIG_PAX_REFCOUNT
6351 + "3: \n"
6352 + _ASM_EXTABLE(2b, 3b)
6353 +#endif
6354 + " .set mips0 \n"
6355 + : "=&r" (temp), "+m" (v->counter)
6356 + : "Ir" (i));
6357 + } else {
6358 + unsigned long flags;
6359 +
6360 + raw_local_irq_save(flags);
6361 + __asm__ __volatile__(
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + /* Exception on overflow. */
6364 + "1: sub %0, %1 \n"
6365 + "2: \n"
6366 + _ASM_EXTABLE(1b, 2b)
6367 +#else
6368 + " subu %0, %1 \n"
6369 +#endif
6370 + : "+r" (v->counter) : "Ir" (i));
6371 + raw_local_irq_restore(flags);
6372 + }
6373 +}
6374 +
6375 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6376 {
6377 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6378 int temp;
6379 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6380 /*
6381 * Same as above, but return the result value
6382 */
6383 -static __inline__ int atomic_add_return(int i, atomic_t * v)
6384 +static __inline__ int atomic_add_return(int i, atomic_t *v)
6385 +{
6386 + int result;
6387 + int temp;
6388 +
6389 + smp_mb__before_llsc();
6390 +
6391 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6392 + __asm__ __volatile__(
6393 + " .set mips3 \n"
6394 + "1: ll %1, %2 # atomic_add_return \n"
6395 +#ifdef CONFIG_PAX_REFCOUNT
6396 + "2: add %0, %1, %3 \n"
6397 +#else
6398 + " addu %0, %1, %3 \n"
6399 +#endif
6400 + " sc %0, %2 \n"
6401 + " beqzl %0, 1b \n"
6402 +#ifdef CONFIG_PAX_REFCOUNT
6403 + " b 4f \n"
6404 + " .set noreorder \n"
6405 + "3: b 5f \n"
6406 + " move %0, %1 \n"
6407 + " .set reorder \n"
6408 + _ASM_EXTABLE(2b, 3b)
6409 +#endif
6410 + "4: addu %0, %1, %3 \n"
6411 +#ifdef CONFIG_PAX_REFCOUNT
6412 + "5: \n"
6413 +#endif
6414 + " .set mips0 \n"
6415 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6416 + : "Ir" (i));
6417 + } else if (kernel_uses_llsc) {
6418 + __asm__ __volatile__(
6419 + " .set mips3 \n"
6420 + "1: ll %1, %2 # atomic_add_return \n"
6421 +#ifdef CONFIG_PAX_REFCOUNT
6422 + "2: add %0, %1, %3 \n"
6423 +#else
6424 + " addu %0, %1, %3 \n"
6425 +#endif
6426 + " sc %0, %2 \n"
6427 + " bnez %0, 4f \n"
6428 + " b 1b \n"
6429 +#ifdef CONFIG_PAX_REFCOUNT
6430 + " .set noreorder \n"
6431 + "3: b 5f \n"
6432 + " move %0, %1 \n"
6433 + " .set reorder \n"
6434 + _ASM_EXTABLE(2b, 3b)
6435 +#endif
6436 + "4: addu %0, %1, %3 \n"
6437 +#ifdef CONFIG_PAX_REFCOUNT
6438 + "5: \n"
6439 +#endif
6440 + " .set mips0 \n"
6441 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6442 + : "Ir" (i));
6443 + } else {
6444 + unsigned long flags;
6445 +
6446 + raw_local_irq_save(flags);
6447 + __asm__ __volatile__(
6448 + " lw %0, %1 \n"
6449 +#ifdef CONFIG_PAX_REFCOUNT
6450 + /* Exception on overflow. */
6451 + "1: add %0, %2 \n"
6452 +#else
6453 + " addu %0, %2 \n"
6454 +#endif
6455 + " sw %0, %1 \n"
6456 +#ifdef CONFIG_PAX_REFCOUNT
6457 + /* Note: Dest reg is not modified on overflow */
6458 + "2: \n"
6459 + _ASM_EXTABLE(1b, 2b)
6460 +#endif
6461 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6462 + raw_local_irq_restore(flags);
6463 + }
6464 +
6465 + smp_llsc_mb();
6466 +
6467 + return result;
6468 +}
6469 +
6470 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6471 {
6472 int result;
6473
6474 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6475 return result;
6476 }
6477
6478 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6479 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6480 +{
6481 + int result;
6482 + int temp;
6483 +
6484 + smp_mb__before_llsc();
6485 +
6486 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6487 + __asm__ __volatile__(
6488 + " .set mips3 \n"
6489 + "1: ll %1, %2 # atomic_sub_return \n"
6490 +#ifdef CONFIG_PAX_REFCOUNT
6491 + "2: sub %0, %1, %3 \n"
6492 +#else
6493 + " subu %0, %1, %3 \n"
6494 +#endif
6495 + " sc %0, %2 \n"
6496 + " beqzl %0, 1b \n"
6497 +#ifdef CONFIG_PAX_REFCOUNT
6498 + " b 4f \n"
6499 + " .set noreorder \n"
6500 + "3: b 5f \n"
6501 + " move %0, %1 \n"
6502 + " .set reorder \n"
6503 + _ASM_EXTABLE(2b, 3b)
6504 +#endif
6505 + "4: subu %0, %1, %3 \n"
6506 +#ifdef CONFIG_PAX_REFCOUNT
6507 + "5: \n"
6508 +#endif
6509 + " .set mips0 \n"
6510 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6511 + : "Ir" (i), "m" (v->counter)
6512 + : "memory");
6513 + } else if (kernel_uses_llsc) {
6514 + __asm__ __volatile__(
6515 + " .set mips3 \n"
6516 + "1: ll %1, %2 # atomic_sub_return \n"
6517 +#ifdef CONFIG_PAX_REFCOUNT
6518 + "2: sub %0, %1, %3 \n"
6519 +#else
6520 + " subu %0, %1, %3 \n"
6521 +#endif
6522 + " sc %0, %2 \n"
6523 + " bnez %0, 4f \n"
6524 + " b 1b \n"
6525 +#ifdef CONFIG_PAX_REFCOUNT
6526 + " .set noreorder \n"
6527 + "3: b 5f \n"
6528 + " move %0, %1 \n"
6529 + " .set reorder \n"
6530 + _ASM_EXTABLE(2b, 3b)
6531 +#endif
6532 + "4: subu %0, %1, %3 \n"
6533 +#ifdef CONFIG_PAX_REFCOUNT
6534 + "5: \n"
6535 +#endif
6536 + " .set mips0 \n"
6537 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6538 + : "Ir" (i));
6539 + } else {
6540 + unsigned long flags;
6541 +
6542 + raw_local_irq_save(flags);
6543 + __asm__ __volatile__(
6544 + " lw %0, %1 \n"
6545 +#ifdef CONFIG_PAX_REFCOUNT
6546 + /* Exception on overflow. */
6547 + "1: sub %0, %2 \n"
6548 +#else
6549 + " subu %0, %2 \n"
6550 +#endif
6551 + " sw %0, %1 \n"
6552 +#ifdef CONFIG_PAX_REFCOUNT
6553 + /* Note: Dest reg is not modified on overflow */
6554 + "2: \n"
6555 + _ASM_EXTABLE(1b, 2b)
6556 +#endif
6557 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6558 + raw_local_irq_restore(flags);
6559 + }
6560 +
6561 + smp_llsc_mb();
6562 +
6563 + return result;
6564 +}
6565 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6566 {
6567 int result;
6568
6569 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6570 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6571 * The function returns the old value of @v minus @i.
6572 */
6573 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6574 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6575 {
6576 int result;
6577
6578 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6579 return result;
6580 }
6581
6582 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6583 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6584 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6585 +{
6586 + return cmpxchg(&v->counter, old, new);
6587 +}
6588 +
6589 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6590 + int new)
6591 +{
6592 + return cmpxchg(&(v->counter), old, new);
6593 +}
6594 +
6595 +static inline int atomic_xchg(atomic_t *v, int new)
6596 +{
6597 + return xchg(&v->counter, new);
6598 +}
6599 +
6600 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6601 +{
6602 + return xchg(&(v->counter), new);
6603 +}
6604
6605 /**
6606 * __atomic_add_unless - add unless the number is a given value
6607 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6608
6609 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6610 #define atomic_inc_return(v) atomic_add_return(1, (v))
6611 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6612 +{
6613 + return atomic_add_return_unchecked(1, v);
6614 +}
6615
6616 /*
6617 * atomic_sub_and_test - subtract value from variable and test result
6618 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6619 * other cases.
6620 */
6621 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6622 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6623 +{
6624 + return atomic_add_return_unchecked(1, v) == 0;
6625 +}
6626
6627 /*
6628 * atomic_dec_and_test - decrement by 1 and test
6629 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6630 * Atomically increments @v by 1.
6631 */
6632 #define atomic_inc(v) atomic_add(1, (v))
6633 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6634 +{
6635 + atomic_add_unchecked(1, v);
6636 +}
6637
6638 /*
6639 * atomic_dec - decrement and test
6640 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6641 * Atomically decrements @v by 1.
6642 */
6643 #define atomic_dec(v) atomic_sub(1, (v))
6644 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6645 +{
6646 + atomic_sub_unchecked(1, v);
6647 +}
6648
6649 /*
6650 * atomic_add_negative - add and test if negative
6651 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6652 * @v: pointer of type atomic64_t
6653 *
6654 */
6655 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6656 +static inline long atomic64_read(const atomic64_t *v)
6657 +{
6658 + return (*(volatile const long *) &v->counter);
6659 +}
6660 +
6661 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6662 +{
6663 + return (*(volatile const long *) &v->counter);
6664 +}
6665
6666 /*
6667 * atomic64_set - set atomic variable
6668 * @v: pointer of type atomic64_t
6669 * @i: required value
6670 */
6671 -#define atomic64_set(v, i) ((v)->counter = (i))
6672 +static inline void atomic64_set(atomic64_t *v, long i)
6673 +{
6674 + v->counter = i;
6675 +}
6676 +
6677 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6678 +{
6679 + v->counter = i;
6680 +}
6681
6682 /*
6683 * atomic64_add - add integer to atomic variable
6684 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6685 *
6686 * Atomically adds @i to @v.
6687 */
6688 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6689 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6690 +{
6691 + long temp;
6692 +
6693 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6694 + __asm__ __volatile__(
6695 + " .set mips3 \n"
6696 + "1: lld %0, %1 # atomic64_add \n"
6697 +#ifdef CONFIG_PAX_REFCOUNT
6698 + /* Exception on overflow. */
6699 + "2: dadd %0, %2 \n"
6700 +#else
6701 + " daddu %0, %2 \n"
6702 +#endif
6703 + " scd %0, %1 \n"
6704 + " beqzl %0, 1b \n"
6705 +#ifdef CONFIG_PAX_REFCOUNT
6706 + "3: \n"
6707 + _ASM_EXTABLE(2b, 3b)
6708 +#endif
6709 + " .set mips0 \n"
6710 + : "=&r" (temp), "+m" (v->counter)
6711 + : "Ir" (i));
6712 + } else if (kernel_uses_llsc) {
6713 + __asm__ __volatile__(
6714 + " .set mips3 \n"
6715 + "1: lld %0, %1 # atomic64_add \n"
6716 +#ifdef CONFIG_PAX_REFCOUNT
6717 + /* Exception on overflow. */
6718 + "2: dadd %0, %2 \n"
6719 +#else
6720 + " daddu %0, %2 \n"
6721 +#endif
6722 + " scd %0, %1 \n"
6723 + " beqz %0, 1b \n"
6724 +#ifdef CONFIG_PAX_REFCOUNT
6725 + "3: \n"
6726 + _ASM_EXTABLE(2b, 3b)
6727 +#endif
6728 + " .set mips0 \n"
6729 + : "=&r" (temp), "+m" (v->counter)
6730 + : "Ir" (i));
6731 + } else {
6732 + unsigned long flags;
6733 +
6734 + raw_local_irq_save(flags);
6735 + __asm__ __volatile__(
6736 +#ifdef CONFIG_PAX_REFCOUNT
6737 + /* Exception on overflow. */
6738 + "1: dadd %0, %1 \n"
6739 + "2: \n"
6740 + _ASM_EXTABLE(1b, 2b)
6741 +#else
6742 + " daddu %0, %1 \n"
6743 +#endif
6744 + : "+r" (v->counter) : "Ir" (i));
6745 + raw_local_irq_restore(flags);
6746 + }
6747 +}
6748 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6749 {
6750 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6751 long temp;
6752 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6753 *
6754 * Atomically subtracts @i from @v.
6755 */
6756 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6757 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6758 +{
6759 + long temp;
6760 +
6761 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6762 + __asm__ __volatile__(
6763 + " .set mips3 \n"
6764 + "1: lld %0, %1 # atomic64_sub \n"
6765 +#ifdef CONFIG_PAX_REFCOUNT
6766 + /* Exception on overflow. */
6767 + "2: dsub %0, %2 \n"
6768 +#else
6769 + " dsubu %0, %2 \n"
6770 +#endif
6771 + " scd %0, %1 \n"
6772 + " beqzl %0, 1b \n"
6773 +#ifdef CONFIG_PAX_REFCOUNT
6774 + "3: \n"
6775 + _ASM_EXTABLE(2b, 3b)
6776 +#endif
6777 + " .set mips0 \n"
6778 + : "=&r" (temp), "+m" (v->counter)
6779 + : "Ir" (i));
6780 + } else if (kernel_uses_llsc) {
6781 + __asm__ __volatile__(
6782 + " .set mips3 \n"
6783 + "1: lld %0, %1 # atomic64_sub \n"
6784 +#ifdef CONFIG_PAX_REFCOUNT
6785 + /* Exception on overflow. */
6786 + "2: dsub %0, %2 \n"
6787 +#else
6788 + " dsubu %0, %2 \n"
6789 +#endif
6790 + " scd %0, %1 \n"
6791 + " beqz %0, 1b \n"
6792 +#ifdef CONFIG_PAX_REFCOUNT
6793 + "3: \n"
6794 + _ASM_EXTABLE(2b, 3b)
6795 +#endif
6796 + " .set mips0 \n"
6797 + : "=&r" (temp), "+m" (v->counter)
6798 + : "Ir" (i));
6799 + } else {
6800 + unsigned long flags;
6801 +
6802 + raw_local_irq_save(flags);
6803 + __asm__ __volatile__(
6804 +#ifdef CONFIG_PAX_REFCOUNT
6805 + /* Exception on overflow. */
6806 + "1: dsub %0, %1 \n"
6807 + "2: \n"
6808 + _ASM_EXTABLE(1b, 2b)
6809 +#else
6810 + " dsubu %0, %1 \n"
6811 +#endif
6812 + : "+r" (v->counter) : "Ir" (i));
6813 + raw_local_irq_restore(flags);
6814 + }
6815 +}
6816 +
6817 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6818 {
6819 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6820 long temp;
6821 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6822 /*
6823 * Same as above, but return the result value
6824 */
6825 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6826 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6827 +{
6828 + long result;
6829 + long temp;
6830 +
6831 + smp_mb__before_llsc();
6832 +
6833 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6834 + __asm__ __volatile__(
6835 + " .set mips3 \n"
6836 + "1: lld %1, %2 # atomic64_add_return \n"
6837 +#ifdef CONFIG_PAX_REFCOUNT
6838 + "2: dadd %0, %1, %3 \n"
6839 +#else
6840 + " daddu %0, %1, %3 \n"
6841 +#endif
6842 + " scd %0, %2 \n"
6843 + " beqzl %0, 1b \n"
6844 +#ifdef CONFIG_PAX_REFCOUNT
6845 + " b 4f \n"
6846 + " .set noreorder \n"
6847 + "3: b 5f \n"
6848 + " move %0, %1 \n"
6849 + " .set reorder \n"
6850 + _ASM_EXTABLE(2b, 3b)
6851 +#endif
6852 + "4: daddu %0, %1, %3 \n"
6853 +#ifdef CONFIG_PAX_REFCOUNT
6854 + "5: \n"
6855 +#endif
6856 + " .set mips0 \n"
6857 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6858 + : "Ir" (i));
6859 + } else if (kernel_uses_llsc) {
6860 + __asm__ __volatile__(
6861 + " .set mips3 \n"
6862 + "1: lld %1, %2 # atomic64_add_return \n"
6863 +#ifdef CONFIG_PAX_REFCOUNT
6864 + "2: dadd %0, %1, %3 \n"
6865 +#else
6866 + " daddu %0, %1, %3 \n"
6867 +#endif
6868 + " scd %0, %2 \n"
6869 + " bnez %0, 4f \n"
6870 + " b 1b \n"
6871 +#ifdef CONFIG_PAX_REFCOUNT
6872 + " .set noreorder \n"
6873 + "3: b 5f \n"
6874 + " move %0, %1 \n"
6875 + " .set reorder \n"
6876 + _ASM_EXTABLE(2b, 3b)
6877 +#endif
6878 + "4: daddu %0, %1, %3 \n"
6879 +#ifdef CONFIG_PAX_REFCOUNT
6880 + "5: \n"
6881 +#endif
6882 + " .set mips0 \n"
6883 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6884 + : "Ir" (i), "m" (v->counter)
6885 + : "memory");
6886 + } else {
6887 + unsigned long flags;
6888 +
6889 + raw_local_irq_save(flags);
6890 + __asm__ __volatile__(
6891 + " ld %0, %1 \n"
6892 +#ifdef CONFIG_PAX_REFCOUNT
6893 + /* Exception on overflow. */
6894 + "1: dadd %0, %2 \n"
6895 +#else
6896 + " daddu %0, %2 \n"
6897 +#endif
6898 + " sd %0, %1 \n"
6899 +#ifdef CONFIG_PAX_REFCOUNT
6900 + /* Note: Dest reg is not modified on overflow */
6901 + "2: \n"
6902 + _ASM_EXTABLE(1b, 2b)
6903 +#endif
6904 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6905 + raw_local_irq_restore(flags);
6906 + }
6907 +
6908 + smp_llsc_mb();
6909 +
6910 + return result;
6911 +}
6912 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6913 {
6914 long result;
6915
6916 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6917 return result;
6918 }
6919
6920 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6921 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6922 +{
6923 + long result;
6924 + long temp;
6925 +
6926 + smp_mb__before_llsc();
6927 +
6928 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6929 + long temp;
6930 +
6931 + __asm__ __volatile__(
6932 + " .set mips3 \n"
6933 + "1: lld %1, %2 # atomic64_sub_return \n"
6934 +#ifdef CONFIG_PAX_REFCOUNT
6935 + "2: dsub %0, %1, %3 \n"
6936 +#else
6937 + " dsubu %0, %1, %3 \n"
6938 +#endif
6939 + " scd %0, %2 \n"
6940 + " beqzl %0, 1b \n"
6941 +#ifdef CONFIG_PAX_REFCOUNT
6942 + " b 4f \n"
6943 + " .set noreorder \n"
6944 + "3: b 5f \n"
6945 + " move %0, %1 \n"
6946 + " .set reorder \n"
6947 + _ASM_EXTABLE(2b, 3b)
6948 +#endif
6949 + "4: dsubu %0, %1, %3 \n"
6950 +#ifdef CONFIG_PAX_REFCOUNT
6951 + "5: \n"
6952 +#endif
6953 + " .set mips0 \n"
6954 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6955 + : "Ir" (i), "m" (v->counter)
6956 + : "memory");
6957 + } else if (kernel_uses_llsc) {
6958 + __asm__ __volatile__(
6959 + " .set mips3 \n"
6960 + "1: lld %1, %2 # atomic64_sub_return \n"
6961 +#ifdef CONFIG_PAX_REFCOUNT
6962 + "2: dsub %0, %1, %3 \n"
6963 +#else
6964 + " dsubu %0, %1, %3 \n"
6965 +#endif
6966 + " scd %0, %2 \n"
6967 + " bnez %0, 4f \n"
6968 + " b 1b \n"
6969 +#ifdef CONFIG_PAX_REFCOUNT
6970 + " .set noreorder \n"
6971 + "3: b 5f \n"
6972 + " move %0, %1 \n"
6973 + " .set reorder \n"
6974 + _ASM_EXTABLE(2b, 3b)
6975 +#endif
6976 + "4: dsubu %0, %1, %3 \n"
6977 +#ifdef CONFIG_PAX_REFCOUNT
6978 + "5: \n"
6979 +#endif
6980 + " .set mips0 \n"
6981 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6982 + : "Ir" (i), "m" (v->counter)
6983 + : "memory");
6984 + } else {
6985 + unsigned long flags;
6986 +
6987 + raw_local_irq_save(flags);
6988 + __asm__ __volatile__(
6989 + " ld %0, %1 \n"
6990 +#ifdef CONFIG_PAX_REFCOUNT
6991 + /* Exception on overflow. */
6992 + "1: dsub %0, %2 \n"
6993 +#else
6994 + " dsubu %0, %2 \n"
6995 +#endif
6996 + " sd %0, %1 \n"
6997 +#ifdef CONFIG_PAX_REFCOUNT
6998 + /* Note: Dest reg is not modified on overflow */
6999 + "2: \n"
7000 + _ASM_EXTABLE(1b, 2b)
7001 +#endif
7002 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
7003 + raw_local_irq_restore(flags);
7004 + }
7005 +
7006 + smp_llsc_mb();
7007 +
7008 + return result;
7009 +}
7010 +
7011 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
7012 {
7013 long result;
7014
7015 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
7016 * Atomically test @v and subtract @i if @v is greater or equal than @i.
7017 * The function returns the old value of @v minus @i.
7018 */
7019 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
7020 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
7021 {
7022 long result;
7023
7024 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
7025 return result;
7026 }
7027
7028 -#define atomic64_cmpxchg(v, o, n) \
7029 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7030 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
7031 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7032 +{
7033 + return cmpxchg(&v->counter, old, new);
7034 +}
7035 +
7036 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
7037 + long new)
7038 +{
7039 + return cmpxchg(&(v->counter), old, new);
7040 +}
7041 +
7042 +static inline long atomic64_xchg(atomic64_t *v, long new)
7043 +{
7044 + return xchg(&v->counter, new);
7045 +}
7046 +
7047 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7048 +{
7049 + return xchg(&(v->counter), new);
7050 +}
7051
7052 /**
7053 * atomic64_add_unless - add unless the number is a given value
7054 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7055
7056 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
7057 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
7058 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
7059
7060 /*
7061 * atomic64_sub_and_test - subtract value from variable and test result
7062 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7063 * other cases.
7064 */
7065 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7066 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
7067
7068 /*
7069 * atomic64_dec_and_test - decrement by 1 and test
7070 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7071 * Atomically increments @v by 1.
7072 */
7073 #define atomic64_inc(v) atomic64_add(1, (v))
7074 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
7075
7076 /*
7077 * atomic64_dec - decrement and test
7078 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
7079 * Atomically decrements @v by 1.
7080 */
7081 #define atomic64_dec(v) atomic64_sub(1, (v))
7082 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
7083
7084 /*
7085 * atomic64_add_negative - add and test if negative
7086 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
7087 index d0101dd..266982c 100644
7088 --- a/arch/mips/include/asm/barrier.h
7089 +++ b/arch/mips/include/asm/barrier.h
7090 @@ -184,7 +184,7 @@
7091 do { \
7092 compiletime_assert_atomic_type(*p); \
7093 smp_mb(); \
7094 - ACCESS_ONCE(*p) = (v); \
7095 + ACCESS_ONCE_RW(*p) = (v); \
7096 } while (0)
7097
7098 #define smp_load_acquire(p) \
7099 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
7100 index b4db69f..8f3b093 100644
7101 --- a/arch/mips/include/asm/cache.h
7102 +++ b/arch/mips/include/asm/cache.h
7103 @@ -9,10 +9,11 @@
7104 #ifndef _ASM_CACHE_H
7105 #define _ASM_CACHE_H
7106
7107 +#include <linux/const.h>
7108 #include <kmalloc.h>
7109
7110 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
7111 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7112 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7113
7114 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
7115 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7116 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
7117 index d414405..6bb4ba2 100644
7118 --- a/arch/mips/include/asm/elf.h
7119 +++ b/arch/mips/include/asm/elf.h
7120 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
7121 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7122 #endif
7123
7124 +#ifdef CONFIG_PAX_ASLR
7125 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7126 +
7127 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7128 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7129 +#endif
7130 +
7131 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7132 struct linux_binprm;
7133 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7134 int uses_interp);
7135
7136 -struct mm_struct;
7137 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7138 -#define arch_randomize_brk arch_randomize_brk
7139 -
7140 #endif /* _ASM_ELF_H */
7141 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
7142 index c1f6afa..38cc6e9 100644
7143 --- a/arch/mips/include/asm/exec.h
7144 +++ b/arch/mips/include/asm/exec.h
7145 @@ -12,6 +12,6 @@
7146 #ifndef _ASM_EXEC_H
7147 #define _ASM_EXEC_H
7148
7149 -extern unsigned long arch_align_stack(unsigned long sp);
7150 +#define arch_align_stack(x) ((x) & ~0xfUL)
7151
7152 #endif /* _ASM_EXEC_H */
7153 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
7154 index 9e8ef59..1139d6b 100644
7155 --- a/arch/mips/include/asm/hw_irq.h
7156 +++ b/arch/mips/include/asm/hw_irq.h
7157 @@ -10,7 +10,7 @@
7158
7159 #include <linux/atomic.h>
7160
7161 -extern atomic_t irq_err_count;
7162 +extern atomic_unchecked_t irq_err_count;
7163
7164 /*
7165 * interrupt-retrigger: NOP for now. This may not be appropriate for all
7166 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
7167 index 46dfc3c..a16b13a 100644
7168 --- a/arch/mips/include/asm/local.h
7169 +++ b/arch/mips/include/asm/local.h
7170 @@ -12,15 +12,25 @@ typedef struct
7171 atomic_long_t a;
7172 } local_t;
7173
7174 +typedef struct {
7175 + atomic_long_unchecked_t a;
7176 +} local_unchecked_t;
7177 +
7178 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7179
7180 #define local_read(l) atomic_long_read(&(l)->a)
7181 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7182 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
7183 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
7184
7185 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
7186 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
7187 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
7188 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
7189 #define local_inc(l) atomic_long_inc(&(l)->a)
7190 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7191 #define local_dec(l) atomic_long_dec(&(l)->a)
7192 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7193
7194 /*
7195 * Same as above, but return the result value
7196 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
7197 return result;
7198 }
7199
7200 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
7201 +{
7202 + unsigned long result;
7203 +
7204 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
7205 + unsigned long temp;
7206 +
7207 + __asm__ __volatile__(
7208 + " .set mips3 \n"
7209 + "1:" __LL "%1, %2 # local_add_return \n"
7210 + " addu %0, %1, %3 \n"
7211 + __SC "%0, %2 \n"
7212 + " beqzl %0, 1b \n"
7213 + " addu %0, %1, %3 \n"
7214 + " .set mips0 \n"
7215 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7216 + : "Ir" (i), "m" (l->a.counter)
7217 + : "memory");
7218 + } else if (kernel_uses_llsc) {
7219 + unsigned long temp;
7220 +
7221 + __asm__ __volatile__(
7222 + " .set mips3 \n"
7223 + "1:" __LL "%1, %2 # local_add_return \n"
7224 + " addu %0, %1, %3 \n"
7225 + __SC "%0, %2 \n"
7226 + " beqz %0, 1b \n"
7227 + " addu %0, %1, %3 \n"
7228 + " .set mips0 \n"
7229 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
7230 + : "Ir" (i), "m" (l->a.counter)
7231 + : "memory");
7232 + } else {
7233 + unsigned long flags;
7234 +
7235 + local_irq_save(flags);
7236 + result = l->a.counter;
7237 + result += i;
7238 + l->a.counter = result;
7239 + local_irq_restore(flags);
7240 + }
7241 +
7242 + return result;
7243 +}
7244 +
7245 static __inline__ long local_sub_return(long i, local_t * l)
7246 {
7247 unsigned long result;
7248 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
7249
7250 #define local_cmpxchg(l, o, n) \
7251 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7252 +#define local_cmpxchg_unchecked(l, o, n) \
7253 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
7254 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
7255
7256 /**
7257 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
7258 index 5699ec3..95def83 100644
7259 --- a/arch/mips/include/asm/page.h
7260 +++ b/arch/mips/include/asm/page.h
7261 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
7262 #ifdef CONFIG_CPU_MIPS32
7263 typedef struct { unsigned long pte_low, pte_high; } pte_t;
7264 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
7265 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
7266 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
7267 #else
7268 typedef struct { unsigned long long pte; } pte_t;
7269 #define pte_val(x) ((x).pte)
7270 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
7271 index b336037..5b874cc 100644
7272 --- a/arch/mips/include/asm/pgalloc.h
7273 +++ b/arch/mips/include/asm/pgalloc.h
7274 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7275 {
7276 set_pud(pud, __pud((unsigned long)pmd));
7277 }
7278 +
7279 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7280 +{
7281 + pud_populate(mm, pud, pmd);
7282 +}
7283 #endif
7284
7285 /*
7286 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
7287 index 539ddd1..8783f9a 100644
7288 --- a/arch/mips/include/asm/pgtable.h
7289 +++ b/arch/mips/include/asm/pgtable.h
7290 @@ -20,6 +20,9 @@
7291 #include <asm/io.h>
7292 #include <asm/pgtable-bits.h>
7293
7294 +#define ktla_ktva(addr) (addr)
7295 +#define ktva_ktla(addr) (addr)
7296 +
7297 struct mm_struct;
7298 struct vm_area_struct;
7299
7300 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
7301 index 7de8658..c109224 100644
7302 --- a/arch/mips/include/asm/thread_info.h
7303 +++ b/arch/mips/include/asm/thread_info.h
7304 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
7305 #define TIF_SECCOMP 4 /* secure computing */
7306 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
7307 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
7308 +/* li takes a 32bit immediate */
7309 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
7310 +
7311 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
7312 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
7313 #define TIF_NOHZ 19 /* in adaptive nohz mode */
7314 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
7315 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
7316 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
7317 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7318 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7319
7320 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7321 _TIF_SYSCALL_AUDIT | \
7322 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
7323 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
7324 + _TIF_GRSEC_SETXID)
7325
7326 /* work to do in syscall_trace_leave() */
7327 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
7328 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
7329 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7330
7331 /* work to do on interrupt/exception return */
7332 #define _TIF_WORK_MASK \
7333 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
7334 /* work to do on any return to u-space */
7335 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
7336 _TIF_WORK_SYSCALL_EXIT | \
7337 - _TIF_SYSCALL_TRACEPOINT)
7338 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7339
7340 /*
7341 * We stash processor id into a COP0 register to retrieve it fast
7342 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
7343 index a109510..94ee3f6 100644
7344 --- a/arch/mips/include/asm/uaccess.h
7345 +++ b/arch/mips/include/asm/uaccess.h
7346 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
7347 __ok == 0; \
7348 })
7349
7350 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
7351 #define access_ok(type, addr, size) \
7352 likely(__access_ok((addr), (size), __access_mask))
7353
7354 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7355 index 1188e00..41cf144 100644
7356 --- a/arch/mips/kernel/binfmt_elfn32.c
7357 +++ b/arch/mips/kernel/binfmt_elfn32.c
7358 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7359 #undef ELF_ET_DYN_BASE
7360 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7361
7362 +#ifdef CONFIG_PAX_ASLR
7363 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7364 +
7365 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7366 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7367 +#endif
7368 +
7369 #include <asm/processor.h>
7370 #include <linux/module.h>
7371 #include <linux/elfcore.h>
7372 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7373 index 7faf5f2..f3d3cf4 100644
7374 --- a/arch/mips/kernel/binfmt_elfo32.c
7375 +++ b/arch/mips/kernel/binfmt_elfo32.c
7376 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7377 #undef ELF_ET_DYN_BASE
7378 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7379
7380 +#ifdef CONFIG_PAX_ASLR
7381 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7382 +
7383 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7384 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7385 +#endif
7386 +
7387 #include <asm/processor.h>
7388
7389 /*
7390 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7391 index 50b3648..c2f3cec 100644
7392 --- a/arch/mips/kernel/i8259.c
7393 +++ b/arch/mips/kernel/i8259.c
7394 @@ -201,7 +201,7 @@ spurious_8259A_irq:
7395 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7396 spurious_irq_mask |= irqmask;
7397 }
7398 - atomic_inc(&irq_err_count);
7399 + atomic_inc_unchecked(&irq_err_count);
7400 /*
7401 * Theoretically we do not have to handle this IRQ,
7402 * but in Linux this does not cause problems and is
7403 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7404 index 44a1f79..2bd6aa3 100644
7405 --- a/arch/mips/kernel/irq-gt641xx.c
7406 +++ b/arch/mips/kernel/irq-gt641xx.c
7407 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7408 }
7409 }
7410
7411 - atomic_inc(&irq_err_count);
7412 + atomic_inc_unchecked(&irq_err_count);
7413 }
7414
7415 void __init gt641xx_irq_init(void)
7416 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7417 index d2bfbc2..a8eacd2 100644
7418 --- a/arch/mips/kernel/irq.c
7419 +++ b/arch/mips/kernel/irq.c
7420 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7421 printk("unexpected IRQ # %d\n", irq);
7422 }
7423
7424 -atomic_t irq_err_count;
7425 +atomic_unchecked_t irq_err_count;
7426
7427 int arch_show_interrupts(struct seq_file *p, int prec)
7428 {
7429 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7430 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7431 return 0;
7432 }
7433
7434 asmlinkage void spurious_interrupt(void)
7435 {
7436 - atomic_inc(&irq_err_count);
7437 + atomic_inc_unchecked(&irq_err_count);
7438 }
7439
7440 void __init init_IRQ(void)
7441 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7442 #endif
7443 }
7444
7445 +
7446 #ifdef DEBUG_STACKOVERFLOW
7447 +extern void gr_handle_kernel_exploit(void);
7448 +
7449 static inline void check_stack_overflow(void)
7450 {
7451 unsigned long sp;
7452 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7453 printk("do_IRQ: stack overflow: %ld\n",
7454 sp - sizeof(struct thread_info));
7455 dump_stack();
7456 + gr_handle_kernel_exploit();
7457 }
7458 }
7459 #else
7460 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7461 index c4c2069..bde8051 100644
7462 --- a/arch/mips/kernel/pm-cps.c
7463 +++ b/arch/mips/kernel/pm-cps.c
7464 @@ -168,7 +168,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7465 nc_core_ready_count = nc_addr;
7466
7467 /* Ensure ready_count is zero-initialised before the assembly runs */
7468 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7469 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7470 coupled_barrier(&per_cpu(pm_barrier, core), online);
7471
7472 /* Run the generated entry code */
7473 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7474 index 0a1ec0f..d9e93b6 100644
7475 --- a/arch/mips/kernel/process.c
7476 +++ b/arch/mips/kernel/process.c
7477 @@ -572,15 +572,3 @@ unsigned long get_wchan(struct task_struct *task)
7478 out:
7479 return pc;
7480 }
7481 -
7482 -/*
7483 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7484 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7485 - */
7486 -unsigned long arch_align_stack(unsigned long sp)
7487 -{
7488 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7489 - sp -= get_random_int() & ~PAGE_MASK;
7490 -
7491 - return sp & ALMASK;
7492 -}
7493 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7494 index f639ccd..e4b110d 100644
7495 --- a/arch/mips/kernel/ptrace.c
7496 +++ b/arch/mips/kernel/ptrace.c
7497 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
7498 return ret;
7499 }
7500
7501 +#ifdef CONFIG_GRKERNSEC_SETXID
7502 +extern void gr_delayed_cred_worker(void);
7503 +#endif
7504 +
7505 /*
7506 * Notification of system call entry/exit
7507 * - triggered by current->work.syscall_trace
7508 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7509 tracehook_report_syscall_entry(regs))
7510 ret = -1;
7511
7512 +#ifdef CONFIG_GRKERNSEC_SETXID
7513 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7514 + gr_delayed_cred_worker();
7515 +#endif
7516 +
7517 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7518 trace_sys_enter(regs, regs->regs[2]);
7519
7520 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7521 index 07fc524..b9d7f28 100644
7522 --- a/arch/mips/kernel/reset.c
7523 +++ b/arch/mips/kernel/reset.c
7524 @@ -13,6 +13,7 @@
7525 #include <linux/reboot.h>
7526
7527 #include <asm/reboot.h>
7528 +#include <asm/bug.h>
7529
7530 /*
7531 * Urgs ... Too many MIPS machines to handle this in a generic way.
7532 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7533 {
7534 if (_machine_restart)
7535 _machine_restart(command);
7536 + BUG();
7537 }
7538
7539 void machine_halt(void)
7540 {
7541 if (_machine_halt)
7542 _machine_halt();
7543 + BUG();
7544 }
7545
7546 void machine_power_off(void)
7547 {
7548 if (pm_power_off)
7549 pm_power_off();
7550 + BUG();
7551 }
7552 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7553 index 2242bdd..b284048 100644
7554 --- a/arch/mips/kernel/sync-r4k.c
7555 +++ b/arch/mips/kernel/sync-r4k.c
7556 @@ -18,8 +18,8 @@
7557 #include <asm/mipsregs.h>
7558
7559 static atomic_t count_start_flag = ATOMIC_INIT(0);
7560 -static atomic_t count_count_start = ATOMIC_INIT(0);
7561 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7562 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7563 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7564 static atomic_t count_reference = ATOMIC_INIT(0);
7565
7566 #define COUNTON 100
7567 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7568
7569 for (i = 0; i < NR_LOOPS; i++) {
7570 /* slaves loop on '!= 2' */
7571 - while (atomic_read(&count_count_start) != 1)
7572 + while (atomic_read_unchecked(&count_count_start) != 1)
7573 mb();
7574 - atomic_set(&count_count_stop, 0);
7575 + atomic_set_unchecked(&count_count_stop, 0);
7576 smp_wmb();
7577
7578 /* this lets the slaves write their count register */
7579 - atomic_inc(&count_count_start);
7580 + atomic_inc_unchecked(&count_count_start);
7581
7582 /*
7583 * Everyone initialises count in the last loop:
7584 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7585 /*
7586 * Wait for all slaves to leave the synchronization point:
7587 */
7588 - while (atomic_read(&count_count_stop) != 1)
7589 + while (atomic_read_unchecked(&count_count_stop) != 1)
7590 mb();
7591 - atomic_set(&count_count_start, 0);
7592 + atomic_set_unchecked(&count_count_start, 0);
7593 smp_wmb();
7594 - atomic_inc(&count_count_stop);
7595 + atomic_inc_unchecked(&count_count_stop);
7596 }
7597 /* Arrange for an interrupt in a short while */
7598 write_c0_compare(read_c0_count() + COUNTON);
7599 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7600 initcount = atomic_read(&count_reference);
7601
7602 for (i = 0; i < NR_LOOPS; i++) {
7603 - atomic_inc(&count_count_start);
7604 - while (atomic_read(&count_count_start) != 2)
7605 + atomic_inc_unchecked(&count_count_start);
7606 + while (atomic_read_unchecked(&count_count_start) != 2)
7607 mb();
7608
7609 /*
7610 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7611 if (i == NR_LOOPS-1)
7612 write_c0_count(initcount);
7613
7614 - atomic_inc(&count_count_stop);
7615 - while (atomic_read(&count_count_stop) != 2)
7616 + atomic_inc_unchecked(&count_count_stop);
7617 + while (atomic_read_unchecked(&count_count_stop) != 2)
7618 mb();
7619 }
7620 /* Arrange for an interrupt in a short while */
7621 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7622 index 51706d6..ec1178c 100644
7623 --- a/arch/mips/kernel/traps.c
7624 +++ b/arch/mips/kernel/traps.c
7625 @@ -687,7 +687,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7626 siginfo_t info;
7627
7628 prev_state = exception_enter();
7629 - die_if_kernel("Integer overflow", regs);
7630 + if (unlikely(!user_mode(regs))) {
7631 +
7632 +#ifdef CONFIG_PAX_REFCOUNT
7633 + if (fixup_exception(regs)) {
7634 + pax_report_refcount_overflow(regs);
7635 + exception_exit(prev_state);
7636 + return;
7637 + }
7638 +#endif
7639 +
7640 + die("Integer overflow", regs);
7641 + }
7642
7643 info.si_code = FPE_INTOVF;
7644 info.si_signo = SIGFPE;
7645 diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
7646 index f3c56a1..6a2f01c 100644
7647 --- a/arch/mips/kvm/kvm_mips.c
7648 +++ b/arch/mips/kvm/kvm_mips.c
7649 @@ -841,7 +841,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7650 return r;
7651 }
7652
7653 -int kvm_arch_init(void *opaque)
7654 +int kvm_arch_init(const void *opaque)
7655 {
7656 int ret;
7657
7658 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7659 index becc42b..9e43d4b 100644
7660 --- a/arch/mips/mm/fault.c
7661 +++ b/arch/mips/mm/fault.c
7662 @@ -28,6 +28,23 @@
7663 #include <asm/highmem.h> /* For VMALLOC_END */
7664 #include <linux/kdebug.h>
7665
7666 +#ifdef CONFIG_PAX_PAGEEXEC
7667 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7668 +{
7669 + unsigned long i;
7670 +
7671 + printk(KERN_ERR "PAX: bytes at PC: ");
7672 + for (i = 0; i < 5; i++) {
7673 + unsigned int c;
7674 + if (get_user(c, (unsigned int *)pc+i))
7675 + printk(KERN_CONT "???????? ");
7676 + else
7677 + printk(KERN_CONT "%08x ", c);
7678 + }
7679 + printk("\n");
7680 +}
7681 +#endif
7682 +
7683 /*
7684 * This routine handles page faults. It determines the address,
7685 * and the problem, and then passes it off to one of the appropriate
7686 @@ -199,6 +216,14 @@ bad_area:
7687 bad_area_nosemaphore:
7688 /* User mode accesses just cause a SIGSEGV */
7689 if (user_mode(regs)) {
7690 +
7691 +#ifdef CONFIG_PAX_PAGEEXEC
7692 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7693 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7694 + do_group_exit(SIGKILL);
7695 + }
7696 +#endif
7697 +
7698 tsk->thread.cp0_badvaddr = address;
7699 tsk->thread.error_code = write;
7700 #if 0
7701 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7702 index f1baadd..5472dca 100644
7703 --- a/arch/mips/mm/mmap.c
7704 +++ b/arch/mips/mm/mmap.c
7705 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7706 struct vm_area_struct *vma;
7707 unsigned long addr = addr0;
7708 int do_color_align;
7709 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7710 struct vm_unmapped_area_info info;
7711
7712 if (unlikely(len > TASK_SIZE))
7713 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7714 do_color_align = 1;
7715
7716 /* requesting a specific address */
7717 +
7718 +#ifdef CONFIG_PAX_RANDMMAP
7719 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7720 +#endif
7721 +
7722 if (addr) {
7723 if (do_color_align)
7724 addr = COLOUR_ALIGN(addr, pgoff);
7725 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7726 addr = PAGE_ALIGN(addr);
7727
7728 vma = find_vma(mm, addr);
7729 - if (TASK_SIZE - len >= addr &&
7730 - (!vma || addr + len <= vma->vm_start))
7731 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7732 return addr;
7733 }
7734
7735 info.length = len;
7736 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7737 info.align_offset = pgoff << PAGE_SHIFT;
7738 + info.threadstack_offset = offset;
7739
7740 if (dir == DOWN) {
7741 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7742 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7743 {
7744 unsigned long random_factor = 0UL;
7745
7746 +#ifdef CONFIG_PAX_RANDMMAP
7747 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7748 +#endif
7749 +
7750 if (current->flags & PF_RANDOMIZE) {
7751 random_factor = get_random_int();
7752 random_factor = random_factor << PAGE_SHIFT;
7753 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7754
7755 if (mmap_is_legacy()) {
7756 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7757 +
7758 +#ifdef CONFIG_PAX_RANDMMAP
7759 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7760 + mm->mmap_base += mm->delta_mmap;
7761 +#endif
7762 +
7763 mm->get_unmapped_area = arch_get_unmapped_area;
7764 } else {
7765 mm->mmap_base = mmap_base(random_factor);
7766 +
7767 +#ifdef CONFIG_PAX_RANDMMAP
7768 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7769 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7770 +#endif
7771 +
7772 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7773 }
7774 }
7775
7776 -static inline unsigned long brk_rnd(void)
7777 -{
7778 - unsigned long rnd = get_random_int();
7779 -
7780 - rnd = rnd << PAGE_SHIFT;
7781 - /* 8MB for 32bit, 256MB for 64bit */
7782 - if (TASK_IS_32BIT_ADDR)
7783 - rnd = rnd & 0x7ffffful;
7784 - else
7785 - rnd = rnd & 0xffffffful;
7786 -
7787 - return rnd;
7788 -}
7789 -
7790 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7791 -{
7792 - unsigned long base = mm->brk;
7793 - unsigned long ret;
7794 -
7795 - ret = PAGE_ALIGN(base + brk_rnd());
7796 -
7797 - if (ret < mm->brk)
7798 - return mm->brk;
7799 -
7800 - return ret;
7801 -}
7802 -
7803 int __virt_addr_valid(const volatile void *kaddr)
7804 {
7805 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7806 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7807 index 59cccd9..f39ac2f 100644
7808 --- a/arch/mips/pci/pci-octeon.c
7809 +++ b/arch/mips/pci/pci-octeon.c
7810 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7811
7812
7813 static struct pci_ops octeon_pci_ops = {
7814 - octeon_read_config,
7815 - octeon_write_config,
7816 + .read = octeon_read_config,
7817 + .write = octeon_write_config,
7818 };
7819
7820 static struct resource octeon_pci_mem_resource = {
7821 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7822 index 5e36c33..eb4a17b 100644
7823 --- a/arch/mips/pci/pcie-octeon.c
7824 +++ b/arch/mips/pci/pcie-octeon.c
7825 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7826 }
7827
7828 static struct pci_ops octeon_pcie0_ops = {
7829 - octeon_pcie0_read_config,
7830 - octeon_pcie0_write_config,
7831 + .read = octeon_pcie0_read_config,
7832 + .write = octeon_pcie0_write_config,
7833 };
7834
7835 static struct resource octeon_pcie0_mem_resource = {
7836 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7837 };
7838
7839 static struct pci_ops octeon_pcie1_ops = {
7840 - octeon_pcie1_read_config,
7841 - octeon_pcie1_write_config,
7842 + .read = octeon_pcie1_read_config,
7843 + .write = octeon_pcie1_write_config,
7844 };
7845
7846 static struct resource octeon_pcie1_mem_resource = {
7847 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7848 };
7849
7850 static struct pci_ops octeon_dummy_ops = {
7851 - octeon_dummy_read_config,
7852 - octeon_dummy_write_config,
7853 + .read = octeon_dummy_read_config,
7854 + .write = octeon_dummy_write_config,
7855 };
7856
7857 static struct resource octeon_dummy_mem_resource = {
7858 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7859 index a2358b4..7cead4f 100644
7860 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7861 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7862 @@ -187,9 +187,9 @@ void
7863 cont_nmi_dump(void)
7864 {
7865 #ifndef REAL_NMI_SIGNAL
7866 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7867 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7868
7869 - atomic_inc(&nmied_cpus);
7870 + atomic_inc_unchecked(&nmied_cpus);
7871 #endif
7872 /*
7873 * Only allow 1 cpu to proceed
7874 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7875 udelay(10000);
7876 }
7877 #else
7878 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7879 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7880 #endif
7881
7882 /*
7883 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7884 index a046b30..6799527 100644
7885 --- a/arch/mips/sni/rm200.c
7886 +++ b/arch/mips/sni/rm200.c
7887 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7888 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7889 spurious_irq_mask |= irqmask;
7890 }
7891 - atomic_inc(&irq_err_count);
7892 + atomic_inc_unchecked(&irq_err_count);
7893 /*
7894 * Theoretically we do not have to handle this IRQ,
7895 * but in Linux this does not cause problems and is
7896 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7897 index 41e873b..34d33a7 100644
7898 --- a/arch/mips/vr41xx/common/icu.c
7899 +++ b/arch/mips/vr41xx/common/icu.c
7900 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7901
7902 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7903
7904 - atomic_inc(&irq_err_count);
7905 + atomic_inc_unchecked(&irq_err_count);
7906
7907 return -1;
7908 }
7909 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7910 index ae0e4ee..e8f0692 100644
7911 --- a/arch/mips/vr41xx/common/irq.c
7912 +++ b/arch/mips/vr41xx/common/irq.c
7913 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7914 irq_cascade_t *cascade;
7915
7916 if (irq >= NR_IRQS) {
7917 - atomic_inc(&irq_err_count);
7918 + atomic_inc_unchecked(&irq_err_count);
7919 return;
7920 }
7921
7922 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7923 ret = cascade->get_irq(irq);
7924 irq = ret;
7925 if (ret < 0)
7926 - atomic_inc(&irq_err_count);
7927 + atomic_inc_unchecked(&irq_err_count);
7928 else
7929 irq_dispatch(irq);
7930 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7931 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7932 index 967d144..db12197 100644
7933 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7934 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7935 @@ -11,12 +11,14 @@
7936 #ifndef _ASM_PROC_CACHE_H
7937 #define _ASM_PROC_CACHE_H
7938
7939 +#include <linux/const.h>
7940 +
7941 /* L1 cache */
7942
7943 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7944 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7945 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7946 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7947 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7948 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7949
7950 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7951 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7952 index bcb5df2..84fabd2 100644
7953 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7954 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7955 @@ -16,13 +16,15 @@
7956 #ifndef _ASM_PROC_CACHE_H
7957 #define _ASM_PROC_CACHE_H
7958
7959 +#include <linux/const.h>
7960 +
7961 /*
7962 * L1 cache
7963 */
7964 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7965 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7966 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7967 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7968 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7969 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7970
7971 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7972 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7973 index 4ce7a01..449202a 100644
7974 --- a/arch/openrisc/include/asm/cache.h
7975 +++ b/arch/openrisc/include/asm/cache.h
7976 @@ -19,11 +19,13 @@
7977 #ifndef __ASM_OPENRISC_CACHE_H
7978 #define __ASM_OPENRISC_CACHE_H
7979
7980 +#include <linux/const.h>
7981 +
7982 /* FIXME: How can we replace these with values from the CPU...
7983 * they shouldn't be hard-coded!
7984 */
7985
7986 -#define L1_CACHE_BYTES 16
7987 #define L1_CACHE_SHIFT 4
7988 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7989
7990 #endif /* __ASM_OPENRISC_CACHE_H */
7991 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7992 index 0be2db2..1b0f26d 100644
7993 --- a/arch/parisc/include/asm/atomic.h
7994 +++ b/arch/parisc/include/asm/atomic.h
7995 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7996 return dec;
7997 }
7998
7999 +#define atomic64_read_unchecked(v) atomic64_read(v)
8000 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8001 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8002 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8003 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8004 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8005 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8006 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8007 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8008 +
8009 #endif /* !CONFIG_64BIT */
8010
8011
8012 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
8013 index 47f11c7..3420df2 100644
8014 --- a/arch/parisc/include/asm/cache.h
8015 +++ b/arch/parisc/include/asm/cache.h
8016 @@ -5,6 +5,7 @@
8017 #ifndef __ARCH_PARISC_CACHE_H
8018 #define __ARCH_PARISC_CACHE_H
8019
8020 +#include <linux/const.h>
8021
8022 /*
8023 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
8024 @@ -15,13 +16,13 @@
8025 * just ruin performance.
8026 */
8027 #ifdef CONFIG_PA20
8028 -#define L1_CACHE_BYTES 64
8029 #define L1_CACHE_SHIFT 6
8030 #else
8031 -#define L1_CACHE_BYTES 32
8032 #define L1_CACHE_SHIFT 5
8033 #endif
8034
8035 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8036 +
8037 #ifndef __ASSEMBLY__
8038
8039 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8040 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
8041 index 3391d06..c23a2cc 100644
8042 --- a/arch/parisc/include/asm/elf.h
8043 +++ b/arch/parisc/include/asm/elf.h
8044 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
8045
8046 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
8047
8048 +#ifdef CONFIG_PAX_ASLR
8049 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
8050 +
8051 +#define PAX_DELTA_MMAP_LEN 16
8052 +#define PAX_DELTA_STACK_LEN 16
8053 +#endif
8054 +
8055 /* This yields a mask that user programs can use to figure out what
8056 instruction set this CPU supports. This could be done in user space,
8057 but it's not easy, and we've already done it here. */
8058 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
8059 index f213f5b..0af3e8e 100644
8060 --- a/arch/parisc/include/asm/pgalloc.h
8061 +++ b/arch/parisc/include/asm/pgalloc.h
8062 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8063 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
8064 }
8065
8066 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
8067 +{
8068 + pgd_populate(mm, pgd, pmd);
8069 +}
8070 +
8071 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
8072 {
8073 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
8074 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
8075 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
8076 #define pmd_free(mm, x) do { } while (0)
8077 #define pgd_populate(mm, pmd, pte) BUG()
8078 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
8079
8080 #endif
8081
8082 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
8083 index 22b89d1..ce34230 100644
8084 --- a/arch/parisc/include/asm/pgtable.h
8085 +++ b/arch/parisc/include/asm/pgtable.h
8086 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
8087 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
8088 #define PAGE_COPY PAGE_EXECREAD
8089 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
8090 +
8091 +#ifdef CONFIG_PAX_PAGEEXEC
8092 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
8093 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8094 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
8095 +#else
8096 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
8097 +# define PAGE_COPY_NOEXEC PAGE_COPY
8098 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
8099 +#endif
8100 +
8101 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
8102 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
8103 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
8104 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
8105 index 4006964..fcb3cc2 100644
8106 --- a/arch/parisc/include/asm/uaccess.h
8107 +++ b/arch/parisc/include/asm/uaccess.h
8108 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
8109 const void __user *from,
8110 unsigned long n)
8111 {
8112 - int sz = __compiletime_object_size(to);
8113 + size_t sz = __compiletime_object_size(to);
8114 int ret = -EFAULT;
8115
8116 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
8117 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
8118 ret = __copy_from_user(to, from, n);
8119 else
8120 copy_from_user_overflow();
8121 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
8122 index 50dfafc..b9fc230 100644
8123 --- a/arch/parisc/kernel/module.c
8124 +++ b/arch/parisc/kernel/module.c
8125 @@ -98,16 +98,38 @@
8126
8127 /* three functions to determine where in the module core
8128 * or init pieces the location is */
8129 +static inline int in_init_rx(struct module *me, void *loc)
8130 +{
8131 + return (loc >= me->module_init_rx &&
8132 + loc < (me->module_init_rx + me->init_size_rx));
8133 +}
8134 +
8135 +static inline int in_init_rw(struct module *me, void *loc)
8136 +{
8137 + return (loc >= me->module_init_rw &&
8138 + loc < (me->module_init_rw + me->init_size_rw));
8139 +}
8140 +
8141 static inline int in_init(struct module *me, void *loc)
8142 {
8143 - return (loc >= me->module_init &&
8144 - loc <= (me->module_init + me->init_size));
8145 + return in_init_rx(me, loc) || in_init_rw(me, loc);
8146 +}
8147 +
8148 +static inline int in_core_rx(struct module *me, void *loc)
8149 +{
8150 + return (loc >= me->module_core_rx &&
8151 + loc < (me->module_core_rx + me->core_size_rx));
8152 +}
8153 +
8154 +static inline int in_core_rw(struct module *me, void *loc)
8155 +{
8156 + return (loc >= me->module_core_rw &&
8157 + loc < (me->module_core_rw + me->core_size_rw));
8158 }
8159
8160 static inline int in_core(struct module *me, void *loc)
8161 {
8162 - return (loc >= me->module_core &&
8163 - loc <= (me->module_core + me->core_size));
8164 + return in_core_rx(me, loc) || in_core_rw(me, loc);
8165 }
8166
8167 static inline int in_local(struct module *me, void *loc)
8168 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
8169 }
8170
8171 /* align things a bit */
8172 - me->core_size = ALIGN(me->core_size, 16);
8173 - me->arch.got_offset = me->core_size;
8174 - me->core_size += gots * sizeof(struct got_entry);
8175 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
8176 + me->arch.got_offset = me->core_size_rw;
8177 + me->core_size_rw += gots * sizeof(struct got_entry);
8178
8179 - me->core_size = ALIGN(me->core_size, 16);
8180 - me->arch.fdesc_offset = me->core_size;
8181 - me->core_size += fdescs * sizeof(Elf_Fdesc);
8182 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
8183 + me->arch.fdesc_offset = me->core_size_rw;
8184 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
8185
8186 me->arch.got_max = gots;
8187 me->arch.fdesc_max = fdescs;
8188 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8189
8190 BUG_ON(value == 0);
8191
8192 - got = me->module_core + me->arch.got_offset;
8193 + got = me->module_core_rw + me->arch.got_offset;
8194 for (i = 0; got[i].addr; i++)
8195 if (got[i].addr == value)
8196 goto out;
8197 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
8198 #ifdef CONFIG_64BIT
8199 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8200 {
8201 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
8202 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
8203
8204 if (!value) {
8205 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
8206 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
8207
8208 /* Create new one */
8209 fdesc->addr = value;
8210 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8211 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8212 return (Elf_Addr)fdesc;
8213 }
8214 #endif /* CONFIG_64BIT */
8215 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
8216
8217 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
8218 end = table + sechdrs[me->arch.unwind_section].sh_size;
8219 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
8220 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
8221
8222 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
8223 me->arch.unwind_section, table, end, gp);
8224 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
8225 index e1ffea2..46ed66e 100644
8226 --- a/arch/parisc/kernel/sys_parisc.c
8227 +++ b/arch/parisc/kernel/sys_parisc.c
8228 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8229 unsigned long task_size = TASK_SIZE;
8230 int do_color_align, last_mmap;
8231 struct vm_unmapped_area_info info;
8232 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8233
8234 if (len > task_size)
8235 return -ENOMEM;
8236 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8237 goto found_addr;
8238 }
8239
8240 +#ifdef CONFIG_PAX_RANDMMAP
8241 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8242 +#endif
8243 +
8244 if (addr) {
8245 if (do_color_align && last_mmap)
8246 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8247 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8248 info.high_limit = mmap_upper_limit();
8249 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8250 info.align_offset = shared_align_offset(last_mmap, pgoff);
8251 + info.threadstack_offset = offset;
8252 addr = vm_unmapped_area(&info);
8253
8254 found_addr:
8255 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8256 unsigned long addr = addr0;
8257 int do_color_align, last_mmap;
8258 struct vm_unmapped_area_info info;
8259 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
8260
8261 #ifdef CONFIG_64BIT
8262 /* This should only ever run for 32-bit processes. */
8263 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8264 }
8265
8266 /* requesting a specific address */
8267 +#ifdef CONFIG_PAX_RANDMMAP
8268 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8269 +#endif
8270 +
8271 if (addr) {
8272 if (do_color_align && last_mmap)
8273 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
8274 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8275 info.high_limit = mm->mmap_base;
8276 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
8277 info.align_offset = shared_align_offset(last_mmap, pgoff);
8278 + info.threadstack_offset = offset;
8279 addr = vm_unmapped_area(&info);
8280 if (!(addr & ~PAGE_MASK))
8281 goto found_addr;
8282 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8283 mm->mmap_legacy_base = mmap_legacy_base();
8284 mm->mmap_base = mmap_upper_limit();
8285
8286 +#ifdef CONFIG_PAX_RANDMMAP
8287 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
8288 + mm->mmap_legacy_base += mm->delta_mmap;
8289 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8290 + }
8291 +#endif
8292 +
8293 if (mmap_is_legacy()) {
8294 mm->mmap_base = mm->mmap_legacy_base;
8295 mm->get_unmapped_area = arch_get_unmapped_area;
8296 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
8297 index 47ee620..1107387 100644
8298 --- a/arch/parisc/kernel/traps.c
8299 +++ b/arch/parisc/kernel/traps.c
8300 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
8301
8302 down_read(&current->mm->mmap_sem);
8303 vma = find_vma(current->mm,regs->iaoq[0]);
8304 - if (vma && (regs->iaoq[0] >= vma->vm_start)
8305 - && (vma->vm_flags & VM_EXEC)) {
8306 -
8307 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
8308 fault_address = regs->iaoq[0];
8309 fault_space = regs->iasq[0];
8310
8311 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
8312 index 3ca9c11..d163ef7 100644
8313 --- a/arch/parisc/mm/fault.c
8314 +++ b/arch/parisc/mm/fault.c
8315 @@ -15,6 +15,7 @@
8316 #include <linux/sched.h>
8317 #include <linux/interrupt.h>
8318 #include <linux/module.h>
8319 +#include <linux/unistd.h>
8320
8321 #include <asm/uaccess.h>
8322 #include <asm/traps.h>
8323 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
8324 static unsigned long
8325 parisc_acctyp(unsigned long code, unsigned int inst)
8326 {
8327 - if (code == 6 || code == 16)
8328 + if (code == 6 || code == 7 || code == 16)
8329 return VM_EXEC;
8330
8331 switch (inst & 0xf0000000) {
8332 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8333 }
8334 #endif
8335
8336 +#ifdef CONFIG_PAX_PAGEEXEC
8337 +/*
8338 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8339 + *
8340 + * returns 1 when task should be killed
8341 + * 2 when rt_sigreturn trampoline was detected
8342 + * 3 when unpatched PLT trampoline was detected
8343 + */
8344 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8345 +{
8346 +
8347 +#ifdef CONFIG_PAX_EMUPLT
8348 + int err;
8349 +
8350 + do { /* PaX: unpatched PLT emulation */
8351 + unsigned int bl, depwi;
8352 +
8353 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8354 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8355 +
8356 + if (err)
8357 + break;
8358 +
8359 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8360 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8361 +
8362 + err = get_user(ldw, (unsigned int *)addr);
8363 + err |= get_user(bv, (unsigned int *)(addr+4));
8364 + err |= get_user(ldw2, (unsigned int *)(addr+8));
8365 +
8366 + if (err)
8367 + break;
8368 +
8369 + if (ldw == 0x0E801096U &&
8370 + bv == 0xEAC0C000U &&
8371 + ldw2 == 0x0E881095U)
8372 + {
8373 + unsigned int resolver, map;
8374 +
8375 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8376 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8377 + if (err)
8378 + break;
8379 +
8380 + regs->gr[20] = instruction_pointer(regs)+8;
8381 + regs->gr[21] = map;
8382 + regs->gr[22] = resolver;
8383 + regs->iaoq[0] = resolver | 3UL;
8384 + regs->iaoq[1] = regs->iaoq[0] + 4;
8385 + return 3;
8386 + }
8387 + }
8388 + } while (0);
8389 +#endif
8390 +
8391 +#ifdef CONFIG_PAX_EMUTRAMP
8392 +
8393 +#ifndef CONFIG_PAX_EMUSIGRT
8394 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8395 + return 1;
8396 +#endif
8397 +
8398 + do { /* PaX: rt_sigreturn emulation */
8399 + unsigned int ldi1, ldi2, bel, nop;
8400 +
8401 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8402 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8403 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8404 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8405 +
8406 + if (err)
8407 + break;
8408 +
8409 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8410 + ldi2 == 0x3414015AU &&
8411 + bel == 0xE4008200U &&
8412 + nop == 0x08000240U)
8413 + {
8414 + regs->gr[25] = (ldi1 & 2) >> 1;
8415 + regs->gr[20] = __NR_rt_sigreturn;
8416 + regs->gr[31] = regs->iaoq[1] + 16;
8417 + regs->sr[0] = regs->iasq[1];
8418 + regs->iaoq[0] = 0x100UL;
8419 + regs->iaoq[1] = regs->iaoq[0] + 4;
8420 + regs->iasq[0] = regs->sr[2];
8421 + regs->iasq[1] = regs->sr[2];
8422 + return 2;
8423 + }
8424 + } while (0);
8425 +#endif
8426 +
8427 + return 1;
8428 +}
8429 +
8430 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8431 +{
8432 + unsigned long i;
8433 +
8434 + printk(KERN_ERR "PAX: bytes at PC: ");
8435 + for (i = 0; i < 5; i++) {
8436 + unsigned int c;
8437 + if (get_user(c, (unsigned int *)pc+i))
8438 + printk(KERN_CONT "???????? ");
8439 + else
8440 + printk(KERN_CONT "%08x ", c);
8441 + }
8442 + printk("\n");
8443 +}
8444 +#endif
8445 +
8446 int fixup_exception(struct pt_regs *regs)
8447 {
8448 const struct exception_table_entry *fix;
8449 @@ -234,8 +345,33 @@ retry:
8450
8451 good_area:
8452
8453 - if ((vma->vm_flags & acc_type) != acc_type)
8454 + if ((vma->vm_flags & acc_type) != acc_type) {
8455 +
8456 +#ifdef CONFIG_PAX_PAGEEXEC
8457 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8458 + (address & ~3UL) == instruction_pointer(regs))
8459 + {
8460 + up_read(&mm->mmap_sem);
8461 + switch (pax_handle_fetch_fault(regs)) {
8462 +
8463 +#ifdef CONFIG_PAX_EMUPLT
8464 + case 3:
8465 + return;
8466 +#endif
8467 +
8468 +#ifdef CONFIG_PAX_EMUTRAMP
8469 + case 2:
8470 + return;
8471 +#endif
8472 +
8473 + }
8474 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8475 + do_group_exit(SIGKILL);
8476 + }
8477 +#endif
8478 +
8479 goto bad_area;
8480 + }
8481
8482 /*
8483 * If for any reason at all we couldn't handle the fault, make
8484 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8485 index 80b94b0..a3274fb 100644
8486 --- a/arch/powerpc/Kconfig
8487 +++ b/arch/powerpc/Kconfig
8488 @@ -398,6 +398,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8489 config KEXEC
8490 bool "kexec system call"
8491 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8492 + depends on !GRKERNSEC_KMEM
8493 help
8494 kexec is a system call that implements the ability to shutdown your
8495 current kernel, and to start another kernel. It is like a reboot
8496 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8497 index 28992d0..c797b20 100644
8498 --- a/arch/powerpc/include/asm/atomic.h
8499 +++ b/arch/powerpc/include/asm/atomic.h
8500 @@ -519,6 +519,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8501 return t1;
8502 }
8503
8504 +#define atomic64_read_unchecked(v) atomic64_read(v)
8505 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8506 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8507 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8508 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8509 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8510 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8511 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8512 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8513 +
8514 #endif /* __powerpc64__ */
8515
8516 #endif /* __KERNEL__ */
8517 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8518 index bab79a1..4a3eabc 100644
8519 --- a/arch/powerpc/include/asm/barrier.h
8520 +++ b/arch/powerpc/include/asm/barrier.h
8521 @@ -73,7 +73,7 @@
8522 do { \
8523 compiletime_assert_atomic_type(*p); \
8524 __lwsync(); \
8525 - ACCESS_ONCE(*p) = (v); \
8526 + ACCESS_ONCE_RW(*p) = (v); \
8527 } while (0)
8528
8529 #define smp_load_acquire(p) \
8530 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8531 index ed0afc1..0332825 100644
8532 --- a/arch/powerpc/include/asm/cache.h
8533 +++ b/arch/powerpc/include/asm/cache.h
8534 @@ -3,6 +3,7 @@
8535
8536 #ifdef __KERNEL__
8537
8538 +#include <linux/const.h>
8539
8540 /* bytes per L1 cache line */
8541 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8542 @@ -22,7 +23,7 @@
8543 #define L1_CACHE_SHIFT 7
8544 #endif
8545
8546 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8547 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8548
8549 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8550
8551 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8552 index 888d8f3..66f581c 100644
8553 --- a/arch/powerpc/include/asm/elf.h
8554 +++ b/arch/powerpc/include/asm/elf.h
8555 @@ -28,8 +28,19 @@
8556 the loader. We need to make sure that it is out of the way of the program
8557 that it will "exec", and that there is sufficient room for the brk. */
8558
8559 -extern unsigned long randomize_et_dyn(unsigned long base);
8560 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8561 +#define ELF_ET_DYN_BASE (0x20000000)
8562 +
8563 +#ifdef CONFIG_PAX_ASLR
8564 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8565 +
8566 +#ifdef __powerpc64__
8567 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8568 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8569 +#else
8570 +#define PAX_DELTA_MMAP_LEN 15
8571 +#define PAX_DELTA_STACK_LEN 15
8572 +#endif
8573 +#endif
8574
8575 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8576
8577 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8578 (0x7ff >> (PAGE_SHIFT - 12)) : \
8579 (0x3ffff >> (PAGE_SHIFT - 12)))
8580
8581 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8582 -#define arch_randomize_brk arch_randomize_brk
8583 -
8584 -
8585 #ifdef CONFIG_SPU_BASE
8586 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8587 #define NT_SPU 1
8588 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8589 index 8196e9c..d83a9f3 100644
8590 --- a/arch/powerpc/include/asm/exec.h
8591 +++ b/arch/powerpc/include/asm/exec.h
8592 @@ -4,6 +4,6 @@
8593 #ifndef _ASM_POWERPC_EXEC_H
8594 #define _ASM_POWERPC_EXEC_H
8595
8596 -extern unsigned long arch_align_stack(unsigned long sp);
8597 +#define arch_align_stack(x) ((x) & ~0xfUL)
8598
8599 #endif /* _ASM_POWERPC_EXEC_H */
8600 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8601 index 5acabbd..7ea14fa 100644
8602 --- a/arch/powerpc/include/asm/kmap_types.h
8603 +++ b/arch/powerpc/include/asm/kmap_types.h
8604 @@ -10,7 +10,7 @@
8605 * 2 of the License, or (at your option) any later version.
8606 */
8607
8608 -#define KM_TYPE_NR 16
8609 +#define KM_TYPE_NR 17
8610
8611 #endif /* __KERNEL__ */
8612 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8613 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8614 index b8da913..60b608a 100644
8615 --- a/arch/powerpc/include/asm/local.h
8616 +++ b/arch/powerpc/include/asm/local.h
8617 @@ -9,15 +9,26 @@ typedef struct
8618 atomic_long_t a;
8619 } local_t;
8620
8621 +typedef struct
8622 +{
8623 + atomic_long_unchecked_t a;
8624 +} local_unchecked_t;
8625 +
8626 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8627
8628 #define local_read(l) atomic_long_read(&(l)->a)
8629 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8630 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8631 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8632
8633 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8634 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8635 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8636 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8637 #define local_inc(l) atomic_long_inc(&(l)->a)
8638 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8639 #define local_dec(l) atomic_long_dec(&(l)->a)
8640 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8641
8642 static __inline__ long local_add_return(long a, local_t *l)
8643 {
8644 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8645
8646 return t;
8647 }
8648 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8649
8650 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8651
8652 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8653
8654 return t;
8655 }
8656 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8657
8658 static __inline__ long local_inc_return(local_t *l)
8659 {
8660 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8661
8662 #define local_cmpxchg(l, o, n) \
8663 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8664 +#define local_cmpxchg_unchecked(l, o, n) \
8665 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8666 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8667
8668 /**
8669 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8670 index 8565c25..2865190 100644
8671 --- a/arch/powerpc/include/asm/mman.h
8672 +++ b/arch/powerpc/include/asm/mman.h
8673 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8674 }
8675 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8676
8677 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8678 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8679 {
8680 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8681 }
8682 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8683 index 32e4e21..62afb12 100644
8684 --- a/arch/powerpc/include/asm/page.h
8685 +++ b/arch/powerpc/include/asm/page.h
8686 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8687 * and needs to be executable. This means the whole heap ends
8688 * up being executable.
8689 */
8690 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8691 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8692 +#define VM_DATA_DEFAULT_FLAGS32 \
8693 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8694 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8695
8696 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8697 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8698 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8699 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8700 #endif
8701
8702 +#define ktla_ktva(addr) (addr)
8703 +#define ktva_ktla(addr) (addr)
8704 +
8705 #ifndef CONFIG_PPC_BOOK3S_64
8706 /*
8707 * Use the top bit of the higher-level page table entries to indicate whether
8708 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8709 index 88693ce..ac6f9ab 100644
8710 --- a/arch/powerpc/include/asm/page_64.h
8711 +++ b/arch/powerpc/include/asm/page_64.h
8712 @@ -153,15 +153,18 @@ do { \
8713 * stack by default, so in the absence of a PT_GNU_STACK program header
8714 * we turn execute permission off.
8715 */
8716 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8717 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8718 +#define VM_STACK_DEFAULT_FLAGS32 \
8719 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8720 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8721
8722 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8723 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8724
8725 +#ifndef CONFIG_PAX_PAGEEXEC
8726 #define VM_STACK_DEFAULT_FLAGS \
8727 (is_32bit_task() ? \
8728 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8729 +#endif
8730
8731 #include <asm-generic/getorder.h>
8732
8733 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8734 index 4b0be20..c15a27d 100644
8735 --- a/arch/powerpc/include/asm/pgalloc-64.h
8736 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8737 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8738 #ifndef CONFIG_PPC_64K_PAGES
8739
8740 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8741 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8742
8743 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8744 {
8745 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8746 pud_set(pud, (unsigned long)pmd);
8747 }
8748
8749 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8750 +{
8751 + pud_populate(mm, pud, pmd);
8752 +}
8753 +
8754 #define pmd_populate(mm, pmd, pte_page) \
8755 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8756 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8757 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8758 #endif
8759
8760 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8761 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8762
8763 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8764 pte_t *pte)
8765 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8766 index d98c1ec..9f61569 100644
8767 --- a/arch/powerpc/include/asm/pgtable.h
8768 +++ b/arch/powerpc/include/asm/pgtable.h
8769 @@ -2,6 +2,7 @@
8770 #define _ASM_POWERPC_PGTABLE_H
8771 #ifdef __KERNEL__
8772
8773 +#include <linux/const.h>
8774 #ifndef __ASSEMBLY__
8775 #include <linux/mmdebug.h>
8776 #include <asm/processor.h> /* For TASK_SIZE */
8777 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8778 index 4aad413..85d86bf 100644
8779 --- a/arch/powerpc/include/asm/pte-hash32.h
8780 +++ b/arch/powerpc/include/asm/pte-hash32.h
8781 @@ -21,6 +21,7 @@
8782 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8783 #define _PAGE_USER 0x004 /* usermode access allowed */
8784 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8785 +#define _PAGE_EXEC _PAGE_GUARDED
8786 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8787 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8788 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8789 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8790 index bffd89d..a6641ed 100644
8791 --- a/arch/powerpc/include/asm/reg.h
8792 +++ b/arch/powerpc/include/asm/reg.h
8793 @@ -251,6 +251,7 @@
8794 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8795 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8796 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8797 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8798 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8799 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8800 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8801 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8802 index 5a6614a..d89995d1 100644
8803 --- a/arch/powerpc/include/asm/smp.h
8804 +++ b/arch/powerpc/include/asm/smp.h
8805 @@ -51,7 +51,7 @@ struct smp_ops_t {
8806 int (*cpu_disable)(void);
8807 void (*cpu_die)(unsigned int nr);
8808 int (*cpu_bootable)(unsigned int nr);
8809 -};
8810 +} __no_const;
8811
8812 extern void smp_send_debugger_break(void);
8813 extern void start_secondary_resume(void);
8814 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8815 index b034ecd..af7e31f 100644
8816 --- a/arch/powerpc/include/asm/thread_info.h
8817 +++ b/arch/powerpc/include/asm/thread_info.h
8818 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8819 #if defined(CONFIG_PPC64)
8820 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8821 #endif
8822 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8823 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8824
8825 /* as above, but as bit values */
8826 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8827 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8828 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8829 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8830 #define _TIF_NOHZ (1<<TIF_NOHZ)
8831 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8832 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8833 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8834 - _TIF_NOHZ)
8835 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8836
8837 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8838 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8839 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8840 index 9485b43..3bd3c16 100644
8841 --- a/arch/powerpc/include/asm/uaccess.h
8842 +++ b/arch/powerpc/include/asm/uaccess.h
8843 @@ -58,6 +58,7 @@
8844
8845 #endif
8846
8847 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8848 #define access_ok(type, addr, size) \
8849 (__chk_user_ptr(addr), \
8850 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8851 @@ -318,52 +319,6 @@ do { \
8852 extern unsigned long __copy_tofrom_user(void __user *to,
8853 const void __user *from, unsigned long size);
8854
8855 -#ifndef __powerpc64__
8856 -
8857 -static inline unsigned long copy_from_user(void *to,
8858 - const void __user *from, unsigned long n)
8859 -{
8860 - unsigned long over;
8861 -
8862 - if (access_ok(VERIFY_READ, from, n))
8863 - return __copy_tofrom_user((__force void __user *)to, from, n);
8864 - if ((unsigned long)from < TASK_SIZE) {
8865 - over = (unsigned long)from + n - TASK_SIZE;
8866 - return __copy_tofrom_user((__force void __user *)to, from,
8867 - n - over) + over;
8868 - }
8869 - return n;
8870 -}
8871 -
8872 -static inline unsigned long copy_to_user(void __user *to,
8873 - const void *from, unsigned long n)
8874 -{
8875 - unsigned long over;
8876 -
8877 - if (access_ok(VERIFY_WRITE, to, n))
8878 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8879 - if ((unsigned long)to < TASK_SIZE) {
8880 - over = (unsigned long)to + n - TASK_SIZE;
8881 - return __copy_tofrom_user(to, (__force void __user *)from,
8882 - n - over) + over;
8883 - }
8884 - return n;
8885 -}
8886 -
8887 -#else /* __powerpc64__ */
8888 -
8889 -#define __copy_in_user(to, from, size) \
8890 - __copy_tofrom_user((to), (from), (size))
8891 -
8892 -extern unsigned long copy_from_user(void *to, const void __user *from,
8893 - unsigned long n);
8894 -extern unsigned long copy_to_user(void __user *to, const void *from,
8895 - unsigned long n);
8896 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8897 - unsigned long n);
8898 -
8899 -#endif /* __powerpc64__ */
8900 -
8901 static inline unsigned long __copy_from_user_inatomic(void *to,
8902 const void __user *from, unsigned long n)
8903 {
8904 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8905 if (ret == 0)
8906 return 0;
8907 }
8908 +
8909 + if (!__builtin_constant_p(n))
8910 + check_object_size(to, n, false);
8911 +
8912 return __copy_tofrom_user((__force void __user *)to, from, n);
8913 }
8914
8915 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8916 if (ret == 0)
8917 return 0;
8918 }
8919 +
8920 + if (!__builtin_constant_p(n))
8921 + check_object_size(from, n, true);
8922 +
8923 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8924 }
8925
8926 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8927 return __copy_to_user_inatomic(to, from, size);
8928 }
8929
8930 +#ifndef __powerpc64__
8931 +
8932 +static inline unsigned long __must_check copy_from_user(void *to,
8933 + const void __user *from, unsigned long n)
8934 +{
8935 + unsigned long over;
8936 +
8937 + if ((long)n < 0)
8938 + return n;
8939 +
8940 + if (access_ok(VERIFY_READ, from, n)) {
8941 + if (!__builtin_constant_p(n))
8942 + check_object_size(to, n, false);
8943 + return __copy_tofrom_user((__force void __user *)to, from, n);
8944 + }
8945 + if ((unsigned long)from < TASK_SIZE) {
8946 + over = (unsigned long)from + n - TASK_SIZE;
8947 + if (!__builtin_constant_p(n - over))
8948 + check_object_size(to, n - over, false);
8949 + return __copy_tofrom_user((__force void __user *)to, from,
8950 + n - over) + over;
8951 + }
8952 + return n;
8953 +}
8954 +
8955 +static inline unsigned long __must_check copy_to_user(void __user *to,
8956 + const void *from, unsigned long n)
8957 +{
8958 + unsigned long over;
8959 +
8960 + if ((long)n < 0)
8961 + return n;
8962 +
8963 + if (access_ok(VERIFY_WRITE, to, n)) {
8964 + if (!__builtin_constant_p(n))
8965 + check_object_size(from, n, true);
8966 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8967 + }
8968 + if ((unsigned long)to < TASK_SIZE) {
8969 + over = (unsigned long)to + n - TASK_SIZE;
8970 + if (!__builtin_constant_p(n))
8971 + check_object_size(from, n - over, true);
8972 + return __copy_tofrom_user(to, (__force void __user *)from,
8973 + n - over) + over;
8974 + }
8975 + return n;
8976 +}
8977 +
8978 +#else /* __powerpc64__ */
8979 +
8980 +#define __copy_in_user(to, from, size) \
8981 + __copy_tofrom_user((to), (from), (size))
8982 +
8983 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8984 +{
8985 + if ((long)n < 0 || n > INT_MAX)
8986 + return n;
8987 +
8988 + if (!__builtin_constant_p(n))
8989 + check_object_size(to, n, false);
8990 +
8991 + if (likely(access_ok(VERIFY_READ, from, n)))
8992 + n = __copy_from_user(to, from, n);
8993 + else
8994 + memset(to, 0, n);
8995 + return n;
8996 +}
8997 +
8998 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8999 +{
9000 + if ((long)n < 0 || n > INT_MAX)
9001 + return n;
9002 +
9003 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
9004 + if (!__builtin_constant_p(n))
9005 + check_object_size(from, n, true);
9006 + n = __copy_to_user(to, from, n);
9007 + }
9008 + return n;
9009 +}
9010 +
9011 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
9012 + unsigned long n);
9013 +
9014 +#endif /* __powerpc64__ */
9015 +
9016 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9017
9018 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9019 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9020 index 670c312..60c2b52 100644
9021 --- a/arch/powerpc/kernel/Makefile
9022 +++ b/arch/powerpc/kernel/Makefile
9023 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9024 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9025 endif
9026
9027 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9028 +
9029 obj-y := cputable.o ptrace.o syscalls.o \
9030 irq.o align.o signal_32.o pmc.o vdso.o \
9031 process.o systbl.o idle.o \
9032 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9033 index bb9cac6..5181202 100644
9034 --- a/arch/powerpc/kernel/exceptions-64e.S
9035 +++ b/arch/powerpc/kernel/exceptions-64e.S
9036 @@ -1010,6 +1010,7 @@ storage_fault_common:
9037 std r14,_DAR(r1)
9038 std r15,_DSISR(r1)
9039 addi r3,r1,STACK_FRAME_OVERHEAD
9040 + bl save_nvgprs
9041 mr r4,r14
9042 mr r5,r15
9043 ld r14,PACA_EXGEN+EX_R14(r13)
9044 @@ -1018,8 +1019,7 @@ storage_fault_common:
9045 cmpdi r3,0
9046 bne- 1f
9047 b ret_from_except_lite
9048 -1: bl save_nvgprs
9049 - mr r5,r3
9050 +1: mr r5,r3
9051 addi r3,r1,STACK_FRAME_OVERHEAD
9052 ld r4,_DAR(r1)
9053 bl bad_page_fault
9054 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9055 index a7d36b1..53af150 100644
9056 --- a/arch/powerpc/kernel/exceptions-64s.S
9057 +++ b/arch/powerpc/kernel/exceptions-64s.S
9058 @@ -1637,10 +1637,10 @@ handle_page_fault:
9059 11: ld r4,_DAR(r1)
9060 ld r5,_DSISR(r1)
9061 addi r3,r1,STACK_FRAME_OVERHEAD
9062 + bl save_nvgprs
9063 bl do_page_fault
9064 cmpdi r3,0
9065 beq+ 12f
9066 - bl save_nvgprs
9067 mr r5,r3
9068 addi r3,r1,STACK_FRAME_OVERHEAD
9069 lwz r4,_DAR(r1)
9070 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9071 index 248ee7e..1eb60dd 100644
9072 --- a/arch/powerpc/kernel/irq.c
9073 +++ b/arch/powerpc/kernel/irq.c
9074 @@ -447,6 +447,8 @@ void migrate_irqs(void)
9075 }
9076 #endif
9077
9078 +extern void gr_handle_kernel_exploit(void);
9079 +
9080 static inline void check_stack_overflow(void)
9081 {
9082 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9083 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
9084 printk("do_IRQ: stack overflow: %ld\n",
9085 sp - sizeof(struct thread_info));
9086 dump_stack();
9087 + gr_handle_kernel_exploit();
9088 }
9089 #endif
9090 }
9091 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9092 index 6cff040..74ac5d1b 100644
9093 --- a/arch/powerpc/kernel/module_32.c
9094 +++ b/arch/powerpc/kernel/module_32.c
9095 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9096 me->arch.core_plt_section = i;
9097 }
9098 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9099 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9100 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9101 return -ENOEXEC;
9102 }
9103
9104 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9105
9106 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9107 /* Init, or core PLT? */
9108 - if (location >= mod->module_core
9109 - && location < mod->module_core + mod->core_size)
9110 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9111 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9112 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9113 - else
9114 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9115 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9116 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9117 + else {
9118 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9119 + return ~0UL;
9120 + }
9121
9122 /* Find this entry, or if that fails, the next avail. entry */
9123 while (entry->jump[0]) {
9124 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9125 }
9126 #ifdef CONFIG_DYNAMIC_FTRACE
9127 module->arch.tramp =
9128 - do_plt_call(module->module_core,
9129 + do_plt_call(module->module_core_rx,
9130 (unsigned long)ftrace_caller,
9131 sechdrs, module);
9132 #endif
9133 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9134 index be99774..9879c82 100644
9135 --- a/arch/powerpc/kernel/process.c
9136 +++ b/arch/powerpc/kernel/process.c
9137 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9138 * Lookup NIP late so we have the best change of getting the
9139 * above info out without failing
9140 */
9141 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9142 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9143 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9144 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9145 #endif
9146 show_stack(current, (unsigned long *) regs->gpr[1]);
9147 if (!user_mode(regs))
9148 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9149 newsp = stack[0];
9150 ip = stack[STACK_FRAME_LR_SAVE];
9151 if (!firstframe || ip != lr) {
9152 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9153 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9154 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9155 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9156 - printk(" (%pS)",
9157 + printk(" (%pA)",
9158 (void *)current->ret_stack[curr_frame].ret);
9159 curr_frame--;
9160 }
9161 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9162 struct pt_regs *regs = (struct pt_regs *)
9163 (sp + STACK_FRAME_OVERHEAD);
9164 lr = regs->link;
9165 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
9166 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
9167 regs->trap, (void *)regs->nip, (void *)lr);
9168 firstframe = 1;
9169 }
9170 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
9171 mtspr(SPRN_CTRLT, ctrl);
9172 }
9173 #endif /* CONFIG_PPC64 */
9174 -
9175 -unsigned long arch_align_stack(unsigned long sp)
9176 -{
9177 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9178 - sp -= get_random_int() & ~PAGE_MASK;
9179 - return sp & ~0xf;
9180 -}
9181 -
9182 -static inline unsigned long brk_rnd(void)
9183 -{
9184 - unsigned long rnd = 0;
9185 -
9186 - /* 8MB for 32bit, 1GB for 64bit */
9187 - if (is_32bit_task())
9188 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9189 - else
9190 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9191 -
9192 - return rnd << PAGE_SHIFT;
9193 -}
9194 -
9195 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9196 -{
9197 - unsigned long base = mm->brk;
9198 - unsigned long ret;
9199 -
9200 -#ifdef CONFIG_PPC_STD_MMU_64
9201 - /*
9202 - * If we are using 1TB segments and we are allowed to randomise
9203 - * the heap, we can put it above 1TB so it is backed by a 1TB
9204 - * segment. Otherwise the heap will be in the bottom 1TB
9205 - * which always uses 256MB segments and this may result in a
9206 - * performance penalty.
9207 - */
9208 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9209 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9210 -#endif
9211 -
9212 - ret = PAGE_ALIGN(base + brk_rnd());
9213 -
9214 - if (ret < mm->brk)
9215 - return mm->brk;
9216 -
9217 - return ret;
9218 -}
9219 -
9220 -unsigned long randomize_et_dyn(unsigned long base)
9221 -{
9222 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9223 -
9224 - if (ret < base)
9225 - return base;
9226 -
9227 - return ret;
9228 -}
9229 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9230 index 2e3d2bf..35df241 100644
9231 --- a/arch/powerpc/kernel/ptrace.c
9232 +++ b/arch/powerpc/kernel/ptrace.c
9233 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9234 return ret;
9235 }
9236
9237 +#ifdef CONFIG_GRKERNSEC_SETXID
9238 +extern void gr_delayed_cred_worker(void);
9239 +#endif
9240 +
9241 /*
9242 * We must return the syscall number to actually look up in the table.
9243 * This can be -1L to skip running any syscall at all.
9244 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9245
9246 secure_computing_strict(regs->gpr[0]);
9247
9248 +#ifdef CONFIG_GRKERNSEC_SETXID
9249 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9250 + gr_delayed_cred_worker();
9251 +#endif
9252 +
9253 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9254 tracehook_report_syscall_entry(regs))
9255 /*
9256 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9257 {
9258 int step;
9259
9260 +#ifdef CONFIG_GRKERNSEC_SETXID
9261 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9262 + gr_delayed_cred_worker();
9263 +#endif
9264 +
9265 audit_syscall_exit(regs);
9266
9267 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9268 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9269 index 1bc5a17..910d3f3 100644
9270 --- a/arch/powerpc/kernel/signal_32.c
9271 +++ b/arch/powerpc/kernel/signal_32.c
9272 @@ -1012,7 +1012,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
9273 /* Save user registers on the stack */
9274 frame = &rt_sf->uc.uc_mcontext;
9275 addr = frame;
9276 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9277 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9278 sigret = 0;
9279 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9280 } else {
9281 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9282 index 97c1e4b..f427f81 100644
9283 --- a/arch/powerpc/kernel/signal_64.c
9284 +++ b/arch/powerpc/kernel/signal_64.c
9285 @@ -755,7 +755,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
9286 current->thread.fp_state.fpscr = 0;
9287
9288 /* Set up to return from userspace. */
9289 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9290 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9291 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9292 } else {
9293 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9294 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9295 index 239f1cd..5359f76 100644
9296 --- a/arch/powerpc/kernel/traps.c
9297 +++ b/arch/powerpc/kernel/traps.c
9298 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9299 return flags;
9300 }
9301
9302 +extern void gr_handle_kernel_exploit(void);
9303 +
9304 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9305 int signr)
9306 {
9307 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9308 panic("Fatal exception in interrupt");
9309 if (panic_on_oops)
9310 panic("Fatal exception");
9311 +
9312 + gr_handle_kernel_exploit();
9313 +
9314 do_exit(signr);
9315 }
9316
9317 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9318 index ce74c33..0803371 100644
9319 --- a/arch/powerpc/kernel/vdso.c
9320 +++ b/arch/powerpc/kernel/vdso.c
9321 @@ -35,6 +35,7 @@
9322 #include <asm/vdso.h>
9323 #include <asm/vdso_datapage.h>
9324 #include <asm/setup.h>
9325 +#include <asm/mman.h>
9326
9327 #undef DEBUG
9328
9329 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9330 vdso_base = VDSO32_MBASE;
9331 #endif
9332
9333 - current->mm->context.vdso_base = 0;
9334 + current->mm->context.vdso_base = ~0UL;
9335
9336 /* vDSO has a problem and was disabled, just don't "enable" it for the
9337 * process
9338 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9339 vdso_base = get_unmapped_area(NULL, vdso_base,
9340 (vdso_pages << PAGE_SHIFT) +
9341 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9342 - 0, 0);
9343 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9344 if (IS_ERR_VALUE(vdso_base)) {
9345 rc = vdso_base;
9346 goto fail_mmapsem;
9347 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9348 index 61c738a..b1092d6 100644
9349 --- a/arch/powerpc/kvm/powerpc.c
9350 +++ b/arch/powerpc/kvm/powerpc.c
9351 @@ -1195,7 +1195,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9352 }
9353 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9354
9355 -int kvm_arch_init(void *opaque)
9356 +int kvm_arch_init(const void *opaque)
9357 {
9358 return 0;
9359 }
9360 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9361 index 5eea6f3..5d10396 100644
9362 --- a/arch/powerpc/lib/usercopy_64.c
9363 +++ b/arch/powerpc/lib/usercopy_64.c
9364 @@ -9,22 +9,6 @@
9365 #include <linux/module.h>
9366 #include <asm/uaccess.h>
9367
9368 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9369 -{
9370 - if (likely(access_ok(VERIFY_READ, from, n)))
9371 - n = __copy_from_user(to, from, n);
9372 - else
9373 - memset(to, 0, n);
9374 - return n;
9375 -}
9376 -
9377 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9378 -{
9379 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9380 - n = __copy_to_user(to, from, n);
9381 - return n;
9382 -}
9383 -
9384 unsigned long copy_in_user(void __user *to, const void __user *from,
9385 unsigned long n)
9386 {
9387 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9388 return n;
9389 }
9390
9391 -EXPORT_SYMBOL(copy_from_user);
9392 -EXPORT_SYMBOL(copy_to_user);
9393 EXPORT_SYMBOL(copy_in_user);
9394
9395 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9396 index 51ab9e7..7d3c78b 100644
9397 --- a/arch/powerpc/mm/fault.c
9398 +++ b/arch/powerpc/mm/fault.c
9399 @@ -33,6 +33,10 @@
9400 #include <linux/magic.h>
9401 #include <linux/ratelimit.h>
9402 #include <linux/context_tracking.h>
9403 +#include <linux/slab.h>
9404 +#include <linux/pagemap.h>
9405 +#include <linux/compiler.h>
9406 +#include <linux/unistd.h>
9407
9408 #include <asm/firmware.h>
9409 #include <asm/page.h>
9410 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9411 }
9412 #endif
9413
9414 +#ifdef CONFIG_PAX_PAGEEXEC
9415 +/*
9416 + * PaX: decide what to do with offenders (regs->nip = fault address)
9417 + *
9418 + * returns 1 when task should be killed
9419 + */
9420 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9421 +{
9422 + return 1;
9423 +}
9424 +
9425 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9426 +{
9427 + unsigned long i;
9428 +
9429 + printk(KERN_ERR "PAX: bytes at PC: ");
9430 + for (i = 0; i < 5; i++) {
9431 + unsigned int c;
9432 + if (get_user(c, (unsigned int __user *)pc+i))
9433 + printk(KERN_CONT "???????? ");
9434 + else
9435 + printk(KERN_CONT "%08x ", c);
9436 + }
9437 + printk("\n");
9438 +}
9439 +#endif
9440 +
9441 /*
9442 * Check whether the instruction at regs->nip is a store using
9443 * an update addressing form which will update r1.
9444 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9445 * indicate errors in DSISR but can validly be set in SRR1.
9446 */
9447 if (trap == 0x400)
9448 - error_code &= 0x48200000;
9449 + error_code &= 0x58200000;
9450 else
9451 is_write = error_code & DSISR_ISSTORE;
9452 #else
9453 @@ -378,7 +409,7 @@ good_area:
9454 * "undefined". Of those that can be set, this is the only
9455 * one which seems bad.
9456 */
9457 - if (error_code & 0x10000000)
9458 + if (error_code & DSISR_GUARDED)
9459 /* Guarded storage error. */
9460 goto bad_area;
9461 #endif /* CONFIG_8xx */
9462 @@ -393,7 +424,7 @@ good_area:
9463 * processors use the same I/D cache coherency mechanism
9464 * as embedded.
9465 */
9466 - if (error_code & DSISR_PROTFAULT)
9467 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9468 goto bad_area;
9469 #endif /* CONFIG_PPC_STD_MMU */
9470
9471 @@ -483,6 +514,23 @@ bad_area:
9472 bad_area_nosemaphore:
9473 /* User mode accesses cause a SIGSEGV */
9474 if (user_mode(regs)) {
9475 +
9476 +#ifdef CONFIG_PAX_PAGEEXEC
9477 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9478 +#ifdef CONFIG_PPC_STD_MMU
9479 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9480 +#else
9481 + if (is_exec && regs->nip == address) {
9482 +#endif
9483 + switch (pax_handle_fetch_fault(regs)) {
9484 + }
9485 +
9486 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9487 + do_group_exit(SIGKILL);
9488 + }
9489 + }
9490 +#endif
9491 +
9492 _exception(SIGSEGV, regs, code, address);
9493 goto bail;
9494 }
9495 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9496 index cb8bdbe..cde4bc7 100644
9497 --- a/arch/powerpc/mm/mmap.c
9498 +++ b/arch/powerpc/mm/mmap.c
9499 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9500 return sysctl_legacy_va_layout;
9501 }
9502
9503 -static unsigned long mmap_rnd(void)
9504 +static unsigned long mmap_rnd(struct mm_struct *mm)
9505 {
9506 unsigned long rnd = 0;
9507
9508 +#ifdef CONFIG_PAX_RANDMMAP
9509 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9510 +#endif
9511 +
9512 if (current->flags & PF_RANDOMIZE) {
9513 /* 8MB for 32bit, 1GB for 64bit */
9514 if (is_32bit_task())
9515 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9516 return rnd << PAGE_SHIFT;
9517 }
9518
9519 -static inline unsigned long mmap_base(void)
9520 +static inline unsigned long mmap_base(struct mm_struct *mm)
9521 {
9522 unsigned long gap = rlimit(RLIMIT_STACK);
9523
9524 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9525 else if (gap > MAX_GAP)
9526 gap = MAX_GAP;
9527
9528 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9529 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9530 }
9531
9532 /*
9533 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9534 */
9535 if (mmap_is_legacy()) {
9536 mm->mmap_base = TASK_UNMAPPED_BASE;
9537 +
9538 +#ifdef CONFIG_PAX_RANDMMAP
9539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9540 + mm->mmap_base += mm->delta_mmap;
9541 +#endif
9542 +
9543 mm->get_unmapped_area = arch_get_unmapped_area;
9544 } else {
9545 - mm->mmap_base = mmap_base();
9546 + mm->mmap_base = mmap_base(mm);
9547 +
9548 +#ifdef CONFIG_PAX_RANDMMAP
9549 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9550 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9551 +#endif
9552 +
9553 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9554 }
9555 }
9556 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9557 index b0c75cc..ef7fb93 100644
9558 --- a/arch/powerpc/mm/slice.c
9559 +++ b/arch/powerpc/mm/slice.c
9560 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9561 if ((mm->task_size - len) < addr)
9562 return 0;
9563 vma = find_vma(mm, addr);
9564 - return (!vma || (addr + len) <= vma->vm_start);
9565 + return check_heap_stack_gap(vma, addr, len, 0);
9566 }
9567
9568 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9569 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9570 info.align_offset = 0;
9571
9572 addr = TASK_UNMAPPED_BASE;
9573 +
9574 +#ifdef CONFIG_PAX_RANDMMAP
9575 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9576 + addr += mm->delta_mmap;
9577 +#endif
9578 +
9579 while (addr < TASK_SIZE) {
9580 info.low_limit = addr;
9581 if (!slice_scan_available(addr, available, 1, &addr))
9582 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9583 if (fixed && addr > (mm->task_size - len))
9584 return -ENOMEM;
9585
9586 +#ifdef CONFIG_PAX_RANDMMAP
9587 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9588 + addr = 0;
9589 +#endif
9590 +
9591 /* If hint, make sure it matches our alignment restrictions */
9592 if (!fixed && addr) {
9593 addr = _ALIGN_UP(addr, 1ul << pshift);
9594 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9595 index 4278acf..67fd0e6 100644
9596 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9597 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9598 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9599 }
9600
9601 static struct pci_ops scc_pciex_pci_ops = {
9602 - scc_pciex_read_config,
9603 - scc_pciex_write_config,
9604 + .read = scc_pciex_read_config,
9605 + .write = scc_pciex_write_config,
9606 };
9607
9608 static void pciex_clear_intr_all(unsigned int __iomem *base)
9609 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9610 index 9098692..3d54cd1 100644
9611 --- a/arch/powerpc/platforms/cell/spufs/file.c
9612 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9613 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9614 return VM_FAULT_NOPAGE;
9615 }
9616
9617 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9618 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9619 unsigned long address,
9620 - void *buf, int len, int write)
9621 + void *buf, size_t len, int write)
9622 {
9623 struct spu_context *ctx = vma->vm_file->private_data;
9624 unsigned long offset = address - vma->vm_start;
9625 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9626 index fa934fe..c296056 100644
9627 --- a/arch/s390/include/asm/atomic.h
9628 +++ b/arch/s390/include/asm/atomic.h
9629 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9630 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9631 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9632
9633 +#define atomic64_read_unchecked(v) atomic64_read(v)
9634 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9635 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9636 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9637 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9638 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9639 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9640 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9641 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9642 +
9643 #endif /* __ARCH_S390_ATOMIC__ */
9644 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9645 index 19ff956..8d39cb1 100644
9646 --- a/arch/s390/include/asm/barrier.h
9647 +++ b/arch/s390/include/asm/barrier.h
9648 @@ -37,7 +37,7 @@
9649 do { \
9650 compiletime_assert_atomic_type(*p); \
9651 barrier(); \
9652 - ACCESS_ONCE(*p) = (v); \
9653 + ACCESS_ONCE_RW(*p) = (v); \
9654 } while (0)
9655
9656 #define smp_load_acquire(p) \
9657 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9658 index 4d7ccac..d03d0ad 100644
9659 --- a/arch/s390/include/asm/cache.h
9660 +++ b/arch/s390/include/asm/cache.h
9661 @@ -9,8 +9,10 @@
9662 #ifndef __ARCH_S390_CACHE_H
9663 #define __ARCH_S390_CACHE_H
9664
9665 -#define L1_CACHE_BYTES 256
9666 +#include <linux/const.h>
9667 +
9668 #define L1_CACHE_SHIFT 8
9669 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9670 #define NET_SKB_PAD 32
9671
9672 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9673 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9674 index 78f4f87..598ce39 100644
9675 --- a/arch/s390/include/asm/elf.h
9676 +++ b/arch/s390/include/asm/elf.h
9677 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9678 the loader. We need to make sure that it is out of the way of the program
9679 that it will "exec", and that there is sufficient room for the brk. */
9680
9681 -extern unsigned long randomize_et_dyn(unsigned long base);
9682 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9683 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9684 +
9685 +#ifdef CONFIG_PAX_ASLR
9686 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9687 +
9688 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9689 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9690 +#endif
9691
9692 /* This yields a mask that user programs can use to figure out what
9693 instruction set this CPU supports. */
9694 @@ -222,9 +228,6 @@ struct linux_binprm;
9695 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9696 int arch_setup_additional_pages(struct linux_binprm *, int);
9697
9698 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9699 -#define arch_randomize_brk arch_randomize_brk
9700 -
9701 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9702
9703 #endif
9704 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9705 index c4a93d6..4d2a9b4 100644
9706 --- a/arch/s390/include/asm/exec.h
9707 +++ b/arch/s390/include/asm/exec.h
9708 @@ -7,6 +7,6 @@
9709 #ifndef __ASM_EXEC_H
9710 #define __ASM_EXEC_H
9711
9712 -extern unsigned long arch_align_stack(unsigned long sp);
9713 +#define arch_align_stack(x) ((x) & ~0xfUL)
9714
9715 #endif /* __ASM_EXEC_H */
9716 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9717 index cd4c68e..6764641 100644
9718 --- a/arch/s390/include/asm/uaccess.h
9719 +++ b/arch/s390/include/asm/uaccess.h
9720 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9721 __range_ok((unsigned long)(addr), (size)); \
9722 })
9723
9724 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9725 #define access_ok(type, addr, size) __access_ok(addr, size)
9726
9727 /*
9728 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9729 copy_to_user(void __user *to, const void *from, unsigned long n)
9730 {
9731 might_fault();
9732 +
9733 + if ((long)n < 0)
9734 + return n;
9735 +
9736 return __copy_to_user(to, from, n);
9737 }
9738
9739 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9740 static inline unsigned long __must_check
9741 copy_from_user(void *to, const void __user *from, unsigned long n)
9742 {
9743 - unsigned int sz = __compiletime_object_size(to);
9744 + size_t sz = __compiletime_object_size(to);
9745
9746 might_fault();
9747 - if (unlikely(sz != -1 && sz < n)) {
9748 +
9749 + if ((long)n < 0)
9750 + return n;
9751 +
9752 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9753 copy_from_user_overflow();
9754 return n;
9755 }
9756 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9757 index b89b591..fd9609d 100644
9758 --- a/arch/s390/kernel/module.c
9759 +++ b/arch/s390/kernel/module.c
9760 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9761
9762 /* Increase core size by size of got & plt and set start
9763 offsets for got and plt. */
9764 - me->core_size = ALIGN(me->core_size, 4);
9765 - me->arch.got_offset = me->core_size;
9766 - me->core_size += me->arch.got_size;
9767 - me->arch.plt_offset = me->core_size;
9768 - me->core_size += me->arch.plt_size;
9769 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9770 + me->arch.got_offset = me->core_size_rw;
9771 + me->core_size_rw += me->arch.got_size;
9772 + me->arch.plt_offset = me->core_size_rx;
9773 + me->core_size_rx += me->arch.plt_size;
9774 return 0;
9775 }
9776
9777 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9778 if (info->got_initialized == 0) {
9779 Elf_Addr *gotent;
9780
9781 - gotent = me->module_core + me->arch.got_offset +
9782 + gotent = me->module_core_rw + me->arch.got_offset +
9783 info->got_offset;
9784 *gotent = val;
9785 info->got_initialized = 1;
9786 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9787 rc = apply_rela_bits(loc, val, 0, 64, 0);
9788 else if (r_type == R_390_GOTENT ||
9789 r_type == R_390_GOTPLTENT) {
9790 - val += (Elf_Addr) me->module_core - loc;
9791 + val += (Elf_Addr) me->module_core_rw - loc;
9792 rc = apply_rela_bits(loc, val, 1, 32, 1);
9793 }
9794 break;
9795 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9796 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9797 if (info->plt_initialized == 0) {
9798 unsigned int *ip;
9799 - ip = me->module_core + me->arch.plt_offset +
9800 + ip = me->module_core_rx + me->arch.plt_offset +
9801 info->plt_offset;
9802 #ifndef CONFIG_64BIT
9803 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9804 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9805 val - loc + 0xffffUL < 0x1ffffeUL) ||
9806 (r_type == R_390_PLT32DBL &&
9807 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9808 - val = (Elf_Addr) me->module_core +
9809 + val = (Elf_Addr) me->module_core_rx +
9810 me->arch.plt_offset +
9811 info->plt_offset;
9812 val += rela->r_addend - loc;
9813 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9814 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9815 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9816 val = val + rela->r_addend -
9817 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9818 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9819 if (r_type == R_390_GOTOFF16)
9820 rc = apply_rela_bits(loc, val, 0, 16, 0);
9821 else if (r_type == R_390_GOTOFF32)
9822 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9823 break;
9824 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9825 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9826 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9827 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9828 rela->r_addend - loc;
9829 if (r_type == R_390_GOTPC)
9830 rc = apply_rela_bits(loc, val, 1, 32, 0);
9831 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9832 index 93b9ca4..4ea1454 100644
9833 --- a/arch/s390/kernel/process.c
9834 +++ b/arch/s390/kernel/process.c
9835 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9836 }
9837 return 0;
9838 }
9839 -
9840 -unsigned long arch_align_stack(unsigned long sp)
9841 -{
9842 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9843 - sp -= get_random_int() & ~PAGE_MASK;
9844 - return sp & ~0xf;
9845 -}
9846 -
9847 -static inline unsigned long brk_rnd(void)
9848 -{
9849 - /* 8MB for 32bit, 1GB for 64bit */
9850 - if (is_32bit_task())
9851 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9852 - else
9853 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9854 -}
9855 -
9856 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9857 -{
9858 - unsigned long ret;
9859 -
9860 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9861 - return (ret > mm->brk) ? ret : mm->brk;
9862 -}
9863 -
9864 -unsigned long randomize_et_dyn(unsigned long base)
9865 -{
9866 - unsigned long ret;
9867 -
9868 - if (!(current->flags & PF_RANDOMIZE))
9869 - return base;
9870 - ret = PAGE_ALIGN(base + brk_rnd());
9871 - return (ret > base) ? ret : base;
9872 -}
9873 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9874 index 9b436c2..54fbf0a 100644
9875 --- a/arch/s390/mm/mmap.c
9876 +++ b/arch/s390/mm/mmap.c
9877 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9878 */
9879 if (mmap_is_legacy()) {
9880 mm->mmap_base = mmap_base_legacy();
9881 +
9882 +#ifdef CONFIG_PAX_RANDMMAP
9883 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9884 + mm->mmap_base += mm->delta_mmap;
9885 +#endif
9886 +
9887 mm->get_unmapped_area = arch_get_unmapped_area;
9888 } else {
9889 mm->mmap_base = mmap_base();
9890 +
9891 +#ifdef CONFIG_PAX_RANDMMAP
9892 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9893 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9894 +#endif
9895 +
9896 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9897 }
9898 }
9899 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9900 */
9901 if (mmap_is_legacy()) {
9902 mm->mmap_base = mmap_base_legacy();
9903 +
9904 +#ifdef CONFIG_PAX_RANDMMAP
9905 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9906 + mm->mmap_base += mm->delta_mmap;
9907 +#endif
9908 +
9909 mm->get_unmapped_area = s390_get_unmapped_area;
9910 } else {
9911 mm->mmap_base = mmap_base();
9912 +
9913 +#ifdef CONFIG_PAX_RANDMMAP
9914 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9915 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9916 +#endif
9917 +
9918 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9919 }
9920 }
9921 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9922 index ae3d59f..f65f075 100644
9923 --- a/arch/score/include/asm/cache.h
9924 +++ b/arch/score/include/asm/cache.h
9925 @@ -1,7 +1,9 @@
9926 #ifndef _ASM_SCORE_CACHE_H
9927 #define _ASM_SCORE_CACHE_H
9928
9929 +#include <linux/const.h>
9930 +
9931 #define L1_CACHE_SHIFT 4
9932 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9933 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9934
9935 #endif /* _ASM_SCORE_CACHE_H */
9936 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9937 index f9f3cd5..58ff438 100644
9938 --- a/arch/score/include/asm/exec.h
9939 +++ b/arch/score/include/asm/exec.h
9940 @@ -1,6 +1,6 @@
9941 #ifndef _ASM_SCORE_EXEC_H
9942 #define _ASM_SCORE_EXEC_H
9943
9944 -extern unsigned long arch_align_stack(unsigned long sp);
9945 +#define arch_align_stack(x) (x)
9946
9947 #endif /* _ASM_SCORE_EXEC_H */
9948 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9949 index a1519ad3..e8ac1ff 100644
9950 --- a/arch/score/kernel/process.c
9951 +++ b/arch/score/kernel/process.c
9952 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9953
9954 return task_pt_regs(task)->cp0_epc;
9955 }
9956 -
9957 -unsigned long arch_align_stack(unsigned long sp)
9958 -{
9959 - return sp;
9960 -}
9961 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9962 index ef9e555..331bd29 100644
9963 --- a/arch/sh/include/asm/cache.h
9964 +++ b/arch/sh/include/asm/cache.h
9965 @@ -9,10 +9,11 @@
9966 #define __ASM_SH_CACHE_H
9967 #ifdef __KERNEL__
9968
9969 +#include <linux/const.h>
9970 #include <linux/init.h>
9971 #include <cpu/cache.h>
9972
9973 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9974 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9975
9976 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9977
9978 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9979 index 6777177..cb5e44f 100644
9980 --- a/arch/sh/mm/mmap.c
9981 +++ b/arch/sh/mm/mmap.c
9982 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9983 struct mm_struct *mm = current->mm;
9984 struct vm_area_struct *vma;
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 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
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 if (addr) {
9999 if (do_colour_align)
10000 addr = COLOUR_ALIGN(addr, pgoff);
10001 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
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 info.flags = 0;
10012 info.length = len;
10013 - info.low_limit = TASK_UNMAPPED_BASE;
10014 + info.low_limit = mm->mmap_base;
10015 info.high_limit = TASK_SIZE;
10016 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10017 info.align_offset = pgoff << PAGE_SHIFT;
10018 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10019 struct mm_struct *mm = current->mm;
10020 unsigned long addr = addr0;
10021 int do_colour_align;
10022 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10023 struct vm_unmapped_area_info info;
10024
10025 if (flags & MAP_FIXED) {
10026 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10027 if (filp || (flags & MAP_SHARED))
10028 do_colour_align = 1;
10029
10030 +#ifdef CONFIG_PAX_RANDMMAP
10031 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10032 +#endif
10033 +
10034 /* requesting a specific address */
10035 if (addr) {
10036 if (do_colour_align)
10037 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10038 addr = PAGE_ALIGN(addr);
10039
10040 vma = find_vma(mm, addr);
10041 - if (TASK_SIZE - len >= addr &&
10042 - (!vma || addr + len <= vma->vm_start))
10043 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10044 return addr;
10045 }
10046
10047 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10048 VM_BUG_ON(addr != -ENOMEM);
10049 info.flags = 0;
10050 info.low_limit = TASK_UNMAPPED_BASE;
10051 +
10052 +#ifdef CONFIG_PAX_RANDMMAP
10053 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10054 + info.low_limit += mm->delta_mmap;
10055 +#endif
10056 +
10057 info.high_limit = TASK_SIZE;
10058 addr = vm_unmapped_area(&info);
10059 }
10060 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10061 index bb894c8..8141d5c 100644
10062 --- a/arch/sparc/include/asm/atomic_64.h
10063 +++ b/arch/sparc/include/asm/atomic_64.h
10064 @@ -15,18 +15,40 @@
10065 #define ATOMIC64_INIT(i) { (i) }
10066
10067 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10068 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10069 +{
10070 + return v->counter;
10071 +}
10072 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10073 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10074 +{
10075 + return v->counter;
10076 +}
10077
10078 #define atomic_set(v, i) (((v)->counter) = i)
10079 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10080 +{
10081 + v->counter = i;
10082 +}
10083 #define atomic64_set(v, i) (((v)->counter) = i)
10084 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10085 +{
10086 + v->counter = i;
10087 +}
10088
10089 void atomic_add(int, atomic_t *);
10090 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10091 void atomic64_add(long, atomic64_t *);
10092 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10093 void atomic_sub(int, atomic_t *);
10094 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10095 void atomic64_sub(long, atomic64_t *);
10096 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10097
10098 int atomic_add_ret(int, atomic_t *);
10099 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10100 long atomic64_add_ret(long, atomic64_t *);
10101 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10102 int atomic_sub_ret(int, atomic_t *);
10103 long atomic64_sub_ret(long, atomic64_t *);
10104
10105 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10106 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10107
10108 #define atomic_inc_return(v) atomic_add_ret(1, v)
10109 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10110 +{
10111 + return atomic_add_ret_unchecked(1, v);
10112 +}
10113 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10114 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10115 +{
10116 + return atomic64_add_ret_unchecked(1, v);
10117 +}
10118
10119 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10120 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10121
10122 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10123 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10124 +{
10125 + return atomic_add_ret_unchecked(i, v);
10126 +}
10127 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10128 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10129 +{
10130 + return atomic64_add_ret_unchecked(i, v);
10131 +}
10132
10133 /*
10134 * atomic_inc_and_test - increment and test
10135 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10136 * other cases.
10137 */
10138 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10139 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10140 +{
10141 + return atomic_inc_return_unchecked(v) == 0;
10142 +}
10143 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10144
10145 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10146 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10147 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10148
10149 #define atomic_inc(v) atomic_add(1, v)
10150 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10151 +{
10152 + atomic_add_unchecked(1, v);
10153 +}
10154 #define atomic64_inc(v) atomic64_add(1, v)
10155 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10156 +{
10157 + atomic64_add_unchecked(1, v);
10158 +}
10159
10160 #define atomic_dec(v) atomic_sub(1, v)
10161 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10162 +{
10163 + atomic_sub_unchecked(1, v);
10164 +}
10165 #define atomic64_dec(v) atomic64_sub(1, v)
10166 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10167 +{
10168 + atomic64_sub_unchecked(1, v);
10169 +}
10170
10171 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10172 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10173
10174 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10175 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10176 +{
10177 + return cmpxchg(&v->counter, old, new);
10178 +}
10179 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10180 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10181 +{
10182 + return xchg(&v->counter, new);
10183 +}
10184
10185 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10186 {
10187 - int c, old;
10188 + int c, old, new;
10189 c = atomic_read(v);
10190 for (;;) {
10191 - if (unlikely(c == (u)))
10192 + if (unlikely(c == u))
10193 break;
10194 - old = atomic_cmpxchg((v), c, c + (a));
10195 +
10196 + asm volatile("addcc %2, %0, %0\n"
10197 +
10198 +#ifdef CONFIG_PAX_REFCOUNT
10199 + "tvs %%icc, 6\n"
10200 +#endif
10201 +
10202 + : "=r" (new)
10203 + : "0" (c), "ir" (a)
10204 + : "cc");
10205 +
10206 + old = atomic_cmpxchg(v, c, new);
10207 if (likely(old == c))
10208 break;
10209 c = old;
10210 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10211 #define atomic64_cmpxchg(v, o, n) \
10212 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10213 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10214 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10215 +{
10216 + return xchg(&v->counter, new);
10217 +}
10218
10219 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10220 {
10221 - long c, old;
10222 + long c, old, new;
10223 c = atomic64_read(v);
10224 for (;;) {
10225 - if (unlikely(c == (u)))
10226 + if (unlikely(c == u))
10227 break;
10228 - old = atomic64_cmpxchg((v), c, c + (a));
10229 +
10230 + asm volatile("addcc %2, %0, %0\n"
10231 +
10232 +#ifdef CONFIG_PAX_REFCOUNT
10233 + "tvs %%xcc, 6\n"
10234 +#endif
10235 +
10236 + : "=r" (new)
10237 + : "0" (c), "ir" (a)
10238 + : "cc");
10239 +
10240 + old = atomic64_cmpxchg(v, c, new);
10241 if (likely(old == c))
10242 break;
10243 c = old;
10244 }
10245 - return c != (u);
10246 + return c != u;
10247 }
10248
10249 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10250 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10251 index 305dcc3..7835030 100644
10252 --- a/arch/sparc/include/asm/barrier_64.h
10253 +++ b/arch/sparc/include/asm/barrier_64.h
10254 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10255 do { \
10256 compiletime_assert_atomic_type(*p); \
10257 barrier(); \
10258 - ACCESS_ONCE(*p) = (v); \
10259 + ACCESS_ONCE_RW(*p) = (v); \
10260 } while (0)
10261
10262 #define smp_load_acquire(p) \
10263 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10264 index 5bb6991..5c2132e 100644
10265 --- a/arch/sparc/include/asm/cache.h
10266 +++ b/arch/sparc/include/asm/cache.h
10267 @@ -7,10 +7,12 @@
10268 #ifndef _SPARC_CACHE_H
10269 #define _SPARC_CACHE_H
10270
10271 +#include <linux/const.h>
10272 +
10273 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10274
10275 #define L1_CACHE_SHIFT 5
10276 -#define L1_CACHE_BYTES 32
10277 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10278
10279 #ifdef CONFIG_SPARC32
10280 #define SMP_CACHE_BYTES_SHIFT 5
10281 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10282 index a24e41f..47677ff 100644
10283 --- a/arch/sparc/include/asm/elf_32.h
10284 +++ b/arch/sparc/include/asm/elf_32.h
10285 @@ -114,6 +114,13 @@ typedef struct {
10286
10287 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10288
10289 +#ifdef CONFIG_PAX_ASLR
10290 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10291 +
10292 +#define PAX_DELTA_MMAP_LEN 16
10293 +#define PAX_DELTA_STACK_LEN 16
10294 +#endif
10295 +
10296 /* This yields a mask that user programs can use to figure out what
10297 instruction set this cpu supports. This can NOT be done in userspace
10298 on Sparc. */
10299 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10300 index 370ca1e..d4f4a98 100644
10301 --- a/arch/sparc/include/asm/elf_64.h
10302 +++ b/arch/sparc/include/asm/elf_64.h
10303 @@ -189,6 +189,13 @@ typedef struct {
10304 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10305 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10306
10307 +#ifdef CONFIG_PAX_ASLR
10308 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10309 +
10310 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10311 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10312 +#endif
10313 +
10314 extern unsigned long sparc64_elf_hwcap;
10315 #define ELF_HWCAP sparc64_elf_hwcap
10316
10317 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10318 index a3890da..f6a408e 100644
10319 --- a/arch/sparc/include/asm/pgalloc_32.h
10320 +++ b/arch/sparc/include/asm/pgalloc_32.h
10321 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10322 }
10323
10324 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10325 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10326
10327 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10328 unsigned long address)
10329 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10330 index 39a7ac4..2c9b586 100644
10331 --- a/arch/sparc/include/asm/pgalloc_64.h
10332 +++ b/arch/sparc/include/asm/pgalloc_64.h
10333 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
10334 }
10335
10336 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
10337 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10338
10339 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
10340 {
10341 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10342 index 59ba6f6..4518128 100644
10343 --- a/arch/sparc/include/asm/pgtable.h
10344 +++ b/arch/sparc/include/asm/pgtable.h
10345 @@ -5,4 +5,8 @@
10346 #else
10347 #include <asm/pgtable_32.h>
10348 #endif
10349 +
10350 +#define ktla_ktva(addr) (addr)
10351 +#define ktva_ktla(addr) (addr)
10352 +
10353 #endif
10354 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10355 index b9b91ae..950b91e 100644
10356 --- a/arch/sparc/include/asm/pgtable_32.h
10357 +++ b/arch/sparc/include/asm/pgtable_32.h
10358 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10359 #define PAGE_SHARED SRMMU_PAGE_SHARED
10360 #define PAGE_COPY SRMMU_PAGE_COPY
10361 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10362 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10363 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10364 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10365 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10366
10367 /* Top-level page directory - dummy used by init-mm.
10368 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10369
10370 /* xwr */
10371 #define __P000 PAGE_NONE
10372 -#define __P001 PAGE_READONLY
10373 -#define __P010 PAGE_COPY
10374 -#define __P011 PAGE_COPY
10375 +#define __P001 PAGE_READONLY_NOEXEC
10376 +#define __P010 PAGE_COPY_NOEXEC
10377 +#define __P011 PAGE_COPY_NOEXEC
10378 #define __P100 PAGE_READONLY
10379 #define __P101 PAGE_READONLY
10380 #define __P110 PAGE_COPY
10381 #define __P111 PAGE_COPY
10382
10383 #define __S000 PAGE_NONE
10384 -#define __S001 PAGE_READONLY
10385 -#define __S010 PAGE_SHARED
10386 -#define __S011 PAGE_SHARED
10387 +#define __S001 PAGE_READONLY_NOEXEC
10388 +#define __S010 PAGE_SHARED_NOEXEC
10389 +#define __S011 PAGE_SHARED_NOEXEC
10390 #define __S100 PAGE_READONLY
10391 #define __S101 PAGE_READONLY
10392 #define __S110 PAGE_SHARED
10393 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10394 index 79da178..c2eede8 100644
10395 --- a/arch/sparc/include/asm/pgtsrmmu.h
10396 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10397 @@ -115,6 +115,11 @@
10398 SRMMU_EXEC | SRMMU_REF)
10399 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10400 SRMMU_EXEC | SRMMU_REF)
10401 +
10402 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10403 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10404 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10405 +
10406 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10407 SRMMU_DIRTY | SRMMU_REF)
10408
10409 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10410 index f5fffd8..a0669f0 100644
10411 --- a/arch/sparc/include/asm/setup.h
10412 +++ b/arch/sparc/include/asm/setup.h
10413 @@ -53,8 +53,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10414 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10415
10416 /* init_64.c */
10417 -extern atomic_t dcpage_flushes;
10418 -extern atomic_t dcpage_flushes_xcall;
10419 +extern atomic_unchecked_t dcpage_flushes;
10420 +extern atomic_unchecked_t dcpage_flushes_xcall;
10421
10422 extern int sysctl_tsb_ratio;
10423 #endif
10424 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10425 index 9689176..63c18ea 100644
10426 --- a/arch/sparc/include/asm/spinlock_64.h
10427 +++ b/arch/sparc/include/asm/spinlock_64.h
10428 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10429
10430 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10431
10432 -static void inline arch_read_lock(arch_rwlock_t *lock)
10433 +static inline void arch_read_lock(arch_rwlock_t *lock)
10434 {
10435 unsigned long tmp1, tmp2;
10436
10437 __asm__ __volatile__ (
10438 "1: ldsw [%2], %0\n"
10439 " brlz,pn %0, 2f\n"
10440 -"4: add %0, 1, %1\n"
10441 +"4: addcc %0, 1, %1\n"
10442 +
10443 +#ifdef CONFIG_PAX_REFCOUNT
10444 +" tvs %%icc, 6\n"
10445 +#endif
10446 +
10447 " cas [%2], %0, %1\n"
10448 " cmp %0, %1\n"
10449 " bne,pn %%icc, 1b\n"
10450 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10451 " .previous"
10452 : "=&r" (tmp1), "=&r" (tmp2)
10453 : "r" (lock)
10454 - : "memory");
10455 + : "memory", "cc");
10456 }
10457
10458 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10459 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10460 {
10461 int tmp1, tmp2;
10462
10463 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10464 "1: ldsw [%2], %0\n"
10465 " brlz,a,pn %0, 2f\n"
10466 " mov 0, %0\n"
10467 -" add %0, 1, %1\n"
10468 +" addcc %0, 1, %1\n"
10469 +
10470 +#ifdef CONFIG_PAX_REFCOUNT
10471 +" tvs %%icc, 6\n"
10472 +#endif
10473 +
10474 " cas [%2], %0, %1\n"
10475 " cmp %0, %1\n"
10476 " bne,pn %%icc, 1b\n"
10477 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10478 return tmp1;
10479 }
10480
10481 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10482 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10483 {
10484 unsigned long tmp1, tmp2;
10485
10486 __asm__ __volatile__(
10487 "1: lduw [%2], %0\n"
10488 -" sub %0, 1, %1\n"
10489 +" subcc %0, 1, %1\n"
10490 +
10491 +#ifdef CONFIG_PAX_REFCOUNT
10492 +" tvs %%icc, 6\n"
10493 +#endif
10494 +
10495 " cas [%2], %0, %1\n"
10496 " cmp %0, %1\n"
10497 " bne,pn %%xcc, 1b\n"
10498 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10499 : "memory");
10500 }
10501
10502 -static void inline arch_write_lock(arch_rwlock_t *lock)
10503 +static inline void arch_write_lock(arch_rwlock_t *lock)
10504 {
10505 unsigned long mask, tmp1, tmp2;
10506
10507 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10508 : "memory");
10509 }
10510
10511 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10512 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10513 {
10514 __asm__ __volatile__(
10515 " stw %%g0, [%0]"
10516 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10517 : "memory");
10518 }
10519
10520 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10521 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10522 {
10523 unsigned long mask, tmp1, tmp2, result;
10524
10525 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10526 index 96efa7a..16858bf 100644
10527 --- a/arch/sparc/include/asm/thread_info_32.h
10528 +++ b/arch/sparc/include/asm/thread_info_32.h
10529 @@ -49,6 +49,8 @@ struct thread_info {
10530 unsigned long w_saved;
10531
10532 struct restart_block restart_block;
10533 +
10534 + unsigned long lowest_stack;
10535 };
10536
10537 /*
10538 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10539 index a5f01ac..703b554 100644
10540 --- a/arch/sparc/include/asm/thread_info_64.h
10541 +++ b/arch/sparc/include/asm/thread_info_64.h
10542 @@ -63,6 +63,8 @@ struct thread_info {
10543 struct pt_regs *kern_una_regs;
10544 unsigned int kern_una_insn;
10545
10546 + unsigned long lowest_stack;
10547 +
10548 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10549 };
10550
10551 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10552 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10553 /* flag bit 4 is available */
10554 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10555 -/* flag bit 6 is available */
10556 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10557 #define TIF_32BIT 7 /* 32-bit binary */
10558 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10559 #define TIF_SECCOMP 9 /* secure computing */
10560 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10561 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10562 +
10563 /* NOTE: Thread flags >= 12 should be ones we have no interest
10564 * in using in assembly, else we can't use the mask as
10565 * an immediate value in instructions such as andcc.
10566 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10567 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10568 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10569 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10570 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10571
10572 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10573 _TIF_DO_NOTIFY_RESUME_MASK | \
10574 _TIF_NEED_RESCHED)
10575 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10576
10577 +#define _TIF_WORK_SYSCALL \
10578 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10579 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10580 +
10581 +
10582 /*
10583 * Thread-synchronous status.
10584 *
10585 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10586 index bd56c28..4b63d83 100644
10587 --- a/arch/sparc/include/asm/uaccess.h
10588 +++ b/arch/sparc/include/asm/uaccess.h
10589 @@ -1,5 +1,6 @@
10590 #ifndef ___ASM_SPARC_UACCESS_H
10591 #define ___ASM_SPARC_UACCESS_H
10592 +
10593 #if defined(__sparc__) && defined(__arch64__)
10594 #include <asm/uaccess_64.h>
10595 #else
10596 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10597 index 9634d08..f55fe4f 100644
10598 --- a/arch/sparc/include/asm/uaccess_32.h
10599 +++ b/arch/sparc/include/asm/uaccess_32.h
10600 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10601
10602 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10603 {
10604 - if (n && __access_ok((unsigned long) to, n))
10605 + if ((long)n < 0)
10606 + return n;
10607 +
10608 + if (n && __access_ok((unsigned long) to, n)) {
10609 + if (!__builtin_constant_p(n))
10610 + check_object_size(from, n, true);
10611 return __copy_user(to, (__force void __user *) from, n);
10612 - else
10613 + } else
10614 return n;
10615 }
10616
10617 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10618 {
10619 + if ((long)n < 0)
10620 + return n;
10621 +
10622 + if (!__builtin_constant_p(n))
10623 + check_object_size(from, n, true);
10624 +
10625 return __copy_user(to, (__force void __user *) from, n);
10626 }
10627
10628 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10629 {
10630 - if (n && __access_ok((unsigned long) from, n))
10631 + if ((long)n < 0)
10632 + return n;
10633 +
10634 + if (n && __access_ok((unsigned long) from, n)) {
10635 + if (!__builtin_constant_p(n))
10636 + check_object_size(to, n, false);
10637 return __copy_user((__force void __user *) to, from, n);
10638 - else
10639 + } else
10640 return n;
10641 }
10642
10643 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10644 {
10645 + if ((long)n < 0)
10646 + return n;
10647 +
10648 return __copy_user((__force void __user *) to, from, n);
10649 }
10650
10651 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10652 index c990a5e..f17b9c1 100644
10653 --- a/arch/sparc/include/asm/uaccess_64.h
10654 +++ b/arch/sparc/include/asm/uaccess_64.h
10655 @@ -10,6 +10,7 @@
10656 #include <linux/compiler.h>
10657 #include <linux/string.h>
10658 #include <linux/thread_info.h>
10659 +#include <linux/kernel.h>
10660 #include <asm/asi.h>
10661 #include <asm/spitfire.h>
10662 #include <asm-generic/uaccess-unaligned.h>
10663 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10664 static inline unsigned long __must_check
10665 copy_from_user(void *to, const void __user *from, unsigned long size)
10666 {
10667 - unsigned long ret = ___copy_from_user(to, from, size);
10668 + unsigned long ret;
10669
10670 + if ((long)size < 0 || size > INT_MAX)
10671 + return size;
10672 +
10673 + if (!__builtin_constant_p(size))
10674 + check_object_size(to, size, false);
10675 +
10676 + ret = ___copy_from_user(to, from, size);
10677 if (unlikely(ret))
10678 ret = copy_from_user_fixup(to, from, size);
10679
10680 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10681 static inline unsigned long __must_check
10682 copy_to_user(void __user *to, const void *from, unsigned long size)
10683 {
10684 - unsigned long ret = ___copy_to_user(to, from, size);
10685 + unsigned long ret;
10686
10687 + if ((long)size < 0 || size > INT_MAX)
10688 + return size;
10689 +
10690 + if (!__builtin_constant_p(size))
10691 + check_object_size(from, size, true);
10692 +
10693 + ret = ___copy_to_user(to, from, size);
10694 if (unlikely(ret))
10695 ret = copy_to_user_fixup(to, from, size);
10696 return ret;
10697 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10698 index 7cf9c6e..6206648 100644
10699 --- a/arch/sparc/kernel/Makefile
10700 +++ b/arch/sparc/kernel/Makefile
10701 @@ -4,7 +4,7 @@
10702 #
10703
10704 asflags-y := -ansi
10705 -ccflags-y := -Werror
10706 +#ccflags-y := -Werror
10707
10708 extra-y := head_$(BITS).o
10709
10710 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10711 index 50e7b62..79fae35 100644
10712 --- a/arch/sparc/kernel/process_32.c
10713 +++ b/arch/sparc/kernel/process_32.c
10714 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10715
10716 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10717 r->psr, r->pc, r->npc, r->y, print_tainted());
10718 - printk("PC: <%pS>\n", (void *) r->pc);
10719 + printk("PC: <%pA>\n", (void *) r->pc);
10720 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10721 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10722 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10723 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10724 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10725 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10726 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10727 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10728
10729 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10730 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10731 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10732 rw = (struct reg_window32 *) fp;
10733 pc = rw->ins[7];
10734 printk("[%08lx : ", pc);
10735 - printk("%pS ] ", (void *) pc);
10736 + printk("%pA ] ", (void *) pc);
10737 fp = rw->ins[6];
10738 } while (++count < 16);
10739 printk("\n");
10740 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10741 index 027e099..6d4178f 100644
10742 --- a/arch/sparc/kernel/process_64.c
10743 +++ b/arch/sparc/kernel/process_64.c
10744 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10745 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10746 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10747 if (regs->tstate & TSTATE_PRIV)
10748 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10749 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10750 }
10751
10752 void show_regs(struct pt_regs *regs)
10753 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10754
10755 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10756 regs->tpc, regs->tnpc, regs->y, print_tainted());
10757 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10758 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10759 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10760 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10761 regs->u_regs[3]);
10762 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10763 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10764 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10765 regs->u_regs[15]);
10766 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10767 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10768 show_regwindow(regs);
10769 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10770 }
10771 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10772 ((tp && tp->task) ? tp->task->pid : -1));
10773
10774 if (gp->tstate & TSTATE_PRIV) {
10775 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10776 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10777 (void *) gp->tpc,
10778 (void *) gp->o7,
10779 (void *) gp->i7,
10780 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10781 index 79cc0d1..ec62734 100644
10782 --- a/arch/sparc/kernel/prom_common.c
10783 +++ b/arch/sparc/kernel/prom_common.c
10784 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10785
10786 unsigned int prom_early_allocated __initdata;
10787
10788 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10789 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10790 .nextprop = prom_common_nextprop,
10791 .getproplen = prom_getproplen,
10792 .getproperty = prom_getproperty,
10793 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10794 index c13c9f2..d572c34 100644
10795 --- a/arch/sparc/kernel/ptrace_64.c
10796 +++ b/arch/sparc/kernel/ptrace_64.c
10797 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10798 return ret;
10799 }
10800
10801 +#ifdef CONFIG_GRKERNSEC_SETXID
10802 +extern void gr_delayed_cred_worker(void);
10803 +#endif
10804 +
10805 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10806 {
10807 int ret = 0;
10808 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10809 if (test_thread_flag(TIF_NOHZ))
10810 user_exit();
10811
10812 +#ifdef CONFIG_GRKERNSEC_SETXID
10813 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10814 + gr_delayed_cred_worker();
10815 +#endif
10816 +
10817 if (test_thread_flag(TIF_SYSCALL_TRACE))
10818 ret = tracehook_report_syscall_entry(regs);
10819
10820 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10821 if (test_thread_flag(TIF_NOHZ))
10822 user_exit();
10823
10824 +#ifdef CONFIG_GRKERNSEC_SETXID
10825 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10826 + gr_delayed_cred_worker();
10827 +#endif
10828 +
10829 audit_syscall_exit(regs);
10830
10831 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10832 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10833 index 41aa247..eadfb74 100644
10834 --- a/arch/sparc/kernel/smp_64.c
10835 +++ b/arch/sparc/kernel/smp_64.c
10836 @@ -883,7 +883,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10837 return;
10838
10839 #ifdef CONFIG_DEBUG_DCFLUSH
10840 - atomic_inc(&dcpage_flushes);
10841 + atomic_inc_unchecked(&dcpage_flushes);
10842 #endif
10843
10844 this_cpu = get_cpu();
10845 @@ -907,7 +907,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10846 xcall_deliver(data0, __pa(pg_addr),
10847 (u64) pg_addr, cpumask_of(cpu));
10848 #ifdef CONFIG_DEBUG_DCFLUSH
10849 - atomic_inc(&dcpage_flushes_xcall);
10850 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10851 #endif
10852 }
10853 }
10854 @@ -926,7 +926,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10855 preempt_disable();
10856
10857 #ifdef CONFIG_DEBUG_DCFLUSH
10858 - atomic_inc(&dcpage_flushes);
10859 + atomic_inc_unchecked(&dcpage_flushes);
10860 #endif
10861 data0 = 0;
10862 pg_addr = page_address(page);
10863 @@ -943,7 +943,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10864 xcall_deliver(data0, __pa(pg_addr),
10865 (u64) pg_addr, cpu_online_mask);
10866 #ifdef CONFIG_DEBUG_DCFLUSH
10867 - atomic_inc(&dcpage_flushes_xcall);
10868 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10869 #endif
10870 }
10871 __local_flush_dcache_page(page);
10872 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10873 index 646988d..b88905f 100644
10874 --- a/arch/sparc/kernel/sys_sparc_32.c
10875 +++ b/arch/sparc/kernel/sys_sparc_32.c
10876 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10877 if (len > TASK_SIZE - PAGE_SIZE)
10878 return -ENOMEM;
10879 if (!addr)
10880 - addr = TASK_UNMAPPED_BASE;
10881 + addr = current->mm->mmap_base;
10882
10883 info.flags = 0;
10884 info.length = len;
10885 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10886 index c85403d..6af95c9 100644
10887 --- a/arch/sparc/kernel/sys_sparc_64.c
10888 +++ b/arch/sparc/kernel/sys_sparc_64.c
10889 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10890 struct vm_area_struct * vma;
10891 unsigned long task_size = TASK_SIZE;
10892 int do_color_align;
10893 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10894 struct vm_unmapped_area_info info;
10895
10896 if (flags & MAP_FIXED) {
10897 /* We do not accept a shared mapping if it would violate
10898 * cache aliasing constraints.
10899 */
10900 - if ((flags & MAP_SHARED) &&
10901 + if ((filp || (flags & MAP_SHARED)) &&
10902 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10903 return -EINVAL;
10904 return addr;
10905 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10906 if (filp || (flags & MAP_SHARED))
10907 do_color_align = 1;
10908
10909 +#ifdef CONFIG_PAX_RANDMMAP
10910 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10911 +#endif
10912 +
10913 if (addr) {
10914 if (do_color_align)
10915 addr = COLOR_ALIGN(addr, pgoff);
10916 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10917 addr = PAGE_ALIGN(addr);
10918
10919 vma = find_vma(mm, addr);
10920 - if (task_size - len >= addr &&
10921 - (!vma || addr + len <= vma->vm_start))
10922 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10923 return addr;
10924 }
10925
10926 info.flags = 0;
10927 info.length = len;
10928 - info.low_limit = TASK_UNMAPPED_BASE;
10929 + info.low_limit = mm->mmap_base;
10930 info.high_limit = min(task_size, VA_EXCLUDE_START);
10931 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10932 info.align_offset = pgoff << PAGE_SHIFT;
10933 + info.threadstack_offset = offset;
10934 addr = vm_unmapped_area(&info);
10935
10936 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10937 VM_BUG_ON(addr != -ENOMEM);
10938 info.low_limit = VA_EXCLUDE_END;
10939 +
10940 +#ifdef CONFIG_PAX_RANDMMAP
10941 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10942 + info.low_limit += mm->delta_mmap;
10943 +#endif
10944 +
10945 info.high_limit = task_size;
10946 addr = vm_unmapped_area(&info);
10947 }
10948 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10949 unsigned long task_size = STACK_TOP32;
10950 unsigned long addr = addr0;
10951 int do_color_align;
10952 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10953 struct vm_unmapped_area_info info;
10954
10955 /* This should only ever run for 32-bit processes. */
10956 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10957 /* We do not accept a shared mapping if it would violate
10958 * cache aliasing constraints.
10959 */
10960 - if ((flags & MAP_SHARED) &&
10961 + if ((filp || (flags & MAP_SHARED)) &&
10962 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10963 return -EINVAL;
10964 return addr;
10965 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10966 if (filp || (flags & MAP_SHARED))
10967 do_color_align = 1;
10968
10969 +#ifdef CONFIG_PAX_RANDMMAP
10970 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10971 +#endif
10972 +
10973 /* requesting a specific address */
10974 if (addr) {
10975 if (do_color_align)
10976 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10977 addr = PAGE_ALIGN(addr);
10978
10979 vma = find_vma(mm, addr);
10980 - if (task_size - len >= addr &&
10981 - (!vma || addr + len <= vma->vm_start))
10982 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10983 return addr;
10984 }
10985
10986 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10987 info.high_limit = mm->mmap_base;
10988 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10989 info.align_offset = pgoff << PAGE_SHIFT;
10990 + info.threadstack_offset = offset;
10991 addr = vm_unmapped_area(&info);
10992
10993 /*
10994 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10995 VM_BUG_ON(addr != -ENOMEM);
10996 info.flags = 0;
10997 info.low_limit = TASK_UNMAPPED_BASE;
10998 +
10999 +#ifdef CONFIG_PAX_RANDMMAP
11000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11001 + info.low_limit += mm->delta_mmap;
11002 +#endif
11003 +
11004 info.high_limit = STACK_TOP32;
11005 addr = vm_unmapped_area(&info);
11006 }
11007 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11008 EXPORT_SYMBOL(get_fb_unmapped_area);
11009
11010 /* Essentially the same as PowerPC. */
11011 -static unsigned long mmap_rnd(void)
11012 +static unsigned long mmap_rnd(struct mm_struct *mm)
11013 {
11014 unsigned long rnd = 0UL;
11015
11016 +#ifdef CONFIG_PAX_RANDMMAP
11017 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11018 +#endif
11019 +
11020 if (current->flags & PF_RANDOMIZE) {
11021 unsigned long val = get_random_int();
11022 if (test_thread_flag(TIF_32BIT))
11023 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11024
11025 void arch_pick_mmap_layout(struct mm_struct *mm)
11026 {
11027 - unsigned long random_factor = mmap_rnd();
11028 + unsigned long random_factor = mmap_rnd(mm);
11029 unsigned long gap;
11030
11031 /*
11032 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11033 gap == RLIM_INFINITY ||
11034 sysctl_legacy_va_layout) {
11035 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11036 +
11037 +#ifdef CONFIG_PAX_RANDMMAP
11038 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11039 + mm->mmap_base += mm->delta_mmap;
11040 +#endif
11041 +
11042 mm->get_unmapped_area = arch_get_unmapped_area;
11043 } else {
11044 /* We know it's 32-bit */
11045 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11046 gap = (task_size / 6 * 5);
11047
11048 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11049 +
11050 +#ifdef CONFIG_PAX_RANDMMAP
11051 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11052 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11053 +#endif
11054 +
11055 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11056 }
11057 }
11058 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11059 index 33a17e7..d87fb1f 100644
11060 --- a/arch/sparc/kernel/syscalls.S
11061 +++ b/arch/sparc/kernel/syscalls.S
11062 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11063 #endif
11064 .align 32
11065 1: ldx [%g6 + TI_FLAGS], %l5
11066 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11067 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11068 be,pt %icc, rtrap
11069 nop
11070 call syscall_trace_leave
11071 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11072
11073 srl %i3, 0, %o3 ! IEU0
11074 srl %i2, 0, %o2 ! IEU0 Group
11075 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11076 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11077 bne,pn %icc, linux_syscall_trace32 ! CTI
11078 mov %i0, %l5 ! IEU1
11079 5: call %l7 ! CTI Group brk forced
11080 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11081
11082 mov %i3, %o3 ! IEU1
11083 mov %i4, %o4 ! IEU0 Group
11084 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11085 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11086 bne,pn %icc, linux_syscall_trace ! CTI Group
11087 mov %i0, %l5 ! IEU0
11088 2: call %l7 ! CTI Group brk forced
11089 @@ -223,7 +223,7 @@ ret_sys_call:
11090
11091 cmp %o0, -ERESTART_RESTARTBLOCK
11092 bgeu,pn %xcc, 1f
11093 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11094 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11095 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11096
11097 2:
11098 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11099 index 6fd386c5..6907d81 100644
11100 --- a/arch/sparc/kernel/traps_32.c
11101 +++ b/arch/sparc/kernel/traps_32.c
11102 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11103 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11104 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11105
11106 +extern void gr_handle_kernel_exploit(void);
11107 +
11108 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11109 {
11110 static int die_counter;
11111 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11112 count++ < 30 &&
11113 (((unsigned long) rw) >= PAGE_OFFSET) &&
11114 !(((unsigned long) rw) & 0x7)) {
11115 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11116 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11117 (void *) rw->ins[7]);
11118 rw = (struct reg_window32 *)rw->ins[6];
11119 }
11120 }
11121 printk("Instruction DUMP:");
11122 instruction_dump ((unsigned long *) regs->pc);
11123 - if(regs->psr & PSR_PS)
11124 + if(regs->psr & PSR_PS) {
11125 + gr_handle_kernel_exploit();
11126 do_exit(SIGKILL);
11127 + }
11128 do_exit(SIGSEGV);
11129 }
11130
11131 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11132 index fb6640e..2daada8 100644
11133 --- a/arch/sparc/kernel/traps_64.c
11134 +++ b/arch/sparc/kernel/traps_64.c
11135 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11136 i + 1,
11137 p->trapstack[i].tstate, p->trapstack[i].tpc,
11138 p->trapstack[i].tnpc, p->trapstack[i].tt);
11139 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11140 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11141 }
11142 }
11143
11144 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11145
11146 lvl -= 0x100;
11147 if (regs->tstate & TSTATE_PRIV) {
11148 +
11149 +#ifdef CONFIG_PAX_REFCOUNT
11150 + if (lvl == 6)
11151 + pax_report_refcount_overflow(regs);
11152 +#endif
11153 +
11154 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11155 die_if_kernel(buffer, regs);
11156 }
11157 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11158 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11159 {
11160 char buffer[32];
11161 -
11162 +
11163 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11164 0, lvl, SIGTRAP) == NOTIFY_STOP)
11165 return;
11166
11167 +#ifdef CONFIG_PAX_REFCOUNT
11168 + if (lvl == 6)
11169 + pax_report_refcount_overflow(regs);
11170 +#endif
11171 +
11172 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11173
11174 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11175 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11176 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11177 printk("%s" "ERROR(%d): ",
11178 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11179 - printk("TPC<%pS>\n", (void *) regs->tpc);
11180 + printk("TPC<%pA>\n", (void *) regs->tpc);
11181 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11182 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11183 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11184 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11185 smp_processor_id(),
11186 (type & 0x1) ? 'I' : 'D',
11187 regs->tpc);
11188 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11189 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11190 panic("Irrecoverable Cheetah+ parity error.");
11191 }
11192
11193 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11194 smp_processor_id(),
11195 (type & 0x1) ? 'I' : 'D',
11196 regs->tpc);
11197 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11198 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11199 }
11200
11201 struct sun4v_error_entry {
11202 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11203 /*0x38*/u64 reserved_5;
11204 };
11205
11206 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11207 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11208 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11209 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11210
11211 static const char *sun4v_err_type_to_str(u8 type)
11212 {
11213 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11214 }
11215
11216 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11217 - int cpu, const char *pfx, atomic_t *ocnt)
11218 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11219 {
11220 u64 *raw_ptr = (u64 *) ent;
11221 u32 attrs;
11222 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11223
11224 show_regs(regs);
11225
11226 - if ((cnt = atomic_read(ocnt)) != 0) {
11227 - atomic_set(ocnt, 0);
11228 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11229 + atomic_set_unchecked(ocnt, 0);
11230 wmb();
11231 printk("%s: Queue overflowed %d times.\n",
11232 pfx, cnt);
11233 @@ -2048,7 +2059,7 @@ out:
11234 */
11235 void sun4v_resum_overflow(struct pt_regs *regs)
11236 {
11237 - atomic_inc(&sun4v_resum_oflow_cnt);
11238 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11239 }
11240
11241 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11242 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11243 /* XXX Actually even this can make not that much sense. Perhaps
11244 * XXX we should just pull the plug and panic directly from here?
11245 */
11246 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11247 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11248 }
11249
11250 unsigned long sun4v_err_itlb_vaddr;
11251 @@ -2116,9 +2127,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11252
11253 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11254 regs->tpc, tl);
11255 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11256 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11257 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11258 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11259 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11260 (void *) regs->u_regs[UREG_I7]);
11261 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11262 "pte[%lx] error[%lx]\n",
11263 @@ -2140,9 +2151,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11264
11265 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11266 regs->tpc, tl);
11267 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11268 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11269 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11270 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11271 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11272 (void *) regs->u_regs[UREG_I7]);
11273 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11274 "pte[%lx] error[%lx]\n",
11275 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11276 fp = (unsigned long)sf->fp + STACK_BIAS;
11277 }
11278
11279 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11280 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11281 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11282 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11283 int index = tsk->curr_ret_stack;
11284 if (tsk->ret_stack && index >= graph) {
11285 pc = tsk->ret_stack[index - graph].ret;
11286 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11287 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11288 graph++;
11289 }
11290 }
11291 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11292 return (struct reg_window *) (fp + STACK_BIAS);
11293 }
11294
11295 +extern void gr_handle_kernel_exploit(void);
11296 +
11297 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11298 {
11299 static int die_counter;
11300 @@ -2411,7 +2424,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11301 while (rw &&
11302 count++ < 30 &&
11303 kstack_valid(tp, (unsigned long) rw)) {
11304 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11305 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11306 (void *) rw->ins[7]);
11307
11308 rw = kernel_stack_up(rw);
11309 @@ -2424,8 +2437,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11310 }
11311 user_instruction_dump ((unsigned int __user *) regs->tpc);
11312 }
11313 - if (regs->tstate & TSTATE_PRIV)
11314 + if (regs->tstate & TSTATE_PRIV) {
11315 + gr_handle_kernel_exploit();
11316 do_exit(SIGKILL);
11317 + }
11318 do_exit(SIGSEGV);
11319 }
11320 EXPORT_SYMBOL(die_if_kernel);
11321 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11322 index 62098a8..547ab2c 100644
11323 --- a/arch/sparc/kernel/unaligned_64.c
11324 +++ b/arch/sparc/kernel/unaligned_64.c
11325 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11326 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11327
11328 if (__ratelimit(&ratelimit)) {
11329 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11330 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11331 regs->tpc, (void *) regs->tpc);
11332 }
11333 }
11334 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11335 index 3269b02..64f5231 100644
11336 --- a/arch/sparc/lib/Makefile
11337 +++ b/arch/sparc/lib/Makefile
11338 @@ -2,7 +2,7 @@
11339 #
11340
11341 asflags-y := -ansi -DST_DIV0=0x02
11342 -ccflags-y := -Werror
11343 +#ccflags-y := -Werror
11344
11345 lib-$(CONFIG_SPARC32) += ashrdi3.o
11346 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11347 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11348 index 85c233d..68500e0 100644
11349 --- a/arch/sparc/lib/atomic_64.S
11350 +++ b/arch/sparc/lib/atomic_64.S
11351 @@ -17,7 +17,12 @@
11352 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11353 BACKOFF_SETUP(%o2)
11354 1: lduw [%o1], %g1
11355 - add %g1, %o0, %g7
11356 + addcc %g1, %o0, %g7
11357 +
11358 +#ifdef CONFIG_PAX_REFCOUNT
11359 + tvs %icc, 6
11360 +#endif
11361 +
11362 cas [%o1], %g1, %g7
11363 cmp %g1, %g7
11364 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11365 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11366 2: BACKOFF_SPIN(%o2, %o3, 1b)
11367 ENDPROC(atomic_add)
11368
11369 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11370 + BACKOFF_SETUP(%o2)
11371 +1: lduw [%o1], %g1
11372 + add %g1, %o0, %g7
11373 + cas [%o1], %g1, %g7
11374 + cmp %g1, %g7
11375 + bne,pn %icc, 2f
11376 + nop
11377 + retl
11378 + nop
11379 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11380 +ENDPROC(atomic_add_unchecked)
11381 +
11382 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11383 BACKOFF_SETUP(%o2)
11384 1: lduw [%o1], %g1
11385 - sub %g1, %o0, %g7
11386 + subcc %g1, %o0, %g7
11387 +
11388 +#ifdef CONFIG_PAX_REFCOUNT
11389 + tvs %icc, 6
11390 +#endif
11391 +
11392 cas [%o1], %g1, %g7
11393 cmp %g1, %g7
11394 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11395 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11396 2: BACKOFF_SPIN(%o2, %o3, 1b)
11397 ENDPROC(atomic_sub)
11398
11399 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11400 + BACKOFF_SETUP(%o2)
11401 +1: lduw [%o1], %g1
11402 + sub %g1, %o0, %g7
11403 + cas [%o1], %g1, %g7
11404 + cmp %g1, %g7
11405 + bne,pn %icc, 2f
11406 + nop
11407 + retl
11408 + nop
11409 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11410 +ENDPROC(atomic_sub_unchecked)
11411 +
11412 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11413 BACKOFF_SETUP(%o2)
11414 1: lduw [%o1], %g1
11415 - add %g1, %o0, %g7
11416 + addcc %g1, %o0, %g7
11417 +
11418 +#ifdef CONFIG_PAX_REFCOUNT
11419 + tvs %icc, 6
11420 +#endif
11421 +
11422 cas [%o1], %g1, %g7
11423 cmp %g1, %g7
11424 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11425 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11426 2: BACKOFF_SPIN(%o2, %o3, 1b)
11427 ENDPROC(atomic_add_ret)
11428
11429 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11430 + BACKOFF_SETUP(%o2)
11431 +1: lduw [%o1], %g1
11432 + addcc %g1, %o0, %g7
11433 + cas [%o1], %g1, %g7
11434 + cmp %g1, %g7
11435 + bne,pn %icc, 2f
11436 + add %g7, %o0, %g7
11437 + sra %g7, 0, %o0
11438 + retl
11439 + nop
11440 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11441 +ENDPROC(atomic_add_ret_unchecked)
11442 +
11443 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11444 BACKOFF_SETUP(%o2)
11445 1: lduw [%o1], %g1
11446 - sub %g1, %o0, %g7
11447 + subcc %g1, %o0, %g7
11448 +
11449 +#ifdef CONFIG_PAX_REFCOUNT
11450 + tvs %icc, 6
11451 +#endif
11452 +
11453 cas [%o1], %g1, %g7
11454 cmp %g1, %g7
11455 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11456 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11457 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11458 BACKOFF_SETUP(%o2)
11459 1: ldx [%o1], %g1
11460 - add %g1, %o0, %g7
11461 + addcc %g1, %o0, %g7
11462 +
11463 +#ifdef CONFIG_PAX_REFCOUNT
11464 + tvs %xcc, 6
11465 +#endif
11466 +
11467 casx [%o1], %g1, %g7
11468 cmp %g1, %g7
11469 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11470 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11471 2: BACKOFF_SPIN(%o2, %o3, 1b)
11472 ENDPROC(atomic64_add)
11473
11474 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11475 + BACKOFF_SETUP(%o2)
11476 +1: ldx [%o1], %g1
11477 + addcc %g1, %o0, %g7
11478 + casx [%o1], %g1, %g7
11479 + cmp %g1, %g7
11480 + bne,pn %xcc, 2f
11481 + nop
11482 + retl
11483 + nop
11484 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11485 +ENDPROC(atomic64_add_unchecked)
11486 +
11487 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11488 BACKOFF_SETUP(%o2)
11489 1: ldx [%o1], %g1
11490 - sub %g1, %o0, %g7
11491 + subcc %g1, %o0, %g7
11492 +
11493 +#ifdef CONFIG_PAX_REFCOUNT
11494 + tvs %xcc, 6
11495 +#endif
11496 +
11497 casx [%o1], %g1, %g7
11498 cmp %g1, %g7
11499 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11500 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11501 2: BACKOFF_SPIN(%o2, %o3, 1b)
11502 ENDPROC(atomic64_sub)
11503
11504 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11505 + BACKOFF_SETUP(%o2)
11506 +1: ldx [%o1], %g1
11507 + subcc %g1, %o0, %g7
11508 + casx [%o1], %g1, %g7
11509 + cmp %g1, %g7
11510 + bne,pn %xcc, 2f
11511 + nop
11512 + retl
11513 + nop
11514 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11515 +ENDPROC(atomic64_sub_unchecked)
11516 +
11517 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11518 BACKOFF_SETUP(%o2)
11519 1: ldx [%o1], %g1
11520 - add %g1, %o0, %g7
11521 + addcc %g1, %o0, %g7
11522 +
11523 +#ifdef CONFIG_PAX_REFCOUNT
11524 + tvs %xcc, 6
11525 +#endif
11526 +
11527 casx [%o1], %g1, %g7
11528 cmp %g1, %g7
11529 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11530 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11531 2: BACKOFF_SPIN(%o2, %o3, 1b)
11532 ENDPROC(atomic64_add_ret)
11533
11534 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11535 + BACKOFF_SETUP(%o2)
11536 +1: ldx [%o1], %g1
11537 + addcc %g1, %o0, %g7
11538 + casx [%o1], %g1, %g7
11539 + cmp %g1, %g7
11540 + bne,pn %xcc, 2f
11541 + add %g7, %o0, %g7
11542 + mov %g7, %o0
11543 + retl
11544 + nop
11545 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11546 +ENDPROC(atomic64_add_ret_unchecked)
11547 +
11548 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11549 BACKOFF_SETUP(%o2)
11550 1: ldx [%o1], %g1
11551 - sub %g1, %o0, %g7
11552 + subcc %g1, %o0, %g7
11553 +
11554 +#ifdef CONFIG_PAX_REFCOUNT
11555 + tvs %xcc, 6
11556 +#endif
11557 +
11558 casx [%o1], %g1, %g7
11559 cmp %g1, %g7
11560 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11561 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11562 index 323335b..ed85ea2 100644
11563 --- a/arch/sparc/lib/ksyms.c
11564 +++ b/arch/sparc/lib/ksyms.c
11565 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11566
11567 /* Atomic counter implementation. */
11568 EXPORT_SYMBOL(atomic_add);
11569 +EXPORT_SYMBOL(atomic_add_unchecked);
11570 EXPORT_SYMBOL(atomic_add_ret);
11571 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11572 EXPORT_SYMBOL(atomic_sub);
11573 +EXPORT_SYMBOL(atomic_sub_unchecked);
11574 EXPORT_SYMBOL(atomic_sub_ret);
11575 EXPORT_SYMBOL(atomic64_add);
11576 +EXPORT_SYMBOL(atomic64_add_unchecked);
11577 EXPORT_SYMBOL(atomic64_add_ret);
11578 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11579 EXPORT_SYMBOL(atomic64_sub);
11580 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11581 EXPORT_SYMBOL(atomic64_sub_ret);
11582 EXPORT_SYMBOL(atomic64_dec_if_positive);
11583
11584 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11585 index 30c3ecc..736f015 100644
11586 --- a/arch/sparc/mm/Makefile
11587 +++ b/arch/sparc/mm/Makefile
11588 @@ -2,7 +2,7 @@
11589 #
11590
11591 asflags-y := -ansi
11592 -ccflags-y := -Werror
11593 +#ccflags-y := -Werror
11594
11595 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11596 obj-y += fault_$(BITS).o
11597 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11598 index 908e8c1..1524793 100644
11599 --- a/arch/sparc/mm/fault_32.c
11600 +++ b/arch/sparc/mm/fault_32.c
11601 @@ -21,6 +21,9 @@
11602 #include <linux/perf_event.h>
11603 #include <linux/interrupt.h>
11604 #include <linux/kdebug.h>
11605 +#include <linux/slab.h>
11606 +#include <linux/pagemap.h>
11607 +#include <linux/compiler.h>
11608
11609 #include <asm/page.h>
11610 #include <asm/pgtable.h>
11611 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11612 return safe_compute_effective_address(regs, insn);
11613 }
11614
11615 +#ifdef CONFIG_PAX_PAGEEXEC
11616 +#ifdef CONFIG_PAX_DLRESOLVE
11617 +static void pax_emuplt_close(struct vm_area_struct *vma)
11618 +{
11619 + vma->vm_mm->call_dl_resolve = 0UL;
11620 +}
11621 +
11622 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11623 +{
11624 + unsigned int *kaddr;
11625 +
11626 + vmf->page = alloc_page(GFP_HIGHUSER);
11627 + if (!vmf->page)
11628 + return VM_FAULT_OOM;
11629 +
11630 + kaddr = kmap(vmf->page);
11631 + memset(kaddr, 0, PAGE_SIZE);
11632 + kaddr[0] = 0x9DE3BFA8U; /* save */
11633 + flush_dcache_page(vmf->page);
11634 + kunmap(vmf->page);
11635 + return VM_FAULT_MAJOR;
11636 +}
11637 +
11638 +static const struct vm_operations_struct pax_vm_ops = {
11639 + .close = pax_emuplt_close,
11640 + .fault = pax_emuplt_fault
11641 +};
11642 +
11643 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11644 +{
11645 + int ret;
11646 +
11647 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11648 + vma->vm_mm = current->mm;
11649 + vma->vm_start = addr;
11650 + vma->vm_end = addr + PAGE_SIZE;
11651 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11652 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11653 + vma->vm_ops = &pax_vm_ops;
11654 +
11655 + ret = insert_vm_struct(current->mm, vma);
11656 + if (ret)
11657 + return ret;
11658 +
11659 + ++current->mm->total_vm;
11660 + return 0;
11661 +}
11662 +#endif
11663 +
11664 +/*
11665 + * PaX: decide what to do with offenders (regs->pc = fault address)
11666 + *
11667 + * returns 1 when task should be killed
11668 + * 2 when patched PLT trampoline was detected
11669 + * 3 when unpatched PLT trampoline was detected
11670 + */
11671 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11672 +{
11673 +
11674 +#ifdef CONFIG_PAX_EMUPLT
11675 + int err;
11676 +
11677 + do { /* PaX: patched PLT emulation #1 */
11678 + unsigned int sethi1, sethi2, jmpl;
11679 +
11680 + err = get_user(sethi1, (unsigned int *)regs->pc);
11681 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11682 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11683 +
11684 + if (err)
11685 + break;
11686 +
11687 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11688 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11689 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11690 + {
11691 + unsigned int addr;
11692 +
11693 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11694 + addr = regs->u_regs[UREG_G1];
11695 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11696 + regs->pc = addr;
11697 + regs->npc = addr+4;
11698 + return 2;
11699 + }
11700 + } while (0);
11701 +
11702 + do { /* PaX: patched PLT emulation #2 */
11703 + unsigned int ba;
11704 +
11705 + err = get_user(ba, (unsigned int *)regs->pc);
11706 +
11707 + if (err)
11708 + break;
11709 +
11710 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11711 + unsigned int addr;
11712 +
11713 + if ((ba & 0xFFC00000U) == 0x30800000U)
11714 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11715 + else
11716 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11717 + regs->pc = addr;
11718 + regs->npc = addr+4;
11719 + return 2;
11720 + }
11721 + } while (0);
11722 +
11723 + do { /* PaX: patched PLT emulation #3 */
11724 + unsigned int sethi, bajmpl, nop;
11725 +
11726 + err = get_user(sethi, (unsigned int *)regs->pc);
11727 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11728 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11729 +
11730 + if (err)
11731 + break;
11732 +
11733 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11734 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11735 + nop == 0x01000000U)
11736 + {
11737 + unsigned int addr;
11738 +
11739 + addr = (sethi & 0x003FFFFFU) << 10;
11740 + regs->u_regs[UREG_G1] = addr;
11741 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11742 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11743 + else
11744 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11745 + regs->pc = addr;
11746 + regs->npc = addr+4;
11747 + return 2;
11748 + }
11749 + } while (0);
11750 +
11751 + do { /* PaX: unpatched PLT emulation step 1 */
11752 + unsigned int sethi, ba, nop;
11753 +
11754 + err = get_user(sethi, (unsigned int *)regs->pc);
11755 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11756 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11757 +
11758 + if (err)
11759 + break;
11760 +
11761 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11762 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11763 + nop == 0x01000000U)
11764 + {
11765 + unsigned int addr, save, call;
11766 +
11767 + if ((ba & 0xFFC00000U) == 0x30800000U)
11768 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11769 + else
11770 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11771 +
11772 + err = get_user(save, (unsigned int *)addr);
11773 + err |= get_user(call, (unsigned int *)(addr+4));
11774 + err |= get_user(nop, (unsigned int *)(addr+8));
11775 + if (err)
11776 + break;
11777 +
11778 +#ifdef CONFIG_PAX_DLRESOLVE
11779 + if (save == 0x9DE3BFA8U &&
11780 + (call & 0xC0000000U) == 0x40000000U &&
11781 + nop == 0x01000000U)
11782 + {
11783 + struct vm_area_struct *vma;
11784 + unsigned long call_dl_resolve;
11785 +
11786 + down_read(&current->mm->mmap_sem);
11787 + call_dl_resolve = current->mm->call_dl_resolve;
11788 + up_read(&current->mm->mmap_sem);
11789 + if (likely(call_dl_resolve))
11790 + goto emulate;
11791 +
11792 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11793 +
11794 + down_write(&current->mm->mmap_sem);
11795 + if (current->mm->call_dl_resolve) {
11796 + call_dl_resolve = current->mm->call_dl_resolve;
11797 + up_write(&current->mm->mmap_sem);
11798 + if (vma)
11799 + kmem_cache_free(vm_area_cachep, vma);
11800 + goto emulate;
11801 + }
11802 +
11803 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11804 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11805 + up_write(&current->mm->mmap_sem);
11806 + if (vma)
11807 + kmem_cache_free(vm_area_cachep, vma);
11808 + return 1;
11809 + }
11810 +
11811 + if (pax_insert_vma(vma, call_dl_resolve)) {
11812 + up_write(&current->mm->mmap_sem);
11813 + kmem_cache_free(vm_area_cachep, vma);
11814 + return 1;
11815 + }
11816 +
11817 + current->mm->call_dl_resolve = call_dl_resolve;
11818 + up_write(&current->mm->mmap_sem);
11819 +
11820 +emulate:
11821 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11822 + regs->pc = call_dl_resolve;
11823 + regs->npc = addr+4;
11824 + return 3;
11825 + }
11826 +#endif
11827 +
11828 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11829 + if ((save & 0xFFC00000U) == 0x05000000U &&
11830 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11831 + nop == 0x01000000U)
11832 + {
11833 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11834 + regs->u_regs[UREG_G2] = addr + 4;
11835 + addr = (save & 0x003FFFFFU) << 10;
11836 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11837 + regs->pc = addr;
11838 + regs->npc = addr+4;
11839 + return 3;
11840 + }
11841 + }
11842 + } while (0);
11843 +
11844 + do { /* PaX: unpatched PLT emulation step 2 */
11845 + unsigned int save, call, nop;
11846 +
11847 + err = get_user(save, (unsigned int *)(regs->pc-4));
11848 + err |= get_user(call, (unsigned int *)regs->pc);
11849 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11850 + if (err)
11851 + break;
11852 +
11853 + if (save == 0x9DE3BFA8U &&
11854 + (call & 0xC0000000U) == 0x40000000U &&
11855 + nop == 0x01000000U)
11856 + {
11857 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11858 +
11859 + regs->u_regs[UREG_RETPC] = regs->pc;
11860 + regs->pc = dl_resolve;
11861 + regs->npc = dl_resolve+4;
11862 + return 3;
11863 + }
11864 + } while (0);
11865 +#endif
11866 +
11867 + return 1;
11868 +}
11869 +
11870 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11871 +{
11872 + unsigned long i;
11873 +
11874 + printk(KERN_ERR "PAX: bytes at PC: ");
11875 + for (i = 0; i < 8; i++) {
11876 + unsigned int c;
11877 + if (get_user(c, (unsigned int *)pc+i))
11878 + printk(KERN_CONT "???????? ");
11879 + else
11880 + printk(KERN_CONT "%08x ", c);
11881 + }
11882 + printk("\n");
11883 +}
11884 +#endif
11885 +
11886 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11887 int text_fault)
11888 {
11889 @@ -226,6 +500,24 @@ good_area:
11890 if (!(vma->vm_flags & VM_WRITE))
11891 goto bad_area;
11892 } else {
11893 +
11894 +#ifdef CONFIG_PAX_PAGEEXEC
11895 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11896 + up_read(&mm->mmap_sem);
11897 + switch (pax_handle_fetch_fault(regs)) {
11898 +
11899 +#ifdef CONFIG_PAX_EMUPLT
11900 + case 2:
11901 + case 3:
11902 + return;
11903 +#endif
11904 +
11905 + }
11906 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11907 + do_group_exit(SIGKILL);
11908 + }
11909 +#endif
11910 +
11911 /* Allow reads even for write-only mappings */
11912 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11913 goto bad_area;
11914 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11915 index 587cd05..fbdf17a 100644
11916 --- a/arch/sparc/mm/fault_64.c
11917 +++ b/arch/sparc/mm/fault_64.c
11918 @@ -22,6 +22,9 @@
11919 #include <linux/kdebug.h>
11920 #include <linux/percpu.h>
11921 #include <linux/context_tracking.h>
11922 +#include <linux/slab.h>
11923 +#include <linux/pagemap.h>
11924 +#include <linux/compiler.h>
11925
11926 #include <asm/page.h>
11927 #include <asm/pgtable.h>
11928 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11929 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11930 regs->tpc);
11931 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11932 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11933 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11934 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11935 dump_stack();
11936 unhandled_fault(regs->tpc, current, regs);
11937 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11938 show_regs(regs);
11939 }
11940
11941 +#ifdef CONFIG_PAX_PAGEEXEC
11942 +#ifdef CONFIG_PAX_DLRESOLVE
11943 +static void pax_emuplt_close(struct vm_area_struct *vma)
11944 +{
11945 + vma->vm_mm->call_dl_resolve = 0UL;
11946 +}
11947 +
11948 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11949 +{
11950 + unsigned int *kaddr;
11951 +
11952 + vmf->page = alloc_page(GFP_HIGHUSER);
11953 + if (!vmf->page)
11954 + return VM_FAULT_OOM;
11955 +
11956 + kaddr = kmap(vmf->page);
11957 + memset(kaddr, 0, PAGE_SIZE);
11958 + kaddr[0] = 0x9DE3BFA8U; /* save */
11959 + flush_dcache_page(vmf->page);
11960 + kunmap(vmf->page);
11961 + return VM_FAULT_MAJOR;
11962 +}
11963 +
11964 +static const struct vm_operations_struct pax_vm_ops = {
11965 + .close = pax_emuplt_close,
11966 + .fault = pax_emuplt_fault
11967 +};
11968 +
11969 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11970 +{
11971 + int ret;
11972 +
11973 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11974 + vma->vm_mm = current->mm;
11975 + vma->vm_start = addr;
11976 + vma->vm_end = addr + PAGE_SIZE;
11977 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11978 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11979 + vma->vm_ops = &pax_vm_ops;
11980 +
11981 + ret = insert_vm_struct(current->mm, vma);
11982 + if (ret)
11983 + return ret;
11984 +
11985 + ++current->mm->total_vm;
11986 + return 0;
11987 +}
11988 +#endif
11989 +
11990 +/*
11991 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11992 + *
11993 + * returns 1 when task should be killed
11994 + * 2 when patched PLT trampoline was detected
11995 + * 3 when unpatched PLT trampoline was detected
11996 + */
11997 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11998 +{
11999 +
12000 +#ifdef CONFIG_PAX_EMUPLT
12001 + int err;
12002 +
12003 + do { /* PaX: patched PLT emulation #1 */
12004 + unsigned int sethi1, sethi2, jmpl;
12005 +
12006 + err = get_user(sethi1, (unsigned int *)regs->tpc);
12007 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12008 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12009 +
12010 + if (err)
12011 + break;
12012 +
12013 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12014 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12015 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12016 + {
12017 + unsigned long addr;
12018 +
12019 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12020 + addr = regs->u_regs[UREG_G1];
12021 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12022 +
12023 + if (test_thread_flag(TIF_32BIT))
12024 + addr &= 0xFFFFFFFFUL;
12025 +
12026 + regs->tpc = addr;
12027 + regs->tnpc = addr+4;
12028 + return 2;
12029 + }
12030 + } while (0);
12031 +
12032 + do { /* PaX: patched PLT emulation #2 */
12033 + unsigned int ba;
12034 +
12035 + err = get_user(ba, (unsigned int *)regs->tpc);
12036 +
12037 + if (err)
12038 + break;
12039 +
12040 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12041 + unsigned long addr;
12042 +
12043 + if ((ba & 0xFFC00000U) == 0x30800000U)
12044 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12045 + else
12046 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12047 +
12048 + if (test_thread_flag(TIF_32BIT))
12049 + addr &= 0xFFFFFFFFUL;
12050 +
12051 + regs->tpc = addr;
12052 + regs->tnpc = addr+4;
12053 + return 2;
12054 + }
12055 + } while (0);
12056 +
12057 + do { /* PaX: patched PLT emulation #3 */
12058 + unsigned int sethi, bajmpl, nop;
12059 +
12060 + err = get_user(sethi, (unsigned int *)regs->tpc);
12061 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12062 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12063 +
12064 + if (err)
12065 + break;
12066 +
12067 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12068 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12069 + nop == 0x01000000U)
12070 + {
12071 + unsigned long addr;
12072 +
12073 + addr = (sethi & 0x003FFFFFU) << 10;
12074 + regs->u_regs[UREG_G1] = addr;
12075 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12076 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12077 + else
12078 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12079 +
12080 + if (test_thread_flag(TIF_32BIT))
12081 + addr &= 0xFFFFFFFFUL;
12082 +
12083 + regs->tpc = addr;
12084 + regs->tnpc = addr+4;
12085 + return 2;
12086 + }
12087 + } while (0);
12088 +
12089 + do { /* PaX: patched PLT emulation #4 */
12090 + unsigned int sethi, mov1, call, mov2;
12091 +
12092 + err = get_user(sethi, (unsigned int *)regs->tpc);
12093 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12094 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12095 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12096 +
12097 + if (err)
12098 + break;
12099 +
12100 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12101 + mov1 == 0x8210000FU &&
12102 + (call & 0xC0000000U) == 0x40000000U &&
12103 + mov2 == 0x9E100001U)
12104 + {
12105 + unsigned long addr;
12106 +
12107 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12108 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12109 +
12110 + if (test_thread_flag(TIF_32BIT))
12111 + addr &= 0xFFFFFFFFUL;
12112 +
12113 + regs->tpc = addr;
12114 + regs->tnpc = addr+4;
12115 + return 2;
12116 + }
12117 + } while (0);
12118 +
12119 + do { /* PaX: patched PLT emulation #5 */
12120 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, 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(or1, (unsigned int *)(regs->tpc+12));
12126 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12127 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12128 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12129 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12130 +
12131 + if (err)
12132 + break;
12133 +
12134 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12135 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12136 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12137 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12138 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12139 + sllx == 0x83287020U &&
12140 + jmpl == 0x81C04005U &&
12141 + nop == 0x01000000U)
12142 + {
12143 + unsigned long addr;
12144 +
12145 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12146 + regs->u_regs[UREG_G1] <<= 32;
12147 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12148 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12149 + regs->tpc = addr;
12150 + regs->tnpc = addr+4;
12151 + return 2;
12152 + }
12153 + } while (0);
12154 +
12155 + do { /* PaX: patched PLT emulation #6 */
12156 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12157 +
12158 + err = get_user(sethi, (unsigned int *)regs->tpc);
12159 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12160 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12161 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12162 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12163 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12164 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12165 +
12166 + if (err)
12167 + break;
12168 +
12169 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12170 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12171 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12172 + sllx == 0x83287020U &&
12173 + (or & 0xFFFFE000U) == 0x8A116000U &&
12174 + jmpl == 0x81C04005U &&
12175 + nop == 0x01000000U)
12176 + {
12177 + unsigned long addr;
12178 +
12179 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12180 + regs->u_regs[UREG_G1] <<= 32;
12181 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12182 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12183 + regs->tpc = addr;
12184 + regs->tnpc = addr+4;
12185 + return 2;
12186 + }
12187 + } while (0);
12188 +
12189 + do { /* PaX: unpatched PLT emulation step 1 */
12190 + unsigned int sethi, ba, nop;
12191 +
12192 + err = get_user(sethi, (unsigned int *)regs->tpc);
12193 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12194 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12195 +
12196 + if (err)
12197 + break;
12198 +
12199 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12200 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12201 + nop == 0x01000000U)
12202 + {
12203 + unsigned long addr;
12204 + unsigned int save, call;
12205 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12206 +
12207 + if ((ba & 0xFFC00000U) == 0x30800000U)
12208 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12209 + else
12210 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12211 +
12212 + if (test_thread_flag(TIF_32BIT))
12213 + addr &= 0xFFFFFFFFUL;
12214 +
12215 + err = get_user(save, (unsigned int *)addr);
12216 + err |= get_user(call, (unsigned int *)(addr+4));
12217 + err |= get_user(nop, (unsigned int *)(addr+8));
12218 + if (err)
12219 + break;
12220 +
12221 +#ifdef CONFIG_PAX_DLRESOLVE
12222 + if (save == 0x9DE3BFA8U &&
12223 + (call & 0xC0000000U) == 0x40000000U &&
12224 + nop == 0x01000000U)
12225 + {
12226 + struct vm_area_struct *vma;
12227 + unsigned long call_dl_resolve;
12228 +
12229 + down_read(&current->mm->mmap_sem);
12230 + call_dl_resolve = current->mm->call_dl_resolve;
12231 + up_read(&current->mm->mmap_sem);
12232 + if (likely(call_dl_resolve))
12233 + goto emulate;
12234 +
12235 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12236 +
12237 + down_write(&current->mm->mmap_sem);
12238 + if (current->mm->call_dl_resolve) {
12239 + call_dl_resolve = current->mm->call_dl_resolve;
12240 + up_write(&current->mm->mmap_sem);
12241 + if (vma)
12242 + kmem_cache_free(vm_area_cachep, vma);
12243 + goto emulate;
12244 + }
12245 +
12246 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12247 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12248 + up_write(&current->mm->mmap_sem);
12249 + if (vma)
12250 + kmem_cache_free(vm_area_cachep, vma);
12251 + return 1;
12252 + }
12253 +
12254 + if (pax_insert_vma(vma, call_dl_resolve)) {
12255 + up_write(&current->mm->mmap_sem);
12256 + kmem_cache_free(vm_area_cachep, vma);
12257 + return 1;
12258 + }
12259 +
12260 + current->mm->call_dl_resolve = call_dl_resolve;
12261 + up_write(&current->mm->mmap_sem);
12262 +
12263 +emulate:
12264 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12265 + regs->tpc = call_dl_resolve;
12266 + regs->tnpc = addr+4;
12267 + return 3;
12268 + }
12269 +#endif
12270 +
12271 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12272 + if ((save & 0xFFC00000U) == 0x05000000U &&
12273 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12274 + nop == 0x01000000U)
12275 + {
12276 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12277 + regs->u_regs[UREG_G2] = addr + 4;
12278 + addr = (save & 0x003FFFFFU) << 10;
12279 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12280 +
12281 + if (test_thread_flag(TIF_32BIT))
12282 + addr &= 0xFFFFFFFFUL;
12283 +
12284 + regs->tpc = addr;
12285 + regs->tnpc = addr+4;
12286 + return 3;
12287 + }
12288 +
12289 + /* PaX: 64-bit PLT stub */
12290 + err = get_user(sethi1, (unsigned int *)addr);
12291 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12292 + err |= get_user(or1, (unsigned int *)(addr+8));
12293 + err |= get_user(or2, (unsigned int *)(addr+12));
12294 + err |= get_user(sllx, (unsigned int *)(addr+16));
12295 + err |= get_user(add, (unsigned int *)(addr+20));
12296 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12297 + err |= get_user(nop, (unsigned int *)(addr+28));
12298 + if (err)
12299 + break;
12300 +
12301 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12302 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12303 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12304 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12305 + sllx == 0x89293020U &&
12306 + add == 0x8A010005U &&
12307 + jmpl == 0x89C14000U &&
12308 + nop == 0x01000000U)
12309 + {
12310 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12311 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12312 + regs->u_regs[UREG_G4] <<= 32;
12313 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12314 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12315 + regs->u_regs[UREG_G4] = addr + 24;
12316 + addr = regs->u_regs[UREG_G5];
12317 + regs->tpc = addr;
12318 + regs->tnpc = addr+4;
12319 + return 3;
12320 + }
12321 + }
12322 + } while (0);
12323 +
12324 +#ifdef CONFIG_PAX_DLRESOLVE
12325 + do { /* PaX: unpatched PLT emulation step 2 */
12326 + unsigned int save, call, nop;
12327 +
12328 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12329 + err |= get_user(call, (unsigned int *)regs->tpc);
12330 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12331 + if (err)
12332 + break;
12333 +
12334 + if (save == 0x9DE3BFA8U &&
12335 + (call & 0xC0000000U) == 0x40000000U &&
12336 + nop == 0x01000000U)
12337 + {
12338 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12339 +
12340 + if (test_thread_flag(TIF_32BIT))
12341 + dl_resolve &= 0xFFFFFFFFUL;
12342 +
12343 + regs->u_regs[UREG_RETPC] = regs->tpc;
12344 + regs->tpc = dl_resolve;
12345 + regs->tnpc = dl_resolve+4;
12346 + return 3;
12347 + }
12348 + } while (0);
12349 +#endif
12350 +
12351 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12352 + unsigned int sethi, ba, nop;
12353 +
12354 + err = get_user(sethi, (unsigned int *)regs->tpc);
12355 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12356 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12357 +
12358 + if (err)
12359 + break;
12360 +
12361 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12362 + (ba & 0xFFF00000U) == 0x30600000U &&
12363 + nop == 0x01000000U)
12364 + {
12365 + unsigned long addr;
12366 +
12367 + addr = (sethi & 0x003FFFFFU) << 10;
12368 + regs->u_regs[UREG_G1] = addr;
12369 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12370 +
12371 + if (test_thread_flag(TIF_32BIT))
12372 + addr &= 0xFFFFFFFFUL;
12373 +
12374 + regs->tpc = addr;
12375 + regs->tnpc = addr+4;
12376 + return 2;
12377 + }
12378 + } while (0);
12379 +
12380 +#endif
12381 +
12382 + return 1;
12383 +}
12384 +
12385 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12386 +{
12387 + unsigned long i;
12388 +
12389 + printk(KERN_ERR "PAX: bytes at PC: ");
12390 + for (i = 0; i < 8; i++) {
12391 + unsigned int c;
12392 + if (get_user(c, (unsigned int *)pc+i))
12393 + printk(KERN_CONT "???????? ");
12394 + else
12395 + printk(KERN_CONT "%08x ", c);
12396 + }
12397 + printk("\n");
12398 +}
12399 +#endif
12400 +
12401 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12402 {
12403 enum ctx_state prev_state = exception_enter();
12404 @@ -350,6 +813,29 @@ retry:
12405 if (!vma)
12406 goto bad_area;
12407
12408 +#ifdef CONFIG_PAX_PAGEEXEC
12409 + /* PaX: detect ITLB misses on non-exec pages */
12410 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12411 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12412 + {
12413 + if (address != regs->tpc)
12414 + goto good_area;
12415 +
12416 + up_read(&mm->mmap_sem);
12417 + switch (pax_handle_fetch_fault(regs)) {
12418 +
12419 +#ifdef CONFIG_PAX_EMUPLT
12420 + case 2:
12421 + case 3:
12422 + return;
12423 +#endif
12424 +
12425 + }
12426 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12427 + do_group_exit(SIGKILL);
12428 + }
12429 +#endif
12430 +
12431 /* Pure DTLB misses do not tell us whether the fault causing
12432 * load/store/atomic was a write or not, it only says that there
12433 * was no match. So in such a case we (carefully) read the
12434 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12435 index d329537..2c3746a 100644
12436 --- a/arch/sparc/mm/hugetlbpage.c
12437 +++ b/arch/sparc/mm/hugetlbpage.c
12438 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12439 unsigned long addr,
12440 unsigned long len,
12441 unsigned long pgoff,
12442 - unsigned long flags)
12443 + unsigned long flags,
12444 + unsigned long offset)
12445 {
12446 + struct mm_struct *mm = current->mm;
12447 unsigned long task_size = TASK_SIZE;
12448 struct vm_unmapped_area_info info;
12449
12450 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12451
12452 info.flags = 0;
12453 info.length = len;
12454 - info.low_limit = TASK_UNMAPPED_BASE;
12455 + info.low_limit = mm->mmap_base;
12456 info.high_limit = min(task_size, VA_EXCLUDE_START);
12457 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12458 info.align_offset = 0;
12459 + info.threadstack_offset = offset;
12460 addr = vm_unmapped_area(&info);
12461
12462 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12463 VM_BUG_ON(addr != -ENOMEM);
12464 info.low_limit = VA_EXCLUDE_END;
12465 +
12466 +#ifdef CONFIG_PAX_RANDMMAP
12467 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12468 + info.low_limit += mm->delta_mmap;
12469 +#endif
12470 +
12471 info.high_limit = task_size;
12472 addr = vm_unmapped_area(&info);
12473 }
12474 @@ -55,7 +64,8 @@ static unsigned long
12475 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12476 const unsigned long len,
12477 const unsigned long pgoff,
12478 - const unsigned long flags)
12479 + const unsigned long flags,
12480 + const unsigned long offset)
12481 {
12482 struct mm_struct *mm = current->mm;
12483 unsigned long addr = addr0;
12484 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12485 info.high_limit = mm->mmap_base;
12486 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12487 info.align_offset = 0;
12488 + info.threadstack_offset = offset;
12489 addr = vm_unmapped_area(&info);
12490
12491 /*
12492 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12493 VM_BUG_ON(addr != -ENOMEM);
12494 info.flags = 0;
12495 info.low_limit = TASK_UNMAPPED_BASE;
12496 +
12497 +#ifdef CONFIG_PAX_RANDMMAP
12498 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12499 + info.low_limit += mm->delta_mmap;
12500 +#endif
12501 +
12502 info.high_limit = STACK_TOP32;
12503 addr = vm_unmapped_area(&info);
12504 }
12505 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12506 struct mm_struct *mm = current->mm;
12507 struct vm_area_struct *vma;
12508 unsigned long task_size = TASK_SIZE;
12509 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12510
12511 if (test_thread_flag(TIF_32BIT))
12512 task_size = STACK_TOP32;
12513 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12514 return addr;
12515 }
12516
12517 +#ifdef CONFIG_PAX_RANDMMAP
12518 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12519 +#endif
12520 +
12521 if (addr) {
12522 addr = ALIGN(addr, HPAGE_SIZE);
12523 vma = find_vma(mm, addr);
12524 - if (task_size - len >= addr &&
12525 - (!vma || addr + len <= vma->vm_start))
12526 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12527 return addr;
12528 }
12529 if (mm->get_unmapped_area == arch_get_unmapped_area)
12530 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12531 - pgoff, flags);
12532 + pgoff, flags, offset);
12533 else
12534 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12535 - pgoff, flags);
12536 + pgoff, flags, offset);
12537 }
12538
12539 pte_t *huge_pte_alloc(struct mm_struct *mm,
12540 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12541 index 2cfb0f2..e917d9f 100644
12542 --- a/arch/sparc/mm/init_64.c
12543 +++ b/arch/sparc/mm/init_64.c
12544 @@ -189,9 +189,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12545 int num_kernel_image_mappings;
12546
12547 #ifdef CONFIG_DEBUG_DCFLUSH
12548 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12549 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12550 #ifdef CONFIG_SMP
12551 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12552 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12553 #endif
12554 #endif
12555
12556 @@ -199,7 +199,7 @@ inline void flush_dcache_page_impl(struct page *page)
12557 {
12558 BUG_ON(tlb_type == hypervisor);
12559 #ifdef CONFIG_DEBUG_DCFLUSH
12560 - atomic_inc(&dcpage_flushes);
12561 + atomic_inc_unchecked(&dcpage_flushes);
12562 #endif
12563
12564 #ifdef DCACHE_ALIASING_POSSIBLE
12565 @@ -471,10 +471,10 @@ void mmu_info(struct seq_file *m)
12566
12567 #ifdef CONFIG_DEBUG_DCFLUSH
12568 seq_printf(m, "DCPageFlushes\t: %d\n",
12569 - atomic_read(&dcpage_flushes));
12570 + atomic_read_unchecked(&dcpage_flushes));
12571 #ifdef CONFIG_SMP
12572 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12573 - atomic_read(&dcpage_flushes_xcall));
12574 + atomic_read_unchecked(&dcpage_flushes_xcall));
12575 #endif /* CONFIG_SMP */
12576 #endif /* CONFIG_DEBUG_DCFLUSH */
12577 }
12578 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12579 index 4f3006b..453f625f 100644
12580 --- a/arch/tile/Kconfig
12581 +++ b/arch/tile/Kconfig
12582 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12583
12584 config KEXEC
12585 bool "kexec system call"
12586 + depends on !GRKERNSEC_KMEM
12587 ---help---
12588 kexec is a system call that implements the ability to shutdown your
12589 current kernel, and to start another kernel. It is like a reboot
12590 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12591 index 7b11c5f..755a026 100644
12592 --- a/arch/tile/include/asm/atomic_64.h
12593 +++ b/arch/tile/include/asm/atomic_64.h
12594 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12595
12596 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12597
12598 +#define atomic64_read_unchecked(v) atomic64_read(v)
12599 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12600 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12601 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12602 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12603 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12604 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12605 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12606 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12607 +
12608 /* Define this to indicate that cmpxchg is an efficient operation. */
12609 #define __HAVE_ARCH_CMPXCHG
12610
12611 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12612 index 6160761..00cac88 100644
12613 --- a/arch/tile/include/asm/cache.h
12614 +++ b/arch/tile/include/asm/cache.h
12615 @@ -15,11 +15,12 @@
12616 #ifndef _ASM_TILE_CACHE_H
12617 #define _ASM_TILE_CACHE_H
12618
12619 +#include <linux/const.h>
12620 #include <arch/chip.h>
12621
12622 /* bytes per L1 data cache line */
12623 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12624 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12625 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12626
12627 /* bytes per L2 cache line */
12628 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12629 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12630 index b6cde32..c0cb736 100644
12631 --- a/arch/tile/include/asm/uaccess.h
12632 +++ b/arch/tile/include/asm/uaccess.h
12633 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12634 const void __user *from,
12635 unsigned long n)
12636 {
12637 - int sz = __compiletime_object_size(to);
12638 + size_t sz = __compiletime_object_size(to);
12639
12640 - if (likely(sz == -1 || sz >= n))
12641 + if (likely(sz == (size_t)-1 || sz >= n))
12642 n = _copy_from_user(to, from, n);
12643 else
12644 copy_from_user_overflow();
12645 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12646 index e514899..f8743c4 100644
12647 --- a/arch/tile/mm/hugetlbpage.c
12648 +++ b/arch/tile/mm/hugetlbpage.c
12649 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12650 info.high_limit = TASK_SIZE;
12651 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12652 info.align_offset = 0;
12653 + info.threadstack_offset = 0;
12654 return vm_unmapped_area(&info);
12655 }
12656
12657 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12658 info.high_limit = current->mm->mmap_base;
12659 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12660 info.align_offset = 0;
12661 + info.threadstack_offset = 0;
12662 addr = vm_unmapped_area(&info);
12663
12664 /*
12665 diff --git a/arch/um/Makefile b/arch/um/Makefile
12666 index e4b1a96..16162f8 100644
12667 --- a/arch/um/Makefile
12668 +++ b/arch/um/Makefile
12669 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12670 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12671 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12672
12673 +ifdef CONSTIFY_PLUGIN
12674 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12675 +endif
12676 +
12677 #This will adjust *FLAGS accordingly to the platform.
12678 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12679
12680 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12681 index 19e1bdd..3665b77 100644
12682 --- a/arch/um/include/asm/cache.h
12683 +++ b/arch/um/include/asm/cache.h
12684 @@ -1,6 +1,7 @@
12685 #ifndef __UM_CACHE_H
12686 #define __UM_CACHE_H
12687
12688 +#include <linux/const.h>
12689
12690 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12691 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12692 @@ -12,6 +13,6 @@
12693 # define L1_CACHE_SHIFT 5
12694 #endif
12695
12696 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12697 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12698
12699 #endif
12700 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12701 index 2e0a6b1..a64d0f5 100644
12702 --- a/arch/um/include/asm/kmap_types.h
12703 +++ b/arch/um/include/asm/kmap_types.h
12704 @@ -8,6 +8,6 @@
12705
12706 /* No more #include "asm/arch/kmap_types.h" ! */
12707
12708 -#define KM_TYPE_NR 14
12709 +#define KM_TYPE_NR 15
12710
12711 #endif
12712 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12713 index 5ff53d9..5850cdf 100644
12714 --- a/arch/um/include/asm/page.h
12715 +++ b/arch/um/include/asm/page.h
12716 @@ -14,6 +14,9 @@
12717 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12718 #define PAGE_MASK (~(PAGE_SIZE-1))
12719
12720 +#define ktla_ktva(addr) (addr)
12721 +#define ktva_ktla(addr) (addr)
12722 +
12723 #ifndef __ASSEMBLY__
12724
12725 struct page;
12726 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12727 index 0032f92..cd151e0 100644
12728 --- a/arch/um/include/asm/pgtable-3level.h
12729 +++ b/arch/um/include/asm/pgtable-3level.h
12730 @@ -58,6 +58,7 @@
12731 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12732 #define pud_populate(mm, pud, pmd) \
12733 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12734 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12735
12736 #ifdef CONFIG_64BIT
12737 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12738 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12739 index f17bca8..48adb87 100644
12740 --- a/arch/um/kernel/process.c
12741 +++ b/arch/um/kernel/process.c
12742 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12743 return 2;
12744 }
12745
12746 -/*
12747 - * Only x86 and x86_64 have an arch_align_stack().
12748 - * All other arches have "#define arch_align_stack(x) (x)"
12749 - * in their asm/exec.h
12750 - * As this is included in UML from asm-um/system-generic.h,
12751 - * we can use it to behave as the subarch does.
12752 - */
12753 -#ifndef arch_align_stack
12754 -unsigned long arch_align_stack(unsigned long sp)
12755 -{
12756 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12757 - sp -= get_random_int() % 8192;
12758 - return sp & ~0xf;
12759 -}
12760 -#endif
12761 -
12762 unsigned long get_wchan(struct task_struct *p)
12763 {
12764 unsigned long stack_page, sp, ip;
12765 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12766 index ad8f795..2c7eec6 100644
12767 --- a/arch/unicore32/include/asm/cache.h
12768 +++ b/arch/unicore32/include/asm/cache.h
12769 @@ -12,8 +12,10 @@
12770 #ifndef __UNICORE_CACHE_H__
12771 #define __UNICORE_CACHE_H__
12772
12773 -#define L1_CACHE_SHIFT (5)
12774 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12775 +#include <linux/const.h>
12776 +
12777 +#define L1_CACHE_SHIFT 5
12778 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12779
12780 /*
12781 * Memory returned by kmalloc() may be used for DMA, so we must make
12782 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12783 index 27adfd9..2362ac6 100644
12784 --- a/arch/x86/Kconfig
12785 +++ b/arch/x86/Kconfig
12786 @@ -22,6 +22,7 @@ config X86_64
12787 config X86
12788 def_bool y
12789 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
12790 + select ARCH_HAS_FAST_MULTIPLIER
12791 select ARCH_MIGHT_HAVE_PC_PARPORT
12792 select ARCH_MIGHT_HAVE_PC_SERIO
12793 select HAVE_AOUT if X86_32
12794 @@ -128,7 +129,7 @@ config X86
12795 select RTC_LIB
12796 select HAVE_DEBUG_STACKOVERFLOW
12797 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12798 - select HAVE_CC_STACKPROTECTOR
12799 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12800 select GENERIC_CPU_AUTOPROBE
12801 select HAVE_ARCH_AUDITSYSCALL
12802 select ARCH_SUPPORTS_ATOMIC_RMW
12803 @@ -253,7 +254,7 @@ config X86_HT
12804
12805 config X86_32_LAZY_GS
12806 def_bool y
12807 - depends on X86_32 && !CC_STACKPROTECTOR
12808 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12809
12810 config ARCH_HWEIGHT_CFLAGS
12811 string
12812 @@ -549,6 +550,7 @@ config SCHED_OMIT_FRAME_POINTER
12813
12814 menuconfig HYPERVISOR_GUEST
12815 bool "Linux guest support"
12816 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12817 ---help---
12818 Say Y here to enable options for running Linux under various hyper-
12819 visors. This option enables basic hypervisor detection and platform
12820 @@ -1076,6 +1078,7 @@ choice
12821
12822 config NOHIGHMEM
12823 bool "off"
12824 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12825 ---help---
12826 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12827 However, the address space of 32-bit x86 processors is only 4
12828 @@ -1112,6 +1115,7 @@ config NOHIGHMEM
12829
12830 config HIGHMEM4G
12831 bool "4GB"
12832 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12833 ---help---
12834 Select this if you have a 32-bit processor and between 1 and 4
12835 gigabytes of physical RAM.
12836 @@ -1164,7 +1168,7 @@ config PAGE_OFFSET
12837 hex
12838 default 0xB0000000 if VMSPLIT_3G_OPT
12839 default 0x80000000 if VMSPLIT_2G
12840 - default 0x78000000 if VMSPLIT_2G_OPT
12841 + default 0x70000000 if VMSPLIT_2G_OPT
12842 default 0x40000000 if VMSPLIT_1G
12843 default 0xC0000000
12844 depends on X86_32
12845 @@ -1578,6 +1582,7 @@ source kernel/Kconfig.hz
12846
12847 config KEXEC
12848 bool "kexec system call"
12849 + depends on !GRKERNSEC_KMEM
12850 ---help---
12851 kexec is a system call that implements the ability to shutdown your
12852 current kernel, and to start another kernel. It is like a reboot
12853 @@ -1728,7 +1733,9 @@ config X86_NEED_RELOCS
12854
12855 config PHYSICAL_ALIGN
12856 hex "Alignment value to which kernel should be aligned"
12857 - default "0x200000"
12858 + default "0x1000000"
12859 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12860 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12861 range 0x2000 0x1000000 if X86_32
12862 range 0x200000 0x1000000 if X86_64
12863 ---help---
12864 @@ -1811,6 +1818,7 @@ config COMPAT_VDSO
12865 def_bool n
12866 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12867 depends on X86_32 || IA32_EMULATION
12868 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12869 ---help---
12870 Certain buggy versions of glibc will crash if they are
12871 presented with a 32-bit vDSO that is not mapped at the address
12872 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12873 index 6983314..54ad7e8 100644
12874 --- a/arch/x86/Kconfig.cpu
12875 +++ b/arch/x86/Kconfig.cpu
12876 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12877
12878 config X86_F00F_BUG
12879 def_bool y
12880 - depends on M586MMX || M586TSC || M586 || M486
12881 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12882
12883 config X86_INVD_BUG
12884 def_bool y
12885 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12886
12887 config X86_ALIGNMENT_16
12888 def_bool y
12889 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12890 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12891
12892 config X86_INTEL_USERCOPY
12893 def_bool y
12894 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12895 # generates cmov.
12896 config X86_CMOV
12897 def_bool y
12898 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12899 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12900
12901 config X86_MINIMUM_CPU_FAMILY
12902 int
12903 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12904 index 61bd2ad..50b625d 100644
12905 --- a/arch/x86/Kconfig.debug
12906 +++ b/arch/x86/Kconfig.debug
12907 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12908 config DEBUG_RODATA
12909 bool "Write protect kernel read-only data structures"
12910 default y
12911 - depends on DEBUG_KERNEL
12912 + depends on DEBUG_KERNEL && BROKEN
12913 ---help---
12914 Mark the kernel read-only data as write-protected in the pagetables,
12915 in order to catch accidental (and incorrect) writes to such const
12916 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12917
12918 config DEBUG_SET_MODULE_RONX
12919 bool "Set loadable kernel module data as NX and text as RO"
12920 - depends on MODULES
12921 + depends on MODULES && BROKEN
12922 ---help---
12923 This option helps catch unintended modifications to loadable
12924 kernel module's text and read-only data. It also prevents execution
12925 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12926 index 33f71b0..c2cefa2 100644
12927 --- a/arch/x86/Makefile
12928 +++ b/arch/x86/Makefile
12929 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12930 # CPU-specific tuning. Anything which can be shared with UML should go here.
12931 include $(srctree)/arch/x86/Makefile_32.cpu
12932 KBUILD_CFLAGS += $(cflags-y)
12933 -
12934 - # temporary until string.h is fixed
12935 - KBUILD_CFLAGS += -ffreestanding
12936 else
12937 BITS := 64
12938 UTS_MACHINE := x86_64
12939 @@ -114,6 +111,9 @@ else
12940 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12941 endif
12942
12943 +# temporary until string.h is fixed
12944 +KBUILD_CFLAGS += -ffreestanding
12945 +
12946 # Make sure compiler does not have buggy stack-protector support.
12947 ifdef CONFIG_CC_STACKPROTECTOR
12948 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12949 @@ -271,3 +271,12 @@ define archhelp
12950 echo ' FDINITRD=file initrd for the booted kernel'
12951 echo ' kvmconfig - Enable additional options for guest kernel support'
12952 endef
12953 +
12954 +define OLD_LD
12955 +
12956 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12957 +*** Please upgrade your binutils to 2.18 or newer
12958 +endef
12959 +
12960 +archprepare:
12961 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12962 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12963 index dbe8dd2..2f0a98f 100644
12964 --- a/arch/x86/boot/Makefile
12965 +++ b/arch/x86/boot/Makefile
12966 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12967 # ---------------------------------------------------------------------------
12968
12969 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12970 +ifdef CONSTIFY_PLUGIN
12971 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12972 +endif
12973 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12974 GCOV_PROFILE := n
12975
12976 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12977 index 878e4b9..20537ab 100644
12978 --- a/arch/x86/boot/bitops.h
12979 +++ b/arch/x86/boot/bitops.h
12980 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12981 u8 v;
12982 const u32 *p = (const u32 *)addr;
12983
12984 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12985 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12986 return v;
12987 }
12988
12989 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12990
12991 static inline void set_bit(int nr, void *addr)
12992 {
12993 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12994 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12995 }
12996
12997 #endif /* BOOT_BITOPS_H */
12998 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12999 index bd49ec6..94c7f58 100644
13000 --- a/arch/x86/boot/boot.h
13001 +++ b/arch/x86/boot/boot.h
13002 @@ -84,7 +84,7 @@ static inline void io_delay(void)
13003 static inline u16 ds(void)
13004 {
13005 u16 seg;
13006 - asm("movw %%ds,%0" : "=rm" (seg));
13007 + asm volatile("movw %%ds,%0" : "=rm" (seg));
13008 return seg;
13009 }
13010
13011 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13012 index 0fcd913..3bb5c42 100644
13013 --- a/arch/x86/boot/compressed/Makefile
13014 +++ b/arch/x86/boot/compressed/Makefile
13015 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13016 KBUILD_CFLAGS += -mno-mmx -mno-sse
13017 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13018 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13019 +ifdef CONSTIFY_PLUGIN
13020 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13021 +endif
13022
13023 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13024 GCOV_PROFILE := n
13025 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13026 index a53440e..c3dbf1e 100644
13027 --- a/arch/x86/boot/compressed/efi_stub_32.S
13028 +++ b/arch/x86/boot/compressed/efi_stub_32.S
13029 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13030 * parameter 2, ..., param n. To make things easy, we save the return
13031 * address of efi_call_phys in a global variable.
13032 */
13033 - popl %ecx
13034 - movl %ecx, saved_return_addr(%edx)
13035 - /* get the function pointer into ECX*/
13036 - popl %ecx
13037 - movl %ecx, efi_rt_function_ptr(%edx)
13038 + popl saved_return_addr(%edx)
13039 + popl efi_rt_function_ptr(%edx)
13040
13041 /*
13042 * 3. Call the physical function.
13043 */
13044 - call *%ecx
13045 + call *efi_rt_function_ptr(%edx)
13046
13047 /*
13048 * 4. Balance the stack. And because EAX contain the return value,
13049 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13050 1: popl %edx
13051 subl $1b, %edx
13052
13053 - movl efi_rt_function_ptr(%edx), %ecx
13054 - pushl %ecx
13055 + pushl efi_rt_function_ptr(%edx)
13056
13057 /*
13058 * 10. Push the saved return address onto the stack and return.
13059 */
13060 - movl saved_return_addr(%edx), %ecx
13061 - pushl %ecx
13062 - ret
13063 + jmpl *saved_return_addr(%edx)
13064 ENDPROC(efi_call_phys)
13065 .previous
13066
13067 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13068 index cbed140..5f2ca57 100644
13069 --- a/arch/x86/boot/compressed/head_32.S
13070 +++ b/arch/x86/boot/compressed/head_32.S
13071 @@ -140,10 +140,10 @@ preferred_addr:
13072 addl %eax, %ebx
13073 notl %eax
13074 andl %eax, %ebx
13075 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13076 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13077 jge 1f
13078 #endif
13079 - movl $LOAD_PHYSICAL_ADDR, %ebx
13080 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13081 1:
13082
13083 /* Target address to relocate to for decompression */
13084 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13085 index 2884e0c..904a2f7 100644
13086 --- a/arch/x86/boot/compressed/head_64.S
13087 +++ b/arch/x86/boot/compressed/head_64.S
13088 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13089 addl %eax, %ebx
13090 notl %eax
13091 andl %eax, %ebx
13092 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13093 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13094 jge 1f
13095 #endif
13096 - movl $LOAD_PHYSICAL_ADDR, %ebx
13097 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13098 1:
13099
13100 /* Target address to relocate to for decompression */
13101 @@ -322,10 +322,10 @@ preferred_addr:
13102 addq %rax, %rbp
13103 notq %rax
13104 andq %rax, %rbp
13105 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13106 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13107 jge 1f
13108 #endif
13109 - movq $LOAD_PHYSICAL_ADDR, %rbp
13110 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13111 1:
13112
13113 /* Target address to relocate to for decompression */
13114 @@ -431,8 +431,8 @@ gdt:
13115 .long gdt
13116 .word 0
13117 .quad 0x0000000000000000 /* NULL descriptor */
13118 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13119 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13120 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13121 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13122 .quad 0x0080890000000000 /* TS descriptor */
13123 .quad 0x0000000000000000 /* TS continued */
13124 gdt_end:
13125 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13126 index 57ab74d..7c52182 100644
13127 --- a/arch/x86/boot/compressed/misc.c
13128 +++ b/arch/x86/boot/compressed/misc.c
13129 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13130 * Calculate the delta between where vmlinux was linked to load
13131 * and where it was actually loaded.
13132 */
13133 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13134 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13135 if (!delta) {
13136 debug_putstr("No relocation needed... ");
13137 return;
13138 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13139 Elf32_Ehdr ehdr;
13140 Elf32_Phdr *phdrs, *phdr;
13141 #endif
13142 - void *dest;
13143 + void *dest, *prev;
13144 int i;
13145
13146 memcpy(&ehdr, output, sizeof(ehdr));
13147 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13148 case PT_LOAD:
13149 #ifdef CONFIG_RELOCATABLE
13150 dest = output;
13151 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13152 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13153 #else
13154 dest = (void *)(phdr->p_paddr);
13155 #endif
13156 memcpy(dest,
13157 output + phdr->p_offset,
13158 phdr->p_filesz);
13159 + if (i)
13160 + memset(prev, 0xff, dest - prev);
13161 + prev = dest + phdr->p_filesz;
13162 break;
13163 default: /* Ignore other PT_* */ break;
13164 }
13165 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13166 error("Destination address too large");
13167 #endif
13168 #ifndef CONFIG_RELOCATABLE
13169 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13170 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13171 error("Wrong destination address");
13172 #endif
13173
13174 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13175 index 1fd7d57..0f7d096 100644
13176 --- a/arch/x86/boot/cpucheck.c
13177 +++ b/arch/x86/boot/cpucheck.c
13178 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13179 u32 ecx = MSR_K7_HWCR;
13180 u32 eax, edx;
13181
13182 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13183 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13184 eax &= ~(1 << 15);
13185 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13186 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13187
13188 get_cpuflags(); /* Make sure it really did something */
13189 err = check_cpuflags();
13190 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13191 u32 ecx = MSR_VIA_FCR;
13192 u32 eax, edx;
13193
13194 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13195 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13196 eax |= (1<<1)|(1<<7);
13197 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13198 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13199
13200 set_bit(X86_FEATURE_CX8, cpu.flags);
13201 err = check_cpuflags();
13202 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13203 u32 eax, edx;
13204 u32 level = 1;
13205
13206 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13207 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13208 - asm("cpuid"
13209 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13210 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13211 + asm volatile("cpuid"
13212 : "+a" (level), "=d" (cpu.flags[0])
13213 : : "ecx", "ebx");
13214 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13215 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13216
13217 err = check_cpuflags();
13218 } else if (err == 0x01 &&
13219 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13220 index 7a6d43a..edf6e40 100644
13221 --- a/arch/x86/boot/header.S
13222 +++ b/arch/x86/boot/header.S
13223 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13224 # single linked list of
13225 # struct setup_data
13226
13227 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13228 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13229
13230 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13231 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13232 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13233 +#else
13234 #define VO_INIT_SIZE (VO__end - VO__text)
13235 +#endif
13236 #if ZO_INIT_SIZE > VO_INIT_SIZE
13237 #define INIT_SIZE ZO_INIT_SIZE
13238 #else
13239 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13240 index db75d07..8e6d0af 100644
13241 --- a/arch/x86/boot/memory.c
13242 +++ b/arch/x86/boot/memory.c
13243 @@ -19,7 +19,7 @@
13244
13245 static int detect_memory_e820(void)
13246 {
13247 - int count = 0;
13248 + unsigned int count = 0;
13249 struct biosregs ireg, oreg;
13250 struct e820entry *desc = boot_params.e820_map;
13251 static struct e820entry buf; /* static so it is zeroed */
13252 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13253 index ba3e100..6501b8f 100644
13254 --- a/arch/x86/boot/video-vesa.c
13255 +++ b/arch/x86/boot/video-vesa.c
13256 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13257
13258 boot_params.screen_info.vesapm_seg = oreg.es;
13259 boot_params.screen_info.vesapm_off = oreg.di;
13260 + boot_params.screen_info.vesapm_size = oreg.cx;
13261 }
13262
13263 /*
13264 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13265 index 43eda28..5ab5fdb 100644
13266 --- a/arch/x86/boot/video.c
13267 +++ b/arch/x86/boot/video.c
13268 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13269 static unsigned int get_entry(void)
13270 {
13271 char entry_buf[4];
13272 - int i, len = 0;
13273 + unsigned int i, len = 0;
13274 int key;
13275 unsigned int v;
13276
13277 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13278 index 9105655..41779c1 100644
13279 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13280 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13281 @@ -8,6 +8,8 @@
13282 * including this sentence is retained in full.
13283 */
13284
13285 +#include <asm/alternative-asm.h>
13286 +
13287 .extern crypto_ft_tab
13288 .extern crypto_it_tab
13289 .extern crypto_fl_tab
13290 @@ -70,6 +72,8 @@
13291 je B192; \
13292 leaq 32(r9),r9;
13293
13294 +#define ret pax_force_retaddr; ret
13295 +
13296 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13297 movq r1,r2; \
13298 movq r3,r4; \
13299 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13300 index 477e9d7..c92c7d8 100644
13301 --- a/arch/x86/crypto/aesni-intel_asm.S
13302 +++ b/arch/x86/crypto/aesni-intel_asm.S
13303 @@ -31,6 +31,7 @@
13304
13305 #include <linux/linkage.h>
13306 #include <asm/inst.h>
13307 +#include <asm/alternative-asm.h>
13308
13309 #ifdef __x86_64__
13310 .data
13311 @@ -205,7 +206,7 @@ enc: .octa 0x2
13312 * num_initial_blocks = b mod 4
13313 * encrypt the initial num_initial_blocks blocks and apply ghash on
13314 * the ciphertext
13315 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13316 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13317 * are clobbered
13318 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13319 */
13320 @@ -214,8 +215,8 @@ enc: .octa 0x2
13321 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13322 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13323 mov arg7, %r10 # %r10 = AAD
13324 - mov arg8, %r12 # %r12 = aadLen
13325 - mov %r12, %r11
13326 + mov arg8, %r15 # %r15 = aadLen
13327 + mov %r15, %r11
13328 pxor %xmm\i, %xmm\i
13329 _get_AAD_loop\num_initial_blocks\operation:
13330 movd (%r10), \TMP1
13331 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13332 psrldq $4, %xmm\i
13333 pxor \TMP1, %xmm\i
13334 add $4, %r10
13335 - sub $4, %r12
13336 + sub $4, %r15
13337 jne _get_AAD_loop\num_initial_blocks\operation
13338 cmp $16, %r11
13339 je _get_AAD_loop2_done\num_initial_blocks\operation
13340 - mov $16, %r12
13341 + mov $16, %r15
13342 _get_AAD_loop2\num_initial_blocks\operation:
13343 psrldq $4, %xmm\i
13344 - sub $4, %r12
13345 - cmp %r11, %r12
13346 + sub $4, %r15
13347 + cmp %r11, %r15
13348 jne _get_AAD_loop2\num_initial_blocks\operation
13349 _get_AAD_loop2_done\num_initial_blocks\operation:
13350 movdqa SHUF_MASK(%rip), %xmm14
13351 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13352 * num_initial_blocks = b mod 4
13353 * encrypt the initial num_initial_blocks blocks and apply ghash on
13354 * the ciphertext
13355 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13356 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13357 * are clobbered
13358 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13359 */
13360 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13361 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13362 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13363 mov arg7, %r10 # %r10 = AAD
13364 - mov arg8, %r12 # %r12 = aadLen
13365 - mov %r12, %r11
13366 + mov arg8, %r15 # %r15 = aadLen
13367 + mov %r15, %r11
13368 pxor %xmm\i, %xmm\i
13369 _get_AAD_loop\num_initial_blocks\operation:
13370 movd (%r10), \TMP1
13371 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13372 psrldq $4, %xmm\i
13373 pxor \TMP1, %xmm\i
13374 add $4, %r10
13375 - sub $4, %r12
13376 + sub $4, %r15
13377 jne _get_AAD_loop\num_initial_blocks\operation
13378 cmp $16, %r11
13379 je _get_AAD_loop2_done\num_initial_blocks\operation
13380 - mov $16, %r12
13381 + mov $16, %r15
13382 _get_AAD_loop2\num_initial_blocks\operation:
13383 psrldq $4, %xmm\i
13384 - sub $4, %r12
13385 - cmp %r11, %r12
13386 + sub $4, %r15
13387 + cmp %r11, %r15
13388 jne _get_AAD_loop2\num_initial_blocks\operation
13389 _get_AAD_loop2_done\num_initial_blocks\operation:
13390 movdqa SHUF_MASK(%rip), %xmm14
13391 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13392 *
13393 *****************************************************************************/
13394 ENTRY(aesni_gcm_dec)
13395 - push %r12
13396 + push %r15
13397 push %r13
13398 push %r14
13399 mov %rsp, %r14
13400 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13401 */
13402 sub $VARIABLE_OFFSET, %rsp
13403 and $~63, %rsp # align rsp to 64 bytes
13404 - mov %arg6, %r12
13405 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13406 + mov %arg6, %r15
13407 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13408 movdqa SHUF_MASK(%rip), %xmm2
13409 PSHUFB_XMM %xmm2, %xmm13
13410
13411 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13412 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13413 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13414 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13415 - mov %r13, %r12
13416 - and $(3<<4), %r12
13417 + mov %r13, %r15
13418 + and $(3<<4), %r15
13419 jz _initial_num_blocks_is_0_decrypt
13420 - cmp $(2<<4), %r12
13421 + cmp $(2<<4), %r15
13422 jb _initial_num_blocks_is_1_decrypt
13423 je _initial_num_blocks_is_2_decrypt
13424 _initial_num_blocks_is_3_decrypt:
13425 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13426 sub $16, %r11
13427 add %r13, %r11
13428 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13429 - lea SHIFT_MASK+16(%rip), %r12
13430 - sub %r13, %r12
13431 + lea SHIFT_MASK+16(%rip), %r15
13432 + sub %r13, %r15
13433 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13434 # (%r13 is the number of bytes in plaintext mod 16)
13435 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13436 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13437 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13438
13439 movdqa %xmm1, %xmm2
13440 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13441 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13442 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13443 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13444 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13445 pand %xmm1, %xmm2
13446 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13447 sub $1, %r13
13448 jne _less_than_8_bytes_left_decrypt
13449 _multiple_of_16_bytes_decrypt:
13450 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13451 - shl $3, %r12 # convert into number of bits
13452 - movd %r12d, %xmm15 # len(A) in %xmm15
13453 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13454 + shl $3, %r15 # convert into number of bits
13455 + movd %r15d, %xmm15 # len(A) in %xmm15
13456 shl $3, %arg4 # len(C) in bits (*128)
13457 MOVQ_R64_XMM %arg4, %xmm1
13458 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13459 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13460 mov %r14, %rsp
13461 pop %r14
13462 pop %r13
13463 - pop %r12
13464 + pop %r15
13465 + pax_force_retaddr
13466 ret
13467 ENDPROC(aesni_gcm_dec)
13468
13469 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13470 * poly = x^128 + x^127 + x^126 + x^121 + 1
13471 ***************************************************************************/
13472 ENTRY(aesni_gcm_enc)
13473 - push %r12
13474 + push %r15
13475 push %r13
13476 push %r14
13477 mov %rsp, %r14
13478 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13479 #
13480 sub $VARIABLE_OFFSET, %rsp
13481 and $~63, %rsp
13482 - mov %arg6, %r12
13483 - movdqu (%r12), %xmm13
13484 + mov %arg6, %r15
13485 + movdqu (%r15), %xmm13
13486 movdqa SHUF_MASK(%rip), %xmm2
13487 PSHUFB_XMM %xmm2, %xmm13
13488
13489 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13490 movdqa %xmm13, HashKey(%rsp)
13491 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13492 and $-16, %r13
13493 - mov %r13, %r12
13494 + mov %r13, %r15
13495
13496 # Encrypt first few blocks
13497
13498 - and $(3<<4), %r12
13499 + and $(3<<4), %r15
13500 jz _initial_num_blocks_is_0_encrypt
13501 - cmp $(2<<4), %r12
13502 + cmp $(2<<4), %r15
13503 jb _initial_num_blocks_is_1_encrypt
13504 je _initial_num_blocks_is_2_encrypt
13505 _initial_num_blocks_is_3_encrypt:
13506 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13507 sub $16, %r11
13508 add %r13, %r11
13509 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13510 - lea SHIFT_MASK+16(%rip), %r12
13511 - sub %r13, %r12
13512 + lea SHIFT_MASK+16(%rip), %r15
13513 + sub %r13, %r15
13514 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13515 # (%r13 is the number of bytes in plaintext mod 16)
13516 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13517 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13518 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13519 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13520 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13521 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13522 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13523 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13524 movdqa SHUF_MASK(%rip), %xmm10
13525 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13526 sub $1, %r13
13527 jne _less_than_8_bytes_left_encrypt
13528 _multiple_of_16_bytes_encrypt:
13529 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13530 - shl $3, %r12
13531 - movd %r12d, %xmm15 # len(A) in %xmm15
13532 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13533 + shl $3, %r15
13534 + movd %r15d, %xmm15 # len(A) in %xmm15
13535 shl $3, %arg4 # len(C) in bits (*128)
13536 MOVQ_R64_XMM %arg4, %xmm1
13537 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13538 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13539 mov %r14, %rsp
13540 pop %r14
13541 pop %r13
13542 - pop %r12
13543 + pop %r15
13544 + pax_force_retaddr
13545 ret
13546 ENDPROC(aesni_gcm_enc)
13547
13548 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13549 pxor %xmm1, %xmm0
13550 movaps %xmm0, (TKEYP)
13551 add $0x10, TKEYP
13552 + pax_force_retaddr
13553 ret
13554 ENDPROC(_key_expansion_128)
13555 ENDPROC(_key_expansion_256a)
13556 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13557 shufps $0b01001110, %xmm2, %xmm1
13558 movaps %xmm1, 0x10(TKEYP)
13559 add $0x20, TKEYP
13560 + pax_force_retaddr
13561 ret
13562 ENDPROC(_key_expansion_192a)
13563
13564 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13565
13566 movaps %xmm0, (TKEYP)
13567 add $0x10, TKEYP
13568 + pax_force_retaddr
13569 ret
13570 ENDPROC(_key_expansion_192b)
13571
13572 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13573 pxor %xmm1, %xmm2
13574 movaps %xmm2, (TKEYP)
13575 add $0x10, TKEYP
13576 + pax_force_retaddr
13577 ret
13578 ENDPROC(_key_expansion_256b)
13579
13580 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13581 #ifndef __x86_64__
13582 popl KEYP
13583 #endif
13584 + pax_force_retaddr
13585 ret
13586 ENDPROC(aesni_set_key)
13587
13588 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13589 popl KLEN
13590 popl KEYP
13591 #endif
13592 + pax_force_retaddr
13593 ret
13594 ENDPROC(aesni_enc)
13595
13596 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13597 AESENC KEY STATE
13598 movaps 0x70(TKEYP), KEY
13599 AESENCLAST KEY STATE
13600 + pax_force_retaddr
13601 ret
13602 ENDPROC(_aesni_enc1)
13603
13604 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13605 AESENCLAST KEY STATE2
13606 AESENCLAST KEY STATE3
13607 AESENCLAST KEY STATE4
13608 + pax_force_retaddr
13609 ret
13610 ENDPROC(_aesni_enc4)
13611
13612 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13613 popl KLEN
13614 popl KEYP
13615 #endif
13616 + pax_force_retaddr
13617 ret
13618 ENDPROC(aesni_dec)
13619
13620 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13621 AESDEC KEY STATE
13622 movaps 0x70(TKEYP), KEY
13623 AESDECLAST KEY STATE
13624 + pax_force_retaddr
13625 ret
13626 ENDPROC(_aesni_dec1)
13627
13628 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13629 AESDECLAST KEY STATE2
13630 AESDECLAST KEY STATE3
13631 AESDECLAST KEY STATE4
13632 + pax_force_retaddr
13633 ret
13634 ENDPROC(_aesni_dec4)
13635
13636 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13637 popl KEYP
13638 popl LEN
13639 #endif
13640 + pax_force_retaddr
13641 ret
13642 ENDPROC(aesni_ecb_enc)
13643
13644 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13645 popl KEYP
13646 popl LEN
13647 #endif
13648 + pax_force_retaddr
13649 ret
13650 ENDPROC(aesni_ecb_dec)
13651
13652 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13653 popl LEN
13654 popl IVP
13655 #endif
13656 + pax_force_retaddr
13657 ret
13658 ENDPROC(aesni_cbc_enc)
13659
13660 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13661 popl LEN
13662 popl IVP
13663 #endif
13664 + pax_force_retaddr
13665 ret
13666 ENDPROC(aesni_cbc_dec)
13667
13668 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13669 mov $1, TCTR_LOW
13670 MOVQ_R64_XMM TCTR_LOW INC
13671 MOVQ_R64_XMM CTR TCTR_LOW
13672 + pax_force_retaddr
13673 ret
13674 ENDPROC(_aesni_inc_init)
13675
13676 @@ -2579,6 +2598,7 @@ _aesni_inc:
13677 .Linc_low:
13678 movaps CTR, IV
13679 PSHUFB_XMM BSWAP_MASK IV
13680 + pax_force_retaddr
13681 ret
13682 ENDPROC(_aesni_inc)
13683
13684 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13685 .Lctr_enc_ret:
13686 movups IV, (IVP)
13687 .Lctr_enc_just_ret:
13688 + pax_force_retaddr
13689 ret
13690 ENDPROC(aesni_ctr_enc)
13691
13692 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13693 pxor INC, STATE4
13694 movdqu STATE4, 0x70(OUTP)
13695
13696 + pax_force_retaddr
13697 ret
13698 ENDPROC(aesni_xts_crypt8)
13699
13700 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13701 index 246c670..466e2d6 100644
13702 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13703 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13704 @@ -21,6 +21,7 @@
13705 */
13706
13707 #include <linux/linkage.h>
13708 +#include <asm/alternative-asm.h>
13709
13710 .file "blowfish-x86_64-asm.S"
13711 .text
13712 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13713 jnz .L__enc_xor;
13714
13715 write_block();
13716 + pax_force_retaddr
13717 ret;
13718 .L__enc_xor:
13719 xor_block();
13720 + pax_force_retaddr
13721 ret;
13722 ENDPROC(__blowfish_enc_blk)
13723
13724 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13725
13726 movq %r11, %rbp;
13727
13728 + pax_force_retaddr
13729 ret;
13730 ENDPROC(blowfish_dec_blk)
13731
13732 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13733
13734 popq %rbx;
13735 popq %rbp;
13736 + pax_force_retaddr
13737 ret;
13738
13739 .L__enc_xor4:
13740 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13741
13742 popq %rbx;
13743 popq %rbp;
13744 + pax_force_retaddr
13745 ret;
13746 ENDPROC(__blowfish_enc_blk_4way)
13747
13748 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13749 popq %rbx;
13750 popq %rbp;
13751
13752 + pax_force_retaddr
13753 ret;
13754 ENDPROC(blowfish_dec_blk_4way)
13755 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13756 index ce71f92..1dce7ec 100644
13757 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13758 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13759 @@ -16,6 +16,7 @@
13760 */
13761
13762 #include <linux/linkage.h>
13763 +#include <asm/alternative-asm.h>
13764
13765 #define CAMELLIA_TABLE_BYTE_LEN 272
13766
13767 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13768 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13769 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13770 %rcx, (%r9));
13771 + pax_force_retaddr
13772 ret;
13773 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13774
13775 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13776 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13777 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13778 %rax, (%r9));
13779 + pax_force_retaddr
13780 ret;
13781 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13782
13783 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13784 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13785 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13786
13787 + pax_force_retaddr
13788 ret;
13789
13790 .align 8
13791 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13792 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13793 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13794
13795 + pax_force_retaddr
13796 ret;
13797
13798 .align 8
13799 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13800 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13801 %xmm8, %rsi);
13802
13803 + pax_force_retaddr
13804 ret;
13805 ENDPROC(camellia_ecb_enc_16way)
13806
13807 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13808 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13809 %xmm8, %rsi);
13810
13811 + pax_force_retaddr
13812 ret;
13813 ENDPROC(camellia_ecb_dec_16way)
13814
13815 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13816 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13817 %xmm8, %rsi);
13818
13819 + pax_force_retaddr
13820 ret;
13821 ENDPROC(camellia_cbc_dec_16way)
13822
13823 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13824 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13825 %xmm8, %rsi);
13826
13827 + pax_force_retaddr
13828 ret;
13829 ENDPROC(camellia_ctr_16way)
13830
13831 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13832 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13833 %xmm8, %rsi);
13834
13835 + pax_force_retaddr
13836 ret;
13837 ENDPROC(camellia_xts_crypt_16way)
13838
13839 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13840 index 0e0b886..5a3123c 100644
13841 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13842 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13843 @@ -11,6 +11,7 @@
13844 */
13845
13846 #include <linux/linkage.h>
13847 +#include <asm/alternative-asm.h>
13848
13849 #define CAMELLIA_TABLE_BYTE_LEN 272
13850
13851 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13852 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13853 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13854 %rcx, (%r9));
13855 + pax_force_retaddr
13856 ret;
13857 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13858
13859 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13860 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13861 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13862 %rax, (%r9));
13863 + pax_force_retaddr
13864 ret;
13865 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13866
13867 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13868 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13869 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13870
13871 + pax_force_retaddr
13872 ret;
13873
13874 .align 8
13875 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13876 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13877 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13878
13879 + pax_force_retaddr
13880 ret;
13881
13882 .align 8
13883 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13884
13885 vzeroupper;
13886
13887 + pax_force_retaddr
13888 ret;
13889 ENDPROC(camellia_ecb_enc_32way)
13890
13891 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13892
13893 vzeroupper;
13894
13895 + pax_force_retaddr
13896 ret;
13897 ENDPROC(camellia_ecb_dec_32way)
13898
13899 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13900
13901 vzeroupper;
13902
13903 + pax_force_retaddr
13904 ret;
13905 ENDPROC(camellia_cbc_dec_32way)
13906
13907 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13908
13909 vzeroupper;
13910
13911 + pax_force_retaddr
13912 ret;
13913 ENDPROC(camellia_ctr_32way)
13914
13915 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13916
13917 vzeroupper;
13918
13919 + pax_force_retaddr
13920 ret;
13921 ENDPROC(camellia_xts_crypt_32way)
13922
13923 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13924 index 310319c..db3d7b5 100644
13925 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13926 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13927 @@ -21,6 +21,7 @@
13928 */
13929
13930 #include <linux/linkage.h>
13931 +#include <asm/alternative-asm.h>
13932
13933 .file "camellia-x86_64-asm_64.S"
13934 .text
13935 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13936 enc_outunpack(mov, RT1);
13937
13938 movq RRBP, %rbp;
13939 + pax_force_retaddr
13940 ret;
13941
13942 .L__enc_xor:
13943 enc_outunpack(xor, RT1);
13944
13945 movq RRBP, %rbp;
13946 + pax_force_retaddr
13947 ret;
13948 ENDPROC(__camellia_enc_blk)
13949
13950 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13951 dec_outunpack();
13952
13953 movq RRBP, %rbp;
13954 + pax_force_retaddr
13955 ret;
13956 ENDPROC(camellia_dec_blk)
13957
13958 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13959
13960 movq RRBP, %rbp;
13961 popq %rbx;
13962 + pax_force_retaddr
13963 ret;
13964
13965 .L__enc2_xor:
13966 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13967
13968 movq RRBP, %rbp;
13969 popq %rbx;
13970 + pax_force_retaddr
13971 ret;
13972 ENDPROC(__camellia_enc_blk_2way)
13973
13974 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13975
13976 movq RRBP, %rbp;
13977 movq RXOR, %rbx;
13978 + pax_force_retaddr
13979 ret;
13980 ENDPROC(camellia_dec_blk_2way)
13981 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13982 index c35fd5d..2d8c7db 100644
13983 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13984 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13985 @@ -24,6 +24,7 @@
13986 */
13987
13988 #include <linux/linkage.h>
13989 +#include <asm/alternative-asm.h>
13990
13991 .file "cast5-avx-x86_64-asm_64.S"
13992
13993 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13994 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13995 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13996
13997 + pax_force_retaddr
13998 ret;
13999 ENDPROC(__cast5_enc_blk16)
14000
14001 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
14002 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14003 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14004
14005 + pax_force_retaddr
14006 ret;
14007
14008 .L__skip_dec:
14009 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14010 vmovdqu RR4, (6*4*4)(%r11);
14011 vmovdqu RL4, (7*4*4)(%r11);
14012
14013 + pax_force_retaddr
14014 ret;
14015 ENDPROC(cast5_ecb_enc_16way)
14016
14017 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14018 vmovdqu RR4, (6*4*4)(%r11);
14019 vmovdqu RL4, (7*4*4)(%r11);
14020
14021 + pax_force_retaddr
14022 ret;
14023 ENDPROC(cast5_ecb_dec_16way)
14024
14025 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14026 * %rdx: src
14027 */
14028
14029 - pushq %r12;
14030 + pushq %r14;
14031
14032 movq %rsi, %r11;
14033 - movq %rdx, %r12;
14034 + movq %rdx, %r14;
14035
14036 vmovdqu (0*16)(%rdx), RL1;
14037 vmovdqu (1*16)(%rdx), RR1;
14038 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14039 call __cast5_dec_blk16;
14040
14041 /* xor with src */
14042 - vmovq (%r12), RX;
14043 + vmovq (%r14), RX;
14044 vpshufd $0x4f, RX, RX;
14045 vpxor RX, RR1, RR1;
14046 - vpxor 0*16+8(%r12), RL1, RL1;
14047 - vpxor 1*16+8(%r12), RR2, RR2;
14048 - vpxor 2*16+8(%r12), RL2, RL2;
14049 - vpxor 3*16+8(%r12), RR3, RR3;
14050 - vpxor 4*16+8(%r12), RL3, RL3;
14051 - vpxor 5*16+8(%r12), RR4, RR4;
14052 - vpxor 6*16+8(%r12), RL4, RL4;
14053 + vpxor 0*16+8(%r14), RL1, RL1;
14054 + vpxor 1*16+8(%r14), RR2, RR2;
14055 + vpxor 2*16+8(%r14), RL2, RL2;
14056 + vpxor 3*16+8(%r14), RR3, RR3;
14057 + vpxor 4*16+8(%r14), RL3, RL3;
14058 + vpxor 5*16+8(%r14), RR4, RR4;
14059 + vpxor 6*16+8(%r14), RL4, RL4;
14060
14061 vmovdqu RR1, (0*16)(%r11);
14062 vmovdqu RL1, (1*16)(%r11);
14063 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14064 vmovdqu RR4, (6*16)(%r11);
14065 vmovdqu RL4, (7*16)(%r11);
14066
14067 - popq %r12;
14068 + popq %r14;
14069
14070 + pax_force_retaddr
14071 ret;
14072 ENDPROC(cast5_cbc_dec_16way)
14073
14074 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14075 * %rcx: iv (big endian, 64bit)
14076 */
14077
14078 - pushq %r12;
14079 + pushq %r14;
14080
14081 movq %rsi, %r11;
14082 - movq %rdx, %r12;
14083 + movq %rdx, %r14;
14084
14085 vpcmpeqd RTMP, RTMP, RTMP;
14086 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14087 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14088 call __cast5_enc_blk16;
14089
14090 /* dst = src ^ iv */
14091 - vpxor (0*16)(%r12), RR1, RR1;
14092 - vpxor (1*16)(%r12), RL1, RL1;
14093 - vpxor (2*16)(%r12), RR2, RR2;
14094 - vpxor (3*16)(%r12), RL2, RL2;
14095 - vpxor (4*16)(%r12), RR3, RR3;
14096 - vpxor (5*16)(%r12), RL3, RL3;
14097 - vpxor (6*16)(%r12), RR4, RR4;
14098 - vpxor (7*16)(%r12), RL4, RL4;
14099 + vpxor (0*16)(%r14), RR1, RR1;
14100 + vpxor (1*16)(%r14), RL1, RL1;
14101 + vpxor (2*16)(%r14), RR2, RR2;
14102 + vpxor (3*16)(%r14), RL2, RL2;
14103 + vpxor (4*16)(%r14), RR3, RR3;
14104 + vpxor (5*16)(%r14), RL3, RL3;
14105 + vpxor (6*16)(%r14), RR4, RR4;
14106 + vpxor (7*16)(%r14), RL4, RL4;
14107 vmovdqu RR1, (0*16)(%r11);
14108 vmovdqu RL1, (1*16)(%r11);
14109 vmovdqu RR2, (2*16)(%r11);
14110 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14111 vmovdqu RR4, (6*16)(%r11);
14112 vmovdqu RL4, (7*16)(%r11);
14113
14114 - popq %r12;
14115 + popq %r14;
14116
14117 + pax_force_retaddr
14118 ret;
14119 ENDPROC(cast5_ctr_16way)
14120 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14121 index e3531f8..e123f35 100644
14122 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14123 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14124 @@ -24,6 +24,7 @@
14125 */
14126
14127 #include <linux/linkage.h>
14128 +#include <asm/alternative-asm.h>
14129 #include "glue_helper-asm-avx.S"
14130
14131 .file "cast6-avx-x86_64-asm_64.S"
14132 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14133 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14134 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14135
14136 + pax_force_retaddr
14137 ret;
14138 ENDPROC(__cast6_enc_blk8)
14139
14140 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14141 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14142 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14143
14144 + pax_force_retaddr
14145 ret;
14146 ENDPROC(__cast6_dec_blk8)
14147
14148 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14149
14150 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14151
14152 + pax_force_retaddr
14153 ret;
14154 ENDPROC(cast6_ecb_enc_8way)
14155
14156 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14157
14158 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14159
14160 + pax_force_retaddr
14161 ret;
14162 ENDPROC(cast6_ecb_dec_8way)
14163
14164 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14165 * %rdx: src
14166 */
14167
14168 - pushq %r12;
14169 + pushq %r14;
14170
14171 movq %rsi, %r11;
14172 - movq %rdx, %r12;
14173 + movq %rdx, %r14;
14174
14175 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14176
14177 call __cast6_dec_blk8;
14178
14179 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14180 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14181
14182 - popq %r12;
14183 + popq %r14;
14184
14185 + pax_force_retaddr
14186 ret;
14187 ENDPROC(cast6_cbc_dec_8way)
14188
14189 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14190 * %rcx: iv (little endian, 128bit)
14191 */
14192
14193 - pushq %r12;
14194 + pushq %r14;
14195
14196 movq %rsi, %r11;
14197 - movq %rdx, %r12;
14198 + movq %rdx, %r14;
14199
14200 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14201 RD2, RX, RKR, RKM);
14202
14203 call __cast6_enc_blk8;
14204
14205 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14206 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14207
14208 - popq %r12;
14209 + popq %r14;
14210
14211 + pax_force_retaddr
14212 ret;
14213 ENDPROC(cast6_ctr_8way)
14214
14215 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14216 /* dst <= regs xor IVs(in dst) */
14217 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14218
14219 + pax_force_retaddr
14220 ret;
14221 ENDPROC(cast6_xts_enc_8way)
14222
14223 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14224 /* dst <= regs xor IVs(in dst) */
14225 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14226
14227 + pax_force_retaddr
14228 ret;
14229 ENDPROC(cast6_xts_dec_8way)
14230 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14231 index dbc4339..de6e120 100644
14232 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14233 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14234 @@ -45,6 +45,7 @@
14235
14236 #include <asm/inst.h>
14237 #include <linux/linkage.h>
14238 +#include <asm/alternative-asm.h>
14239
14240 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14241
14242 @@ -312,6 +313,7 @@ do_return:
14243 popq %rsi
14244 popq %rdi
14245 popq %rbx
14246 + pax_force_retaddr
14247 ret
14248
14249 ################################################################
14250 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14251 index 5d1e007..098cb4f 100644
14252 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14253 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14254 @@ -18,6 +18,7 @@
14255
14256 #include <linux/linkage.h>
14257 #include <asm/inst.h>
14258 +#include <asm/alternative-asm.h>
14259
14260 .data
14261
14262 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14263 psrlq $1, T2
14264 pxor T2, T1
14265 pxor T1, DATA
14266 + pax_force_retaddr
14267 ret
14268 ENDPROC(__clmul_gf128mul_ble)
14269
14270 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14271 call __clmul_gf128mul_ble
14272 PSHUFB_XMM BSWAP DATA
14273 movups DATA, (%rdi)
14274 + pax_force_retaddr
14275 ret
14276 ENDPROC(clmul_ghash_mul)
14277
14278 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14279 PSHUFB_XMM BSWAP DATA
14280 movups DATA, (%rdi)
14281 .Lupdate_just_ret:
14282 + pax_force_retaddr
14283 ret
14284 ENDPROC(clmul_ghash_update)
14285 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14286 index 9279e0b..c4b3d2c 100644
14287 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14288 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14289 @@ -1,4 +1,5 @@
14290 #include <linux/linkage.h>
14291 +#include <asm/alternative-asm.h>
14292
14293 # enter salsa20_encrypt_bytes
14294 ENTRY(salsa20_encrypt_bytes)
14295 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14296 add %r11,%rsp
14297 mov %rdi,%rax
14298 mov %rsi,%rdx
14299 + pax_force_retaddr
14300 ret
14301 # bytesatleast65:
14302 ._bytesatleast65:
14303 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14304 add %r11,%rsp
14305 mov %rdi,%rax
14306 mov %rsi,%rdx
14307 + pax_force_retaddr
14308 ret
14309 ENDPROC(salsa20_keysetup)
14310
14311 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14312 add %r11,%rsp
14313 mov %rdi,%rax
14314 mov %rsi,%rdx
14315 + pax_force_retaddr
14316 ret
14317 ENDPROC(salsa20_ivsetup)
14318 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14319 index 2f202f4..d9164d6 100644
14320 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14321 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14322 @@ -24,6 +24,7 @@
14323 */
14324
14325 #include <linux/linkage.h>
14326 +#include <asm/alternative-asm.h>
14327 #include "glue_helper-asm-avx.S"
14328
14329 .file "serpent-avx-x86_64-asm_64.S"
14330 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14331 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14332 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14333
14334 + pax_force_retaddr
14335 ret;
14336 ENDPROC(__serpent_enc_blk8_avx)
14337
14338 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14339 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14340 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14341
14342 + pax_force_retaddr
14343 ret;
14344 ENDPROC(__serpent_dec_blk8_avx)
14345
14346 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14347
14348 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14349
14350 + pax_force_retaddr
14351 ret;
14352 ENDPROC(serpent_ecb_enc_8way_avx)
14353
14354 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14355
14356 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14357
14358 + pax_force_retaddr
14359 ret;
14360 ENDPROC(serpent_ecb_dec_8way_avx)
14361
14362 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14363
14364 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14365
14366 + pax_force_retaddr
14367 ret;
14368 ENDPROC(serpent_cbc_dec_8way_avx)
14369
14370 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14371
14372 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14373
14374 + pax_force_retaddr
14375 ret;
14376 ENDPROC(serpent_ctr_8way_avx)
14377
14378 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14379 /* dst <= regs xor IVs(in dst) */
14380 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14381
14382 + pax_force_retaddr
14383 ret;
14384 ENDPROC(serpent_xts_enc_8way_avx)
14385
14386 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14387 /* dst <= regs xor IVs(in dst) */
14388 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14389
14390 + pax_force_retaddr
14391 ret;
14392 ENDPROC(serpent_xts_dec_8way_avx)
14393 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14394 index b222085..abd483c 100644
14395 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14396 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14397 @@ -15,6 +15,7 @@
14398 */
14399
14400 #include <linux/linkage.h>
14401 +#include <asm/alternative-asm.h>
14402 #include "glue_helper-asm-avx2.S"
14403
14404 .file "serpent-avx2-asm_64.S"
14405 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14406 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14407 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14408
14409 + pax_force_retaddr
14410 ret;
14411 ENDPROC(__serpent_enc_blk16)
14412
14413 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14414 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14415 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14416
14417 + pax_force_retaddr
14418 ret;
14419 ENDPROC(__serpent_dec_blk16)
14420
14421 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14422
14423 vzeroupper;
14424
14425 + pax_force_retaddr
14426 ret;
14427 ENDPROC(serpent_ecb_enc_16way)
14428
14429 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14430
14431 vzeroupper;
14432
14433 + pax_force_retaddr
14434 ret;
14435 ENDPROC(serpent_ecb_dec_16way)
14436
14437 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14438
14439 vzeroupper;
14440
14441 + pax_force_retaddr
14442 ret;
14443 ENDPROC(serpent_cbc_dec_16way)
14444
14445 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14446
14447 vzeroupper;
14448
14449 + pax_force_retaddr
14450 ret;
14451 ENDPROC(serpent_ctr_16way)
14452
14453 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14454
14455 vzeroupper;
14456
14457 + pax_force_retaddr
14458 ret;
14459 ENDPROC(serpent_xts_enc_16way)
14460
14461 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14462
14463 vzeroupper;
14464
14465 + pax_force_retaddr
14466 ret;
14467 ENDPROC(serpent_xts_dec_16way)
14468 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14469 index acc066c..1559cc4 100644
14470 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14471 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14472 @@ -25,6 +25,7 @@
14473 */
14474
14475 #include <linux/linkage.h>
14476 +#include <asm/alternative-asm.h>
14477
14478 .file "serpent-sse2-x86_64-asm_64.S"
14479 .text
14480 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14481 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14482 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14483
14484 + pax_force_retaddr
14485 ret;
14486
14487 .L__enc_xor8:
14488 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14489 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14490
14491 + pax_force_retaddr
14492 ret;
14493 ENDPROC(__serpent_enc_blk_8way)
14494
14495 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14496 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14497 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14498
14499 + pax_force_retaddr
14500 ret;
14501 ENDPROC(serpent_dec_blk_8way)
14502 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14503 index a410950..9dfe7ad 100644
14504 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14505 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14506 @@ -29,6 +29,7 @@
14507 */
14508
14509 #include <linux/linkage.h>
14510 +#include <asm/alternative-asm.h>
14511
14512 #define CTX %rdi // arg1
14513 #define BUF %rsi // arg2
14514 @@ -75,9 +76,9 @@
14515
14516 push %rbx
14517 push %rbp
14518 - push %r12
14519 + push %r14
14520
14521 - mov %rsp, %r12
14522 + mov %rsp, %r14
14523 sub $64, %rsp # allocate workspace
14524 and $~15, %rsp # align stack
14525
14526 @@ -99,11 +100,12 @@
14527 xor %rax, %rax
14528 rep stosq
14529
14530 - mov %r12, %rsp # deallocate workspace
14531 + mov %r14, %rsp # deallocate workspace
14532
14533 - pop %r12
14534 + pop %r14
14535 pop %rbp
14536 pop %rbx
14537 + pax_force_retaddr
14538 ret
14539
14540 ENDPROC(\name)
14541 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14542 index 642f156..51a513c 100644
14543 --- a/arch/x86/crypto/sha256-avx-asm.S
14544 +++ b/arch/x86/crypto/sha256-avx-asm.S
14545 @@ -49,6 +49,7 @@
14546
14547 #ifdef CONFIG_AS_AVX
14548 #include <linux/linkage.h>
14549 +#include <asm/alternative-asm.h>
14550
14551 ## assume buffers not aligned
14552 #define VMOVDQ vmovdqu
14553 @@ -460,6 +461,7 @@ done_hash:
14554 popq %r13
14555 popq %rbp
14556 popq %rbx
14557 + pax_force_retaddr
14558 ret
14559 ENDPROC(sha256_transform_avx)
14560
14561 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14562 index 9e86944..3795e6a 100644
14563 --- a/arch/x86/crypto/sha256-avx2-asm.S
14564 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14565 @@ -50,6 +50,7 @@
14566
14567 #ifdef CONFIG_AS_AVX2
14568 #include <linux/linkage.h>
14569 +#include <asm/alternative-asm.h>
14570
14571 ## assume buffers not aligned
14572 #define VMOVDQ vmovdqu
14573 @@ -720,6 +721,7 @@ done_hash:
14574 popq %r12
14575 popq %rbp
14576 popq %rbx
14577 + pax_force_retaddr
14578 ret
14579 ENDPROC(sha256_transform_rorx)
14580
14581 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14582 index f833b74..8c62a9e 100644
14583 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14584 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14585 @@ -47,6 +47,7 @@
14586 ########################################################################
14587
14588 #include <linux/linkage.h>
14589 +#include <asm/alternative-asm.h>
14590
14591 ## assume buffers not aligned
14592 #define MOVDQ movdqu
14593 @@ -471,6 +472,7 @@ done_hash:
14594 popq %rbp
14595 popq %rbx
14596
14597 + pax_force_retaddr
14598 ret
14599 ENDPROC(sha256_transform_ssse3)
14600
14601 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14602 index 974dde9..a823ff9 100644
14603 --- a/arch/x86/crypto/sha512-avx-asm.S
14604 +++ b/arch/x86/crypto/sha512-avx-asm.S
14605 @@ -49,6 +49,7 @@
14606
14607 #ifdef CONFIG_AS_AVX
14608 #include <linux/linkage.h>
14609 +#include <asm/alternative-asm.h>
14610
14611 .text
14612
14613 @@ -364,6 +365,7 @@ updateblock:
14614 mov frame_RSPSAVE(%rsp), %rsp
14615
14616 nowork:
14617 + pax_force_retaddr
14618 ret
14619 ENDPROC(sha512_transform_avx)
14620
14621 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14622 index 568b961..ed20c37 100644
14623 --- a/arch/x86/crypto/sha512-avx2-asm.S
14624 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14625 @@ -51,6 +51,7 @@
14626
14627 #ifdef CONFIG_AS_AVX2
14628 #include <linux/linkage.h>
14629 +#include <asm/alternative-asm.h>
14630
14631 .text
14632
14633 @@ -678,6 +679,7 @@ done_hash:
14634
14635 # Restore Stack Pointer
14636 mov frame_RSPSAVE(%rsp), %rsp
14637 + pax_force_retaddr
14638 ret
14639 ENDPROC(sha512_transform_rorx)
14640
14641 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14642 index fb56855..6edd768 100644
14643 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14644 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14645 @@ -48,6 +48,7 @@
14646 ########################################################################
14647
14648 #include <linux/linkage.h>
14649 +#include <asm/alternative-asm.h>
14650
14651 .text
14652
14653 @@ -363,6 +364,7 @@ updateblock:
14654 mov frame_RSPSAVE(%rsp), %rsp
14655
14656 nowork:
14657 + pax_force_retaddr
14658 ret
14659 ENDPROC(sha512_transform_ssse3)
14660
14661 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14662 index 0505813..b067311 100644
14663 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14664 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14665 @@ -24,6 +24,7 @@
14666 */
14667
14668 #include <linux/linkage.h>
14669 +#include <asm/alternative-asm.h>
14670 #include "glue_helper-asm-avx.S"
14671
14672 .file "twofish-avx-x86_64-asm_64.S"
14673 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14674 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14675 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14676
14677 + pax_force_retaddr
14678 ret;
14679 ENDPROC(__twofish_enc_blk8)
14680
14681 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14682 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14683 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14684
14685 + pax_force_retaddr
14686 ret;
14687 ENDPROC(__twofish_dec_blk8)
14688
14689 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14690
14691 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14692
14693 + pax_force_retaddr
14694 ret;
14695 ENDPROC(twofish_ecb_enc_8way)
14696
14697 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14698
14699 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14700
14701 + pax_force_retaddr
14702 ret;
14703 ENDPROC(twofish_ecb_dec_8way)
14704
14705 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14706 * %rdx: src
14707 */
14708
14709 - pushq %r12;
14710 + pushq %r14;
14711
14712 movq %rsi, %r11;
14713 - movq %rdx, %r12;
14714 + movq %rdx, %r14;
14715
14716 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14717
14718 call __twofish_dec_blk8;
14719
14720 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14721 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14722
14723 - popq %r12;
14724 + popq %r14;
14725
14726 + pax_force_retaddr
14727 ret;
14728 ENDPROC(twofish_cbc_dec_8way)
14729
14730 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14731 * %rcx: iv (little endian, 128bit)
14732 */
14733
14734 - pushq %r12;
14735 + pushq %r14;
14736
14737 movq %rsi, %r11;
14738 - movq %rdx, %r12;
14739 + movq %rdx, %r14;
14740
14741 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14742 RD2, RX0, RX1, RY0);
14743
14744 call __twofish_enc_blk8;
14745
14746 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14747 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14748
14749 - popq %r12;
14750 + popq %r14;
14751
14752 + pax_force_retaddr
14753 ret;
14754 ENDPROC(twofish_ctr_8way)
14755
14756 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14757 /* dst <= regs xor IVs(in dst) */
14758 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14759
14760 + pax_force_retaddr
14761 ret;
14762 ENDPROC(twofish_xts_enc_8way)
14763
14764 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14765 /* dst <= regs xor IVs(in dst) */
14766 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14767
14768 + pax_force_retaddr
14769 ret;
14770 ENDPROC(twofish_xts_dec_8way)
14771 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14772 index 1c3b7ce..02f578d 100644
14773 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14774 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14775 @@ -21,6 +21,7 @@
14776 */
14777
14778 #include <linux/linkage.h>
14779 +#include <asm/alternative-asm.h>
14780
14781 .file "twofish-x86_64-asm-3way.S"
14782 .text
14783 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14784 popq %r13;
14785 popq %r14;
14786 popq %r15;
14787 + pax_force_retaddr
14788 ret;
14789
14790 .L__enc_xor3:
14791 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14792 popq %r13;
14793 popq %r14;
14794 popq %r15;
14795 + pax_force_retaddr
14796 ret;
14797 ENDPROC(__twofish_enc_blk_3way)
14798
14799 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14800 popq %r13;
14801 popq %r14;
14802 popq %r15;
14803 + pax_force_retaddr
14804 ret;
14805 ENDPROC(twofish_dec_blk_3way)
14806 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14807 index a039d21..524b8b2 100644
14808 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14809 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14810 @@ -22,6 +22,7 @@
14811
14812 #include <linux/linkage.h>
14813 #include <asm/asm-offsets.h>
14814 +#include <asm/alternative-asm.h>
14815
14816 #define a_offset 0
14817 #define b_offset 4
14818 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14819
14820 popq R1
14821 movq $1,%rax
14822 + pax_force_retaddr
14823 ret
14824 ENDPROC(twofish_enc_blk)
14825
14826 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14827
14828 popq R1
14829 movq $1,%rax
14830 + pax_force_retaddr
14831 ret
14832 ENDPROC(twofish_dec_blk)
14833 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14834 index d21ff89..6da8e6e 100644
14835 --- a/arch/x86/ia32/ia32_aout.c
14836 +++ b/arch/x86/ia32/ia32_aout.c
14837 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14838 unsigned long dump_start, dump_size;
14839 struct user32 dump;
14840
14841 + memset(&dump, 0, sizeof(dump));
14842 +
14843 fs = get_fs();
14844 set_fs(KERNEL_DS);
14845 has_dumped = 1;
14846 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14847 index f9e181a..b0df8b3 100644
14848 --- a/arch/x86/ia32/ia32_signal.c
14849 +++ b/arch/x86/ia32/ia32_signal.c
14850 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14851 if (__get_user(set.sig[0], &frame->sc.oldmask)
14852 || (_COMPAT_NSIG_WORDS > 1
14853 && __copy_from_user((((char *) &set.sig) + 4),
14854 - &frame->extramask,
14855 + frame->extramask,
14856 sizeof(frame->extramask))))
14857 goto badframe;
14858
14859 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14860 sp -= frame_size;
14861 /* Align the stack pointer according to the i386 ABI,
14862 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14863 - sp = ((sp + 4) & -16ul) - 4;
14864 + sp = ((sp - 12) & -16ul) - 4;
14865 return (void __user *) sp;
14866 }
14867
14868 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14869 restorer = current->mm->context.vdso +
14870 selected_vdso32->sym___kernel_sigreturn;
14871 else
14872 - restorer = &frame->retcode;
14873 + restorer = frame->retcode;
14874 }
14875
14876 put_user_try {
14877 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14878 * These are actually not used anymore, but left because some
14879 * gdb versions depend on them as a marker.
14880 */
14881 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14882 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14883 } put_user_catch(err);
14884
14885 if (err)
14886 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14887 0xb8,
14888 __NR_ia32_rt_sigreturn,
14889 0x80cd,
14890 - 0,
14891 + 0
14892 };
14893
14894 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14895 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14896
14897 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14898 restorer = ksig->ka.sa.sa_restorer;
14899 - else
14900 + else if (current->mm->context.vdso)
14901 + /* Return stub is in 32bit vsyscall page */
14902 restorer = current->mm->context.vdso +
14903 selected_vdso32->sym___kernel_rt_sigreturn;
14904 + else
14905 + restorer = frame->retcode;
14906 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14907
14908 /*
14909 * Not actually used anymore, but left because some gdb
14910 * versions need it.
14911 */
14912 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14913 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14914 } put_user_catch(err);
14915
14916 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14917 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14918 index 4299eb0..fefe70e 100644
14919 --- a/arch/x86/ia32/ia32entry.S
14920 +++ b/arch/x86/ia32/ia32entry.S
14921 @@ -15,8 +15,10 @@
14922 #include <asm/irqflags.h>
14923 #include <asm/asm.h>
14924 #include <asm/smap.h>
14925 +#include <asm/pgtable.h>
14926 #include <linux/linkage.h>
14927 #include <linux/err.h>
14928 +#include <asm/alternative-asm.h>
14929
14930 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14931 #include <linux/elf-em.h>
14932 @@ -62,12 +64,12 @@
14933 */
14934 .macro LOAD_ARGS32 offset, _r9=0
14935 .if \_r9
14936 - movl \offset+16(%rsp),%r9d
14937 + movl \offset+R9(%rsp),%r9d
14938 .endif
14939 - movl \offset+40(%rsp),%ecx
14940 - movl \offset+48(%rsp),%edx
14941 - movl \offset+56(%rsp),%esi
14942 - movl \offset+64(%rsp),%edi
14943 + movl \offset+RCX(%rsp),%ecx
14944 + movl \offset+RDX(%rsp),%edx
14945 + movl \offset+RSI(%rsp),%esi
14946 + movl \offset+RDI(%rsp),%edi
14947 movl %eax,%eax /* zero extension */
14948 .endm
14949
14950 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14951 ENDPROC(native_irq_enable_sysexit)
14952 #endif
14953
14954 + .macro pax_enter_kernel_user
14955 + pax_set_fptr_mask
14956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14957 + call pax_enter_kernel_user
14958 +#endif
14959 + .endm
14960 +
14961 + .macro pax_exit_kernel_user
14962 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14963 + call pax_exit_kernel_user
14964 +#endif
14965 +#ifdef CONFIG_PAX_RANDKSTACK
14966 + pushq %rax
14967 + pushq %r11
14968 + call pax_randomize_kstack
14969 + popq %r11
14970 + popq %rax
14971 +#endif
14972 + .endm
14973 +
14974 + .macro pax_erase_kstack
14975 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14976 + call pax_erase_kstack
14977 +#endif
14978 + .endm
14979 +
14980 /*
14981 * 32bit SYSENTER instruction entry.
14982 *
14983 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14984 CFI_REGISTER rsp,rbp
14985 SWAPGS_UNSAFE_STACK
14986 movq PER_CPU_VAR(kernel_stack), %rsp
14987 - addq $(KERNEL_STACK_OFFSET),%rsp
14988 - /*
14989 - * No need to follow this irqs on/off section: the syscall
14990 - * disabled irqs, here we enable it straight after entry:
14991 - */
14992 - ENABLE_INTERRUPTS(CLBR_NONE)
14993 movl %ebp,%ebp /* zero extension */
14994 pushq_cfi $__USER32_DS
14995 /*CFI_REL_OFFSET ss,0*/
14996 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14997 CFI_REL_OFFSET rsp,0
14998 pushfq_cfi
14999 /*CFI_REL_OFFSET rflags,0*/
15000 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15001 - CFI_REGISTER rip,r10
15002 + orl $X86_EFLAGS_IF,(%rsp)
15003 + GET_THREAD_INFO(%r11)
15004 + movl TI_sysenter_return(%r11), %r11d
15005 + CFI_REGISTER rip,r11
15006 pushq_cfi $__USER32_CS
15007 /*CFI_REL_OFFSET cs,0*/
15008 movl %eax, %eax
15009 - pushq_cfi %r10
15010 + pushq_cfi %r11
15011 CFI_REL_OFFSET rip,0
15012 pushq_cfi %rax
15013 cld
15014 SAVE_ARGS 0,1,0
15015 + pax_enter_kernel_user
15016 +
15017 +#ifdef CONFIG_PAX_RANDKSTACK
15018 + pax_erase_kstack
15019 +#endif
15020 +
15021 + /*
15022 + * No need to follow this irqs on/off section: the syscall
15023 + * disabled irqs, here we enable it straight after entry:
15024 + */
15025 + ENABLE_INTERRUPTS(CLBR_NONE)
15026 /* no need to do an access_ok check here because rbp has been
15027 32bit zero extended */
15028 +
15029 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15030 + addq pax_user_shadow_base,%rbp
15031 + ASM_PAX_OPEN_USERLAND
15032 +#endif
15033 +
15034 ASM_STAC
15035 1: movl (%rbp),%ebp
15036 _ASM_EXTABLE(1b,ia32_badarg)
15037 ASM_CLAC
15038 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15039 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15040 +
15041 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15042 + ASM_PAX_CLOSE_USERLAND
15043 +#endif
15044 +
15045 + GET_THREAD_INFO(%r11)
15046 + orl $TS_COMPAT,TI_status(%r11)
15047 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15048 CFI_REMEMBER_STATE
15049 jnz sysenter_tracesys
15050 cmpq $(IA32_NR_syscalls-1),%rax
15051 @@ -162,15 +209,18 @@ sysenter_do_call:
15052 sysenter_dispatch:
15053 call *ia32_sys_call_table(,%rax,8)
15054 movq %rax,RAX-ARGOFFSET(%rsp)
15055 + GET_THREAD_INFO(%r11)
15056 DISABLE_INTERRUPTS(CLBR_NONE)
15057 TRACE_IRQS_OFF
15058 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15059 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15060 jnz sysexit_audit
15061 sysexit_from_sys_call:
15062 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15063 + pax_exit_kernel_user
15064 + pax_erase_kstack
15065 + andl $~TS_COMPAT,TI_status(%r11)
15066 /* clear IF, that popfq doesn't enable interrupts early */
15067 - andl $~0x200,EFLAGS-R11(%rsp)
15068 - movl RIP-R11(%rsp),%edx /* User %eip */
15069 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15070 + movl RIP(%rsp),%edx /* User %eip */
15071 CFI_REGISTER rip,rdx
15072 RESTORE_ARGS 0,24,0,0,0,0
15073 xorq %r8,%r8
15074 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
15075 movl %eax,%esi /* 2nd arg: syscall number */
15076 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15077 call __audit_syscall_entry
15078 +
15079 + pax_erase_kstack
15080 +
15081 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15082 cmpq $(IA32_NR_syscalls-1),%rax
15083 ja ia32_badsys
15084 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
15085 .endm
15086
15087 .macro auditsys_exit exit
15088 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15089 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15090 jnz ia32_ret_from_sys_call
15091 TRACE_IRQS_ON
15092 ENABLE_INTERRUPTS(CLBR_NONE)
15093 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
15094 1: setbe %al /* 1 if error, 0 if not */
15095 movzbl %al,%edi /* zero-extend that into %edi */
15096 call __audit_syscall_exit
15097 + GET_THREAD_INFO(%r11)
15098 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15099 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15100 DISABLE_INTERRUPTS(CLBR_NONE)
15101 TRACE_IRQS_OFF
15102 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15103 + testl %edi,TI_flags(%r11)
15104 jz \exit
15105 CLEAR_RREGS -ARGOFFSET
15106 jmp int_with_check
15107 @@ -237,7 +291,7 @@ sysexit_audit:
15108
15109 sysenter_tracesys:
15110 #ifdef CONFIG_AUDITSYSCALL
15111 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15112 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15113 jz sysenter_auditsys
15114 #endif
15115 SAVE_REST
15116 @@ -249,6 +303,9 @@ sysenter_tracesys:
15117 RESTORE_REST
15118 cmpq $(IA32_NR_syscalls-1),%rax
15119 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15120 +
15121 + pax_erase_kstack
15122 +
15123 jmp sysenter_do_call
15124 CFI_ENDPROC
15125 ENDPROC(ia32_sysenter_target)
15126 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
15127 ENTRY(ia32_cstar_target)
15128 CFI_STARTPROC32 simple
15129 CFI_SIGNAL_FRAME
15130 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15131 + CFI_DEF_CFA rsp,0
15132 CFI_REGISTER rip,rcx
15133 /*CFI_REGISTER rflags,r11*/
15134 SWAPGS_UNSAFE_STACK
15135 movl %esp,%r8d
15136 CFI_REGISTER rsp,r8
15137 movq PER_CPU_VAR(kernel_stack),%rsp
15138 + SAVE_ARGS 8*6,0,0
15139 + pax_enter_kernel_user
15140 +
15141 +#ifdef CONFIG_PAX_RANDKSTACK
15142 + pax_erase_kstack
15143 +#endif
15144 +
15145 /*
15146 * No need to follow this irqs on/off section: the syscall
15147 * disabled irqs and here we enable it straight after entry:
15148 */
15149 ENABLE_INTERRUPTS(CLBR_NONE)
15150 - SAVE_ARGS 8,0,0
15151 movl %eax,%eax /* zero extension */
15152 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15153 movq %rcx,RIP-ARGOFFSET(%rsp)
15154 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
15155 /* no need to do an access_ok check here because r8 has been
15156 32bit zero extended */
15157 /* hardware stack frame is complete now */
15158 +
15159 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15160 + ASM_PAX_OPEN_USERLAND
15161 + movq pax_user_shadow_base,%r8
15162 + addq RSP-ARGOFFSET(%rsp),%r8
15163 +#endif
15164 +
15165 ASM_STAC
15166 1: movl (%r8),%r9d
15167 _ASM_EXTABLE(1b,ia32_badarg)
15168 ASM_CLAC
15169 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15170 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15171 +
15172 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15173 + ASM_PAX_CLOSE_USERLAND
15174 +#endif
15175 +
15176 + GET_THREAD_INFO(%r11)
15177 + orl $TS_COMPAT,TI_status(%r11)
15178 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15179 CFI_REMEMBER_STATE
15180 jnz cstar_tracesys
15181 cmpq $IA32_NR_syscalls-1,%rax
15182 @@ -319,13 +395,16 @@ cstar_do_call:
15183 cstar_dispatch:
15184 call *ia32_sys_call_table(,%rax,8)
15185 movq %rax,RAX-ARGOFFSET(%rsp)
15186 + GET_THREAD_INFO(%r11)
15187 DISABLE_INTERRUPTS(CLBR_NONE)
15188 TRACE_IRQS_OFF
15189 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15190 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15191 jnz sysretl_audit
15192 sysretl_from_sys_call:
15193 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15194 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15195 + pax_exit_kernel_user
15196 + pax_erase_kstack
15197 + andl $~TS_COMPAT,TI_status(%r11)
15198 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15199 movl RIP-ARGOFFSET(%rsp),%ecx
15200 CFI_REGISTER rip,rcx
15201 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15202 @@ -352,7 +431,7 @@ sysretl_audit:
15203
15204 cstar_tracesys:
15205 #ifdef CONFIG_AUDITSYSCALL
15206 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15207 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15208 jz cstar_auditsys
15209 #endif
15210 xchgl %r9d,%ebp
15211 @@ -366,11 +445,19 @@ cstar_tracesys:
15212 xchgl %ebp,%r9d
15213 cmpq $(IA32_NR_syscalls-1),%rax
15214 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15215 +
15216 + pax_erase_kstack
15217 +
15218 jmp cstar_do_call
15219 END(ia32_cstar_target)
15220
15221 ia32_badarg:
15222 ASM_CLAC
15223 +
15224 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15225 + ASM_PAX_CLOSE_USERLAND
15226 +#endif
15227 +
15228 movq $-EFAULT,%rax
15229 jmp ia32_sysret
15230 CFI_ENDPROC
15231 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15232 CFI_REL_OFFSET rip,RIP-RIP
15233 PARAVIRT_ADJUST_EXCEPTION_FRAME
15234 SWAPGS
15235 - /*
15236 - * No need to follow this irqs on/off section: the syscall
15237 - * disabled irqs and here we enable it straight after entry:
15238 - */
15239 - ENABLE_INTERRUPTS(CLBR_NONE)
15240 movl %eax,%eax
15241 pushq_cfi %rax
15242 cld
15243 /* note the registers are not zero extended to the sf.
15244 this could be a problem. */
15245 SAVE_ARGS 0,1,0
15246 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15247 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15248 + pax_enter_kernel_user
15249 +
15250 +#ifdef CONFIG_PAX_RANDKSTACK
15251 + pax_erase_kstack
15252 +#endif
15253 +
15254 + /*
15255 + * No need to follow this irqs on/off section: the syscall
15256 + * disabled irqs and here we enable it straight after entry:
15257 + */
15258 + ENABLE_INTERRUPTS(CLBR_NONE)
15259 + GET_THREAD_INFO(%r11)
15260 + orl $TS_COMPAT,TI_status(%r11)
15261 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15262 jnz ia32_tracesys
15263 cmpq $(IA32_NR_syscalls-1),%rax
15264 ja ia32_badsys
15265 @@ -442,6 +536,9 @@ ia32_tracesys:
15266 RESTORE_REST
15267 cmpq $(IA32_NR_syscalls-1),%rax
15268 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15269 +
15270 + pax_erase_kstack
15271 +
15272 jmp ia32_do_call
15273 END(ia32_syscall)
15274
15275 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15276 index 8e0ceec..af13504 100644
15277 --- a/arch/x86/ia32/sys_ia32.c
15278 +++ b/arch/x86/ia32/sys_ia32.c
15279 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15280 */
15281 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15282 {
15283 - typeof(ubuf->st_uid) uid = 0;
15284 - typeof(ubuf->st_gid) gid = 0;
15285 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15286 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15287 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15288 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15289 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15290 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15291 index 372231c..51b537d 100644
15292 --- a/arch/x86/include/asm/alternative-asm.h
15293 +++ b/arch/x86/include/asm/alternative-asm.h
15294 @@ -18,6 +18,45 @@
15295 .endm
15296 #endif
15297
15298 +#ifdef KERNEXEC_PLUGIN
15299 + .macro pax_force_retaddr_bts rip=0
15300 + btsq $63,\rip(%rsp)
15301 + .endm
15302 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15303 + .macro pax_force_retaddr rip=0, reload=0
15304 + btsq $63,\rip(%rsp)
15305 + .endm
15306 + .macro pax_force_fptr ptr
15307 + btsq $63,\ptr
15308 + .endm
15309 + .macro pax_set_fptr_mask
15310 + .endm
15311 +#endif
15312 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15313 + .macro pax_force_retaddr rip=0, reload=0
15314 + .if \reload
15315 + pax_set_fptr_mask
15316 + .endif
15317 + orq %r12,\rip(%rsp)
15318 + .endm
15319 + .macro pax_force_fptr ptr
15320 + orq %r12,\ptr
15321 + .endm
15322 + .macro pax_set_fptr_mask
15323 + movabs $0x8000000000000000,%r12
15324 + .endm
15325 +#endif
15326 +#else
15327 + .macro pax_force_retaddr rip=0, reload=0
15328 + .endm
15329 + .macro pax_force_fptr ptr
15330 + .endm
15331 + .macro pax_force_retaddr_bts rip=0
15332 + .endm
15333 + .macro pax_set_fptr_mask
15334 + .endm
15335 +#endif
15336 +
15337 .macro altinstruction_entry orig alt feature orig_len alt_len
15338 .long \orig - .
15339 .long \alt - .
15340 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15341 index 0a3f9c9..c9d081d 100644
15342 --- a/arch/x86/include/asm/alternative.h
15343 +++ b/arch/x86/include/asm/alternative.h
15344 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15345 ".pushsection .discard,\"aw\",@progbits\n" \
15346 DISCARD_ENTRY(1) \
15347 ".popsection\n" \
15348 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15349 + ".pushsection .altinstr_replacement, \"a\"\n" \
15350 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15351 ".popsection"
15352
15353 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15354 DISCARD_ENTRY(1) \
15355 DISCARD_ENTRY(2) \
15356 ".popsection\n" \
15357 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15358 + ".pushsection .altinstr_replacement, \"a\"\n" \
15359 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15360 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15361 ".popsection"
15362 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15363 index 19b0eba..12254cd 100644
15364 --- a/arch/x86/include/asm/apic.h
15365 +++ b/arch/x86/include/asm/apic.h
15366 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15367
15368 #ifdef CONFIG_X86_LOCAL_APIC
15369
15370 -extern unsigned int apic_verbosity;
15371 +extern int apic_verbosity;
15372 extern int local_apic_timer_c2_ok;
15373
15374 extern int disable_apic;
15375 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15376 index 20370c6..a2eb9b0 100644
15377 --- a/arch/x86/include/asm/apm.h
15378 +++ b/arch/x86/include/asm/apm.h
15379 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15380 __asm__ __volatile__(APM_DO_ZERO_SEGS
15381 "pushl %%edi\n\t"
15382 "pushl %%ebp\n\t"
15383 - "lcall *%%cs:apm_bios_entry\n\t"
15384 + "lcall *%%ss:apm_bios_entry\n\t"
15385 "setc %%al\n\t"
15386 "popl %%ebp\n\t"
15387 "popl %%edi\n\t"
15388 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15389 __asm__ __volatile__(APM_DO_ZERO_SEGS
15390 "pushl %%edi\n\t"
15391 "pushl %%ebp\n\t"
15392 - "lcall *%%cs:apm_bios_entry\n\t"
15393 + "lcall *%%ss:apm_bios_entry\n\t"
15394 "setc %%bl\n\t"
15395 "popl %%ebp\n\t"
15396 "popl %%edi\n\t"
15397 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15398 index 6dd1c7dd..2edd216 100644
15399 --- a/arch/x86/include/asm/atomic.h
15400 +++ b/arch/x86/include/asm/atomic.h
15401 @@ -24,7 +24,18 @@
15402 */
15403 static inline int atomic_read(const atomic_t *v)
15404 {
15405 - return (*(volatile int *)&(v)->counter);
15406 + return (*(volatile const int *)&(v)->counter);
15407 +}
15408 +
15409 +/**
15410 + * atomic_read_unchecked - read atomic variable
15411 + * @v: pointer of type atomic_unchecked_t
15412 + *
15413 + * Atomically reads the value of @v.
15414 + */
15415 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15416 +{
15417 + return (*(volatile const int *)&(v)->counter);
15418 }
15419
15420 /**
15421 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15422 }
15423
15424 /**
15425 + * atomic_set_unchecked - set atomic variable
15426 + * @v: pointer of type atomic_unchecked_t
15427 + * @i: required value
15428 + *
15429 + * Atomically sets the value of @v to @i.
15430 + */
15431 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15432 +{
15433 + v->counter = i;
15434 +}
15435 +
15436 +/**
15437 * atomic_add - add integer to atomic variable
15438 * @i: integer value to add
15439 * @v: pointer of type atomic_t
15440 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15441 */
15442 static inline void atomic_add(int i, atomic_t *v)
15443 {
15444 - asm volatile(LOCK_PREFIX "addl %1,%0"
15445 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15446 +
15447 +#ifdef CONFIG_PAX_REFCOUNT
15448 + "jno 0f\n"
15449 + LOCK_PREFIX "subl %1,%0\n"
15450 + "int $4\n0:\n"
15451 + _ASM_EXTABLE(0b, 0b)
15452 +#endif
15453 +
15454 + : "+m" (v->counter)
15455 + : "ir" (i));
15456 +}
15457 +
15458 +/**
15459 + * atomic_add_unchecked - add integer to atomic variable
15460 + * @i: integer value to add
15461 + * @v: pointer of type atomic_unchecked_t
15462 + *
15463 + * Atomically adds @i to @v.
15464 + */
15465 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15466 +{
15467 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15468 : "+m" (v->counter)
15469 : "ir" (i));
15470 }
15471 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15472 */
15473 static inline void atomic_sub(int i, atomic_t *v)
15474 {
15475 - asm volatile(LOCK_PREFIX "subl %1,%0"
15476 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15477 +
15478 +#ifdef CONFIG_PAX_REFCOUNT
15479 + "jno 0f\n"
15480 + LOCK_PREFIX "addl %1,%0\n"
15481 + "int $4\n0:\n"
15482 + _ASM_EXTABLE(0b, 0b)
15483 +#endif
15484 +
15485 + : "+m" (v->counter)
15486 + : "ir" (i));
15487 +}
15488 +
15489 +/**
15490 + * atomic_sub_unchecked - subtract integer from atomic variable
15491 + * @i: integer value to subtract
15492 + * @v: pointer of type atomic_unchecked_t
15493 + *
15494 + * Atomically subtracts @i from @v.
15495 + */
15496 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15497 +{
15498 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15499 : "+m" (v->counter)
15500 : "ir" (i));
15501 }
15502 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15503 */
15504 static inline int atomic_sub_and_test(int i, atomic_t *v)
15505 {
15506 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15507 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15508 }
15509
15510 /**
15511 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15512 */
15513 static inline void atomic_inc(atomic_t *v)
15514 {
15515 - asm volatile(LOCK_PREFIX "incl %0"
15516 + asm volatile(LOCK_PREFIX "incl %0\n"
15517 +
15518 +#ifdef CONFIG_PAX_REFCOUNT
15519 + "jno 0f\n"
15520 + LOCK_PREFIX "decl %0\n"
15521 + "int $4\n0:\n"
15522 + _ASM_EXTABLE(0b, 0b)
15523 +#endif
15524 +
15525 + : "+m" (v->counter));
15526 +}
15527 +
15528 +/**
15529 + * atomic_inc_unchecked - increment atomic variable
15530 + * @v: pointer of type atomic_unchecked_t
15531 + *
15532 + * Atomically increments @v by 1.
15533 + */
15534 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15535 +{
15536 + asm volatile(LOCK_PREFIX "incl %0\n"
15537 : "+m" (v->counter));
15538 }
15539
15540 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15541 */
15542 static inline void atomic_dec(atomic_t *v)
15543 {
15544 - asm volatile(LOCK_PREFIX "decl %0"
15545 + asm volatile(LOCK_PREFIX "decl %0\n"
15546 +
15547 +#ifdef CONFIG_PAX_REFCOUNT
15548 + "jno 0f\n"
15549 + LOCK_PREFIX "incl %0\n"
15550 + "int $4\n0:\n"
15551 + _ASM_EXTABLE(0b, 0b)
15552 +#endif
15553 +
15554 + : "+m" (v->counter));
15555 +}
15556 +
15557 +/**
15558 + * atomic_dec_unchecked - decrement atomic variable
15559 + * @v: pointer of type atomic_unchecked_t
15560 + *
15561 + * Atomically decrements @v by 1.
15562 + */
15563 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15564 +{
15565 + asm volatile(LOCK_PREFIX "decl %0\n"
15566 : "+m" (v->counter));
15567 }
15568
15569 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15570 */
15571 static inline int atomic_dec_and_test(atomic_t *v)
15572 {
15573 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15574 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15575 }
15576
15577 /**
15578 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15579 */
15580 static inline int atomic_inc_and_test(atomic_t *v)
15581 {
15582 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15583 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15584 +}
15585 +
15586 +/**
15587 + * atomic_inc_and_test_unchecked - increment and test
15588 + * @v: pointer of type atomic_unchecked_t
15589 + *
15590 + * Atomically increments @v by 1
15591 + * and returns true if the result is zero, or false for all
15592 + * other cases.
15593 + */
15594 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15595 +{
15596 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15597 }
15598
15599 /**
15600 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15601 */
15602 static inline int atomic_add_negative(int i, atomic_t *v)
15603 {
15604 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15605 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15606 }
15607
15608 /**
15609 @@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15610 */
15611 static inline int atomic_add_return(int i, atomic_t *v)
15612 {
15613 + return i + xadd_check_overflow(&v->counter, i);
15614 +}
15615 +
15616 +/**
15617 + * atomic_add_return_unchecked - add integer and return
15618 + * @i: integer value to add
15619 + * @v: pointer of type atomic_unchecked_t
15620 + *
15621 + * Atomically adds @i to @v and returns @i + @v
15622 + */
15623 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15624 +{
15625 return i + xadd(&v->counter, i);
15626 }
15627
15628 @@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15629 }
15630
15631 #define atomic_inc_return(v) (atomic_add_return(1, v))
15632 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15633 +{
15634 + return atomic_add_return_unchecked(1, v);
15635 +}
15636 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15637
15638 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15639 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15640 +{
15641 + return cmpxchg(&v->counter, old, new);
15642 +}
15643 +
15644 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15645 {
15646 return cmpxchg(&v->counter, old, new);
15647 }
15648 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15649 return xchg(&v->counter, new);
15650 }
15651
15652 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15653 +{
15654 + return xchg(&v->counter, new);
15655 +}
15656 +
15657 /**
15658 * __atomic_add_unless - add unless the number is already a given value
15659 * @v: pointer of type atomic_t
15660 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15661 * Atomically adds @a to @v, so long as @v was not already @u.
15662 * Returns the old value of @v.
15663 */
15664 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15665 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15666 {
15667 - int c, old;
15668 + int c, old, new;
15669 c = atomic_read(v);
15670 for (;;) {
15671 - if (unlikely(c == (u)))
15672 + if (unlikely(c == u))
15673 break;
15674 - old = atomic_cmpxchg((v), c, c + (a));
15675 +
15676 + asm volatile("addl %2,%0\n"
15677 +
15678 +#ifdef CONFIG_PAX_REFCOUNT
15679 + "jno 0f\n"
15680 + "subl %2,%0\n"
15681 + "int $4\n0:\n"
15682 + _ASM_EXTABLE(0b, 0b)
15683 +#endif
15684 +
15685 + : "=r" (new)
15686 + : "0" (c), "ir" (a));
15687 +
15688 + old = atomic_cmpxchg(v, c, new);
15689 if (likely(old == c))
15690 break;
15691 c = old;
15692 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15693 }
15694
15695 /**
15696 + * atomic_inc_not_zero_hint - increment if not null
15697 + * @v: pointer of type atomic_t
15698 + * @hint: probable value of the atomic before the increment
15699 + *
15700 + * This version of atomic_inc_not_zero() gives a hint of probable
15701 + * value of the atomic. This helps processor to not read the memory
15702 + * before doing the atomic read/modify/write cycle, lowering
15703 + * number of bus transactions on some arches.
15704 + *
15705 + * Returns: 0 if increment was not done, 1 otherwise.
15706 + */
15707 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15708 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15709 +{
15710 + int val, c = hint, new;
15711 +
15712 + /* sanity test, should be removed by compiler if hint is a constant */
15713 + if (!hint)
15714 + return __atomic_add_unless(v, 1, 0);
15715 +
15716 + do {
15717 + asm volatile("incl %0\n"
15718 +
15719 +#ifdef CONFIG_PAX_REFCOUNT
15720 + "jno 0f\n"
15721 + "decl %0\n"
15722 + "int $4\n0:\n"
15723 + _ASM_EXTABLE(0b, 0b)
15724 +#endif
15725 +
15726 + : "=r" (new)
15727 + : "0" (c));
15728 +
15729 + val = atomic_cmpxchg(v, c, new);
15730 + if (val == c)
15731 + return 1;
15732 + c = val;
15733 + } while (c);
15734 +
15735 + return 0;
15736 +}
15737 +
15738 +/**
15739 * atomic_inc_short - increment of a short integer
15740 * @v: pointer to type int
15741 *
15742 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15743 #endif
15744
15745 /* These are x86-specific, used by some header files */
15746 -#define atomic_clear_mask(mask, addr) \
15747 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15748 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15749 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15750 +{
15751 + asm volatile(LOCK_PREFIX "andl %1,%0"
15752 + : "+m" (v->counter)
15753 + : "r" (~(mask))
15754 + : "memory");
15755 +}
15756
15757 -#define atomic_set_mask(mask, addr) \
15758 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15759 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15760 - : "memory")
15761 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15762 +{
15763 + asm volatile(LOCK_PREFIX "andl %1,%0"
15764 + : "+m" (v->counter)
15765 + : "r" (~(mask))
15766 + : "memory");
15767 +}
15768 +
15769 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15770 +{
15771 + asm volatile(LOCK_PREFIX "orl %1,%0"
15772 + : "+m" (v->counter)
15773 + : "r" (mask)
15774 + : "memory");
15775 +}
15776 +
15777 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15778 +{
15779 + asm volatile(LOCK_PREFIX "orl %1,%0"
15780 + : "+m" (v->counter)
15781 + : "r" (mask)
15782 + : "memory");
15783 +}
15784
15785 #ifdef CONFIG_X86_32
15786 # include <asm/atomic64_32.h>
15787 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15788 index b154de7..bf18a5a 100644
15789 --- a/arch/x86/include/asm/atomic64_32.h
15790 +++ b/arch/x86/include/asm/atomic64_32.h
15791 @@ -12,6 +12,14 @@ typedef struct {
15792 u64 __aligned(8) counter;
15793 } atomic64_t;
15794
15795 +#ifdef CONFIG_PAX_REFCOUNT
15796 +typedef struct {
15797 + u64 __aligned(8) counter;
15798 +} atomic64_unchecked_t;
15799 +#else
15800 +typedef atomic64_t atomic64_unchecked_t;
15801 +#endif
15802 +
15803 #define ATOMIC64_INIT(val) { (val) }
15804
15805 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15806 @@ -37,21 +45,31 @@ typedef struct {
15807 ATOMIC64_DECL_ONE(sym##_386)
15808
15809 ATOMIC64_DECL_ONE(add_386);
15810 +ATOMIC64_DECL_ONE(add_unchecked_386);
15811 ATOMIC64_DECL_ONE(sub_386);
15812 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15813 ATOMIC64_DECL_ONE(inc_386);
15814 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15815 ATOMIC64_DECL_ONE(dec_386);
15816 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15817 #endif
15818
15819 #define alternative_atomic64(f, out, in...) \
15820 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15821
15822 ATOMIC64_DECL(read);
15823 +ATOMIC64_DECL(read_unchecked);
15824 ATOMIC64_DECL(set);
15825 +ATOMIC64_DECL(set_unchecked);
15826 ATOMIC64_DECL(xchg);
15827 ATOMIC64_DECL(add_return);
15828 +ATOMIC64_DECL(add_return_unchecked);
15829 ATOMIC64_DECL(sub_return);
15830 +ATOMIC64_DECL(sub_return_unchecked);
15831 ATOMIC64_DECL(inc_return);
15832 +ATOMIC64_DECL(inc_return_unchecked);
15833 ATOMIC64_DECL(dec_return);
15834 +ATOMIC64_DECL(dec_return_unchecked);
15835 ATOMIC64_DECL(dec_if_positive);
15836 ATOMIC64_DECL(inc_not_zero);
15837 ATOMIC64_DECL(add_unless);
15838 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15839 }
15840
15841 /**
15842 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15843 + * @p: pointer to type atomic64_unchecked_t
15844 + * @o: expected value
15845 + * @n: new value
15846 + *
15847 + * Atomically sets @v to @n if it was equal to @o and returns
15848 + * the old value.
15849 + */
15850 +
15851 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15852 +{
15853 + return cmpxchg64(&v->counter, o, n);
15854 +}
15855 +
15856 +/**
15857 * atomic64_xchg - xchg atomic64 variable
15858 * @v: pointer to type atomic64_t
15859 * @n: value to assign
15860 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15861 }
15862
15863 /**
15864 + * atomic64_set_unchecked - set atomic64 variable
15865 + * @v: pointer to type atomic64_unchecked_t
15866 + * @n: value to assign
15867 + *
15868 + * Atomically sets the value of @v to @n.
15869 + */
15870 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15871 +{
15872 + unsigned high = (unsigned)(i >> 32);
15873 + unsigned low = (unsigned)i;
15874 + alternative_atomic64(set, /* no output */,
15875 + "S" (v), "b" (low), "c" (high)
15876 + : "eax", "edx", "memory");
15877 +}
15878 +
15879 +/**
15880 * atomic64_read - read atomic64 variable
15881 * @v: pointer to type atomic64_t
15882 *
15883 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15884 }
15885
15886 /**
15887 + * atomic64_read_unchecked - read atomic64 variable
15888 + * @v: pointer to type atomic64_unchecked_t
15889 + *
15890 + * Atomically reads the value of @v and returns it.
15891 + */
15892 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15893 +{
15894 + long long r;
15895 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15896 + return r;
15897 + }
15898 +
15899 +/**
15900 * atomic64_add_return - add and return
15901 * @i: integer value to add
15902 * @v: pointer to type atomic64_t
15903 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15904 return i;
15905 }
15906
15907 +/**
15908 + * atomic64_add_return_unchecked - add and return
15909 + * @i: integer value to add
15910 + * @v: pointer to type atomic64_unchecked_t
15911 + *
15912 + * Atomically adds @i to @v and returns @i + *@v
15913 + */
15914 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15915 +{
15916 + alternative_atomic64(add_return_unchecked,
15917 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15918 + ASM_NO_INPUT_CLOBBER("memory"));
15919 + return i;
15920 +}
15921 +
15922 /*
15923 * Other variants with different arithmetic operators:
15924 */
15925 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15926 return a;
15927 }
15928
15929 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15930 +{
15931 + long long a;
15932 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15933 + "S" (v) : "memory", "ecx");
15934 + return a;
15935 +}
15936 +
15937 static inline long long atomic64_dec_return(atomic64_t *v)
15938 {
15939 long long a;
15940 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15941 }
15942
15943 /**
15944 + * atomic64_add_unchecked - add integer to atomic64 variable
15945 + * @i: integer value to add
15946 + * @v: pointer to type atomic64_unchecked_t
15947 + *
15948 + * Atomically adds @i to @v.
15949 + */
15950 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15951 +{
15952 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15953 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15954 + ASM_NO_INPUT_CLOBBER("memory"));
15955 + return i;
15956 +}
15957 +
15958 +/**
15959 * atomic64_sub - subtract the atomic64 variable
15960 * @i: integer value to subtract
15961 * @v: pointer to type atomic64_t
15962 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15963 index 46e9052..ae45136 100644
15964 --- a/arch/x86/include/asm/atomic64_64.h
15965 +++ b/arch/x86/include/asm/atomic64_64.h
15966 @@ -18,7 +18,19 @@
15967 */
15968 static inline long atomic64_read(const atomic64_t *v)
15969 {
15970 - return (*(volatile long *)&(v)->counter);
15971 + return (*(volatile const long *)&(v)->counter);
15972 +}
15973 +
15974 +/**
15975 + * atomic64_read_unchecked - read atomic64 variable
15976 + * @v: pointer of type atomic64_unchecked_t
15977 + *
15978 + * Atomically reads the value of @v.
15979 + * Doesn't imply a read memory barrier.
15980 + */
15981 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15982 +{
15983 + return (*(volatile const long *)&(v)->counter);
15984 }
15985
15986 /**
15987 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15988 }
15989
15990 /**
15991 + * atomic64_set_unchecked - set atomic64 variable
15992 + * @v: pointer to type atomic64_unchecked_t
15993 + * @i: required value
15994 + *
15995 + * Atomically sets the value of @v to @i.
15996 + */
15997 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15998 +{
15999 + v->counter = i;
16000 +}
16001 +
16002 +/**
16003 * atomic64_add - add integer to atomic64 variable
16004 * @i: integer value to add
16005 * @v: pointer to type atomic64_t
16006 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16007 */
16008 static inline void atomic64_add(long i, atomic64_t *v)
16009 {
16010 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
16011 +
16012 +#ifdef CONFIG_PAX_REFCOUNT
16013 + "jno 0f\n"
16014 + LOCK_PREFIX "subq %1,%0\n"
16015 + "int $4\n0:\n"
16016 + _ASM_EXTABLE(0b, 0b)
16017 +#endif
16018 +
16019 + : "=m" (v->counter)
16020 + : "er" (i), "m" (v->counter));
16021 +}
16022 +
16023 +/**
16024 + * atomic64_add_unchecked - add integer to atomic64 variable
16025 + * @i: integer value to add
16026 + * @v: pointer to type atomic64_unchecked_t
16027 + *
16028 + * Atomically adds @i to @v.
16029 + */
16030 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16031 +{
16032 asm volatile(LOCK_PREFIX "addq %1,%0"
16033 : "=m" (v->counter)
16034 : "er" (i), "m" (v->counter));
16035 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16036 */
16037 static inline void atomic64_sub(long i, atomic64_t *v)
16038 {
16039 - asm volatile(LOCK_PREFIX "subq %1,%0"
16040 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16041 +
16042 +#ifdef CONFIG_PAX_REFCOUNT
16043 + "jno 0f\n"
16044 + LOCK_PREFIX "addq %1,%0\n"
16045 + "int $4\n0:\n"
16046 + _ASM_EXTABLE(0b, 0b)
16047 +#endif
16048 +
16049 + : "=m" (v->counter)
16050 + : "er" (i), "m" (v->counter));
16051 +}
16052 +
16053 +/**
16054 + * atomic64_sub_unchecked - subtract the atomic64 variable
16055 + * @i: integer value to subtract
16056 + * @v: pointer to type atomic64_unchecked_t
16057 + *
16058 + * Atomically subtracts @i from @v.
16059 + */
16060 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16061 +{
16062 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16063 : "=m" (v->counter)
16064 : "er" (i), "m" (v->counter));
16065 }
16066 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16067 */
16068 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16069 {
16070 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16071 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16072 }
16073
16074 /**
16075 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16076 */
16077 static inline void atomic64_inc(atomic64_t *v)
16078 {
16079 + asm volatile(LOCK_PREFIX "incq %0\n"
16080 +
16081 +#ifdef CONFIG_PAX_REFCOUNT
16082 + "jno 0f\n"
16083 + LOCK_PREFIX "decq %0\n"
16084 + "int $4\n0:\n"
16085 + _ASM_EXTABLE(0b, 0b)
16086 +#endif
16087 +
16088 + : "=m" (v->counter)
16089 + : "m" (v->counter));
16090 +}
16091 +
16092 +/**
16093 + * atomic64_inc_unchecked - increment atomic64 variable
16094 + * @v: pointer to type atomic64_unchecked_t
16095 + *
16096 + * Atomically increments @v by 1.
16097 + */
16098 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16099 +{
16100 asm volatile(LOCK_PREFIX "incq %0"
16101 : "=m" (v->counter)
16102 : "m" (v->counter));
16103 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16104 */
16105 static inline void atomic64_dec(atomic64_t *v)
16106 {
16107 - asm volatile(LOCK_PREFIX "decq %0"
16108 + asm volatile(LOCK_PREFIX "decq %0\n"
16109 +
16110 +#ifdef CONFIG_PAX_REFCOUNT
16111 + "jno 0f\n"
16112 + LOCK_PREFIX "incq %0\n"
16113 + "int $4\n0:\n"
16114 + _ASM_EXTABLE(0b, 0b)
16115 +#endif
16116 +
16117 + : "=m" (v->counter)
16118 + : "m" (v->counter));
16119 +}
16120 +
16121 +/**
16122 + * atomic64_dec_unchecked - decrement atomic64 variable
16123 + * @v: pointer to type atomic64_t
16124 + *
16125 + * Atomically decrements @v by 1.
16126 + */
16127 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16128 +{
16129 + asm volatile(LOCK_PREFIX "decq %0\n"
16130 : "=m" (v->counter)
16131 : "m" (v->counter));
16132 }
16133 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16134 */
16135 static inline int atomic64_dec_and_test(atomic64_t *v)
16136 {
16137 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16138 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16139 }
16140
16141 /**
16142 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16143 */
16144 static inline int atomic64_inc_and_test(atomic64_t *v)
16145 {
16146 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16147 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16148 }
16149
16150 /**
16151 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16152 */
16153 static inline int atomic64_add_negative(long i, atomic64_t *v)
16154 {
16155 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16156 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16157 }
16158
16159 /**
16160 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16161 */
16162 static inline long atomic64_add_return(long i, atomic64_t *v)
16163 {
16164 + return i + xadd_check_overflow(&v->counter, i);
16165 +}
16166 +
16167 +/**
16168 + * atomic64_add_return_unchecked - add and return
16169 + * @i: integer value to add
16170 + * @v: pointer to type atomic64_unchecked_t
16171 + *
16172 + * Atomically adds @i to @v and returns @i + @v
16173 + */
16174 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16175 +{
16176 return i + xadd(&v->counter, i);
16177 }
16178
16179 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16180 }
16181
16182 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16183 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16184 +{
16185 + return atomic64_add_return_unchecked(1, v);
16186 +}
16187 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16188
16189 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16190 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16191 return cmpxchg(&v->counter, old, new);
16192 }
16193
16194 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16195 +{
16196 + return cmpxchg(&v->counter, old, new);
16197 +}
16198 +
16199 static inline long atomic64_xchg(atomic64_t *v, long new)
16200 {
16201 return xchg(&v->counter, new);
16202 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16203 */
16204 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16205 {
16206 - long c, old;
16207 + long c, old, new;
16208 c = atomic64_read(v);
16209 for (;;) {
16210 - if (unlikely(c == (u)))
16211 + if (unlikely(c == u))
16212 break;
16213 - old = atomic64_cmpxchg((v), c, c + (a));
16214 +
16215 + asm volatile("add %2,%0\n"
16216 +
16217 +#ifdef CONFIG_PAX_REFCOUNT
16218 + "jno 0f\n"
16219 + "sub %2,%0\n"
16220 + "int $4\n0:\n"
16221 + _ASM_EXTABLE(0b, 0b)
16222 +#endif
16223 +
16224 + : "=r" (new)
16225 + : "0" (c), "ir" (a));
16226 +
16227 + old = atomic64_cmpxchg(v, c, new);
16228 if (likely(old == c))
16229 break;
16230 c = old;
16231 }
16232 - return c != (u);
16233 + return c != u;
16234 }
16235
16236 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16237 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16238 index 5c7198c..44180b5 100644
16239 --- a/arch/x86/include/asm/barrier.h
16240 +++ b/arch/x86/include/asm/barrier.h
16241 @@ -107,7 +107,7 @@
16242 do { \
16243 compiletime_assert_atomic_type(*p); \
16244 smp_mb(); \
16245 - ACCESS_ONCE(*p) = (v); \
16246 + ACCESS_ONCE_RW(*p) = (v); \
16247 } while (0)
16248
16249 #define smp_load_acquire(p) \
16250 @@ -124,7 +124,7 @@ do { \
16251 do { \
16252 compiletime_assert_atomic_type(*p); \
16253 barrier(); \
16254 - ACCESS_ONCE(*p) = (v); \
16255 + ACCESS_ONCE_RW(*p) = (v); \
16256 } while (0)
16257
16258 #define smp_load_acquire(p) \
16259 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16260 index afcd35d..d01b118 100644
16261 --- a/arch/x86/include/asm/bitops.h
16262 +++ b/arch/x86/include/asm/bitops.h
16263 @@ -50,7 +50,7 @@
16264 * a mask operation on a byte.
16265 */
16266 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16267 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16268 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16269 #define CONST_MASK(nr) (1 << ((nr) & 7))
16270
16271 /**
16272 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16273 */
16274 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16275 {
16276 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16277 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16278 }
16279
16280 /**
16281 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16282 */
16283 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16284 {
16285 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16286 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16287 }
16288
16289 /**
16290 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16291 */
16292 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16293 {
16294 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16295 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16296 }
16297
16298 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16299 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16300 *
16301 * Undefined if no bit exists, so code should check against 0 first.
16302 */
16303 -static inline unsigned long __ffs(unsigned long word)
16304 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16305 {
16306 asm("rep; bsf %1,%0"
16307 : "=r" (word)
16308 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16309 *
16310 * Undefined if no zero exists, so code should check against ~0UL first.
16311 */
16312 -static inline unsigned long ffz(unsigned long word)
16313 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16314 {
16315 asm("rep; bsf %1,%0"
16316 : "=r" (word)
16317 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16318 *
16319 * Undefined if no set bit exists, so code should check against 0 first.
16320 */
16321 -static inline unsigned long __fls(unsigned long word)
16322 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16323 {
16324 asm("bsr %1,%0"
16325 : "=r" (word)
16326 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16327 * set bit if value is nonzero. The last (most significant) bit is
16328 * at position 32.
16329 */
16330 -static inline int fls(int x)
16331 +static inline int __intentional_overflow(-1) fls(int x)
16332 {
16333 int r;
16334
16335 @@ -476,7 +476,7 @@ static inline int fls(int x)
16336 * at position 64.
16337 */
16338 #ifdef CONFIG_X86_64
16339 -static __always_inline int fls64(__u64 x)
16340 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16341 {
16342 int bitpos = -1;
16343 /*
16344 @@ -497,8 +497,6 @@ static __always_inline int fls64(__u64 x)
16345
16346 #include <asm-generic/bitops/sched.h>
16347
16348 -#define ARCH_HAS_FAST_MULTIPLIER 1
16349 -
16350 #include <asm/arch_hweight.h>
16351
16352 #include <asm-generic/bitops/const_hweight.h>
16353 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16354 index 4fa687a..60f2d39 100644
16355 --- a/arch/x86/include/asm/boot.h
16356 +++ b/arch/x86/include/asm/boot.h
16357 @@ -6,10 +6,15 @@
16358 #include <uapi/asm/boot.h>
16359
16360 /* Physical address where kernel should be loaded. */
16361 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16362 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16363 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16364 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16365
16366 +#ifndef __ASSEMBLY__
16367 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16368 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16369 +#endif
16370 +
16371 /* Minimum kernel alignment, as a power of two */
16372 #ifdef CONFIG_X86_64
16373 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16374 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16375 index 48f99f1..d78ebf9 100644
16376 --- a/arch/x86/include/asm/cache.h
16377 +++ b/arch/x86/include/asm/cache.h
16378 @@ -5,12 +5,13 @@
16379
16380 /* L1 cache line size */
16381 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16382 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16383 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16384
16385 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16386 +#define __read_only __attribute__((__section__(".data..read_only")))
16387
16388 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16389 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16390 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16391
16392 #ifdef CONFIG_X86_VSMP
16393 #ifdef CONFIG_SMP
16394 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16395 index 9863ee3..4a1f8e1 100644
16396 --- a/arch/x86/include/asm/cacheflush.h
16397 +++ b/arch/x86/include/asm/cacheflush.h
16398 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16399 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16400
16401 if (pg_flags == _PGMT_DEFAULT)
16402 - return -1;
16403 + return ~0UL;
16404 else if (pg_flags == _PGMT_WC)
16405 return _PAGE_CACHE_WC;
16406 else if (pg_flags == _PGMT_UC_MINUS)
16407 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16408 index cb4c73b..c473c29 100644
16409 --- a/arch/x86/include/asm/calling.h
16410 +++ b/arch/x86/include/asm/calling.h
16411 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16412 #define RSP 152
16413 #define SS 160
16414
16415 -#define ARGOFFSET R11
16416 -#define SWFRAME ORIG_RAX
16417 +#define ARGOFFSET R15
16418
16419 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16420 - subq $9*8+\addskip, %rsp
16421 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16422 - movq_cfi rdi, 8*8
16423 - movq_cfi rsi, 7*8
16424 - movq_cfi rdx, 6*8
16425 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16426 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16427 + movq_cfi rdi, RDI
16428 + movq_cfi rsi, RSI
16429 + movq_cfi rdx, RDX
16430
16431 .if \save_rcx
16432 - movq_cfi rcx, 5*8
16433 + movq_cfi rcx, RCX
16434 .endif
16435
16436 - movq_cfi rax, 4*8
16437 + movq_cfi rax, RAX
16438
16439 .if \save_r891011
16440 - movq_cfi r8, 3*8
16441 - movq_cfi r9, 2*8
16442 - movq_cfi r10, 1*8
16443 - movq_cfi r11, 0*8
16444 + movq_cfi r8, R8
16445 + movq_cfi r9, R9
16446 + movq_cfi r10, R10
16447 + movq_cfi r11, R11
16448 .endif
16449
16450 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16451 + movq_cfi r12, R12
16452 +#endif
16453 +
16454 .endm
16455
16456 -#define ARG_SKIP (9*8)
16457 +#define ARG_SKIP ORIG_RAX
16458
16459 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16460 rstor_r8910=1, rstor_rdx=1
16461 +
16462 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16463 + movq_cfi_restore R12, r12
16464 +#endif
16465 +
16466 .if \rstor_r11
16467 - movq_cfi_restore 0*8, r11
16468 + movq_cfi_restore R11, r11
16469 .endif
16470
16471 .if \rstor_r8910
16472 - movq_cfi_restore 1*8, r10
16473 - movq_cfi_restore 2*8, r9
16474 - movq_cfi_restore 3*8, r8
16475 + movq_cfi_restore R10, r10
16476 + movq_cfi_restore R9, r9
16477 + movq_cfi_restore R8, r8
16478 .endif
16479
16480 .if \rstor_rax
16481 - movq_cfi_restore 4*8, rax
16482 + movq_cfi_restore RAX, rax
16483 .endif
16484
16485 .if \rstor_rcx
16486 - movq_cfi_restore 5*8, rcx
16487 + movq_cfi_restore RCX, rcx
16488 .endif
16489
16490 .if \rstor_rdx
16491 - movq_cfi_restore 6*8, rdx
16492 + movq_cfi_restore RDX, rdx
16493 .endif
16494
16495 - movq_cfi_restore 7*8, rsi
16496 - movq_cfi_restore 8*8, rdi
16497 + movq_cfi_restore RSI, rsi
16498 + movq_cfi_restore RDI, rdi
16499
16500 - .if ARG_SKIP+\addskip > 0
16501 - addq $ARG_SKIP+\addskip, %rsp
16502 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16503 + .if ORIG_RAX+\addskip > 0
16504 + addq $ORIG_RAX+\addskip, %rsp
16505 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16506 .endif
16507 .endm
16508
16509 - .macro LOAD_ARGS offset, skiprax=0
16510 - movq \offset(%rsp), %r11
16511 - movq \offset+8(%rsp), %r10
16512 - movq \offset+16(%rsp), %r9
16513 - movq \offset+24(%rsp), %r8
16514 - movq \offset+40(%rsp), %rcx
16515 - movq \offset+48(%rsp), %rdx
16516 - movq \offset+56(%rsp), %rsi
16517 - movq \offset+64(%rsp), %rdi
16518 + .macro LOAD_ARGS skiprax=0
16519 + movq R11(%rsp), %r11
16520 + movq R10(%rsp), %r10
16521 + movq R9(%rsp), %r9
16522 + movq R8(%rsp), %r8
16523 + movq RCX(%rsp), %rcx
16524 + movq RDX(%rsp), %rdx
16525 + movq RSI(%rsp), %rsi
16526 + movq RDI(%rsp), %rdi
16527 .if \skiprax
16528 .else
16529 - movq \offset+72(%rsp), %rax
16530 + movq RAX(%rsp), %rax
16531 .endif
16532 .endm
16533
16534 -#define REST_SKIP (6*8)
16535 -
16536 .macro SAVE_REST
16537 - subq $REST_SKIP, %rsp
16538 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16539 - movq_cfi rbx, 5*8
16540 - movq_cfi rbp, 4*8
16541 - movq_cfi r12, 3*8
16542 - movq_cfi r13, 2*8
16543 - movq_cfi r14, 1*8
16544 - movq_cfi r15, 0*8
16545 + movq_cfi rbx, RBX
16546 + movq_cfi rbp, RBP
16547 +
16548 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16549 + movq_cfi r12, R12
16550 +#endif
16551 +
16552 + movq_cfi r13, R13
16553 + movq_cfi r14, R14
16554 + movq_cfi r15, R15
16555 .endm
16556
16557 .macro RESTORE_REST
16558 - movq_cfi_restore 0*8, r15
16559 - movq_cfi_restore 1*8, r14
16560 - movq_cfi_restore 2*8, r13
16561 - movq_cfi_restore 3*8, r12
16562 - movq_cfi_restore 4*8, rbp
16563 - movq_cfi_restore 5*8, rbx
16564 - addq $REST_SKIP, %rsp
16565 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16566 + movq_cfi_restore R15, r15
16567 + movq_cfi_restore R14, r14
16568 + movq_cfi_restore R13, r13
16569 +
16570 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16571 + movq_cfi_restore R12, r12
16572 +#endif
16573 +
16574 + movq_cfi_restore RBP, rbp
16575 + movq_cfi_restore RBX, rbx
16576 .endm
16577
16578 .macro SAVE_ALL
16579 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16580 index f50de69..2b0a458 100644
16581 --- a/arch/x86/include/asm/checksum_32.h
16582 +++ b/arch/x86/include/asm/checksum_32.h
16583 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16584 int len, __wsum sum,
16585 int *src_err_ptr, int *dst_err_ptr);
16586
16587 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16588 + int len, __wsum sum,
16589 + int *src_err_ptr, int *dst_err_ptr);
16590 +
16591 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16592 + int len, __wsum sum,
16593 + int *src_err_ptr, int *dst_err_ptr);
16594 +
16595 /*
16596 * Note: when you get a NULL pointer exception here this means someone
16597 * passed in an incorrect kernel address to one of these functions.
16598 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16599
16600 might_sleep();
16601 stac();
16602 - ret = csum_partial_copy_generic((__force void *)src, dst,
16603 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16604 len, sum, err_ptr, NULL);
16605 clac();
16606
16607 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16608 might_sleep();
16609 if (access_ok(VERIFY_WRITE, dst, len)) {
16610 stac();
16611 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16612 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16613 len, sum, NULL, err_ptr);
16614 clac();
16615 return ret;
16616 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16617 index d47786a..2d8883e 100644
16618 --- a/arch/x86/include/asm/cmpxchg.h
16619 +++ b/arch/x86/include/asm/cmpxchg.h
16620 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16621 __compiletime_error("Bad argument size for cmpxchg");
16622 extern void __xadd_wrong_size(void)
16623 __compiletime_error("Bad argument size for xadd");
16624 +extern void __xadd_check_overflow_wrong_size(void)
16625 + __compiletime_error("Bad argument size for xadd_check_overflow");
16626 extern void __add_wrong_size(void)
16627 __compiletime_error("Bad argument size for add");
16628 +extern void __add_check_overflow_wrong_size(void)
16629 + __compiletime_error("Bad argument size for add_check_overflow");
16630
16631 /*
16632 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16633 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16634 __ret; \
16635 })
16636
16637 +#ifdef CONFIG_PAX_REFCOUNT
16638 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16639 + ({ \
16640 + __typeof__ (*(ptr)) __ret = (arg); \
16641 + switch (sizeof(*(ptr))) { \
16642 + case __X86_CASE_L: \
16643 + asm volatile (lock #op "l %0, %1\n" \
16644 + "jno 0f\n" \
16645 + "mov %0,%1\n" \
16646 + "int $4\n0:\n" \
16647 + _ASM_EXTABLE(0b, 0b) \
16648 + : "+r" (__ret), "+m" (*(ptr)) \
16649 + : : "memory", "cc"); \
16650 + break; \
16651 + case __X86_CASE_Q: \
16652 + asm volatile (lock #op "q %q0, %1\n" \
16653 + "jno 0f\n" \
16654 + "mov %0,%1\n" \
16655 + "int $4\n0:\n" \
16656 + _ASM_EXTABLE(0b, 0b) \
16657 + : "+r" (__ret), "+m" (*(ptr)) \
16658 + : : "memory", "cc"); \
16659 + break; \
16660 + default: \
16661 + __ ## op ## _check_overflow_wrong_size(); \
16662 + } \
16663 + __ret; \
16664 + })
16665 +#else
16666 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16667 +#endif
16668 +
16669 /*
16670 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16671 * Since this is generally used to protect other memory information, we
16672 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16673 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16674 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16675
16676 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16677 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16678 +
16679 #define __add(ptr, inc, lock) \
16680 ({ \
16681 __typeof__ (*(ptr)) __ret = (inc); \
16682 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16683 index 59c6c40..5e0b22c 100644
16684 --- a/arch/x86/include/asm/compat.h
16685 +++ b/arch/x86/include/asm/compat.h
16686 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16687 typedef u32 compat_uint_t;
16688 typedef u32 compat_ulong_t;
16689 typedef u64 __attribute__((aligned(4))) compat_u64;
16690 -typedef u32 compat_uptr_t;
16691 +typedef u32 __user compat_uptr_t;
16692
16693 struct compat_timespec {
16694 compat_time_t tv_sec;
16695 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16696 index e265ff9..72c253b 100644
16697 --- a/arch/x86/include/asm/cpufeature.h
16698 +++ b/arch/x86/include/asm/cpufeature.h
16699 @@ -203,7 +203,7 @@
16700 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16701 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16702 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16703 -
16704 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16705
16706 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16707 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16708 @@ -211,7 +211,7 @@
16709 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16710 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16711 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16712 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16713 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16714 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16715 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16716 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16717 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16718 #undef cpu_has_centaur_mcr
16719 #define cpu_has_centaur_mcr 0
16720
16721 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16722 #endif /* CONFIG_X86_64 */
16723
16724 #if __GNUC__ >= 4
16725 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16726
16727 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16728 t_warn:
16729 - warn_pre_alternatives();
16730 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16731 + warn_pre_alternatives();
16732 return false;
16733 #endif
16734
16735 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16736 ".section .discard,\"aw\",@progbits\n"
16737 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16738 ".previous\n"
16739 - ".section .altinstr_replacement,\"ax\"\n"
16740 + ".section .altinstr_replacement,\"a\"\n"
16741 "3: movb $1,%0\n"
16742 "4:\n"
16743 ".previous\n"
16744 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16745 " .byte 2b - 1b\n" /* src len */
16746 " .byte 4f - 3f\n" /* repl len */
16747 ".previous\n"
16748 - ".section .altinstr_replacement,\"ax\"\n"
16749 + ".section .altinstr_replacement,\"a\"\n"
16750 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16751 "4:\n"
16752 ".previous\n"
16753 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16754 ".section .discard,\"aw\",@progbits\n"
16755 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16756 ".previous\n"
16757 - ".section .altinstr_replacement,\"ax\"\n"
16758 + ".section .altinstr_replacement,\"a\"\n"
16759 "3: movb $0,%0\n"
16760 "4:\n"
16761 ".previous\n"
16762 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16763 ".section .discard,\"aw\",@progbits\n"
16764 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16765 ".previous\n"
16766 - ".section .altinstr_replacement,\"ax\"\n"
16767 + ".section .altinstr_replacement,\"a\"\n"
16768 "5: movb $1,%0\n"
16769 "6:\n"
16770 ".previous\n"
16771 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16772 index 50d033a..37deb26 100644
16773 --- a/arch/x86/include/asm/desc.h
16774 +++ b/arch/x86/include/asm/desc.h
16775 @@ -4,6 +4,7 @@
16776 #include <asm/desc_defs.h>
16777 #include <asm/ldt.h>
16778 #include <asm/mmu.h>
16779 +#include <asm/pgtable.h>
16780
16781 #include <linux/smp.h>
16782 #include <linux/percpu.h>
16783 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16784
16785 desc->type = (info->read_exec_only ^ 1) << 1;
16786 desc->type |= info->contents << 2;
16787 + desc->type |= info->seg_not_present ^ 1;
16788
16789 desc->s = 1;
16790 desc->dpl = 0x3;
16791 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16792 }
16793
16794 extern struct desc_ptr idt_descr;
16795 -extern gate_desc idt_table[];
16796 -extern struct desc_ptr debug_idt_descr;
16797 -extern gate_desc debug_idt_table[];
16798 -
16799 -struct gdt_page {
16800 - struct desc_struct gdt[GDT_ENTRIES];
16801 -} __attribute__((aligned(PAGE_SIZE)));
16802 -
16803 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16804 +extern gate_desc idt_table[IDT_ENTRIES];
16805 +extern const struct desc_ptr debug_idt_descr;
16806 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16807
16808 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16809 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16810 {
16811 - return per_cpu(gdt_page, cpu).gdt;
16812 + return cpu_gdt_table[cpu];
16813 }
16814
16815 #ifdef CONFIG_X86_64
16816 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16817 unsigned long base, unsigned dpl, unsigned flags,
16818 unsigned short seg)
16819 {
16820 - gate->a = (seg << 16) | (base & 0xffff);
16821 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16822 + gate->gate.offset_low = base;
16823 + gate->gate.seg = seg;
16824 + gate->gate.reserved = 0;
16825 + gate->gate.type = type;
16826 + gate->gate.s = 0;
16827 + gate->gate.dpl = dpl;
16828 + gate->gate.p = 1;
16829 + gate->gate.offset_high = base >> 16;
16830 }
16831
16832 #endif
16833 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16834
16835 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16836 {
16837 + pax_open_kernel();
16838 memcpy(&idt[entry], gate, sizeof(*gate));
16839 + pax_close_kernel();
16840 }
16841
16842 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16843 {
16844 + pax_open_kernel();
16845 memcpy(&ldt[entry], desc, 8);
16846 + pax_close_kernel();
16847 }
16848
16849 static inline void
16850 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16851 default: size = sizeof(*gdt); break;
16852 }
16853
16854 + pax_open_kernel();
16855 memcpy(&gdt[entry], desc, size);
16856 + pax_close_kernel();
16857 }
16858
16859 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16860 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16861
16862 static inline void native_load_tr_desc(void)
16863 {
16864 + pax_open_kernel();
16865 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16866 + pax_close_kernel();
16867 }
16868
16869 static inline void native_load_gdt(const struct desc_ptr *dtr)
16870 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16871 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16872 unsigned int i;
16873
16874 + pax_open_kernel();
16875 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16876 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16877 + pax_close_kernel();
16878 }
16879
16880 #define _LDT_empty(info) \
16881 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16882 preempt_enable();
16883 }
16884
16885 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16886 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16887 {
16888 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16889 }
16890 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16891 }
16892
16893 #ifdef CONFIG_X86_64
16894 -static inline void set_nmi_gate(int gate, void *addr)
16895 +static inline void set_nmi_gate(int gate, const void *addr)
16896 {
16897 gate_desc s;
16898
16899 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16900 #endif
16901
16902 #ifdef CONFIG_TRACING
16903 -extern struct desc_ptr trace_idt_descr;
16904 -extern gate_desc trace_idt_table[];
16905 +extern const struct desc_ptr trace_idt_descr;
16906 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16907 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16908 {
16909 write_idt_entry(trace_idt_table, entry, gate);
16910 }
16911
16912 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16913 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16914 unsigned dpl, unsigned ist, unsigned seg)
16915 {
16916 gate_desc s;
16917 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16918 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16919 #endif
16920
16921 -static inline void _set_gate(int gate, unsigned type, void *addr,
16922 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16923 unsigned dpl, unsigned ist, unsigned seg)
16924 {
16925 gate_desc s;
16926 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16927 #define set_intr_gate(n, addr) \
16928 do { \
16929 BUG_ON((unsigned)n > 0xFF); \
16930 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16931 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16932 __KERNEL_CS); \
16933 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16934 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16935 0, 0, __KERNEL_CS); \
16936 } while (0)
16937
16938 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16939 /*
16940 * This routine sets up an interrupt gate at directory privilege level 3.
16941 */
16942 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16943 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16944 {
16945 BUG_ON((unsigned)n > 0xFF);
16946 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16947 }
16948
16949 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16950 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16951 {
16952 BUG_ON((unsigned)n > 0xFF);
16953 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16954 }
16955
16956 -static inline void set_trap_gate(unsigned int n, void *addr)
16957 +static inline void set_trap_gate(unsigned int n, const void *addr)
16958 {
16959 BUG_ON((unsigned)n > 0xFF);
16960 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16961 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16962 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16963 {
16964 BUG_ON((unsigned)n > 0xFF);
16965 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16966 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16967 }
16968
16969 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16970 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16971 {
16972 BUG_ON((unsigned)n > 0xFF);
16973 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16974 }
16975
16976 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16977 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16978 {
16979 BUG_ON((unsigned)n > 0xFF);
16980 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16981 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16982 else
16983 load_idt((const struct desc_ptr *)&idt_descr);
16984 }
16985 +
16986 +#ifdef CONFIG_X86_32
16987 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16988 +{
16989 + struct desc_struct d;
16990 +
16991 + if (likely(limit))
16992 + limit = (limit - 1UL) >> PAGE_SHIFT;
16993 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16994 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16995 +}
16996 +#endif
16997 +
16998 #endif /* _ASM_X86_DESC_H */
16999 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17000 index 278441f..b95a174 100644
17001 --- a/arch/x86/include/asm/desc_defs.h
17002 +++ b/arch/x86/include/asm/desc_defs.h
17003 @@ -31,6 +31,12 @@ struct desc_struct {
17004 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17005 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17006 };
17007 + struct {
17008 + u16 offset_low;
17009 + u16 seg;
17010 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17011 + unsigned offset_high: 16;
17012 + } gate;
17013 };
17014 } __attribute__((packed));
17015
17016 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17017 index ced283a..ffe04cc 100644
17018 --- a/arch/x86/include/asm/div64.h
17019 +++ b/arch/x86/include/asm/div64.h
17020 @@ -39,7 +39,7 @@
17021 __mod; \
17022 })
17023
17024 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17025 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17026 {
17027 union {
17028 u64 v64;
17029 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17030 index 1a055c8..a1701de 100644
17031 --- a/arch/x86/include/asm/elf.h
17032 +++ b/arch/x86/include/asm/elf.h
17033 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17034
17035 #include <asm/vdso.h>
17036
17037 -#ifdef CONFIG_X86_64
17038 -extern unsigned int vdso64_enabled;
17039 -#endif
17040 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17041 extern unsigned int vdso32_enabled;
17042 #endif
17043 @@ -248,7 +245,25 @@ extern int force_personality32;
17044 the loader. We need to make sure that it is out of the way of the program
17045 that it will "exec", and that there is sufficient room for the brk. */
17046
17047 +#ifdef CONFIG_PAX_SEGMEXEC
17048 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17049 +#else
17050 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17051 +#endif
17052 +
17053 +#ifdef CONFIG_PAX_ASLR
17054 +#ifdef CONFIG_X86_32
17055 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17056 +
17057 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17058 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17059 +#else
17060 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17061 +
17062 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17063 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17064 +#endif
17065 +#endif
17066
17067 /* This yields a mask that user programs can use to figure out what
17068 instruction set this CPU supports. This could be done in user space,
17069 @@ -297,17 +312,13 @@ do { \
17070
17071 #define ARCH_DLINFO \
17072 do { \
17073 - if (vdso64_enabled) \
17074 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17075 - (unsigned long __force)current->mm->context.vdso); \
17076 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17077 } while (0)
17078
17079 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17080 #define ARCH_DLINFO_X32 \
17081 do { \
17082 - if (vdso64_enabled) \
17083 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17084 - (unsigned long __force)current->mm->context.vdso); \
17085 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17086 } while (0)
17087
17088 #define AT_SYSINFO 32
17089 @@ -322,10 +333,10 @@ else \
17090
17091 #endif /* !CONFIG_X86_32 */
17092
17093 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17094 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17095
17096 #define VDSO_ENTRY \
17097 - ((unsigned long)current->mm->context.vdso + \
17098 + (current->mm->context.vdso + \
17099 selected_vdso32->sym___kernel_vsyscall)
17100
17101 struct linux_binprm;
17102 @@ -337,9 +348,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17103 int uses_interp);
17104 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17105
17106 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17107 -#define arch_randomize_brk arch_randomize_brk
17108 -
17109 /*
17110 * True on X86_32 or when emulating IA32 on X86_64
17111 */
17112 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17113 index 77a99ac..39ff7f5 100644
17114 --- a/arch/x86/include/asm/emergency-restart.h
17115 +++ b/arch/x86/include/asm/emergency-restart.h
17116 @@ -1,6 +1,6 @@
17117 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17118 #define _ASM_X86_EMERGENCY_RESTART_H
17119
17120 -extern void machine_emergency_restart(void);
17121 +extern void machine_emergency_restart(void) __noreturn;
17122
17123 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17124 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17125 index 1c7eefe..d0e4702 100644
17126 --- a/arch/x86/include/asm/floppy.h
17127 +++ b/arch/x86/include/asm/floppy.h
17128 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17129 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17130 } fd_routine[] = {
17131 {
17132 - request_dma,
17133 - free_dma,
17134 - get_dma_residue,
17135 - dma_mem_alloc,
17136 - hard_dma_setup
17137 + ._request_dma = request_dma,
17138 + ._free_dma = free_dma,
17139 + ._get_dma_residue = get_dma_residue,
17140 + ._dma_mem_alloc = dma_mem_alloc,
17141 + ._dma_setup = hard_dma_setup
17142 },
17143 {
17144 - vdma_request_dma,
17145 - vdma_nop,
17146 - vdma_get_dma_residue,
17147 - vdma_mem_alloc,
17148 - vdma_dma_setup
17149 + ._request_dma = vdma_request_dma,
17150 + ._free_dma = vdma_nop,
17151 + ._get_dma_residue = vdma_get_dma_residue,
17152 + ._dma_mem_alloc = vdma_mem_alloc,
17153 + ._dma_setup = vdma_dma_setup
17154 }
17155 };
17156
17157 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17158 index 115e368..76ecf6c 100644
17159 --- a/arch/x86/include/asm/fpu-internal.h
17160 +++ b/arch/x86/include/asm/fpu-internal.h
17161 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17162 #define user_insn(insn, output, input...) \
17163 ({ \
17164 int err; \
17165 + pax_open_userland(); \
17166 asm volatile(ASM_STAC "\n" \
17167 - "1:" #insn "\n\t" \
17168 + "1:" \
17169 + __copyuser_seg \
17170 + #insn "\n\t" \
17171 "2: " ASM_CLAC "\n" \
17172 ".section .fixup,\"ax\"\n" \
17173 "3: movl $-1,%[err]\n" \
17174 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17175 _ASM_EXTABLE(1b, 3b) \
17176 : [err] "=r" (err), output \
17177 : "0"(0), input); \
17178 + pax_close_userland(); \
17179 err; \
17180 })
17181
17182 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17183 "fnclex\n\t"
17184 "emms\n\t"
17185 "fildl %P[addr]" /* set F?P to defined value */
17186 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17187 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17188 }
17189
17190 return fpu_restore_checking(&tsk->thread.fpu);
17191 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17192 index b4c1f54..e290c08 100644
17193 --- a/arch/x86/include/asm/futex.h
17194 +++ b/arch/x86/include/asm/futex.h
17195 @@ -12,6 +12,7 @@
17196 #include <asm/smap.h>
17197
17198 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17199 + typecheck(u32 __user *, uaddr); \
17200 asm volatile("\t" ASM_STAC "\n" \
17201 "1:\t" insn "\n" \
17202 "2:\t" ASM_CLAC "\n" \
17203 @@ -20,15 +21,16 @@
17204 "\tjmp\t2b\n" \
17205 "\t.previous\n" \
17206 _ASM_EXTABLE(1b, 3b) \
17207 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17208 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17209 : "i" (-EFAULT), "0" (oparg), "1" (0))
17210
17211 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17212 + typecheck(u32 __user *, uaddr); \
17213 asm volatile("\t" ASM_STAC "\n" \
17214 "1:\tmovl %2, %0\n" \
17215 "\tmovl\t%0, %3\n" \
17216 "\t" insn "\n" \
17217 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17218 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17219 "\tjnz\t1b\n" \
17220 "3:\t" ASM_CLAC "\n" \
17221 "\t.section .fixup,\"ax\"\n" \
17222 @@ -38,7 +40,7 @@
17223 _ASM_EXTABLE(1b, 4b) \
17224 _ASM_EXTABLE(2b, 4b) \
17225 : "=&a" (oldval), "=&r" (ret), \
17226 - "+m" (*uaddr), "=&r" (tem) \
17227 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17228 : "r" (oparg), "i" (-EFAULT), "1" (0))
17229
17230 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17231 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17232
17233 pagefault_disable();
17234
17235 + pax_open_userland();
17236 switch (op) {
17237 case FUTEX_OP_SET:
17238 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17239 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17240 break;
17241 case FUTEX_OP_ADD:
17242 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17243 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17244 uaddr, oparg);
17245 break;
17246 case FUTEX_OP_OR:
17247 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17248 default:
17249 ret = -ENOSYS;
17250 }
17251 + pax_close_userland();
17252
17253 pagefault_enable();
17254
17255 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17256 index 4615906..788c817 100644
17257 --- a/arch/x86/include/asm/hw_irq.h
17258 +++ b/arch/x86/include/asm/hw_irq.h
17259 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17260 extern void enable_IO_APIC(void);
17261
17262 /* Statistics */
17263 -extern atomic_t irq_err_count;
17264 -extern atomic_t irq_mis_count;
17265 +extern atomic_unchecked_t irq_err_count;
17266 +extern atomic_unchecked_t irq_mis_count;
17267
17268 /* EISA */
17269 extern void eisa_set_level_irq(unsigned int irq);
17270 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17271 index a203659..9889f1c 100644
17272 --- a/arch/x86/include/asm/i8259.h
17273 +++ b/arch/x86/include/asm/i8259.h
17274 @@ -62,7 +62,7 @@ struct legacy_pic {
17275 void (*init)(int auto_eoi);
17276 int (*irq_pending)(unsigned int irq);
17277 void (*make_irq)(unsigned int irq);
17278 -};
17279 +} __do_const;
17280
17281 extern struct legacy_pic *legacy_pic;
17282 extern struct legacy_pic null_legacy_pic;
17283 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17284 index b8237d8..3e8864e 100644
17285 --- a/arch/x86/include/asm/io.h
17286 +++ b/arch/x86/include/asm/io.h
17287 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17288 "m" (*(volatile type __force *)addr) barrier); }
17289
17290 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17291 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17292 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17293 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17294 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17295
17296 build_mmio_read(__readb, "b", unsigned char, "=q", )
17297 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17298 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17299 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17300 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17301
17302 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17303 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17304 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17305 * this function
17306 */
17307
17308 -static inline phys_addr_t virt_to_phys(volatile void *address)
17309 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17310 {
17311 return __pa(address);
17312 }
17313 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17314 return ioremap_nocache(offset, size);
17315 }
17316
17317 -extern void iounmap(volatile void __iomem *addr);
17318 +extern void iounmap(const volatile void __iomem *addr);
17319
17320 extern void set_iounmap_nonlazy(void);
17321
17322 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17323
17324 #include <linux/vmalloc.h>
17325
17326 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17327 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17328 +{
17329 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17330 +}
17331 +
17332 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17333 +{
17334 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17335 +}
17336 +
17337 /*
17338 * Convert a virtual cached pointer to an uncached pointer
17339 */
17340 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17341 index 0a8b519..80e7d5b 100644
17342 --- a/arch/x86/include/asm/irqflags.h
17343 +++ b/arch/x86/include/asm/irqflags.h
17344 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17345 sti; \
17346 sysexit
17347
17348 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17349 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17350 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17351 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17352 +
17353 #else
17354 #define INTERRUPT_RETURN iret
17355 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17356 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17357 index 53cdfb2..d1369e6 100644
17358 --- a/arch/x86/include/asm/kprobes.h
17359 +++ b/arch/x86/include/asm/kprobes.h
17360 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17361 #define RELATIVEJUMP_SIZE 5
17362 #define RELATIVECALL_OPCODE 0xe8
17363 #define RELATIVE_ADDR_SIZE 4
17364 -#define MAX_STACK_SIZE 64
17365 -#define MIN_STACK_SIZE(ADDR) \
17366 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17367 - THREAD_SIZE - (unsigned long)(ADDR))) \
17368 - ? (MAX_STACK_SIZE) \
17369 - : (((unsigned long)current_thread_info()) + \
17370 - THREAD_SIZE - (unsigned long)(ADDR)))
17371 +#define MAX_STACK_SIZE 64UL
17372 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17373
17374 #define flush_insn_slot(p) do { } while (0)
17375
17376 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17377 index 4ad6560..75c7bdd 100644
17378 --- a/arch/x86/include/asm/local.h
17379 +++ b/arch/x86/include/asm/local.h
17380 @@ -10,33 +10,97 @@ typedef struct {
17381 atomic_long_t a;
17382 } local_t;
17383
17384 +typedef struct {
17385 + atomic_long_unchecked_t a;
17386 +} local_unchecked_t;
17387 +
17388 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17389
17390 #define local_read(l) atomic_long_read(&(l)->a)
17391 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17392 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17393 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17394
17395 static inline void local_inc(local_t *l)
17396 {
17397 - asm volatile(_ASM_INC "%0"
17398 + asm volatile(_ASM_INC "%0\n"
17399 +
17400 +#ifdef CONFIG_PAX_REFCOUNT
17401 + "jno 0f\n"
17402 + _ASM_DEC "%0\n"
17403 + "int $4\n0:\n"
17404 + _ASM_EXTABLE(0b, 0b)
17405 +#endif
17406 +
17407 + : "+m" (l->a.counter));
17408 +}
17409 +
17410 +static inline void local_inc_unchecked(local_unchecked_t *l)
17411 +{
17412 + asm volatile(_ASM_INC "%0\n"
17413 : "+m" (l->a.counter));
17414 }
17415
17416 static inline void local_dec(local_t *l)
17417 {
17418 - asm volatile(_ASM_DEC "%0"
17419 + asm volatile(_ASM_DEC "%0\n"
17420 +
17421 +#ifdef CONFIG_PAX_REFCOUNT
17422 + "jno 0f\n"
17423 + _ASM_INC "%0\n"
17424 + "int $4\n0:\n"
17425 + _ASM_EXTABLE(0b, 0b)
17426 +#endif
17427 +
17428 + : "+m" (l->a.counter));
17429 +}
17430 +
17431 +static inline void local_dec_unchecked(local_unchecked_t *l)
17432 +{
17433 + asm volatile(_ASM_DEC "%0\n"
17434 : "+m" (l->a.counter));
17435 }
17436
17437 static inline void local_add(long i, local_t *l)
17438 {
17439 - asm volatile(_ASM_ADD "%1,%0"
17440 + asm volatile(_ASM_ADD "%1,%0\n"
17441 +
17442 +#ifdef CONFIG_PAX_REFCOUNT
17443 + "jno 0f\n"
17444 + _ASM_SUB "%1,%0\n"
17445 + "int $4\n0:\n"
17446 + _ASM_EXTABLE(0b, 0b)
17447 +#endif
17448 +
17449 + : "+m" (l->a.counter)
17450 + : "ir" (i));
17451 +}
17452 +
17453 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17454 +{
17455 + asm volatile(_ASM_ADD "%1,%0\n"
17456 : "+m" (l->a.counter)
17457 : "ir" (i));
17458 }
17459
17460 static inline void local_sub(long i, local_t *l)
17461 {
17462 - asm volatile(_ASM_SUB "%1,%0"
17463 + asm volatile(_ASM_SUB "%1,%0\n"
17464 +
17465 +#ifdef CONFIG_PAX_REFCOUNT
17466 + "jno 0f\n"
17467 + _ASM_ADD "%1,%0\n"
17468 + "int $4\n0:\n"
17469 + _ASM_EXTABLE(0b, 0b)
17470 +#endif
17471 +
17472 + : "+m" (l->a.counter)
17473 + : "ir" (i));
17474 +}
17475 +
17476 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17477 +{
17478 + asm volatile(_ASM_SUB "%1,%0\n"
17479 : "+m" (l->a.counter)
17480 : "ir" (i));
17481 }
17482 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17483 */
17484 static inline int local_sub_and_test(long i, local_t *l)
17485 {
17486 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17487 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17488 }
17489
17490 /**
17491 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17492 */
17493 static inline int local_dec_and_test(local_t *l)
17494 {
17495 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17496 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17497 }
17498
17499 /**
17500 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17501 */
17502 static inline int local_inc_and_test(local_t *l)
17503 {
17504 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17505 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17506 }
17507
17508 /**
17509 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17510 */
17511 static inline int local_add_negative(long i, local_t *l)
17512 {
17513 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17514 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17515 }
17516
17517 /**
17518 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17519 static inline long local_add_return(long i, local_t *l)
17520 {
17521 long __i = i;
17522 + asm volatile(_ASM_XADD "%0, %1\n"
17523 +
17524 +#ifdef CONFIG_PAX_REFCOUNT
17525 + "jno 0f\n"
17526 + _ASM_MOV "%0,%1\n"
17527 + "int $4\n0:\n"
17528 + _ASM_EXTABLE(0b, 0b)
17529 +#endif
17530 +
17531 + : "+r" (i), "+m" (l->a.counter)
17532 + : : "memory");
17533 + return i + __i;
17534 +}
17535 +
17536 +/**
17537 + * local_add_return_unchecked - add and return
17538 + * @i: integer value to add
17539 + * @l: pointer to type local_unchecked_t
17540 + *
17541 + * Atomically adds @i to @l and returns @i + @l
17542 + */
17543 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17544 +{
17545 + long __i = i;
17546 asm volatile(_ASM_XADD "%0, %1;"
17547 : "+r" (i), "+m" (l->a.counter)
17548 : : "memory");
17549 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17550
17551 #define local_cmpxchg(l, o, n) \
17552 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17553 +#define local_cmpxchg_unchecked(l, o, n) \
17554 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17555 /* Always has a lock prefix */
17556 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17557
17558 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17559 new file mode 100644
17560 index 0000000..2bfd3ba
17561 --- /dev/null
17562 +++ b/arch/x86/include/asm/mman.h
17563 @@ -0,0 +1,15 @@
17564 +#ifndef _X86_MMAN_H
17565 +#define _X86_MMAN_H
17566 +
17567 +#include <uapi/asm/mman.h>
17568 +
17569 +#ifdef __KERNEL__
17570 +#ifndef __ASSEMBLY__
17571 +#ifdef CONFIG_X86_32
17572 +#define arch_mmap_check i386_mmap_check
17573 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17574 +#endif
17575 +#endif
17576 +#endif
17577 +
17578 +#endif /* X86_MMAN_H */
17579 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17580 index 876e74e..e20bfb1 100644
17581 --- a/arch/x86/include/asm/mmu.h
17582 +++ b/arch/x86/include/asm/mmu.h
17583 @@ -9,7 +9,7 @@
17584 * we put the segment information here.
17585 */
17586 typedef struct {
17587 - void *ldt;
17588 + struct desc_struct *ldt;
17589 int size;
17590
17591 #ifdef CONFIG_X86_64
17592 @@ -18,7 +18,19 @@ typedef struct {
17593 #endif
17594
17595 struct mutex lock;
17596 - void __user *vdso;
17597 + unsigned long vdso;
17598 +
17599 +#ifdef CONFIG_X86_32
17600 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17601 + unsigned long user_cs_base;
17602 + unsigned long user_cs_limit;
17603 +
17604 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17605 + cpumask_t cpu_user_cs_mask;
17606 +#endif
17607 +
17608 +#endif
17609 +#endif
17610 } mm_context_t;
17611
17612 #ifdef CONFIG_SMP
17613 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17614 index be12c53..07fd3ca 100644
17615 --- a/arch/x86/include/asm/mmu_context.h
17616 +++ b/arch/x86/include/asm/mmu_context.h
17617 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17618
17619 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17620 {
17621 +
17622 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17623 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17624 + unsigned int i;
17625 + pgd_t *pgd;
17626 +
17627 + pax_open_kernel();
17628 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17629 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17630 + set_pgd_batched(pgd+i, native_make_pgd(0));
17631 + pax_close_kernel();
17632 + }
17633 +#endif
17634 +
17635 #ifdef CONFIG_SMP
17636 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17637 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17638 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17639 struct task_struct *tsk)
17640 {
17641 unsigned cpu = smp_processor_id();
17642 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17643 + int tlbstate = TLBSTATE_OK;
17644 +#endif
17645
17646 if (likely(prev != next)) {
17647 #ifdef CONFIG_SMP
17648 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17649 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17650 +#endif
17651 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17652 this_cpu_write(cpu_tlbstate.active_mm, next);
17653 #endif
17654 cpumask_set_cpu(cpu, mm_cpumask(next));
17655
17656 /* Re-load page tables */
17657 +#ifdef CONFIG_PAX_PER_CPU_PGD
17658 + pax_open_kernel();
17659 +
17660 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17661 + if (static_cpu_has(X86_FEATURE_PCID))
17662 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17663 + else
17664 +#endif
17665 +
17666 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17667 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17668 + pax_close_kernel();
17669 + 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));
17670 +
17671 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17672 + if (static_cpu_has(X86_FEATURE_PCID)) {
17673 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17674 + u64 descriptor[2];
17675 + descriptor[0] = PCID_USER;
17676 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17677 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17678 + descriptor[0] = PCID_KERNEL;
17679 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17680 + }
17681 + } else {
17682 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17683 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17684 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17685 + else
17686 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17687 + }
17688 + } else
17689 +#endif
17690 +
17691 + load_cr3(get_cpu_pgd(cpu, kernel));
17692 +#else
17693 load_cr3(next->pgd);
17694 +#endif
17695
17696 /* Stop flush ipis for the previous mm */
17697 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17698 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17699 /* Load the LDT, if the LDT is different: */
17700 if (unlikely(prev->context.ldt != next->context.ldt))
17701 load_LDT_nolock(&next->context);
17702 +
17703 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17704 + if (!(__supported_pte_mask & _PAGE_NX)) {
17705 + smp_mb__before_atomic();
17706 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17707 + smp_mb__after_atomic();
17708 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17709 + }
17710 +#endif
17711 +
17712 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17713 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17714 + prev->context.user_cs_limit != next->context.user_cs_limit))
17715 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17716 +#ifdef CONFIG_SMP
17717 + else if (unlikely(tlbstate != TLBSTATE_OK))
17718 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17719 +#endif
17720 +#endif
17721 +
17722 }
17723 + else {
17724 +
17725 +#ifdef CONFIG_PAX_PER_CPU_PGD
17726 + pax_open_kernel();
17727 +
17728 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17729 + if (static_cpu_has(X86_FEATURE_PCID))
17730 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17731 + else
17732 +#endif
17733 +
17734 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17735 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17736 + pax_close_kernel();
17737 + 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));
17738 +
17739 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17740 + if (static_cpu_has(X86_FEATURE_PCID)) {
17741 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17742 + u64 descriptor[2];
17743 + descriptor[0] = PCID_USER;
17744 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17745 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17746 + descriptor[0] = PCID_KERNEL;
17747 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17748 + }
17749 + } else {
17750 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17751 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17752 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17753 + else
17754 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17755 + }
17756 + } else
17757 +#endif
17758 +
17759 + load_cr3(get_cpu_pgd(cpu, kernel));
17760 +#endif
17761 +
17762 #ifdef CONFIG_SMP
17763 - else {
17764 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17765 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17766
17767 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17768 * tlb flush IPI delivery. We must reload CR3
17769 * to make sure to use no freed page tables.
17770 */
17771 +
17772 +#ifndef CONFIG_PAX_PER_CPU_PGD
17773 load_cr3(next->pgd);
17774 +#endif
17775 +
17776 load_LDT_nolock(&next->context);
17777 +
17778 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17779 + if (!(__supported_pte_mask & _PAGE_NX))
17780 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17781 +#endif
17782 +
17783 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17784 +#ifdef CONFIG_PAX_PAGEEXEC
17785 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17786 +#endif
17787 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17788 +#endif
17789 +
17790 }
17791 +#endif
17792 }
17793 -#endif
17794 }
17795
17796 #define activate_mm(prev, next) \
17797 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17798 index e3b7819..b257c64 100644
17799 --- a/arch/x86/include/asm/module.h
17800 +++ b/arch/x86/include/asm/module.h
17801 @@ -5,6 +5,7 @@
17802
17803 #ifdef CONFIG_X86_64
17804 /* X86_64 does not define MODULE_PROC_FAMILY */
17805 +#define MODULE_PROC_FAMILY ""
17806 #elif defined CONFIG_M486
17807 #define MODULE_PROC_FAMILY "486 "
17808 #elif defined CONFIG_M586
17809 @@ -57,8 +58,20 @@
17810 #error unknown processor family
17811 #endif
17812
17813 -#ifdef CONFIG_X86_32
17814 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17815 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17816 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17817 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17818 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17819 +#else
17820 +#define MODULE_PAX_KERNEXEC ""
17821 #endif
17822
17823 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17824 +#define MODULE_PAX_UDEREF "UDEREF "
17825 +#else
17826 +#define MODULE_PAX_UDEREF ""
17827 +#endif
17828 +
17829 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17830 +
17831 #endif /* _ASM_X86_MODULE_H */
17832 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17833 index 5f2fc44..106caa6 100644
17834 --- a/arch/x86/include/asm/nmi.h
17835 +++ b/arch/x86/include/asm/nmi.h
17836 @@ -36,26 +36,35 @@ enum {
17837
17838 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17839
17840 +struct nmiaction;
17841 +
17842 +struct nmiwork {
17843 + const struct nmiaction *action;
17844 + u64 max_duration;
17845 + struct irq_work irq_work;
17846 +};
17847 +
17848 struct nmiaction {
17849 struct list_head list;
17850 nmi_handler_t handler;
17851 - u64 max_duration;
17852 - struct irq_work irq_work;
17853 unsigned long flags;
17854 const char *name;
17855 -};
17856 + struct nmiwork *work;
17857 +} __do_const;
17858
17859 #define register_nmi_handler(t, fn, fg, n, init...) \
17860 ({ \
17861 - static struct nmiaction init fn##_na = { \
17862 + static struct nmiwork fn##_nw; \
17863 + static const struct nmiaction init fn##_na = { \
17864 .handler = (fn), \
17865 .name = (n), \
17866 .flags = (fg), \
17867 + .work = &fn##_nw, \
17868 }; \
17869 __register_nmi_handler((t), &fn##_na); \
17870 })
17871
17872 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17873 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17874
17875 void unregister_nmi_handler(unsigned int, const char *);
17876
17877 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17878 index 775873d..04cd306 100644
17879 --- a/arch/x86/include/asm/page.h
17880 +++ b/arch/x86/include/asm/page.h
17881 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17882 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17883
17884 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17885 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17886
17887 #define __boot_va(x) __va(x)
17888 #define __boot_pa(x) __pa(x)
17889 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17890 * virt_to_page(kaddr) returns a valid pointer if and only if
17891 * virt_addr_valid(kaddr) returns true.
17892 */
17893 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17894 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17895 extern bool __virt_addr_valid(unsigned long kaddr);
17896 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17897
17898 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17899 +#define virt_to_page(kaddr) \
17900 + ({ \
17901 + const void *__kaddr = (const void *)(kaddr); \
17902 + BUG_ON(!virt_addr_valid(__kaddr)); \
17903 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17904 + })
17905 +#else
17906 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17907 +#endif
17908 +
17909 #endif /* __ASSEMBLY__ */
17910
17911 #include <asm-generic/memory_model.h>
17912 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17913 index 0f1ddee..e2fc3d1 100644
17914 --- a/arch/x86/include/asm/page_64.h
17915 +++ b/arch/x86/include/asm/page_64.h
17916 @@ -7,9 +7,9 @@
17917
17918 /* duplicated to the one in bootmem.h */
17919 extern unsigned long max_pfn;
17920 -extern unsigned long phys_base;
17921 +extern const unsigned long phys_base;
17922
17923 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17924 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17925 {
17926 unsigned long y = x - __START_KERNEL_map;
17927
17928 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17929 index cd6e1610..70f4418 100644
17930 --- a/arch/x86/include/asm/paravirt.h
17931 +++ b/arch/x86/include/asm/paravirt.h
17932 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17933 return (pmd_t) { ret };
17934 }
17935
17936 -static inline pmdval_t pmd_val(pmd_t pmd)
17937 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17938 {
17939 pmdval_t ret;
17940
17941 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17942 val);
17943 }
17944
17945 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17946 +{
17947 + pgdval_t val = native_pgd_val(pgd);
17948 +
17949 + if (sizeof(pgdval_t) > sizeof(long))
17950 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17951 + val, (u64)val >> 32);
17952 + else
17953 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17954 + val);
17955 +}
17956 +
17957 static inline void pgd_clear(pgd_t *pgdp)
17958 {
17959 set_pgd(pgdp, __pgd(0));
17960 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17961 pv_mmu_ops.set_fixmap(idx, phys, flags);
17962 }
17963
17964 +#ifdef CONFIG_PAX_KERNEXEC
17965 +static inline unsigned long pax_open_kernel(void)
17966 +{
17967 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17968 +}
17969 +
17970 +static inline unsigned long pax_close_kernel(void)
17971 +{
17972 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17973 +}
17974 +#else
17975 +static inline unsigned long pax_open_kernel(void) { return 0; }
17976 +static inline unsigned long pax_close_kernel(void) { return 0; }
17977 +#endif
17978 +
17979 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17980
17981 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17982 @@ -906,7 +933,7 @@ extern void default_banner(void);
17983
17984 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17985 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17986 -#define PARA_INDIRECT(addr) *%cs:addr
17987 +#define PARA_INDIRECT(addr) *%ss:addr
17988 #endif
17989
17990 #define INTERRUPT_RETURN \
17991 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17992 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17993 CLBR_NONE, \
17994 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17995 +
17996 +#define GET_CR0_INTO_RDI \
17997 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17998 + mov %rax,%rdi
17999 +
18000 +#define SET_RDI_INTO_CR0 \
18001 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18002 +
18003 +#define GET_CR3_INTO_RDI \
18004 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18005 + mov %rax,%rdi
18006 +
18007 +#define SET_RDI_INTO_CR3 \
18008 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18009 +
18010 #endif /* CONFIG_X86_32 */
18011
18012 #endif /* __ASSEMBLY__ */
18013 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18014 index 7549b8b..f0edfda 100644
18015 --- a/arch/x86/include/asm/paravirt_types.h
18016 +++ b/arch/x86/include/asm/paravirt_types.h
18017 @@ -84,7 +84,7 @@ struct pv_init_ops {
18018 */
18019 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18020 unsigned long addr, unsigned len);
18021 -};
18022 +} __no_const __no_randomize_layout;
18023
18024
18025 struct pv_lazy_ops {
18026 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
18027 void (*enter)(void);
18028 void (*leave)(void);
18029 void (*flush)(void);
18030 -};
18031 +} __no_randomize_layout;
18032
18033 struct pv_time_ops {
18034 unsigned long long (*sched_clock)(void);
18035 unsigned long long (*steal_clock)(int cpu);
18036 unsigned long (*get_tsc_khz)(void);
18037 -};
18038 +} __no_const __no_randomize_layout;
18039
18040 struct pv_cpu_ops {
18041 /* hooks for various privileged instructions */
18042 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18043
18044 void (*start_context_switch)(struct task_struct *prev);
18045 void (*end_context_switch)(struct task_struct *next);
18046 -};
18047 +} __no_const __no_randomize_layout;
18048
18049 struct pv_irq_ops {
18050 /*
18051 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18052 #ifdef CONFIG_X86_64
18053 void (*adjust_exception_frame)(void);
18054 #endif
18055 -};
18056 +} __no_randomize_layout;
18057
18058 struct pv_apic_ops {
18059 #ifdef CONFIG_X86_LOCAL_APIC
18060 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18061 unsigned long start_eip,
18062 unsigned long start_esp);
18063 #endif
18064 -};
18065 +} __no_const __no_randomize_layout;
18066
18067 struct pv_mmu_ops {
18068 unsigned long (*read_cr2)(void);
18069 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18070 struct paravirt_callee_save make_pud;
18071
18072 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18073 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18074 #endif /* PAGETABLE_LEVELS == 4 */
18075 #endif /* PAGETABLE_LEVELS >= 3 */
18076
18077 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18078 an mfn. We can tell which is which from the index. */
18079 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18080 phys_addr_t phys, pgprot_t flags);
18081 -};
18082 +
18083 +#ifdef CONFIG_PAX_KERNEXEC
18084 + unsigned long (*pax_open_kernel)(void);
18085 + unsigned long (*pax_close_kernel)(void);
18086 +#endif
18087 +
18088 +} __no_randomize_layout;
18089
18090 struct arch_spinlock;
18091 #ifdef CONFIG_SMP
18092 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18093 struct pv_lock_ops {
18094 struct paravirt_callee_save lock_spinning;
18095 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18096 -};
18097 +} __no_randomize_layout;
18098
18099 /* This contains all the paravirt structures: we get a convenient
18100 * number for each function using the offset which we use to indicate
18101 - * what to patch. */
18102 + * what to patch.
18103 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18104 + */
18105 +
18106 struct paravirt_patch_template {
18107 struct pv_init_ops pv_init_ops;
18108 struct pv_time_ops pv_time_ops;
18109 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18110 struct pv_apic_ops pv_apic_ops;
18111 struct pv_mmu_ops pv_mmu_ops;
18112 struct pv_lock_ops pv_lock_ops;
18113 -};
18114 +} __no_randomize_layout;
18115
18116 extern struct pv_info pv_info;
18117 extern struct pv_init_ops pv_init_ops;
18118 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18119 index c4412e9..90e88c5 100644
18120 --- a/arch/x86/include/asm/pgalloc.h
18121 +++ b/arch/x86/include/asm/pgalloc.h
18122 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18123 pmd_t *pmd, pte_t *pte)
18124 {
18125 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18126 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18127 +}
18128 +
18129 +static inline void pmd_populate_user(struct mm_struct *mm,
18130 + pmd_t *pmd, pte_t *pte)
18131 +{
18132 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18133 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18134 }
18135
18136 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18137
18138 #ifdef CONFIG_X86_PAE
18139 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18140 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18141 +{
18142 + pud_populate(mm, pudp, pmd);
18143 +}
18144 #else /* !CONFIG_X86_PAE */
18145 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18146 {
18147 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18148 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18149 }
18150 +
18151 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18152 +{
18153 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18154 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18155 +}
18156 #endif /* CONFIG_X86_PAE */
18157
18158 #if PAGETABLE_LEVELS > 3
18159 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18160 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18161 }
18162
18163 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18164 +{
18165 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18166 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18167 +}
18168 +
18169 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18170 {
18171 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18172 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18173 index 206a87f..1623b06 100644
18174 --- a/arch/x86/include/asm/pgtable-2level.h
18175 +++ b/arch/x86/include/asm/pgtable-2level.h
18176 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18177
18178 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18179 {
18180 + pax_open_kernel();
18181 *pmdp = pmd;
18182 + pax_close_kernel();
18183 }
18184
18185 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18186 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18187 index 81bb91b..9392125 100644
18188 --- a/arch/x86/include/asm/pgtable-3level.h
18189 +++ b/arch/x86/include/asm/pgtable-3level.h
18190 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18191
18192 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18193 {
18194 + pax_open_kernel();
18195 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18196 + pax_close_kernel();
18197 }
18198
18199 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18200 {
18201 + pax_open_kernel();
18202 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18203 + pax_close_kernel();
18204 }
18205
18206 /*
18207 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18208 index aa97a07..f169e5b 100644
18209 --- a/arch/x86/include/asm/pgtable.h
18210 +++ b/arch/x86/include/asm/pgtable.h
18211 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18212
18213 #ifndef __PAGETABLE_PUD_FOLDED
18214 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18215 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18216 #define pgd_clear(pgd) native_pgd_clear(pgd)
18217 #endif
18218
18219 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18220
18221 #define arch_end_context_switch(prev) do {} while(0)
18222
18223 +#define pax_open_kernel() native_pax_open_kernel()
18224 +#define pax_close_kernel() native_pax_close_kernel()
18225 #endif /* CONFIG_PARAVIRT */
18226
18227 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18228 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18229 +
18230 +#ifdef CONFIG_PAX_KERNEXEC
18231 +static inline unsigned long native_pax_open_kernel(void)
18232 +{
18233 + unsigned long cr0;
18234 +
18235 + preempt_disable();
18236 + barrier();
18237 + cr0 = read_cr0() ^ X86_CR0_WP;
18238 + BUG_ON(cr0 & X86_CR0_WP);
18239 + write_cr0(cr0);
18240 + return cr0 ^ X86_CR0_WP;
18241 +}
18242 +
18243 +static inline unsigned long native_pax_close_kernel(void)
18244 +{
18245 + unsigned long cr0;
18246 +
18247 + cr0 = read_cr0() ^ X86_CR0_WP;
18248 + BUG_ON(!(cr0 & X86_CR0_WP));
18249 + write_cr0(cr0);
18250 + barrier();
18251 + preempt_enable_no_resched();
18252 + return cr0 ^ X86_CR0_WP;
18253 +}
18254 +#else
18255 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18256 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18257 +#endif
18258 +
18259 /*
18260 * The following only work if pte_present() is true.
18261 * Undefined behaviour if not..
18262 */
18263 +static inline int pte_user(pte_t pte)
18264 +{
18265 + return pte_val(pte) & _PAGE_USER;
18266 +}
18267 +
18268 static inline int pte_dirty(pte_t pte)
18269 {
18270 return pte_flags(pte) & _PAGE_DIRTY;
18271 @@ -155,6 +195,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18272 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18273 }
18274
18275 +static inline unsigned long pgd_pfn(pgd_t pgd)
18276 +{
18277 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18278 +}
18279 +
18280 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18281
18282 static inline int pmd_large(pmd_t pte)
18283 @@ -208,9 +253,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18284 return pte_clear_flags(pte, _PAGE_RW);
18285 }
18286
18287 +static inline pte_t pte_mkread(pte_t pte)
18288 +{
18289 + return __pte(pte_val(pte) | _PAGE_USER);
18290 +}
18291 +
18292 static inline pte_t pte_mkexec(pte_t pte)
18293 {
18294 - return pte_clear_flags(pte, _PAGE_NX);
18295 +#ifdef CONFIG_X86_PAE
18296 + if (__supported_pte_mask & _PAGE_NX)
18297 + return pte_clear_flags(pte, _PAGE_NX);
18298 + else
18299 +#endif
18300 + return pte_set_flags(pte, _PAGE_USER);
18301 +}
18302 +
18303 +static inline pte_t pte_exprotect(pte_t pte)
18304 +{
18305 +#ifdef CONFIG_X86_PAE
18306 + if (__supported_pte_mask & _PAGE_NX)
18307 + return pte_set_flags(pte, _PAGE_NX);
18308 + else
18309 +#endif
18310 + return pte_clear_flags(pte, _PAGE_USER);
18311 }
18312
18313 static inline pte_t pte_mkdirty(pte_t pte)
18314 @@ -440,6 +505,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18315 #endif
18316
18317 #ifndef __ASSEMBLY__
18318 +
18319 +#ifdef CONFIG_PAX_PER_CPU_PGD
18320 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18321 +enum cpu_pgd_type {kernel = 0, user = 1};
18322 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18323 +{
18324 + return cpu_pgd[cpu][type];
18325 +}
18326 +#endif
18327 +
18328 #include <linux/mm_types.h>
18329 #include <linux/mmdebug.h>
18330 #include <linux/log2.h>
18331 @@ -586,7 +661,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18332 * Currently stuck as a macro due to indirect forward reference to
18333 * linux/mmzone.h's __section_mem_map_addr() definition:
18334 */
18335 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18336 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18337
18338 /* Find an entry in the second-level page table.. */
18339 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18340 @@ -626,7 +701,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18341 * Currently stuck as a macro due to indirect forward reference to
18342 * linux/mmzone.h's __section_mem_map_addr() definition:
18343 */
18344 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18345 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18346
18347 /* to find an entry in a page-table-directory. */
18348 static inline unsigned long pud_index(unsigned long address)
18349 @@ -641,7 +716,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18350
18351 static inline int pgd_bad(pgd_t pgd)
18352 {
18353 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18354 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18355 }
18356
18357 static inline int pgd_none(pgd_t pgd)
18358 @@ -664,7 +739,12 @@ static inline int pgd_none(pgd_t pgd)
18359 * pgd_offset() returns a (pgd_t *)
18360 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18361 */
18362 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18363 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18364 +
18365 +#ifdef CONFIG_PAX_PER_CPU_PGD
18366 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18367 +#endif
18368 +
18369 /*
18370 * a shortcut which implies the use of the kernel's pgd, instead
18371 * of a process's
18372 @@ -675,6 +755,23 @@ static inline int pgd_none(pgd_t pgd)
18373 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18374 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18375
18376 +#ifdef CONFIG_X86_32
18377 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18378 +#else
18379 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18380 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18381 +
18382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18383 +#ifdef __ASSEMBLY__
18384 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18385 +#else
18386 +extern unsigned long pax_user_shadow_base;
18387 +extern pgdval_t clone_pgd_mask;
18388 +#endif
18389 +#endif
18390 +
18391 +#endif
18392 +
18393 #ifndef __ASSEMBLY__
18394
18395 extern int direct_gbpages;
18396 @@ -841,11 +938,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18397 * dst and src can be on the same page, but the range must not overlap,
18398 * and must not cross a page boundary.
18399 */
18400 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18401 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18402 {
18403 - memcpy(dst, src, count * sizeof(pgd_t));
18404 + pax_open_kernel();
18405 + while (count--)
18406 + *dst++ = *src++;
18407 + pax_close_kernel();
18408 }
18409
18410 +#ifdef CONFIG_PAX_PER_CPU_PGD
18411 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18412 +#endif
18413 +
18414 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18415 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18416 +#else
18417 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18418 +#endif
18419 +
18420 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18421 static inline int page_level_shift(enum pg_level level)
18422 {
18423 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18424 index 9ee3221..b979c6b 100644
18425 --- a/arch/x86/include/asm/pgtable_32.h
18426 +++ b/arch/x86/include/asm/pgtable_32.h
18427 @@ -25,9 +25,6 @@
18428 struct mm_struct;
18429 struct vm_area_struct;
18430
18431 -extern pgd_t swapper_pg_dir[1024];
18432 -extern pgd_t initial_page_table[1024];
18433 -
18434 static inline void pgtable_cache_init(void) { }
18435 static inline void check_pgt_cache(void) { }
18436 void paging_init(void);
18437 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18438 # include <asm/pgtable-2level.h>
18439 #endif
18440
18441 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18442 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18443 +#ifdef CONFIG_X86_PAE
18444 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18445 +#endif
18446 +
18447 #if defined(CONFIG_HIGHPTE)
18448 #define pte_offset_map(dir, address) \
18449 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18450 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18451 /* Clear a kernel PTE and flush it from the TLB */
18452 #define kpte_clear_flush(ptep, vaddr) \
18453 do { \
18454 + pax_open_kernel(); \
18455 pte_clear(&init_mm, (vaddr), (ptep)); \
18456 + pax_close_kernel(); \
18457 __flush_tlb_one((vaddr)); \
18458 } while (0)
18459
18460 #endif /* !__ASSEMBLY__ */
18461
18462 +#define HAVE_ARCH_UNMAPPED_AREA
18463 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18464 +
18465 /*
18466 * kern_addr_valid() is (1) for FLATMEM and (0) for
18467 * SPARSEMEM and DISCONTIGMEM
18468 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18469 index ed5903b..c7fe163 100644
18470 --- a/arch/x86/include/asm/pgtable_32_types.h
18471 +++ b/arch/x86/include/asm/pgtable_32_types.h
18472 @@ -8,7 +8,7 @@
18473 */
18474 #ifdef CONFIG_X86_PAE
18475 # include <asm/pgtable-3level_types.h>
18476 -# define PMD_SIZE (1UL << PMD_SHIFT)
18477 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18478 # define PMD_MASK (~(PMD_SIZE - 1))
18479 #else
18480 # include <asm/pgtable-2level_types.h>
18481 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18482 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18483 #endif
18484
18485 +#ifdef CONFIG_PAX_KERNEXEC
18486 +#ifndef __ASSEMBLY__
18487 +extern unsigned char MODULES_EXEC_VADDR[];
18488 +extern unsigned char MODULES_EXEC_END[];
18489 +#endif
18490 +#include <asm/boot.h>
18491 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18492 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18493 +#else
18494 +#define ktla_ktva(addr) (addr)
18495 +#define ktva_ktla(addr) (addr)
18496 +#endif
18497 +
18498 #define MODULES_VADDR VMALLOC_START
18499 #define MODULES_END VMALLOC_END
18500 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18501 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18502 index 5be9063..d62185b 100644
18503 --- a/arch/x86/include/asm/pgtable_64.h
18504 +++ b/arch/x86/include/asm/pgtable_64.h
18505 @@ -16,10 +16,14 @@
18506
18507 extern pud_t level3_kernel_pgt[512];
18508 extern pud_t level3_ident_pgt[512];
18509 +extern pud_t level3_vmalloc_start_pgt[512];
18510 +extern pud_t level3_vmalloc_end_pgt[512];
18511 +extern pud_t level3_vmemmap_pgt[512];
18512 +extern pud_t level2_vmemmap_pgt[512];
18513 extern pmd_t level2_kernel_pgt[512];
18514 extern pmd_t level2_fixmap_pgt[512];
18515 -extern pmd_t level2_ident_pgt[512];
18516 -extern pgd_t init_level4_pgt[];
18517 +extern pmd_t level2_ident_pgt[512*2];
18518 +extern pgd_t init_level4_pgt[512];
18519
18520 #define swapper_pg_dir init_level4_pgt
18521
18522 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18523
18524 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18525 {
18526 + pax_open_kernel();
18527 *pmdp = pmd;
18528 + pax_close_kernel();
18529 }
18530
18531 static inline void native_pmd_clear(pmd_t *pmd)
18532 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18533
18534 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18535 {
18536 + pax_open_kernel();
18537 *pudp = pud;
18538 + pax_close_kernel();
18539 }
18540
18541 static inline void native_pud_clear(pud_t *pud)
18542 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18543
18544 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18545 {
18546 + pax_open_kernel();
18547 + *pgdp = pgd;
18548 + pax_close_kernel();
18549 +}
18550 +
18551 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18552 +{
18553 *pgdp = pgd;
18554 }
18555
18556 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18557 index 7166e25..baaa6fe 100644
18558 --- a/arch/x86/include/asm/pgtable_64_types.h
18559 +++ b/arch/x86/include/asm/pgtable_64_types.h
18560 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18561 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18562 #define MODULES_END _AC(0xffffffffff000000, UL)
18563 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18564 +#define MODULES_EXEC_VADDR MODULES_VADDR
18565 +#define MODULES_EXEC_END MODULES_END
18566 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18567 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18568
18569 +#define ktla_ktva(addr) (addr)
18570 +#define ktva_ktla(addr) (addr)
18571 +
18572 #define EARLY_DYNAMIC_PAGE_TABLES 64
18573
18574 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18575 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18576 index f216963..6bd7c21 100644
18577 --- a/arch/x86/include/asm/pgtable_types.h
18578 +++ b/arch/x86/include/asm/pgtable_types.h
18579 @@ -111,8 +111,10 @@
18580
18581 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18582 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18583 -#else
18584 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18585 #define _PAGE_NX (_AT(pteval_t, 0))
18586 +#else
18587 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18588 #endif
18589
18590 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18591 @@ -151,6 +153,9 @@
18592 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18593 _PAGE_ACCESSED)
18594
18595 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18596 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18597 +
18598 #define __PAGE_KERNEL_EXEC \
18599 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18600 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18601 @@ -161,7 +166,7 @@
18602 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18603 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18604 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18605 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18606 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18607 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18608 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18609 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18610 @@ -218,7 +223,7 @@
18611 #ifdef CONFIG_X86_64
18612 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18613 #else
18614 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18615 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18616 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18617 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18618 #endif
18619 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18620 {
18621 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18622 }
18623 +#endif
18624
18625 +#if PAGETABLE_LEVELS == 3
18626 +#include <asm-generic/pgtable-nopud.h>
18627 +#endif
18628 +
18629 +#if PAGETABLE_LEVELS == 2
18630 +#include <asm-generic/pgtable-nopmd.h>
18631 +#endif
18632 +
18633 +#ifndef __ASSEMBLY__
18634 #if PAGETABLE_LEVELS > 3
18635 typedef struct { pudval_t pud; } pud_t;
18636
18637 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18638 return pud.pud;
18639 }
18640 #else
18641 -#include <asm-generic/pgtable-nopud.h>
18642 -
18643 static inline pudval_t native_pud_val(pud_t pud)
18644 {
18645 return native_pgd_val(pud.pgd);
18646 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18647 return pmd.pmd;
18648 }
18649 #else
18650 -#include <asm-generic/pgtable-nopmd.h>
18651 -
18652 static inline pmdval_t native_pmd_val(pmd_t pmd)
18653 {
18654 return native_pgd_val(pmd.pud.pgd);
18655 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
18656
18657 extern pteval_t __supported_pte_mask;
18658 extern void set_nx(void);
18659 -extern int nx_enabled;
18660
18661 #define pgprot_writecombine pgprot_writecombine
18662 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18663 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18664 index 7024c12..71c46b9 100644
18665 --- a/arch/x86/include/asm/preempt.h
18666 +++ b/arch/x86/include/asm/preempt.h
18667 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18668 */
18669 static __always_inline bool __preempt_count_dec_and_test(void)
18670 {
18671 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18672 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18673 }
18674
18675 /*
18676 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18677 index a4ea023..2ff3cb8 100644
18678 --- a/arch/x86/include/asm/processor.h
18679 +++ b/arch/x86/include/asm/processor.h
18680 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18681 /* Index into per_cpu list: */
18682 u16 cpu_index;
18683 u32 microcode;
18684 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18685 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18686
18687 #define X86_VENDOR_INTEL 0
18688 #define X86_VENDOR_CYRIX 1
18689 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18690 : "memory");
18691 }
18692
18693 +/* invpcid (%rdx),%rax */
18694 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18695 +
18696 +#define INVPCID_SINGLE_ADDRESS 0UL
18697 +#define INVPCID_SINGLE_CONTEXT 1UL
18698 +#define INVPCID_ALL_GLOBAL 2UL
18699 +#define INVPCID_ALL_NONGLOBAL 3UL
18700 +
18701 +#define PCID_KERNEL 0UL
18702 +#define PCID_USER 1UL
18703 +#define PCID_NOFLUSH (1UL << 63)
18704 +
18705 static inline void load_cr3(pgd_t *pgdir)
18706 {
18707 - write_cr3(__pa(pgdir));
18708 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18709 }
18710
18711 #ifdef CONFIG_X86_32
18712 @@ -283,7 +295,7 @@ struct tss_struct {
18713
18714 } ____cacheline_aligned;
18715
18716 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18717 +extern struct tss_struct init_tss[NR_CPUS];
18718
18719 /*
18720 * Save the original ist values for checking stack pointers during debugging
18721 @@ -479,6 +491,7 @@ struct thread_struct {
18722 unsigned short ds;
18723 unsigned short fsindex;
18724 unsigned short gsindex;
18725 + unsigned short ss;
18726 #endif
18727 #ifdef CONFIG_X86_32
18728 unsigned long ip;
18729 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18730 extern unsigned long mmu_cr4_features;
18731 extern u32 *trampoline_cr4_features;
18732
18733 -static inline void set_in_cr4(unsigned long mask)
18734 -{
18735 - unsigned long cr4;
18736 -
18737 - mmu_cr4_features |= mask;
18738 - if (trampoline_cr4_features)
18739 - *trampoline_cr4_features = mmu_cr4_features;
18740 - cr4 = read_cr4();
18741 - cr4 |= mask;
18742 - write_cr4(cr4);
18743 -}
18744 -
18745 -static inline void clear_in_cr4(unsigned long mask)
18746 -{
18747 - unsigned long cr4;
18748 -
18749 - mmu_cr4_features &= ~mask;
18750 - if (trampoline_cr4_features)
18751 - *trampoline_cr4_features = mmu_cr4_features;
18752 - cr4 = read_cr4();
18753 - cr4 &= ~mask;
18754 - write_cr4(cr4);
18755 -}
18756 +extern void set_in_cr4(unsigned long mask);
18757 +extern void clear_in_cr4(unsigned long mask);
18758
18759 typedef struct {
18760 unsigned long seg;
18761 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18762 */
18763 #define TASK_SIZE PAGE_OFFSET
18764 #define TASK_SIZE_MAX TASK_SIZE
18765 +
18766 +#ifdef CONFIG_PAX_SEGMEXEC
18767 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18768 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18769 +#else
18770 #define STACK_TOP TASK_SIZE
18771 -#define STACK_TOP_MAX STACK_TOP
18772 +#endif
18773 +
18774 +#define STACK_TOP_MAX TASK_SIZE
18775
18776 #define INIT_THREAD { \
18777 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18778 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18779 .vm86_info = NULL, \
18780 .sysenter_cs = __KERNEL_CS, \
18781 .io_bitmap_ptr = NULL, \
18782 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18783 */
18784 #define INIT_TSS { \
18785 .x86_tss = { \
18786 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18787 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18788 .ss0 = __KERNEL_DS, \
18789 .ss1 = __KERNEL_CS, \
18790 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18791 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18792 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18793
18794 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18795 -#define KSTK_TOP(info) \
18796 -({ \
18797 - unsigned long *__ptr = (unsigned long *)(info); \
18798 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18799 -})
18800 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18801
18802 /*
18803 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18804 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18805 #define task_pt_regs(task) \
18806 ({ \
18807 struct pt_regs *__regs__; \
18808 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18809 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18810 __regs__ - 1; \
18811 })
18812
18813 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18814 /*
18815 * User space process size. 47bits minus one guard page.
18816 */
18817 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18818 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18819
18820 /* This decides where the kernel will search for a free chunk of vm
18821 * space during mmap's.
18822 */
18823 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18824 - 0xc0000000 : 0xFFFFe000)
18825 + 0xc0000000 : 0xFFFFf000)
18826
18827 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18828 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18829 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18830 #define STACK_TOP_MAX TASK_SIZE_MAX
18831
18832 #define INIT_THREAD { \
18833 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18834 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18835 }
18836
18837 #define INIT_TSS { \
18838 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18839 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18840 }
18841
18842 /*
18843 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18844 */
18845 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18846
18847 +#ifdef CONFIG_PAX_SEGMEXEC
18848 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18849 +#endif
18850 +
18851 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18852
18853 /* Get/set a process' ability to use the timestamp counter instruction */
18854 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18855 return 0;
18856 }
18857
18858 -extern unsigned long arch_align_stack(unsigned long sp);
18859 +#define arch_align_stack(x) ((x) & ~0xfUL)
18860 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18861
18862 void default_idle(void);
18863 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18864 #define xen_set_default_idle 0
18865 #endif
18866
18867 -void stop_this_cpu(void *dummy);
18868 +void stop_this_cpu(void *dummy) __noreturn;
18869 void df_debug(struct pt_regs *regs, long error_code);
18870 #endif /* _ASM_X86_PROCESSOR_H */
18871 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18872 index 6205f0c..688a3a9 100644
18873 --- a/arch/x86/include/asm/ptrace.h
18874 +++ b/arch/x86/include/asm/ptrace.h
18875 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18876 }
18877
18878 /*
18879 - * user_mode_vm(regs) determines whether a register set came from user mode.
18880 + * user_mode(regs) determines whether a register set came from user mode.
18881 * This is true if V8086 mode was enabled OR if the register set was from
18882 * protected mode with RPL-3 CS value. This tricky test checks that with
18883 * one comparison. Many places in the kernel can bypass this full check
18884 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18885 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18886 + * be used.
18887 */
18888 -static inline int user_mode(struct pt_regs *regs)
18889 +static inline int user_mode_novm(struct pt_regs *regs)
18890 {
18891 #ifdef CONFIG_X86_32
18892 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18893 #else
18894 - return !!(regs->cs & 3);
18895 + return !!(regs->cs & SEGMENT_RPL_MASK);
18896 #endif
18897 }
18898
18899 -static inline int user_mode_vm(struct pt_regs *regs)
18900 +static inline int user_mode(struct pt_regs *regs)
18901 {
18902 #ifdef CONFIG_X86_32
18903 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18904 USER_RPL;
18905 #else
18906 - return user_mode(regs);
18907 + return user_mode_novm(regs);
18908 #endif
18909 }
18910
18911 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18912 #ifdef CONFIG_X86_64
18913 static inline bool user_64bit_mode(struct pt_regs *regs)
18914 {
18915 + unsigned long cs = regs->cs & 0xffff;
18916 #ifndef CONFIG_PARAVIRT
18917 /*
18918 * On non-paravirt systems, this is the only long mode CPL 3
18919 * selector. We do not allow long mode selectors in the LDT.
18920 */
18921 - return regs->cs == __USER_CS;
18922 + return cs == __USER_CS;
18923 #else
18924 /* Headers are too twisted for this to go in paravirt.h. */
18925 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18926 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18927 #endif
18928 }
18929
18930 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18931 * Traps from the kernel do not save sp and ss.
18932 * Use the helper function to retrieve sp.
18933 */
18934 - if (offset == offsetof(struct pt_regs, sp) &&
18935 - regs->cs == __KERNEL_CS)
18936 - return kernel_stack_pointer(regs);
18937 + if (offset == offsetof(struct pt_regs, sp)) {
18938 + unsigned long cs = regs->cs & 0xffff;
18939 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18940 + return kernel_stack_pointer(regs);
18941 + }
18942 #endif
18943 return *(unsigned long *)((unsigned long)regs + offset);
18944 }
18945 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18946 index 70f46f0..adfbdb4 100644
18947 --- a/arch/x86/include/asm/qrwlock.h
18948 +++ b/arch/x86/include/asm/qrwlock.h
18949 @@ -7,8 +7,8 @@
18950 #define queue_write_unlock queue_write_unlock
18951 static inline void queue_write_unlock(struct qrwlock *lock)
18952 {
18953 - barrier();
18954 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18955 + barrier();
18956 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18957 }
18958 #endif
18959
18960 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18961 index 9c6b890..5305f53 100644
18962 --- a/arch/x86/include/asm/realmode.h
18963 +++ b/arch/x86/include/asm/realmode.h
18964 @@ -22,16 +22,14 @@ struct real_mode_header {
18965 #endif
18966 /* APM/BIOS reboot */
18967 u32 machine_real_restart_asm;
18968 -#ifdef CONFIG_X86_64
18969 u32 machine_real_restart_seg;
18970 -#endif
18971 };
18972
18973 /* This must match data at trampoline_32/64.S */
18974 struct trampoline_header {
18975 #ifdef CONFIG_X86_32
18976 u32 start;
18977 - u16 gdt_pad;
18978 + u16 boot_cs;
18979 u16 gdt_limit;
18980 u32 gdt_base;
18981 #else
18982 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18983 index a82c4f1..ac45053 100644
18984 --- a/arch/x86/include/asm/reboot.h
18985 +++ b/arch/x86/include/asm/reboot.h
18986 @@ -6,13 +6,13 @@
18987 struct pt_regs;
18988
18989 struct machine_ops {
18990 - void (*restart)(char *cmd);
18991 - void (*halt)(void);
18992 - void (*power_off)(void);
18993 + void (* __noreturn restart)(char *cmd);
18994 + void (* __noreturn halt)(void);
18995 + void (* __noreturn power_off)(void);
18996 void (*shutdown)(void);
18997 void (*crash_shutdown)(struct pt_regs *);
18998 - void (*emergency_restart)(void);
18999 -};
19000 + void (* __noreturn emergency_restart)(void);
19001 +} __no_const;
19002
19003 extern struct machine_ops machine_ops;
19004
19005 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19006 index 8f7866a..e442f20 100644
19007 --- a/arch/x86/include/asm/rmwcc.h
19008 +++ b/arch/x86/include/asm/rmwcc.h
19009 @@ -3,7 +3,34 @@
19010
19011 #ifdef CC_HAVE_ASM_GOTO
19012
19013 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19014 +#ifdef CONFIG_PAX_REFCOUNT
19015 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19016 +do { \
19017 + asm_volatile_goto (fullop \
19018 + ";jno 0f\n" \
19019 + fullantiop \
19020 + ";int $4\n0:\n" \
19021 + _ASM_EXTABLE(0b, 0b) \
19022 + ";j" cc " %l[cc_label]" \
19023 + : : "m" (var), ## __VA_ARGS__ \
19024 + : "memory" : cc_label); \
19025 + return 0; \
19026 +cc_label: \
19027 + return 1; \
19028 +} while (0)
19029 +#else
19030 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19031 +do { \
19032 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19033 + : : "m" (var), ## __VA_ARGS__ \
19034 + : "memory" : cc_label); \
19035 + return 0; \
19036 +cc_label: \
19037 + return 1; \
19038 +} while (0)
19039 +#endif
19040 +
19041 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19042 do { \
19043 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19044 : : "m" (var), ## __VA_ARGS__ \
19045 @@ -13,15 +40,46 @@ cc_label: \
19046 return 1; \
19047 } while (0)
19048
19049 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19050 - __GEN_RMWcc(op " " arg0, var, cc)
19051 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19052 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19053
19054 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19055 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19056 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19057 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19058 +
19059 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19060 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19061 +
19062 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19063 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19064
19065 #else /* !CC_HAVE_ASM_GOTO */
19066
19067 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19068 +#ifdef CONFIG_PAX_REFCOUNT
19069 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19070 +do { \
19071 + char c; \
19072 + asm volatile (fullop \
19073 + ";jno 0f\n" \
19074 + fullantiop \
19075 + ";int $4\n0:\n" \
19076 + _ASM_EXTABLE(0b, 0b) \
19077 + "; set" cc " %1" \
19078 + : "+m" (var), "=qm" (c) \
19079 + : __VA_ARGS__ : "memory"); \
19080 + return c != 0; \
19081 +} while (0)
19082 +#else
19083 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19084 +do { \
19085 + char c; \
19086 + asm volatile (fullop "; set" cc " %1" \
19087 + : "+m" (var), "=qm" (c) \
19088 + : __VA_ARGS__ : "memory"); \
19089 + return c != 0; \
19090 +} while (0)
19091 +#endif
19092 +
19093 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19094 do { \
19095 char c; \
19096 asm volatile (fullop "; set" cc " %1" \
19097 @@ -30,11 +88,17 @@ do { \
19098 return c != 0; \
19099 } while (0)
19100
19101 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19102 - __GEN_RMWcc(op " " arg0, var, cc)
19103 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19104 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19105 +
19106 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19107 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19108 +
19109 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19110 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19111
19112 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19113 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19114 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19115 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19116
19117 #endif /* CC_HAVE_ASM_GOTO */
19118
19119 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19120 index cad82c9..2e5c5c1 100644
19121 --- a/arch/x86/include/asm/rwsem.h
19122 +++ b/arch/x86/include/asm/rwsem.h
19123 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19124 {
19125 asm volatile("# beginning down_read\n\t"
19126 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19127 +
19128 +#ifdef CONFIG_PAX_REFCOUNT
19129 + "jno 0f\n"
19130 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19131 + "int $4\n0:\n"
19132 + _ASM_EXTABLE(0b, 0b)
19133 +#endif
19134 +
19135 /* adds 0x00000001 */
19136 " jns 1f\n"
19137 " call call_rwsem_down_read_failed\n"
19138 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19139 "1:\n\t"
19140 " mov %1,%2\n\t"
19141 " add %3,%2\n\t"
19142 +
19143 +#ifdef CONFIG_PAX_REFCOUNT
19144 + "jno 0f\n"
19145 + "sub %3,%2\n"
19146 + "int $4\n0:\n"
19147 + _ASM_EXTABLE(0b, 0b)
19148 +#endif
19149 +
19150 " jle 2f\n\t"
19151 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19152 " jnz 1b\n\t"
19153 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19154 long tmp;
19155 asm volatile("# beginning down_write\n\t"
19156 LOCK_PREFIX " xadd %1,(%2)\n\t"
19157 +
19158 +#ifdef CONFIG_PAX_REFCOUNT
19159 + "jno 0f\n"
19160 + "mov %1,(%2)\n"
19161 + "int $4\n0:\n"
19162 + _ASM_EXTABLE(0b, 0b)
19163 +#endif
19164 +
19165 /* adds 0xffff0001, returns the old value */
19166 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19167 /* was the active mask 0 before? */
19168 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19169 long tmp;
19170 asm volatile("# beginning __up_read\n\t"
19171 LOCK_PREFIX " xadd %1,(%2)\n\t"
19172 +
19173 +#ifdef CONFIG_PAX_REFCOUNT
19174 + "jno 0f\n"
19175 + "mov %1,(%2)\n"
19176 + "int $4\n0:\n"
19177 + _ASM_EXTABLE(0b, 0b)
19178 +#endif
19179 +
19180 /* subtracts 1, returns the old value */
19181 " jns 1f\n\t"
19182 " call call_rwsem_wake\n" /* expects old value in %edx */
19183 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19184 long tmp;
19185 asm volatile("# beginning __up_write\n\t"
19186 LOCK_PREFIX " xadd %1,(%2)\n\t"
19187 +
19188 +#ifdef CONFIG_PAX_REFCOUNT
19189 + "jno 0f\n"
19190 + "mov %1,(%2)\n"
19191 + "int $4\n0:\n"
19192 + _ASM_EXTABLE(0b, 0b)
19193 +#endif
19194 +
19195 /* subtracts 0xffff0001, returns the old value */
19196 " jns 1f\n\t"
19197 " call call_rwsem_wake\n" /* expects old value in %edx */
19198 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19199 {
19200 asm volatile("# beginning __downgrade_write\n\t"
19201 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19202 +
19203 +#ifdef CONFIG_PAX_REFCOUNT
19204 + "jno 0f\n"
19205 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19206 + "int $4\n0:\n"
19207 + _ASM_EXTABLE(0b, 0b)
19208 +#endif
19209 +
19210 /*
19211 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19212 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19213 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19214 */
19215 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19216 {
19217 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19218 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19219 +
19220 +#ifdef CONFIG_PAX_REFCOUNT
19221 + "jno 0f\n"
19222 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19223 + "int $4\n0:\n"
19224 + _ASM_EXTABLE(0b, 0b)
19225 +#endif
19226 +
19227 : "+m" (sem->count)
19228 : "er" (delta));
19229 }
19230 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19231 */
19232 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19233 {
19234 - return delta + xadd(&sem->count, delta);
19235 + return delta + xadd_check_overflow(&sem->count, delta);
19236 }
19237
19238 #endif /* __KERNEL__ */
19239 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19240 index 6f1c3a8..7744f19 100644
19241 --- a/arch/x86/include/asm/segment.h
19242 +++ b/arch/x86/include/asm/segment.h
19243 @@ -64,10 +64,15 @@
19244 * 26 - ESPFIX small SS
19245 * 27 - per-cpu [ offset to per-cpu data area ]
19246 * 28 - stack_canary-20 [ for stack protector ]
19247 - * 29 - unused
19248 - * 30 - unused
19249 + * 29 - PCI BIOS CS
19250 + * 30 - PCI BIOS DS
19251 * 31 - TSS for double fault handler
19252 */
19253 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19254 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19255 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19256 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19257 +
19258 #define GDT_ENTRY_TLS_MIN 6
19259 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19260
19261 @@ -79,6 +84,8 @@
19262
19263 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19264
19265 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19266 +
19267 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19268
19269 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19270 @@ -104,6 +111,12 @@
19271 #define __KERNEL_STACK_CANARY 0
19272 #endif
19273
19274 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19275 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19276 +
19277 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19278 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19279 +
19280 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19281
19282 /*
19283 @@ -141,7 +154,7 @@
19284 */
19285
19286 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19287 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19288 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19289
19290
19291 #else
19292 @@ -165,6 +178,8 @@
19293 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19294 #define __USER32_DS __USER_DS
19295
19296 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19297 +
19298 #define GDT_ENTRY_TSS 8 /* needs two entries */
19299 #define GDT_ENTRY_LDT 10 /* needs two entries */
19300 #define GDT_ENTRY_TLS_MIN 12
19301 @@ -173,6 +188,8 @@
19302 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19303 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19304
19305 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19306 +
19307 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19308 #define FS_TLS 0
19309 #define GS_TLS 1
19310 @@ -180,12 +197,14 @@
19311 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19312 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19313
19314 -#define GDT_ENTRIES 16
19315 +#define GDT_ENTRIES 17
19316
19317 #endif
19318
19319 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19320 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19321 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19322 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19323 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19324 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19325 #ifndef CONFIG_PARAVIRT
19326 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19327 {
19328 unsigned long __limit;
19329 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19330 - return __limit + 1;
19331 + return __limit;
19332 }
19333
19334 #endif /* !__ASSEMBLY__ */
19335 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19336 index 8d3120f..352b440 100644
19337 --- a/arch/x86/include/asm/smap.h
19338 +++ b/arch/x86/include/asm/smap.h
19339 @@ -25,11 +25,40 @@
19340
19341 #include <asm/alternative-asm.h>
19342
19343 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19344 +#define ASM_PAX_OPEN_USERLAND \
19345 + 661: jmp 663f; \
19346 + .pushsection .altinstr_replacement, "a" ; \
19347 + 662: pushq %rax; nop; \
19348 + .popsection ; \
19349 + .pushsection .altinstructions, "a" ; \
19350 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19351 + .popsection ; \
19352 + call __pax_open_userland; \
19353 + popq %rax; \
19354 + 663:
19355 +
19356 +#define ASM_PAX_CLOSE_USERLAND \
19357 + 661: jmp 663f; \
19358 + .pushsection .altinstr_replacement, "a" ; \
19359 + 662: pushq %rax; nop; \
19360 + .popsection; \
19361 + .pushsection .altinstructions, "a" ; \
19362 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19363 + .popsection; \
19364 + call __pax_close_userland; \
19365 + popq %rax; \
19366 + 663:
19367 +#else
19368 +#define ASM_PAX_OPEN_USERLAND
19369 +#define ASM_PAX_CLOSE_USERLAND
19370 +#endif
19371 +
19372 #ifdef CONFIG_X86_SMAP
19373
19374 #define ASM_CLAC \
19375 661: ASM_NOP3 ; \
19376 - .pushsection .altinstr_replacement, "ax" ; \
19377 + .pushsection .altinstr_replacement, "a" ; \
19378 662: __ASM_CLAC ; \
19379 .popsection ; \
19380 .pushsection .altinstructions, "a" ; \
19381 @@ -38,7 +67,7 @@
19382
19383 #define ASM_STAC \
19384 661: ASM_NOP3 ; \
19385 - .pushsection .altinstr_replacement, "ax" ; \
19386 + .pushsection .altinstr_replacement, "a" ; \
19387 662: __ASM_STAC ; \
19388 .popsection ; \
19389 .pushsection .altinstructions, "a" ; \
19390 @@ -56,6 +85,37 @@
19391
19392 #include <asm/alternative.h>
19393
19394 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19395 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19396 +
19397 +extern void __pax_open_userland(void);
19398 +static __always_inline unsigned long pax_open_userland(void)
19399 +{
19400 +
19401 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19402 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19403 + :
19404 + : [open] "i" (__pax_open_userland)
19405 + : "memory", "rax");
19406 +#endif
19407 +
19408 + return 0;
19409 +}
19410 +
19411 +extern void __pax_close_userland(void);
19412 +static __always_inline unsigned long pax_close_userland(void)
19413 +{
19414 +
19415 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19416 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19417 + :
19418 + : [close] "i" (__pax_close_userland)
19419 + : "memory", "rax");
19420 +#endif
19421 +
19422 + return 0;
19423 +}
19424 +
19425 #ifdef CONFIG_X86_SMAP
19426
19427 static __always_inline void clac(void)
19428 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19429 index 8cd27e0..7f05ec8 100644
19430 --- a/arch/x86/include/asm/smp.h
19431 +++ b/arch/x86/include/asm/smp.h
19432 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19433 /* cpus sharing the last level cache: */
19434 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19435 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19436 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19437 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19438
19439 static inline struct cpumask *cpu_sibling_mask(int cpu)
19440 {
19441 @@ -78,7 +78,7 @@ struct smp_ops {
19442
19443 void (*send_call_func_ipi)(const struct cpumask *mask);
19444 void (*send_call_func_single_ipi)(int cpu);
19445 -};
19446 +} __no_const;
19447
19448 /* Globals due to paravirt */
19449 extern void set_cpu_sibling_map(int cpu);
19450 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19451 extern int safe_smp_processor_id(void);
19452
19453 #elif defined(CONFIG_X86_64_SMP)
19454 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19455 -
19456 -#define stack_smp_processor_id() \
19457 -({ \
19458 - struct thread_info *ti; \
19459 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19460 - ti->cpu; \
19461 -})
19462 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19463 +#define stack_smp_processor_id() raw_smp_processor_id()
19464 #define safe_smp_processor_id() smp_processor_id()
19465
19466 #endif
19467 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19468 index 54f1c80..39362a5 100644
19469 --- a/arch/x86/include/asm/spinlock.h
19470 +++ b/arch/x86/include/asm/spinlock.h
19471 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19472 static inline void arch_read_lock(arch_rwlock_t *rw)
19473 {
19474 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19475 +
19476 +#ifdef CONFIG_PAX_REFCOUNT
19477 + "jno 0f\n"
19478 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19479 + "int $4\n0:\n"
19480 + _ASM_EXTABLE(0b, 0b)
19481 +#endif
19482 +
19483 "jns 1f\n"
19484 "call __read_lock_failed\n\t"
19485 "1:\n"
19486 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19487 static inline void arch_write_lock(arch_rwlock_t *rw)
19488 {
19489 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19490 +
19491 +#ifdef CONFIG_PAX_REFCOUNT
19492 + "jno 0f\n"
19493 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19494 + "int $4\n0:\n"
19495 + _ASM_EXTABLE(0b, 0b)
19496 +#endif
19497 +
19498 "jz 1f\n"
19499 "call __write_lock_failed\n\t"
19500 "1:\n"
19501 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19502
19503 static inline void arch_read_unlock(arch_rwlock_t *rw)
19504 {
19505 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19506 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19507 +
19508 +#ifdef CONFIG_PAX_REFCOUNT
19509 + "jno 0f\n"
19510 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19511 + "int $4\n0:\n"
19512 + _ASM_EXTABLE(0b, 0b)
19513 +#endif
19514 +
19515 :"+m" (rw->lock) : : "memory");
19516 }
19517
19518 static inline void arch_write_unlock(arch_rwlock_t *rw)
19519 {
19520 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19521 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19522 +
19523 +#ifdef CONFIG_PAX_REFCOUNT
19524 + "jno 0f\n"
19525 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19526 + "int $4\n0:\n"
19527 + _ASM_EXTABLE(0b, 0b)
19528 +#endif
19529 +
19530 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19531 }
19532 #else
19533 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19534 index 6a99859..03cb807 100644
19535 --- a/arch/x86/include/asm/stackprotector.h
19536 +++ b/arch/x86/include/asm/stackprotector.h
19537 @@ -47,7 +47,7 @@
19538 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19539 */
19540 #define GDT_STACK_CANARY_INIT \
19541 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19542 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19543
19544 /*
19545 * Initialize the stackprotector canary value.
19546 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19547
19548 static inline void load_stack_canary_segment(void)
19549 {
19550 -#ifdef CONFIG_X86_32
19551 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19552 asm volatile ("mov %0, %%gs" : : "r" (0));
19553 #endif
19554 }
19555 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19556 index 70bbe39..4ae2bd4 100644
19557 --- a/arch/x86/include/asm/stacktrace.h
19558 +++ b/arch/x86/include/asm/stacktrace.h
19559 @@ -11,28 +11,20 @@
19560
19561 extern int kstack_depth_to_print;
19562
19563 -struct thread_info;
19564 +struct task_struct;
19565 struct stacktrace_ops;
19566
19567 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19568 - unsigned long *stack,
19569 - unsigned long bp,
19570 - const struct stacktrace_ops *ops,
19571 - void *data,
19572 - unsigned long *end,
19573 - int *graph);
19574 +typedef unsigned long walk_stack_t(struct task_struct *task,
19575 + void *stack_start,
19576 + unsigned long *stack,
19577 + unsigned long bp,
19578 + const struct stacktrace_ops *ops,
19579 + void *data,
19580 + unsigned long *end,
19581 + int *graph);
19582
19583 -extern unsigned long
19584 -print_context_stack(struct thread_info *tinfo,
19585 - unsigned long *stack, unsigned long bp,
19586 - const struct stacktrace_ops *ops, void *data,
19587 - unsigned long *end, int *graph);
19588 -
19589 -extern unsigned long
19590 -print_context_stack_bp(struct thread_info *tinfo,
19591 - unsigned long *stack, unsigned long bp,
19592 - const struct stacktrace_ops *ops, void *data,
19593 - unsigned long *end, int *graph);
19594 +extern walk_stack_t print_context_stack;
19595 +extern walk_stack_t print_context_stack_bp;
19596
19597 /* Generic stack tracer with callbacks */
19598
19599 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19600 void (*address)(void *data, unsigned long address, int reliable);
19601 /* On negative return stop dumping */
19602 int (*stack)(void *data, char *name);
19603 - walk_stack_t walk_stack;
19604 + walk_stack_t *walk_stack;
19605 };
19606
19607 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19608 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19609 index d7f3b3b..3cc39f1 100644
19610 --- a/arch/x86/include/asm/switch_to.h
19611 +++ b/arch/x86/include/asm/switch_to.h
19612 @@ -108,7 +108,7 @@ do { \
19613 "call __switch_to\n\t" \
19614 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19615 __switch_canary \
19616 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19617 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19618 "movq %%rax,%%rdi\n\t" \
19619 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19620 "jnz ret_from_fork\n\t" \
19621 @@ -119,7 +119,7 @@ do { \
19622 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19623 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19624 [_tif_fork] "i" (_TIF_FORK), \
19625 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19626 + [thread_info] "m" (current_tinfo), \
19627 [current_task] "m" (current_task) \
19628 __switch_canary_iparam \
19629 : "memory", "cc" __EXTRA_CLOBBER)
19630 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19631 index 8540538..4b0b5e9 100644
19632 --- a/arch/x86/include/asm/thread_info.h
19633 +++ b/arch/x86/include/asm/thread_info.h
19634 @@ -24,7 +24,6 @@ struct exec_domain;
19635 #include <linux/atomic.h>
19636
19637 struct thread_info {
19638 - struct task_struct *task; /* main task structure */
19639 struct exec_domain *exec_domain; /* execution domain */
19640 __u32 flags; /* low level flags */
19641 __u32 status; /* thread synchronous flags */
19642 @@ -33,13 +32,13 @@ struct thread_info {
19643 mm_segment_t addr_limit;
19644 struct restart_block restart_block;
19645 void __user *sysenter_return;
19646 + unsigned long lowest_stack;
19647 unsigned int sig_on_uaccess_error:1;
19648 unsigned int uaccess_err:1; /* uaccess failed */
19649 };
19650
19651 -#define INIT_THREAD_INFO(tsk) \
19652 +#define INIT_THREAD_INFO \
19653 { \
19654 - .task = &tsk, \
19655 .exec_domain = &default_exec_domain, \
19656 .flags = 0, \
19657 .cpu = 0, \
19658 @@ -50,7 +49,7 @@ struct thread_info {
19659 }, \
19660 }
19661
19662 -#define init_thread_info (init_thread_union.thread_info)
19663 +#define init_thread_info (init_thread_union.stack)
19664 #define init_stack (init_thread_union.stack)
19665
19666 #else /* !__ASSEMBLY__ */
19667 @@ -91,6 +90,7 @@ struct thread_info {
19668 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19669 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19670 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19671 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19672
19673 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19674 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19675 @@ -115,17 +115,18 @@ struct thread_info {
19676 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19677 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19678 #define _TIF_X32 (1 << TIF_X32)
19679 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19680
19681 /* work to do in syscall_trace_enter() */
19682 #define _TIF_WORK_SYSCALL_ENTRY \
19683 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19684 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19685 - _TIF_NOHZ)
19686 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19687
19688 /* work to do in syscall_trace_leave() */
19689 #define _TIF_WORK_SYSCALL_EXIT \
19690 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19691 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19692 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19693
19694 /* work to do on interrupt/exception return */
19695 #define _TIF_WORK_MASK \
19696 @@ -136,7 +137,7 @@ struct thread_info {
19697 /* work to do on any return to user space */
19698 #define _TIF_ALLWORK_MASK \
19699 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19700 - _TIF_NOHZ)
19701 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19702
19703 /* Only used for 64 bit */
19704 #define _TIF_DO_NOTIFY_MASK \
19705 @@ -151,7 +152,6 @@ struct thread_info {
19706 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19707
19708 #define STACK_WARN (THREAD_SIZE/8)
19709 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19710
19711 /*
19712 * macros/functions for gaining access to the thread information structure
19713 @@ -162,26 +162,18 @@ struct thread_info {
19714
19715 DECLARE_PER_CPU(unsigned long, kernel_stack);
19716
19717 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19718 +
19719 static inline struct thread_info *current_thread_info(void)
19720 {
19721 - struct thread_info *ti;
19722 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19723 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19724 - return ti;
19725 + return this_cpu_read_stable(current_tinfo);
19726 }
19727
19728 #else /* !__ASSEMBLY__ */
19729
19730 /* how to get the thread information struct from ASM */
19731 #define GET_THREAD_INFO(reg) \
19732 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19733 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19734 -
19735 -/*
19736 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19737 - * a certain register (to be used in assembler memory operands).
19738 - */
19739 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19740 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19741
19742 #endif
19743
19744 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19745 extern void arch_task_cache_init(void);
19746 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19747 extern void arch_release_task_struct(struct task_struct *tsk);
19748 +
19749 +#define __HAVE_THREAD_FUNCTIONS
19750 +#define task_thread_info(task) (&(task)->tinfo)
19751 +#define task_stack_page(task) ((task)->stack)
19752 +#define setup_thread_stack(p, org) do {} while (0)
19753 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19754 +
19755 #endif
19756 #endif /* _ASM_X86_THREAD_INFO_H */
19757 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19758 index 04905bf..1178cdf 100644
19759 --- a/arch/x86/include/asm/tlbflush.h
19760 +++ b/arch/x86/include/asm/tlbflush.h
19761 @@ -17,18 +17,44 @@
19762
19763 static inline void __native_flush_tlb(void)
19764 {
19765 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19766 + u64 descriptor[2];
19767 +
19768 + descriptor[0] = PCID_KERNEL;
19769 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19770 + return;
19771 + }
19772 +
19773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19774 + if (static_cpu_has(X86_FEATURE_PCID)) {
19775 + unsigned int cpu = raw_get_cpu();
19776 +
19777 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19778 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19779 + raw_put_cpu_no_resched();
19780 + return;
19781 + }
19782 +#endif
19783 +
19784 native_write_cr3(native_read_cr3());
19785 }
19786
19787 static inline void __native_flush_tlb_global_irq_disabled(void)
19788 {
19789 - unsigned long cr4;
19790 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19791 + u64 descriptor[2];
19792
19793 - cr4 = native_read_cr4();
19794 - /* clear PGE */
19795 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19796 - /* write old PGE again and flush TLBs */
19797 - native_write_cr4(cr4);
19798 + descriptor[0] = PCID_KERNEL;
19799 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19800 + } else {
19801 + unsigned long cr4;
19802 +
19803 + cr4 = native_read_cr4();
19804 + /* clear PGE */
19805 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19806 + /* write old PGE again and flush TLBs */
19807 + native_write_cr4(cr4);
19808 + }
19809 }
19810
19811 static inline void __native_flush_tlb_global(void)
19812 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19813
19814 static inline void __native_flush_tlb_single(unsigned long addr)
19815 {
19816 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19817 + u64 descriptor[2];
19818 +
19819 + descriptor[0] = PCID_KERNEL;
19820 + descriptor[1] = addr;
19821 +
19822 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19823 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19824 + if (addr < TASK_SIZE_MAX)
19825 + descriptor[1] += pax_user_shadow_base;
19826 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19827 + }
19828 +
19829 + descriptor[0] = PCID_USER;
19830 + descriptor[1] = addr;
19831 +#endif
19832 +
19833 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19834 + return;
19835 + }
19836 +
19837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19838 + if (static_cpu_has(X86_FEATURE_PCID)) {
19839 + unsigned int cpu = raw_get_cpu();
19840 +
19841 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19842 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19843 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19844 + raw_put_cpu_no_resched();
19845 +
19846 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19847 + addr += pax_user_shadow_base;
19848 + }
19849 +#endif
19850 +
19851 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19852 }
19853
19854 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19855 index 0d592e0..526f797 100644
19856 --- a/arch/x86/include/asm/uaccess.h
19857 +++ b/arch/x86/include/asm/uaccess.h
19858 @@ -7,6 +7,7 @@
19859 #include <linux/compiler.h>
19860 #include <linux/thread_info.h>
19861 #include <linux/string.h>
19862 +#include <linux/spinlock.h>
19863 #include <asm/asm.h>
19864 #include <asm/page.h>
19865 #include <asm/smap.h>
19866 @@ -29,7 +30,12 @@
19867
19868 #define get_ds() (KERNEL_DS)
19869 #define get_fs() (current_thread_info()->addr_limit)
19870 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19871 +void __set_fs(mm_segment_t x);
19872 +void set_fs(mm_segment_t x);
19873 +#else
19874 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19875 +#endif
19876
19877 #define segment_eq(a, b) ((a).seg == (b).seg)
19878
19879 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19880 * checks that the pointer is in the user space range - after calling
19881 * this function, memory access functions may still return -EFAULT.
19882 */
19883 -#define access_ok(type, addr, size) \
19884 - likely(!__range_not_ok(addr, size, user_addr_max()))
19885 +extern int _cond_resched(void);
19886 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19887 +#define access_ok(type, addr, size) \
19888 +({ \
19889 + unsigned long __size = size; \
19890 + unsigned long __addr = (unsigned long)addr; \
19891 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19892 + if (__ret_ao && __size) { \
19893 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19894 + unsigned long __end_ao = __addr + __size - 1; \
19895 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19896 + while (__addr_ao <= __end_ao) { \
19897 + char __c_ao; \
19898 + __addr_ao += PAGE_SIZE; \
19899 + if (__size > PAGE_SIZE) \
19900 + _cond_resched(); \
19901 + if (__get_user(__c_ao, (char __user *)__addr)) \
19902 + break; \
19903 + if (type != VERIFY_WRITE) { \
19904 + __addr = __addr_ao; \
19905 + continue; \
19906 + } \
19907 + if (__put_user(__c_ao, (char __user *)__addr)) \
19908 + break; \
19909 + __addr = __addr_ao; \
19910 + } \
19911 + } \
19912 + } \
19913 + __ret_ao; \
19914 +})
19915
19916 /*
19917 * The exception table consists of pairs of addresses relative to the
19918 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19919 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19920 __chk_user_ptr(ptr); \
19921 might_fault(); \
19922 + pax_open_userland(); \
19923 asm volatile("call __get_user_%P3" \
19924 : "=a" (__ret_gu), "=r" (__val_gu) \
19925 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19926 (x) = (__typeof__(*(ptr))) __val_gu; \
19927 + pax_close_userland(); \
19928 __ret_gu; \
19929 })
19930
19931 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19932 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19933 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19934
19935 -
19936 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19937 +#define __copyuser_seg "gs;"
19938 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19939 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19940 +#else
19941 +#define __copyuser_seg
19942 +#define __COPYUSER_SET_ES
19943 +#define __COPYUSER_RESTORE_ES
19944 +#endif
19945
19946 #ifdef CONFIG_X86_32
19947 #define __put_user_asm_u64(x, addr, err, errret) \
19948 asm volatile(ASM_STAC "\n" \
19949 - "1: movl %%eax,0(%2)\n" \
19950 - "2: movl %%edx,4(%2)\n" \
19951 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19952 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19953 "3: " ASM_CLAC "\n" \
19954 ".section .fixup,\"ax\"\n" \
19955 "4: movl %3,%0\n" \
19956 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19957
19958 #define __put_user_asm_ex_u64(x, addr) \
19959 asm volatile(ASM_STAC "\n" \
19960 - "1: movl %%eax,0(%1)\n" \
19961 - "2: movl %%edx,4(%1)\n" \
19962 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19963 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19964 "3: " ASM_CLAC "\n" \
19965 _ASM_EXTABLE_EX(1b, 2b) \
19966 _ASM_EXTABLE_EX(2b, 3b) \
19967 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19968 __typeof__(*(ptr)) __pu_val; \
19969 __chk_user_ptr(ptr); \
19970 might_fault(); \
19971 - __pu_val = x; \
19972 + __pu_val = (x); \
19973 + pax_open_userland(); \
19974 switch (sizeof(*(ptr))) { \
19975 case 1: \
19976 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19977 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19978 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19979 break; \
19980 } \
19981 + pax_close_userland(); \
19982 __ret_pu; \
19983 })
19984
19985 @@ -355,8 +401,10 @@ do { \
19986 } while (0)
19987
19988 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19989 +do { \
19990 + pax_open_userland(); \
19991 asm volatile(ASM_STAC "\n" \
19992 - "1: mov"itype" %2,%"rtype"1\n" \
19993 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19994 "2: " ASM_CLAC "\n" \
19995 ".section .fixup,\"ax\"\n" \
19996 "3: mov %3,%0\n" \
19997 @@ -364,8 +412,10 @@ do { \
19998 " jmp 2b\n" \
19999 ".previous\n" \
20000 _ASM_EXTABLE(1b, 3b) \
20001 - : "=r" (err), ltype(x) \
20002 - : "m" (__m(addr)), "i" (errret), "0" (err))
20003 + : "=r" (err), ltype (x) \
20004 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
20005 + pax_close_userland(); \
20006 +} while (0)
20007
20008 #define __get_user_size_ex(x, ptr, size) \
20009 do { \
20010 @@ -389,7 +439,7 @@ do { \
20011 } while (0)
20012
20013 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20014 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20015 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20016 "2:\n" \
20017 _ASM_EXTABLE_EX(1b, 2b) \
20018 : ltype(x) : "m" (__m(addr)))
20019 @@ -406,13 +456,24 @@ do { \
20020 int __gu_err; \
20021 unsigned long __gu_val; \
20022 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20023 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
20024 + (x) = (__typeof__(*(ptr)))__gu_val; \
20025 __gu_err; \
20026 })
20027
20028 /* FIXME: this hack is definitely wrong -AK */
20029 struct __large_struct { unsigned long buf[100]; };
20030 -#define __m(x) (*(struct __large_struct __user *)(x))
20031 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20032 +#define ____m(x) \
20033 +({ \
20034 + unsigned long ____x = (unsigned long)(x); \
20035 + if (____x < pax_user_shadow_base) \
20036 + ____x += pax_user_shadow_base; \
20037 + (typeof(x))____x; \
20038 +})
20039 +#else
20040 +#define ____m(x) (x)
20041 +#endif
20042 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20043
20044 /*
20045 * Tell gcc we read from memory instead of writing: this is because
20046 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20047 * aliasing issues.
20048 */
20049 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20050 +do { \
20051 + pax_open_userland(); \
20052 asm volatile(ASM_STAC "\n" \
20053 - "1: mov"itype" %"rtype"1,%2\n" \
20054 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20055 "2: " ASM_CLAC "\n" \
20056 ".section .fixup,\"ax\"\n" \
20057 "3: mov %3,%0\n" \
20058 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20059 ".previous\n" \
20060 _ASM_EXTABLE(1b, 3b) \
20061 : "=r"(err) \
20062 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20063 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20064 + pax_close_userland(); \
20065 +} while (0)
20066
20067 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20068 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20069 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20070 "2:\n" \
20071 _ASM_EXTABLE_EX(1b, 2b) \
20072 : : ltype(x), "m" (__m(addr)))
20073 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20074 */
20075 #define uaccess_try do { \
20076 current_thread_info()->uaccess_err = 0; \
20077 + pax_open_userland(); \
20078 stac(); \
20079 barrier();
20080
20081 #define uaccess_catch(err) \
20082 clac(); \
20083 + pax_close_userland(); \
20084 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20085 } while (0)
20086
20087 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20088 * On error, the variable @x is set to zero.
20089 */
20090
20091 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20092 +#define __get_user(x, ptr) get_user((x), (ptr))
20093 +#else
20094 #define __get_user(x, ptr) \
20095 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20096 +#endif
20097
20098 /**
20099 * __put_user: - Write a simple value into user space, with less checking.
20100 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20101 * Returns zero on success, or -EFAULT on error.
20102 */
20103
20104 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20105 +#define __put_user(x, ptr) put_user((x), (ptr))
20106 +#else
20107 #define __put_user(x, ptr) \
20108 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20109 +#endif
20110
20111 #define __get_user_unaligned __get_user
20112 #define __put_user_unaligned __put_user
20113 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20114 #define get_user_ex(x, ptr) do { \
20115 unsigned long __gue_val; \
20116 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20117 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20118 + (x) = (__typeof__(*(ptr)))__gue_val; \
20119 } while (0)
20120
20121 #define put_user_try uaccess_try
20122 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20123 __typeof__(ptr) __uval = (uval); \
20124 __typeof__(*(ptr)) __old = (old); \
20125 __typeof__(*(ptr)) __new = (new); \
20126 + pax_open_userland(); \
20127 switch (size) { \
20128 case 1: \
20129 { \
20130 asm volatile("\t" ASM_STAC "\n" \
20131 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20132 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20133 "2:\t" ASM_CLAC "\n" \
20134 "\t.section .fixup, \"ax\"\n" \
20135 "3:\tmov %3, %0\n" \
20136 "\tjmp 2b\n" \
20137 "\t.previous\n" \
20138 _ASM_EXTABLE(1b, 3b) \
20139 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20140 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20141 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20142 : "memory" \
20143 ); \
20144 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20145 case 2: \
20146 { \
20147 asm volatile("\t" ASM_STAC "\n" \
20148 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20149 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20150 "2:\t" ASM_CLAC "\n" \
20151 "\t.section .fixup, \"ax\"\n" \
20152 "3:\tmov %3, %0\n" \
20153 "\tjmp 2b\n" \
20154 "\t.previous\n" \
20155 _ASM_EXTABLE(1b, 3b) \
20156 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20157 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20158 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20159 : "memory" \
20160 ); \
20161 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20162 case 4: \
20163 { \
20164 asm volatile("\t" ASM_STAC "\n" \
20165 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20166 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20167 "2:\t" ASM_CLAC "\n" \
20168 "\t.section .fixup, \"ax\"\n" \
20169 "3:\tmov %3, %0\n" \
20170 "\tjmp 2b\n" \
20171 "\t.previous\n" \
20172 _ASM_EXTABLE(1b, 3b) \
20173 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20174 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20175 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20176 : "memory" \
20177 ); \
20178 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20179 __cmpxchg_wrong_size(); \
20180 \
20181 asm volatile("\t" ASM_STAC "\n" \
20182 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20183 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20184 "2:\t" ASM_CLAC "\n" \
20185 "\t.section .fixup, \"ax\"\n" \
20186 "3:\tmov %3, %0\n" \
20187 "\tjmp 2b\n" \
20188 "\t.previous\n" \
20189 _ASM_EXTABLE(1b, 3b) \
20190 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20191 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20192 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20193 : "memory" \
20194 ); \
20195 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20196 default: \
20197 __cmpxchg_wrong_size(); \
20198 } \
20199 + pax_close_userland(); \
20200 *__uval = __old; \
20201 __ret; \
20202 })
20203 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20204
20205 #define ARCH_HAS_NOCACHE_UACCESS 1
20206
20207 -#ifdef CONFIG_X86_32
20208 -# include <asm/uaccess_32.h>
20209 -#else
20210 -# include <asm/uaccess_64.h>
20211 -#endif
20212 -
20213 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20214 - unsigned n);
20215 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20216 - unsigned n);
20217 -
20218 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20219 # define copy_user_diag __compiletime_error
20220 #else
20221 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20222 extern void copy_user_diag("copy_from_user() buffer size is too small")
20223 copy_from_user_overflow(void);
20224 extern void copy_user_diag("copy_to_user() buffer size is too small")
20225 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20226 +copy_to_user_overflow(void);
20227
20228 #undef copy_user_diag
20229
20230 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20231
20232 extern void
20233 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20234 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20235 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20236 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20237
20238 #else
20239 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20240
20241 #endif
20242
20243 +#ifdef CONFIG_X86_32
20244 +# include <asm/uaccess_32.h>
20245 +#else
20246 +# include <asm/uaccess_64.h>
20247 +#endif
20248 +
20249 static inline unsigned long __must_check
20250 copy_from_user(void *to, const void __user *from, unsigned long n)
20251 {
20252 - int sz = __compiletime_object_size(to);
20253 + size_t sz = __compiletime_object_size(to);
20254
20255 might_fault();
20256
20257 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20258 * case, and do only runtime checking for non-constant sizes.
20259 */
20260
20261 - if (likely(sz < 0 || sz >= n))
20262 - n = _copy_from_user(to, from, n);
20263 - else if(__builtin_constant_p(n))
20264 - copy_from_user_overflow();
20265 - else
20266 - __copy_from_user_overflow(sz, n);
20267 + if (likely(sz != (size_t)-1 && sz < n)) {
20268 + if(__builtin_constant_p(n))
20269 + copy_from_user_overflow();
20270 + else
20271 + __copy_from_user_overflow(sz, n);
20272 + } else if (access_ok(VERIFY_READ, from, n))
20273 + n = __copy_from_user(to, from, n);
20274 + else if ((long)n > 0)
20275 + memset(to, 0, n);
20276
20277 return n;
20278 }
20279 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20280 static inline unsigned long __must_check
20281 copy_to_user(void __user *to, const void *from, unsigned long n)
20282 {
20283 - int sz = __compiletime_object_size(from);
20284 + size_t sz = __compiletime_object_size(from);
20285
20286 might_fault();
20287
20288 /* See the comment in copy_from_user() above. */
20289 - if (likely(sz < 0 || sz >= n))
20290 - n = _copy_to_user(to, from, n);
20291 - else if(__builtin_constant_p(n))
20292 - copy_to_user_overflow();
20293 - else
20294 - __copy_to_user_overflow(sz, n);
20295 + if (likely(sz != (size_t)-1 && sz < n)) {
20296 + if(__builtin_constant_p(n))
20297 + copy_to_user_overflow();
20298 + else
20299 + __copy_to_user_overflow(sz, n);
20300 + } else if (access_ok(VERIFY_WRITE, to, n))
20301 + n = __copy_to_user(to, from, n);
20302
20303 return n;
20304 }
20305 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20306 index 3c03a5d..1071638 100644
20307 --- a/arch/x86/include/asm/uaccess_32.h
20308 +++ b/arch/x86/include/asm/uaccess_32.h
20309 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20310 static __always_inline unsigned long __must_check
20311 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20312 {
20313 + if ((long)n < 0)
20314 + return n;
20315 +
20316 + check_object_size(from, n, true);
20317 +
20318 if (__builtin_constant_p(n)) {
20319 unsigned long ret;
20320
20321 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20322 __copy_to_user(void __user *to, const void *from, unsigned long n)
20323 {
20324 might_fault();
20325 +
20326 return __copy_to_user_inatomic(to, from, n);
20327 }
20328
20329 static __always_inline unsigned long
20330 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20331 {
20332 + if ((long)n < 0)
20333 + return n;
20334 +
20335 /* Avoid zeroing the tail if the copy fails..
20336 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20337 * but as the zeroing behaviour is only significant when n is not
20338 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20339 __copy_from_user(void *to, const void __user *from, unsigned long n)
20340 {
20341 might_fault();
20342 +
20343 + if ((long)n < 0)
20344 + return n;
20345 +
20346 + check_object_size(to, n, false);
20347 +
20348 if (__builtin_constant_p(n)) {
20349 unsigned long ret;
20350
20351 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20352 const void __user *from, unsigned long n)
20353 {
20354 might_fault();
20355 +
20356 + if ((long)n < 0)
20357 + return n;
20358 +
20359 if (__builtin_constant_p(n)) {
20360 unsigned long ret;
20361
20362 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20363 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20364 unsigned long n)
20365 {
20366 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20367 + if ((long)n < 0)
20368 + return n;
20369 +
20370 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20371 }
20372
20373 #endif /* _ASM_X86_UACCESS_32_H */
20374 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20375 index 12a26b9..206c200 100644
20376 --- a/arch/x86/include/asm/uaccess_64.h
20377 +++ b/arch/x86/include/asm/uaccess_64.h
20378 @@ -10,6 +10,9 @@
20379 #include <asm/alternative.h>
20380 #include <asm/cpufeature.h>
20381 #include <asm/page.h>
20382 +#include <asm/pgtable.h>
20383 +
20384 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20385
20386 /*
20387 * Copy To/From Userspace
20388 @@ -17,14 +20,14 @@
20389
20390 /* Handles exceptions in both to and from, but doesn't do access_ok */
20391 __must_check unsigned long
20392 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20393 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20394 __must_check unsigned long
20395 -copy_user_generic_string(void *to, const void *from, unsigned len);
20396 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20397 __must_check unsigned long
20398 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20399 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20400
20401 static __always_inline __must_check unsigned long
20402 -copy_user_generic(void *to, const void *from, unsigned len)
20403 +copy_user_generic(void *to, const void *from, unsigned long len)
20404 {
20405 unsigned ret;
20406
20407 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20408 }
20409
20410 __must_check unsigned long
20411 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20412 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20413
20414 static __always_inline __must_check
20415 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20416 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20417 {
20418 - int ret = 0;
20419 + size_t sz = __compiletime_object_size(dst);
20420 + unsigned ret = 0;
20421 +
20422 + if (size > INT_MAX)
20423 + return size;
20424 +
20425 + check_object_size(dst, size, false);
20426 +
20427 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20428 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20429 + return size;
20430 +#endif
20431 +
20432 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20433 + if(__builtin_constant_p(size))
20434 + copy_from_user_overflow();
20435 + else
20436 + __copy_from_user_overflow(sz, size);
20437 + return size;
20438 + }
20439
20440 if (!__builtin_constant_p(size))
20441 - return copy_user_generic(dst, (__force void *)src, size);
20442 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20443 switch (size) {
20444 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20445 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20446 ret, "b", "b", "=q", 1);
20447 return ret;
20448 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20449 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20450 ret, "w", "w", "=r", 2);
20451 return ret;
20452 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20453 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20454 ret, "l", "k", "=r", 4);
20455 return ret;
20456 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20457 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20458 ret, "q", "", "=r", 8);
20459 return ret;
20460 case 10:
20461 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20462 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20463 ret, "q", "", "=r", 10);
20464 if (unlikely(ret))
20465 return ret;
20466 __get_user_asm(*(u16 *)(8 + (char *)dst),
20467 - (u16 __user *)(8 + (char __user *)src),
20468 + (const u16 __user *)(8 + (const char __user *)src),
20469 ret, "w", "w", "=r", 2);
20470 return ret;
20471 case 16:
20472 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20473 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20474 ret, "q", "", "=r", 16);
20475 if (unlikely(ret))
20476 return ret;
20477 __get_user_asm(*(u64 *)(8 + (char *)dst),
20478 - (u64 __user *)(8 + (char __user *)src),
20479 + (const u64 __user *)(8 + (const char __user *)src),
20480 ret, "q", "", "=r", 8);
20481 return ret;
20482 default:
20483 - return copy_user_generic(dst, (__force void *)src, size);
20484 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20485 }
20486 }
20487
20488 static __always_inline __must_check
20489 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20490 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20491 {
20492 might_fault();
20493 return __copy_from_user_nocheck(dst, src, size);
20494 }
20495
20496 static __always_inline __must_check
20497 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20498 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20499 {
20500 - int ret = 0;
20501 + size_t sz = __compiletime_object_size(src);
20502 + unsigned ret = 0;
20503 +
20504 + if (size > INT_MAX)
20505 + return size;
20506 +
20507 + check_object_size(src, size, true);
20508 +
20509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20510 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20511 + return size;
20512 +#endif
20513 +
20514 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20515 + if(__builtin_constant_p(size))
20516 + copy_to_user_overflow();
20517 + else
20518 + __copy_to_user_overflow(sz, size);
20519 + return size;
20520 + }
20521
20522 if (!__builtin_constant_p(size))
20523 - return copy_user_generic((__force void *)dst, src, size);
20524 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20525 switch (size) {
20526 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20527 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20528 ret, "b", "b", "iq", 1);
20529 return ret;
20530 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20531 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20532 ret, "w", "w", "ir", 2);
20533 return ret;
20534 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20535 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20536 ret, "l", "k", "ir", 4);
20537 return ret;
20538 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20539 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20540 ret, "q", "", "er", 8);
20541 return ret;
20542 case 10:
20543 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20544 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20545 ret, "q", "", "er", 10);
20546 if (unlikely(ret))
20547 return ret;
20548 asm("":::"memory");
20549 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20550 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20551 ret, "w", "w", "ir", 2);
20552 return ret;
20553 case 16:
20554 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20555 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20556 ret, "q", "", "er", 16);
20557 if (unlikely(ret))
20558 return ret;
20559 asm("":::"memory");
20560 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20561 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20562 ret, "q", "", "er", 8);
20563 return ret;
20564 default:
20565 - return copy_user_generic((__force void *)dst, src, size);
20566 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20567 }
20568 }
20569
20570 static __always_inline __must_check
20571 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20572 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20573 {
20574 might_fault();
20575 return __copy_to_user_nocheck(dst, src, size);
20576 }
20577
20578 static __always_inline __must_check
20579 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20580 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20581 {
20582 - int ret = 0;
20583 + unsigned ret = 0;
20584
20585 might_fault();
20586 +
20587 + if (size > INT_MAX)
20588 + return size;
20589 +
20590 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20591 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20592 + return size;
20593 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20594 + return size;
20595 +#endif
20596 +
20597 if (!__builtin_constant_p(size))
20598 - return copy_user_generic((__force void *)dst,
20599 - (__force void *)src, size);
20600 + return copy_user_generic((__force_kernel void *)____m(dst),
20601 + (__force_kernel const void *)____m(src), size);
20602 switch (size) {
20603 case 1: {
20604 u8 tmp;
20605 - __get_user_asm(tmp, (u8 __user *)src,
20606 + __get_user_asm(tmp, (const u8 __user *)src,
20607 ret, "b", "b", "=q", 1);
20608 if (likely(!ret))
20609 __put_user_asm(tmp, (u8 __user *)dst,
20610 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20611 }
20612 case 2: {
20613 u16 tmp;
20614 - __get_user_asm(tmp, (u16 __user *)src,
20615 + __get_user_asm(tmp, (const u16 __user *)src,
20616 ret, "w", "w", "=r", 2);
20617 if (likely(!ret))
20618 __put_user_asm(tmp, (u16 __user *)dst,
20619 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20620
20621 case 4: {
20622 u32 tmp;
20623 - __get_user_asm(tmp, (u32 __user *)src,
20624 + __get_user_asm(tmp, (const u32 __user *)src,
20625 ret, "l", "k", "=r", 4);
20626 if (likely(!ret))
20627 __put_user_asm(tmp, (u32 __user *)dst,
20628 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20629 }
20630 case 8: {
20631 u64 tmp;
20632 - __get_user_asm(tmp, (u64 __user *)src,
20633 + __get_user_asm(tmp, (const u64 __user *)src,
20634 ret, "q", "", "=r", 8);
20635 if (likely(!ret))
20636 __put_user_asm(tmp, (u64 __user *)dst,
20637 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20638 return ret;
20639 }
20640 default:
20641 - return copy_user_generic((__force void *)dst,
20642 - (__force void *)src, size);
20643 + return copy_user_generic((__force_kernel void *)____m(dst),
20644 + (__force_kernel const void *)____m(src), size);
20645 }
20646 }
20647
20648 -static __must_check __always_inline int
20649 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20650 +static __must_check __always_inline unsigned long
20651 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20652 {
20653 return __copy_from_user_nocheck(dst, src, size);
20654 }
20655
20656 -static __must_check __always_inline int
20657 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20658 +static __must_check __always_inline unsigned long
20659 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20660 {
20661 return __copy_to_user_nocheck(dst, src, size);
20662 }
20663
20664 -extern long __copy_user_nocache(void *dst, const void __user *src,
20665 - unsigned size, int zerorest);
20666 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20667 + unsigned long size, int zerorest);
20668
20669 -static inline int
20670 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20671 +static inline unsigned long
20672 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20673 {
20674 might_fault();
20675 +
20676 + if (size > INT_MAX)
20677 + return size;
20678 +
20679 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20680 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20681 + return size;
20682 +#endif
20683 +
20684 return __copy_user_nocache(dst, src, size, 1);
20685 }
20686
20687 -static inline int
20688 +static inline unsigned long
20689 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20690 - unsigned size)
20691 + unsigned long size)
20692 {
20693 + if (size > INT_MAX)
20694 + return size;
20695 +
20696 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20697 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20698 + return size;
20699 +#endif
20700 +
20701 return __copy_user_nocache(dst, src, size, 0);
20702 }
20703
20704 unsigned long
20705 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20706 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20707
20708 #endif /* _ASM_X86_UACCESS_64_H */
20709 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20710 index 5b238981..77fdd78 100644
20711 --- a/arch/x86/include/asm/word-at-a-time.h
20712 +++ b/arch/x86/include/asm/word-at-a-time.h
20713 @@ -11,7 +11,7 @@
20714 * and shift, for example.
20715 */
20716 struct word_at_a_time {
20717 - const unsigned long one_bits, high_bits;
20718 + unsigned long one_bits, high_bits;
20719 };
20720
20721 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20722 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20723 index e45e4da..44e8572 100644
20724 --- a/arch/x86/include/asm/x86_init.h
20725 +++ b/arch/x86/include/asm/x86_init.h
20726 @@ -129,7 +129,7 @@ struct x86_init_ops {
20727 struct x86_init_timers timers;
20728 struct x86_init_iommu iommu;
20729 struct x86_init_pci pci;
20730 -};
20731 +} __no_const;
20732
20733 /**
20734 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20735 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20736 void (*setup_percpu_clockev)(void);
20737 void (*early_percpu_clock_init)(void);
20738 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20739 -};
20740 +} __no_const;
20741
20742 struct timespec;
20743
20744 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20745 void (*save_sched_clock_state)(void);
20746 void (*restore_sched_clock_state)(void);
20747 void (*apic_post_init)(void);
20748 -};
20749 +} __no_const;
20750
20751 struct pci_dev;
20752 struct msi_msg;
20753 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20754 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20755 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20756 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20757 -};
20758 +} __no_const;
20759
20760 struct IO_APIC_route_entry;
20761 struct io_apic_irq_attr;
20762 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20763 unsigned int destination, int vector,
20764 struct io_apic_irq_attr *attr);
20765 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20766 -};
20767 +} __no_const;
20768
20769 extern struct x86_init_ops x86_init;
20770 extern struct x86_cpuinit_ops x86_cpuinit;
20771 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20772 index c949923..c22bfa4 100644
20773 --- a/arch/x86/include/asm/xen/page.h
20774 +++ b/arch/x86/include/asm/xen/page.h
20775 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20776 extern struct page *m2p_find_override(unsigned long mfn);
20777 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20778
20779 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20780 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20781 {
20782 unsigned long mfn;
20783
20784 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20785 index d949ef2..479b9d1 100644
20786 --- a/arch/x86/include/asm/xsave.h
20787 +++ b/arch/x86/include/asm/xsave.h
20788 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20789 if (unlikely(err))
20790 return -EFAULT;
20791
20792 + pax_open_userland();
20793 __asm__ __volatile__(ASM_STAC "\n"
20794 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20795 + "1:"
20796 + __copyuser_seg
20797 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20798 "2: " ASM_CLAC "\n"
20799 ".section .fixup,\"ax\"\n"
20800 "3: movl $-1,%[err]\n"
20801 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20802 : [err] "=r" (err)
20803 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20804 : "memory");
20805 + pax_close_userland();
20806 return err;
20807 }
20808
20809 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20810 {
20811 int err;
20812 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20813 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20814 u32 lmask = mask;
20815 u32 hmask = mask >> 32;
20816
20817 + pax_open_userland();
20818 __asm__ __volatile__(ASM_STAC "\n"
20819 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20820 + "1:"
20821 + __copyuser_seg
20822 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20823 "2: " ASM_CLAC "\n"
20824 ".section .fixup,\"ax\"\n"
20825 "3: movl $-1,%[err]\n"
20826 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20827 : [err] "=r" (err)
20828 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20829 : "memory"); /* memory required? */
20830 + pax_close_userland();
20831 return err;
20832 }
20833
20834 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20835 index bbae024..e1528f9 100644
20836 --- a/arch/x86/include/uapi/asm/e820.h
20837 +++ b/arch/x86/include/uapi/asm/e820.h
20838 @@ -63,7 +63,7 @@ struct e820map {
20839 #define ISA_START_ADDRESS 0xa0000
20840 #define ISA_END_ADDRESS 0x100000
20841
20842 -#define BIOS_BEGIN 0x000a0000
20843 +#define BIOS_BEGIN 0x000c0000
20844 #define BIOS_END 0x00100000
20845
20846 #define BIOS_ROM_BASE 0xffe00000
20847 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20848 index 7b0a55a..ad115bf 100644
20849 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20850 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20851 @@ -49,7 +49,6 @@
20852 #define EFLAGS 144
20853 #define RSP 152
20854 #define SS 160
20855 -#define ARGOFFSET R11
20856 #endif /* __ASSEMBLY__ */
20857
20858 /* top of stack page */
20859 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20860 index 047f9ff..4ba5ea6 100644
20861 --- a/arch/x86/kernel/Makefile
20862 +++ b/arch/x86/kernel/Makefile
20863 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20864 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20865 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20866 obj-y += probe_roms.o
20867 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20868 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20869 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20870 obj-$(CONFIG_X86_64) += mcount_64.o
20871 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20872 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20873 index 86281ff..e046fc2 100644
20874 --- a/arch/x86/kernel/acpi/boot.c
20875 +++ b/arch/x86/kernel/acpi/boot.c
20876 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20877 * If your system is blacklisted here, but you find that acpi=force
20878 * works for you, please contact linux-acpi@vger.kernel.org
20879 */
20880 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20881 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20882 /*
20883 * Boxes that need ACPI disabled
20884 */
20885 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20886 };
20887
20888 /* second table for DMI checks that should run after early-quirks */
20889 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20890 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20891 /*
20892 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20893 * which includes some code which overrides all temperature
20894 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20895 index 3136820..e2c6577 100644
20896 --- a/arch/x86/kernel/acpi/sleep.c
20897 +++ b/arch/x86/kernel/acpi/sleep.c
20898 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20899 #else /* CONFIG_64BIT */
20900 #ifdef CONFIG_SMP
20901 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20902 +
20903 + pax_open_kernel();
20904 early_gdt_descr.address =
20905 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20906 + pax_close_kernel();
20907 +
20908 initial_gs = per_cpu_offset(smp_processor_id());
20909 #endif
20910 initial_code = (unsigned long)wakeup_long64;
20911 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20912 index 665c6b7..eae4d56 100644
20913 --- a/arch/x86/kernel/acpi/wakeup_32.S
20914 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20915 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20916 # and restore the stack ... but you need gdt for this to work
20917 movl saved_context_esp, %esp
20918
20919 - movl %cs:saved_magic, %eax
20920 - cmpl $0x12345678, %eax
20921 + cmpl $0x12345678, saved_magic
20922 jne bogus_magic
20923
20924 # jump to place where we left off
20925 - movl saved_eip, %eax
20926 - jmp *%eax
20927 + jmp *(saved_eip)
20928
20929 bogus_magic:
20930 jmp bogus_magic
20931 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20932 index 703130f..27a155d 100644
20933 --- a/arch/x86/kernel/alternative.c
20934 +++ b/arch/x86/kernel/alternative.c
20935 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20936 */
20937 for (a = start; a < end; a++) {
20938 instr = (u8 *)&a->instr_offset + a->instr_offset;
20939 +
20940 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20941 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20942 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20943 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20944 +#endif
20945 +
20946 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20947 BUG_ON(a->replacementlen > a->instrlen);
20948 BUG_ON(a->instrlen > sizeof(insnbuf));
20949 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20950 add_nops(insnbuf + a->replacementlen,
20951 a->instrlen - a->replacementlen);
20952
20953 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20954 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20955 + instr = ktva_ktla(instr);
20956 +#endif
20957 +
20958 text_poke_early(instr, insnbuf, a->instrlen);
20959 }
20960 }
20961 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20962 for (poff = start; poff < end; poff++) {
20963 u8 *ptr = (u8 *)poff + *poff;
20964
20965 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20966 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20967 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20968 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20969 +#endif
20970 +
20971 if (!*poff || ptr < text || ptr >= text_end)
20972 continue;
20973 /* turn DS segment override prefix into lock prefix */
20974 - if (*ptr == 0x3e)
20975 + if (*ktla_ktva(ptr) == 0x3e)
20976 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20977 }
20978 mutex_unlock(&text_mutex);
20979 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20980 for (poff = start; poff < end; poff++) {
20981 u8 *ptr = (u8 *)poff + *poff;
20982
20983 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20984 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20985 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20986 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20987 +#endif
20988 +
20989 if (!*poff || ptr < text || ptr >= text_end)
20990 continue;
20991 /* turn lock prefix into DS segment override prefix */
20992 - if (*ptr == 0xf0)
20993 + if (*ktla_ktva(ptr) == 0xf0)
20994 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20995 }
20996 mutex_unlock(&text_mutex);
20997 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20998
20999 BUG_ON(p->len > MAX_PATCH_LEN);
21000 /* prep the buffer with the original instructions */
21001 - memcpy(insnbuf, p->instr, p->len);
21002 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21003 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21004 (unsigned long)p->instr, p->len);
21005
21006 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21007 if (!uniproc_patched || num_possible_cpus() == 1)
21008 free_init_pages("SMP alternatives",
21009 (unsigned long)__smp_locks,
21010 - (unsigned long)__smp_locks_end);
21011 + PAGE_ALIGN((unsigned long)__smp_locks_end));
21012 #endif
21013
21014 apply_paravirt(__parainstructions, __parainstructions_end);
21015 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21016 * instructions. And on the local CPU you need to be protected again NMI or MCE
21017 * handlers seeing an inconsistent instruction while you patch.
21018 */
21019 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
21020 +void *__kprobes text_poke_early(void *addr, const void *opcode,
21021 size_t len)
21022 {
21023 unsigned long flags;
21024 local_irq_save(flags);
21025 - memcpy(addr, opcode, len);
21026 +
21027 + pax_open_kernel();
21028 + memcpy(ktla_ktva(addr), opcode, len);
21029 sync_core();
21030 + pax_close_kernel();
21031 +
21032 local_irq_restore(flags);
21033 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21034 that causes hangs on some VIA CPUs. */
21035 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21036 */
21037 void *text_poke(void *addr, const void *opcode, size_t len)
21038 {
21039 - unsigned long flags;
21040 - char *vaddr;
21041 + unsigned char *vaddr = ktla_ktva(addr);
21042 struct page *pages[2];
21043 - int i;
21044 + size_t i;
21045
21046 if (!core_kernel_text((unsigned long)addr)) {
21047 - pages[0] = vmalloc_to_page(addr);
21048 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21049 + pages[0] = vmalloc_to_page(vaddr);
21050 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21051 } else {
21052 - pages[0] = virt_to_page(addr);
21053 + pages[0] = virt_to_page(vaddr);
21054 WARN_ON(!PageReserved(pages[0]));
21055 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21056 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21057 }
21058 BUG_ON(!pages[0]);
21059 - local_irq_save(flags);
21060 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21061 - if (pages[1])
21062 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21063 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21064 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21065 - clear_fixmap(FIX_TEXT_POKE0);
21066 - if (pages[1])
21067 - clear_fixmap(FIX_TEXT_POKE1);
21068 - local_flush_tlb();
21069 - sync_core();
21070 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21071 - that causes hangs on some VIA CPUs. */
21072 + text_poke_early(addr, opcode, len);
21073 for (i = 0; i < len; i++)
21074 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21075 - local_irq_restore(flags);
21076 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21077 return addr;
21078 }
21079
21080 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21081 if (likely(!bp_patching_in_progress))
21082 return 0;
21083
21084 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21085 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21086 return 0;
21087
21088 /* set up the specified breakpoint handler */
21089 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21090 */
21091 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21092 {
21093 - unsigned char int3 = 0xcc;
21094 + const unsigned char int3 = 0xcc;
21095
21096 bp_int3_handler = handler;
21097 bp_int3_addr = (u8 *)addr + sizeof(int3);
21098 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21099 index ad28db7..c538b2c 100644
21100 --- a/arch/x86/kernel/apic/apic.c
21101 +++ b/arch/x86/kernel/apic/apic.c
21102 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21103 /*
21104 * Debug level, exported for io_apic.c
21105 */
21106 -unsigned int apic_verbosity;
21107 +int apic_verbosity;
21108
21109 int pic_mode;
21110
21111 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21112 apic_write(APIC_ESR, 0);
21113 v = apic_read(APIC_ESR);
21114 ack_APIC_irq();
21115 - atomic_inc(&irq_err_count);
21116 + atomic_inc_unchecked(&irq_err_count);
21117
21118 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21119 smp_processor_id(), v);
21120 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21121 index 7c1b294..e71d27f 100644
21122 --- a/arch/x86/kernel/apic/apic_flat_64.c
21123 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21124 @@ -154,7 +154,7 @@ static int flat_probe(void)
21125 return 1;
21126 }
21127
21128 -static struct apic apic_flat = {
21129 +static struct apic apic_flat __read_only = {
21130 .name = "flat",
21131 .probe = flat_probe,
21132 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21133 @@ -268,7 +268,7 @@ static int physflat_probe(void)
21134 return 0;
21135 }
21136
21137 -static struct apic apic_physflat = {
21138 +static struct apic apic_physflat __read_only = {
21139
21140 .name = "physical flat",
21141 .probe = physflat_probe,
21142 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21143 index 8c7c982..a225910 100644
21144 --- a/arch/x86/kernel/apic/apic_noop.c
21145 +++ b/arch/x86/kernel/apic/apic_noop.c
21146 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
21147 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21148 }
21149
21150 -struct apic apic_noop = {
21151 +struct apic apic_noop __read_only = {
21152 .name = "noop",
21153 .probe = noop_probe,
21154 .acpi_madt_oem_check = NULL,
21155 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21156 index e4840aa..e7d9dac 100644
21157 --- a/arch/x86/kernel/apic/bigsmp_32.c
21158 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21159 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
21160 return dmi_bigsmp;
21161 }
21162
21163 -static struct apic apic_bigsmp = {
21164 +static struct apic apic_bigsmp __read_only = {
21165
21166 .name = "bigsmp",
21167 .probe = probe_bigsmp,
21168 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21169 index 81e08ef..abc77e5 100644
21170 --- a/arch/x86/kernel/apic/io_apic.c
21171 +++ b/arch/x86/kernel/apic/io_apic.c
21172 @@ -1042,7 +1042,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
21173 }
21174 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21175
21176 -void lock_vector_lock(void)
21177 +void lock_vector_lock(void) __acquires(vector_lock)
21178 {
21179 /* Used to the online set of cpus does not change
21180 * during assign_irq_vector.
21181 @@ -1050,7 +1050,7 @@ void lock_vector_lock(void)
21182 raw_spin_lock(&vector_lock);
21183 }
21184
21185 -void unlock_vector_lock(void)
21186 +void unlock_vector_lock(void) __releases(vector_lock)
21187 {
21188 raw_spin_unlock(&vector_lock);
21189 }
21190 @@ -2349,7 +2349,7 @@ static void ack_apic_edge(struct irq_data *data)
21191 ack_APIC_irq();
21192 }
21193
21194 -atomic_t irq_mis_count;
21195 +atomic_unchecked_t irq_mis_count;
21196
21197 #ifdef CONFIG_GENERIC_PENDING_IRQ
21198 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21199 @@ -2490,7 +2490,7 @@ static void ack_apic_level(struct irq_data *data)
21200 * at the cpu.
21201 */
21202 if (!(v & (1 << (i & 0x1f)))) {
21203 - atomic_inc(&irq_mis_count);
21204 + atomic_inc_unchecked(&irq_mis_count);
21205
21206 eoi_ioapic_irq(irq, cfg);
21207 }
21208 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21209 index cceb352..a635fd8 100644
21210 --- a/arch/x86/kernel/apic/probe_32.c
21211 +++ b/arch/x86/kernel/apic/probe_32.c
21212 @@ -72,7 +72,7 @@ static int probe_default(void)
21213 return 1;
21214 }
21215
21216 -static struct apic apic_default = {
21217 +static struct apic apic_default __read_only = {
21218
21219 .name = "default",
21220 .probe = probe_default,
21221 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21222 index e66766b..1c008ba 100644
21223 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21224 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21225 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21226 return notifier_from_errno(err);
21227 }
21228
21229 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21230 +static struct notifier_block x2apic_cpu_notifier = {
21231 .notifier_call = update_clusterinfo,
21232 };
21233
21234 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21235 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21236 }
21237
21238 -static struct apic apic_x2apic_cluster = {
21239 +static struct apic apic_x2apic_cluster __read_only = {
21240
21241 .name = "cluster x2apic",
21242 .probe = x2apic_cluster_probe,
21243 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21244 index 6d600eb..0300c00 100644
21245 --- a/arch/x86/kernel/apic/x2apic_phys.c
21246 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21247 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21248 return apic == &apic_x2apic_phys;
21249 }
21250
21251 -static struct apic apic_x2apic_phys = {
21252 +static struct apic apic_x2apic_phys __read_only = {
21253
21254 .name = "physical x2apic",
21255 .probe = x2apic_phys_probe,
21256 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21257 index 293b41d..4df25fd 100644
21258 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21259 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21260 @@ -350,7 +350,7 @@ static int uv_probe(void)
21261 return apic == &apic_x2apic_uv_x;
21262 }
21263
21264 -static struct apic __refdata apic_x2apic_uv_x = {
21265 +static struct apic apic_x2apic_uv_x __read_only = {
21266
21267 .name = "UV large system",
21268 .probe = uv_probe,
21269 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21270 index 5848744..56cb598 100644
21271 --- a/arch/x86/kernel/apm_32.c
21272 +++ b/arch/x86/kernel/apm_32.c
21273 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21274 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21275 * even though they are called in protected mode.
21276 */
21277 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21278 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21279 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21280
21281 static const char driver_version[] = "1.16ac"; /* no spaces */
21282 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21283 BUG_ON(cpu != 0);
21284 gdt = get_cpu_gdt_table(cpu);
21285 save_desc_40 = gdt[0x40 / 8];
21286 +
21287 + pax_open_kernel();
21288 gdt[0x40 / 8] = bad_bios_desc;
21289 + pax_close_kernel();
21290
21291 apm_irq_save(flags);
21292 APM_DO_SAVE_SEGS;
21293 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21294 &call->esi);
21295 APM_DO_RESTORE_SEGS;
21296 apm_irq_restore(flags);
21297 +
21298 + pax_open_kernel();
21299 gdt[0x40 / 8] = save_desc_40;
21300 + pax_close_kernel();
21301 +
21302 put_cpu();
21303
21304 return call->eax & 0xff;
21305 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21306 BUG_ON(cpu != 0);
21307 gdt = get_cpu_gdt_table(cpu);
21308 save_desc_40 = gdt[0x40 / 8];
21309 +
21310 + pax_open_kernel();
21311 gdt[0x40 / 8] = bad_bios_desc;
21312 + pax_close_kernel();
21313
21314 apm_irq_save(flags);
21315 APM_DO_SAVE_SEGS;
21316 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21317 &call->eax);
21318 APM_DO_RESTORE_SEGS;
21319 apm_irq_restore(flags);
21320 +
21321 + pax_open_kernel();
21322 gdt[0x40 / 8] = save_desc_40;
21323 + pax_close_kernel();
21324 +
21325 put_cpu();
21326 return error;
21327 }
21328 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21329 * code to that CPU.
21330 */
21331 gdt = get_cpu_gdt_table(0);
21332 +
21333 + pax_open_kernel();
21334 set_desc_base(&gdt[APM_CS >> 3],
21335 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21336 set_desc_base(&gdt[APM_CS_16 >> 3],
21337 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21338 set_desc_base(&gdt[APM_DS >> 3],
21339 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21340 + pax_close_kernel();
21341
21342 proc_create("apm", 0, NULL, &apm_file_ops);
21343
21344 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21345 index 9f6b934..cf5ffb3 100644
21346 --- a/arch/x86/kernel/asm-offsets.c
21347 +++ b/arch/x86/kernel/asm-offsets.c
21348 @@ -32,6 +32,8 @@ void common(void) {
21349 OFFSET(TI_flags, thread_info, flags);
21350 OFFSET(TI_status, thread_info, status);
21351 OFFSET(TI_addr_limit, thread_info, addr_limit);
21352 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21353 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21354
21355 BLANK();
21356 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21357 @@ -52,8 +54,26 @@ void common(void) {
21358 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21359 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21360 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21361 +
21362 +#ifdef CONFIG_PAX_KERNEXEC
21363 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21364 #endif
21365
21366 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21367 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21368 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21369 +#ifdef CONFIG_X86_64
21370 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21371 +#endif
21372 +#endif
21373 +
21374 +#endif
21375 +
21376 + BLANK();
21377 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21378 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21379 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21380 +
21381 #ifdef CONFIG_XEN
21382 BLANK();
21383 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21384 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21385 index e7c798b..2b2019b 100644
21386 --- a/arch/x86/kernel/asm-offsets_64.c
21387 +++ b/arch/x86/kernel/asm-offsets_64.c
21388 @@ -77,6 +77,7 @@ int main(void)
21389 BLANK();
21390 #undef ENTRY
21391
21392 + DEFINE(TSS_size, sizeof(struct tss_struct));
21393 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21394 BLANK();
21395
21396 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21397 index 7fd54f0..0691410 100644
21398 --- a/arch/x86/kernel/cpu/Makefile
21399 +++ b/arch/x86/kernel/cpu/Makefile
21400 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21401 CFLAGS_REMOVE_perf_event.o = -pg
21402 endif
21403
21404 -# Make sure load_percpu_segment has no stackprotector
21405 -nostackp := $(call cc-option, -fno-stack-protector)
21406 -CFLAGS_common.o := $(nostackp)
21407 -
21408 obj-y := intel_cacheinfo.o scattered.o topology.o
21409 obj-y += proc.o capflags.o powerflags.o common.o
21410 obj-y += rdrand.o
21411 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21412 index ce8b8ff..d7d8851 100644
21413 --- a/arch/x86/kernel/cpu/amd.c
21414 +++ b/arch/x86/kernel/cpu/amd.c
21415 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21416 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21417 {
21418 /* AMD errata T13 (order #21922) */
21419 - if ((c->x86 == 6)) {
21420 + if (c->x86 == 6) {
21421 /* Duron Rev A0 */
21422 if (c->x86_model == 3 && c->x86_mask == 0)
21423 size = 64;
21424 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21425 index ef1b93f..150db65 100644
21426 --- a/arch/x86/kernel/cpu/common.c
21427 +++ b/arch/x86/kernel/cpu/common.c
21428 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21429
21430 static const struct cpu_dev *this_cpu = &default_cpu;
21431
21432 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21433 -#ifdef CONFIG_X86_64
21434 - /*
21435 - * We need valid kernel segments for data and code in long mode too
21436 - * IRET will check the segment types kkeil 2000/10/28
21437 - * Also sysret mandates a special GDT layout
21438 - *
21439 - * TLS descriptors are currently at a different place compared to i386.
21440 - * Hopefully nobody expects them at a fixed place (Wine?)
21441 - */
21442 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21443 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21444 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21445 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21446 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21447 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21448 -#else
21449 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21450 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21451 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21452 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21453 - /*
21454 - * Segments used for calling PnP BIOS have byte granularity.
21455 - * They code segments and data segments have fixed 64k limits,
21456 - * the transfer segment sizes are set at run time.
21457 - */
21458 - /* 32-bit code */
21459 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21460 - /* 16-bit code */
21461 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21462 - /* 16-bit data */
21463 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21464 - /* 16-bit data */
21465 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21466 - /* 16-bit data */
21467 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21468 - /*
21469 - * The APM segments have byte granularity and their bases
21470 - * are set at run time. All have 64k limits.
21471 - */
21472 - /* 32-bit code */
21473 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21474 - /* 16-bit code */
21475 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21476 - /* data */
21477 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21478 -
21479 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21480 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21481 - GDT_STACK_CANARY_INIT
21482 -#endif
21483 -} };
21484 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21485 -
21486 static int __init x86_xsave_setup(char *s)
21487 {
21488 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21489 @@ -295,6 +241,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21490 }
21491 }
21492
21493 +#ifdef CONFIG_X86_64
21494 +static __init int setup_disable_pcid(char *arg)
21495 +{
21496 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21497 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21498 +
21499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21500 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21501 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21502 +#endif
21503 +
21504 + return 1;
21505 +}
21506 +__setup("nopcid", setup_disable_pcid);
21507 +
21508 +static void setup_pcid(struct cpuinfo_x86 *c)
21509 +{
21510 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21511 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21512 +
21513 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21514 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21515 + pax_open_kernel();
21516 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21517 + pax_close_kernel();
21518 + printk("PAX: slow and weak UDEREF enabled\n");
21519 + } else
21520 + printk("PAX: UDEREF disabled\n");
21521 +#endif
21522 +
21523 + return;
21524 + }
21525 +
21526 + printk("PAX: PCID detected\n");
21527 + set_in_cr4(X86_CR4_PCIDE);
21528 +
21529 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21530 + pax_open_kernel();
21531 + clone_pgd_mask = ~(pgdval_t)0UL;
21532 + pax_close_kernel();
21533 + if (pax_user_shadow_base)
21534 + printk("PAX: weak UDEREF enabled\n");
21535 + else {
21536 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21537 + printk("PAX: strong UDEREF enabled\n");
21538 + }
21539 +#endif
21540 +
21541 + if (cpu_has(c, X86_FEATURE_INVPCID))
21542 + printk("PAX: INVPCID detected\n");
21543 +}
21544 +#endif
21545 +
21546 /*
21547 * Some CPU features depend on higher CPUID levels, which may not always
21548 * be available due to CPUID level capping or broken virtualization
21549 @@ -395,7 +394,7 @@ void switch_to_new_gdt(int cpu)
21550 {
21551 struct desc_ptr gdt_descr;
21552
21553 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21554 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21555 gdt_descr.size = GDT_SIZE - 1;
21556 load_gdt(&gdt_descr);
21557 /* Reload the per-cpu base */
21558 @@ -885,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21559 setup_smep(c);
21560 setup_smap(c);
21561
21562 +#ifdef CONFIG_X86_64
21563 + setup_pcid(c);
21564 +#endif
21565 +
21566 /*
21567 * The vendor-specific functions might have changed features.
21568 * Now we do "generic changes."
21569 @@ -893,6 +896,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21570 /* Filter out anything that depends on CPUID levels we don't have */
21571 filter_cpuid_features(c, true);
21572
21573 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21574 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21575 +#endif
21576 +
21577 /* If the model name is still unset, do table lookup. */
21578 if (!c->x86_model_id[0]) {
21579 const char *p;
21580 @@ -973,7 +980,7 @@ static void syscall32_cpu_init(void)
21581 void enable_sep_cpu(void)
21582 {
21583 int cpu = get_cpu();
21584 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21585 + struct tss_struct *tss = init_tss + cpu;
21586
21587 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21588 put_cpu();
21589 @@ -1113,14 +1120,16 @@ static __init int setup_disablecpuid(char *arg)
21590 }
21591 __setup("clearcpuid=", setup_disablecpuid);
21592
21593 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21594 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21595 +
21596 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21597 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21598 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21599 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21600
21601 #ifdef CONFIG_X86_64
21602 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21603 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21604 - (unsigned long) debug_idt_table };
21605 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21606 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21607
21608 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21609 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21610 @@ -1283,7 +1292,7 @@ void cpu_init(void)
21611 load_ucode_ap();
21612
21613 cpu = stack_smp_processor_id();
21614 - t = &per_cpu(init_tss, cpu);
21615 + t = init_tss + cpu;
21616 oist = &per_cpu(orig_ist, cpu);
21617
21618 #ifdef CONFIG_NUMA
21619 @@ -1318,7 +1327,6 @@ void cpu_init(void)
21620 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21621 barrier();
21622
21623 - x86_configure_nx();
21624 enable_x2apic();
21625
21626 /*
21627 @@ -1370,7 +1378,7 @@ void cpu_init(void)
21628 {
21629 int cpu = smp_processor_id();
21630 struct task_struct *curr = current;
21631 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21632 + struct tss_struct *t = init_tss + cpu;
21633 struct thread_struct *thread = &curr->thread;
21634
21635 show_ucode_info_early();
21636 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21637 index 9c8f739..902a9c5 100644
21638 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21639 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21640 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21641 };
21642
21643 #ifdef CONFIG_AMD_NB
21644 +static struct attribute *default_attrs_amd_nb[] = {
21645 + &type.attr,
21646 + &level.attr,
21647 + &coherency_line_size.attr,
21648 + &physical_line_partition.attr,
21649 + &ways_of_associativity.attr,
21650 + &number_of_sets.attr,
21651 + &size.attr,
21652 + &shared_cpu_map.attr,
21653 + &shared_cpu_list.attr,
21654 + NULL,
21655 + NULL,
21656 + NULL,
21657 + NULL
21658 +};
21659 +
21660 static struct attribute **amd_l3_attrs(void)
21661 {
21662 static struct attribute **attrs;
21663 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21664
21665 n = ARRAY_SIZE(default_attrs);
21666
21667 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21668 - n += 2;
21669 -
21670 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21671 - n += 1;
21672 -
21673 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21674 - if (attrs == NULL)
21675 - return attrs = default_attrs;
21676 -
21677 - for (n = 0; default_attrs[n]; n++)
21678 - attrs[n] = default_attrs[n];
21679 + attrs = default_attrs_amd_nb;
21680
21681 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21682 attrs[n++] = &cache_disable_0.attr;
21683 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21684 .default_attrs = default_attrs,
21685 };
21686
21687 +#ifdef CONFIG_AMD_NB
21688 +static struct kobj_type ktype_cache_amd_nb = {
21689 + .sysfs_ops = &sysfs_ops,
21690 + .default_attrs = default_attrs_amd_nb,
21691 +};
21692 +#endif
21693 +
21694 static struct kobj_type ktype_percpu_entry = {
21695 .sysfs_ops = &sysfs_ops,
21696 };
21697 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21698 return retval;
21699 }
21700
21701 +#ifdef CONFIG_AMD_NB
21702 + amd_l3_attrs();
21703 +#endif
21704 +
21705 for (i = 0; i < num_cache_leaves; i++) {
21706 + struct kobj_type *ktype;
21707 +
21708 this_object = INDEX_KOBJECT_PTR(cpu, i);
21709 this_object->cpu = cpu;
21710 this_object->index = i;
21711
21712 this_leaf = CPUID4_INFO_IDX(cpu, i);
21713
21714 - ktype_cache.default_attrs = default_attrs;
21715 + ktype = &ktype_cache;
21716 #ifdef CONFIG_AMD_NB
21717 if (this_leaf->base.nb)
21718 - ktype_cache.default_attrs = amd_l3_attrs();
21719 + ktype = &ktype_cache_amd_nb;
21720 #endif
21721 retval = kobject_init_and_add(&(this_object->kobj),
21722 - &ktype_cache,
21723 + ktype,
21724 per_cpu(ici_cache_kobject, cpu),
21725 "index%1lu", i);
21726 if (unlikely(retval)) {
21727 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21728 index 9a79c8d..158c2f1 100644
21729 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21730 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21731 @@ -45,6 +45,7 @@
21732 #include <asm/processor.h>
21733 #include <asm/mce.h>
21734 #include <asm/msr.h>
21735 +#include <asm/local.h>
21736
21737 #include "mce-internal.h"
21738
21739 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21740 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21741 m->cs, m->ip);
21742
21743 - if (m->cs == __KERNEL_CS)
21744 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21745 print_symbol("{%s}", m->ip);
21746 pr_cont("\n");
21747 }
21748 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21749
21750 #define PANIC_TIMEOUT 5 /* 5 seconds */
21751
21752 -static atomic_t mce_paniced;
21753 +static atomic_unchecked_t mce_paniced;
21754
21755 static int fake_panic;
21756 -static atomic_t mce_fake_paniced;
21757 +static atomic_unchecked_t mce_fake_paniced;
21758
21759 /* Panic in progress. Enable interrupts and wait for final IPI */
21760 static void wait_for_panic(void)
21761 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21762 /*
21763 * Make sure only one CPU runs in machine check panic
21764 */
21765 - if (atomic_inc_return(&mce_paniced) > 1)
21766 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21767 wait_for_panic();
21768 barrier();
21769
21770 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21771 console_verbose();
21772 } else {
21773 /* Don't log too much for fake panic */
21774 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21775 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21776 return;
21777 }
21778 /* First print corrected ones that are still unlogged */
21779 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21780 if (!fake_panic) {
21781 if (panic_timeout == 0)
21782 panic_timeout = mca_cfg.panic_timeout;
21783 - panic(msg);
21784 + panic("%s", msg);
21785 } else
21786 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21787 }
21788 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21789 * might have been modified by someone else.
21790 */
21791 rmb();
21792 - if (atomic_read(&mce_paniced))
21793 + if (atomic_read_unchecked(&mce_paniced))
21794 wait_for_panic();
21795 if (!mca_cfg.monarch_timeout)
21796 goto out;
21797 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21798 }
21799
21800 /* Call the installed machine check handler for this CPU setup. */
21801 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21802 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21803 unexpected_machine_check;
21804
21805 /*
21806 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21807 return;
21808 }
21809
21810 + pax_open_kernel();
21811 machine_check_vector = do_machine_check;
21812 + pax_close_kernel();
21813
21814 __mcheck_cpu_init_generic();
21815 __mcheck_cpu_init_vendor(c);
21816 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21817 */
21818
21819 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21820 -static int mce_chrdev_open_count; /* #times opened */
21821 +static local_t mce_chrdev_open_count; /* #times opened */
21822 static int mce_chrdev_open_exclu; /* already open exclusive? */
21823
21824 static int mce_chrdev_open(struct inode *inode, struct file *file)
21825 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21826 spin_lock(&mce_chrdev_state_lock);
21827
21828 if (mce_chrdev_open_exclu ||
21829 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21830 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21831 spin_unlock(&mce_chrdev_state_lock);
21832
21833 return -EBUSY;
21834 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21835
21836 if (file->f_flags & O_EXCL)
21837 mce_chrdev_open_exclu = 1;
21838 - mce_chrdev_open_count++;
21839 + local_inc(&mce_chrdev_open_count);
21840
21841 spin_unlock(&mce_chrdev_state_lock);
21842
21843 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21844 {
21845 spin_lock(&mce_chrdev_state_lock);
21846
21847 - mce_chrdev_open_count--;
21848 + local_dec(&mce_chrdev_open_count);
21849 mce_chrdev_open_exclu = 0;
21850
21851 spin_unlock(&mce_chrdev_state_lock);
21852 @@ -2414,7 +2417,7 @@ static __init void mce_init_banks(void)
21853
21854 for (i = 0; i < mca_cfg.banks; i++) {
21855 struct mce_bank *b = &mce_banks[i];
21856 - struct device_attribute *a = &b->attr;
21857 + device_attribute_no_const *a = &b->attr;
21858
21859 sysfs_attr_init(&a->attr);
21860 a->attr.name = b->attrname;
21861 @@ -2521,7 +2524,7 @@ struct dentry *mce_get_debugfs_dir(void)
21862 static void mce_reset(void)
21863 {
21864 cpu_missing = 0;
21865 - atomic_set(&mce_fake_paniced, 0);
21866 + atomic_set_unchecked(&mce_fake_paniced, 0);
21867 atomic_set(&mce_executing, 0);
21868 atomic_set(&mce_callin, 0);
21869 atomic_set(&global_nwo, 0);
21870 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21871 index a304298..49b6d06 100644
21872 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21873 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21874 @@ -10,6 +10,7 @@
21875 #include <asm/processor.h>
21876 #include <asm/mce.h>
21877 #include <asm/msr.h>
21878 +#include <asm/pgtable.h>
21879
21880 /* By default disabled */
21881 int mce_p5_enabled __read_mostly;
21882 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21883 if (!cpu_has(c, X86_FEATURE_MCE))
21884 return;
21885
21886 + pax_open_kernel();
21887 machine_check_vector = pentium_machine_check;
21888 + pax_close_kernel();
21889 /* Make sure the vector pointer is visible before we enable MCEs: */
21890 wmb();
21891
21892 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21893 index 7dc5564..1273569 100644
21894 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21895 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21896 @@ -9,6 +9,7 @@
21897 #include <asm/processor.h>
21898 #include <asm/mce.h>
21899 #include <asm/msr.h>
21900 +#include <asm/pgtable.h>
21901
21902 /* Machine check handler for WinChip C6: */
21903 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21904 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21905 {
21906 u32 lo, hi;
21907
21908 + pax_open_kernel();
21909 machine_check_vector = winchip_machine_check;
21910 + pax_close_kernel();
21911 /* Make sure the vector pointer is visible before we enable MCEs: */
21912 wmb();
21913
21914 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21915 index dd9d619..86e1d81 100644
21916 --- a/arch/x86/kernel/cpu/microcode/core.c
21917 +++ b/arch/x86/kernel/cpu/microcode/core.c
21918 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21919 return NOTIFY_OK;
21920 }
21921
21922 -static struct notifier_block __refdata mc_cpu_notifier = {
21923 +static struct notifier_block mc_cpu_notifier = {
21924 .notifier_call = mc_cpu_callback,
21925 };
21926
21927 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21928 index a276fa7..e66810f 100644
21929 --- a/arch/x86/kernel/cpu/microcode/intel.c
21930 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21931 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21932
21933 static int get_ucode_user(void *to, const void *from, size_t n)
21934 {
21935 - return copy_from_user(to, from, n);
21936 + return copy_from_user(to, (const void __force_user *)from, n);
21937 }
21938
21939 static enum ucode_state
21940 request_microcode_user(int cpu, const void __user *buf, size_t size)
21941 {
21942 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21943 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21944 }
21945
21946 static void microcode_fini_cpu(int cpu)
21947 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21948 index f961de9..8a9d332 100644
21949 --- a/arch/x86/kernel/cpu/mtrr/main.c
21950 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21951 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21952 u64 size_or_mask, size_and_mask;
21953 static bool mtrr_aps_delayed_init;
21954
21955 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21956 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21957
21958 const struct mtrr_ops *mtrr_if;
21959
21960 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21961 index df5e41f..816c719 100644
21962 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21963 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21964 @@ -25,7 +25,7 @@ struct mtrr_ops {
21965 int (*validate_add_page)(unsigned long base, unsigned long size,
21966 unsigned int type);
21967 int (*have_wrcomb)(void);
21968 -};
21969 +} __do_const;
21970
21971 extern int generic_get_free_region(unsigned long base, unsigned long size,
21972 int replace_reg);
21973 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21974 index 2879ecd..bb8c80b 100644
21975 --- a/arch/x86/kernel/cpu/perf_event.c
21976 +++ b/arch/x86/kernel/cpu/perf_event.c
21977 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
21978
21979 }
21980
21981 -static struct attribute_group x86_pmu_format_group = {
21982 +static attribute_group_no_const x86_pmu_format_group = {
21983 .name = "format",
21984 .attrs = NULL,
21985 };
21986 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
21987 NULL,
21988 };
21989
21990 -static struct attribute_group x86_pmu_events_group = {
21991 +static attribute_group_no_const x86_pmu_events_group = {
21992 .name = "events",
21993 .attrs = events_attr,
21994 };
21995 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
21996 if (idx > GDT_ENTRIES)
21997 return 0;
21998
21999 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22000 + desc = get_cpu_gdt_table(smp_processor_id());
22001 }
22002
22003 return get_desc_base(desc + idx);
22004 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22005 break;
22006
22007 perf_callchain_store(entry, frame.return_address);
22008 - fp = frame.next_frame;
22009 + fp = (const void __force_user *)frame.next_frame;
22010 }
22011 }
22012
22013 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22014 index 639d128..e92d7e5 100644
22015 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22016 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22017 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22018 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22019 {
22020 struct attribute **attrs;
22021 - struct attribute_group *attr_group;
22022 + attribute_group_no_const *attr_group;
22023 int i = 0, j;
22024
22025 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22026 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22027 index 2502d0d..e5cc05c 100644
22028 --- a/arch/x86/kernel/cpu/perf_event_intel.c
22029 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
22030 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22031 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22032
22033 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22034 - u64 capabilities;
22035 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22036
22037 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22038 - x86_pmu.intel_cap.capabilities = capabilities;
22039 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22040 + x86_pmu.intel_cap.capabilities = capabilities;
22041 }
22042
22043 intel_ds_init();
22044 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22045 index 619f769..d510008 100644
22046 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22047 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22048 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22049 NULL,
22050 };
22051
22052 -static struct attribute_group rapl_pmu_events_group = {
22053 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22054 .name = "events",
22055 .attrs = NULL, /* patched at runtime */
22056 };
22057 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22058 index ae6552a..b5be2d3 100644
22059 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22060 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22061 @@ -3694,7 +3694,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22062 static int __init uncore_type_init(struct intel_uncore_type *type)
22063 {
22064 struct intel_uncore_pmu *pmus;
22065 - struct attribute_group *attr_group;
22066 + attribute_group_no_const *attr_group;
22067 struct attribute **attrs;
22068 int i, j;
22069
22070 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22071 index 90236f0..54cb20d 100644
22072 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22073 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22074 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22075 struct uncore_event_desc {
22076 struct kobj_attribute attr;
22077 const char *config;
22078 -};
22079 +} __do_const;
22080
22081 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22082 { \
22083 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22084 index 3225ae6c..ee3c6db 100644
22085 --- a/arch/x86/kernel/cpuid.c
22086 +++ b/arch/x86/kernel/cpuid.c
22087 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22088 return notifier_from_errno(err);
22089 }
22090
22091 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22092 +static struct notifier_block cpuid_class_cpu_notifier =
22093 {
22094 .notifier_call = cpuid_class_cpu_callback,
22095 };
22096 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22097 index 507de80..ebaae2a 100644
22098 --- a/arch/x86/kernel/crash.c
22099 +++ b/arch/x86/kernel/crash.c
22100 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22101 #ifdef CONFIG_X86_32
22102 struct pt_regs fixed_regs;
22103
22104 - if (!user_mode_vm(regs)) {
22105 + if (!user_mode(regs)) {
22106 crash_fixup_ss_esp(&fixed_regs, regs);
22107 regs = &fixed_regs;
22108 }
22109 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22110 index afa64ad..dce67dd 100644
22111 --- a/arch/x86/kernel/crash_dump_64.c
22112 +++ b/arch/x86/kernel/crash_dump_64.c
22113 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22114 return -ENOMEM;
22115
22116 if (userbuf) {
22117 - if (copy_to_user(buf, vaddr + offset, csize)) {
22118 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22119 iounmap(vaddr);
22120 return -EFAULT;
22121 }
22122 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22123 index f6dfd93..892ade4 100644
22124 --- a/arch/x86/kernel/doublefault.c
22125 +++ b/arch/x86/kernel/doublefault.c
22126 @@ -12,7 +12,7 @@
22127
22128 #define DOUBLEFAULT_STACKSIZE (1024)
22129 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22130 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22131 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22132
22133 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22134
22135 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22136 unsigned long gdt, tss;
22137
22138 native_store_gdt(&gdt_desc);
22139 - gdt = gdt_desc.address;
22140 + gdt = (unsigned long)gdt_desc.address;
22141
22142 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22143
22144 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22145 /* 0x2 bit is always set */
22146 .flags = X86_EFLAGS_SF | 0x2,
22147 .sp = STACK_START,
22148 - .es = __USER_DS,
22149 + .es = __KERNEL_DS,
22150 .cs = __KERNEL_CS,
22151 .ss = __KERNEL_DS,
22152 - .ds = __USER_DS,
22153 + .ds = __KERNEL_DS,
22154 .fs = __KERNEL_PERCPU,
22155
22156 .__cr3 = __pa_nodebug(swapper_pg_dir),
22157 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22158 index b74ebc7..6dbb0c5 100644
22159 --- a/arch/x86/kernel/dumpstack.c
22160 +++ b/arch/x86/kernel/dumpstack.c
22161 @@ -2,6 +2,9 @@
22162 * Copyright (C) 1991, 1992 Linus Torvalds
22163 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22164 */
22165 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22166 +#define __INCLUDED_BY_HIDESYM 1
22167 +#endif
22168 #include <linux/kallsyms.h>
22169 #include <linux/kprobes.h>
22170 #include <linux/uaccess.h>
22171 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
22172 static void
22173 print_ftrace_graph_addr(unsigned long addr, void *data,
22174 const struct stacktrace_ops *ops,
22175 - struct thread_info *tinfo, int *graph)
22176 + struct task_struct *task, int *graph)
22177 {
22178 - struct task_struct *task;
22179 unsigned long ret_addr;
22180 int index;
22181
22182 if (addr != (unsigned long)return_to_handler)
22183 return;
22184
22185 - task = tinfo->task;
22186 index = task->curr_ret_stack;
22187
22188 if (!task->ret_stack || index < *graph)
22189 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22190 static inline void
22191 print_ftrace_graph_addr(unsigned long addr, void *data,
22192 const struct stacktrace_ops *ops,
22193 - struct thread_info *tinfo, int *graph)
22194 + struct task_struct *task, int *graph)
22195 { }
22196 #endif
22197
22198 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22199 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22200 */
22201
22202 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22203 - void *p, unsigned int size, void *end)
22204 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22205 {
22206 - void *t = tinfo;
22207 if (end) {
22208 if (p < end && p >= (end-THREAD_SIZE))
22209 return 1;
22210 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22211 }
22212
22213 unsigned long
22214 -print_context_stack(struct thread_info *tinfo,
22215 +print_context_stack(struct task_struct *task, void *stack_start,
22216 unsigned long *stack, unsigned long bp,
22217 const struct stacktrace_ops *ops, void *data,
22218 unsigned long *end, int *graph)
22219 {
22220 struct stack_frame *frame = (struct stack_frame *)bp;
22221
22222 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22223 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22224 unsigned long addr;
22225
22226 addr = *stack;
22227 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22228 } else {
22229 ops->address(data, addr, 0);
22230 }
22231 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22232 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22233 }
22234 stack++;
22235 }
22236 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22237 EXPORT_SYMBOL_GPL(print_context_stack);
22238
22239 unsigned long
22240 -print_context_stack_bp(struct thread_info *tinfo,
22241 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22242 unsigned long *stack, unsigned long bp,
22243 const struct stacktrace_ops *ops, void *data,
22244 unsigned long *end, int *graph)
22245 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22246 struct stack_frame *frame = (struct stack_frame *)bp;
22247 unsigned long *ret_addr = &frame->return_address;
22248
22249 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22250 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22251 unsigned long addr = *ret_addr;
22252
22253 if (!__kernel_text_address(addr))
22254 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22255 ops->address(data, addr, 1);
22256 frame = frame->next_frame;
22257 ret_addr = &frame->return_address;
22258 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22259 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22260 }
22261
22262 return (unsigned long)frame;
22263 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22264 static void print_trace_address(void *data, unsigned long addr, int reliable)
22265 {
22266 touch_nmi_watchdog();
22267 - printk(data);
22268 + printk("%s", (char *)data);
22269 printk_stack_address(addr, reliable);
22270 }
22271
22272 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22273 EXPORT_SYMBOL_GPL(oops_begin);
22274 NOKPROBE_SYMBOL(oops_begin);
22275
22276 +extern void gr_handle_kernel_exploit(void);
22277 +
22278 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22279 {
22280 if (regs && kexec_should_crash(current))
22281 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22282 panic("Fatal exception in interrupt");
22283 if (panic_on_oops)
22284 panic("Fatal exception");
22285 - do_exit(signr);
22286 +
22287 + gr_handle_kernel_exploit();
22288 +
22289 + do_group_exit(signr);
22290 }
22291 NOKPROBE_SYMBOL(oops_end);
22292
22293 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22294 print_modules();
22295 show_regs(regs);
22296 #ifdef CONFIG_X86_32
22297 - if (user_mode_vm(regs)) {
22298 + if (user_mode(regs)) {
22299 sp = regs->sp;
22300 ss = regs->ss & 0xffff;
22301 } else {
22302 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22303 unsigned long flags = oops_begin();
22304 int sig = SIGSEGV;
22305
22306 - if (!user_mode_vm(regs))
22307 + if (!user_mode(regs))
22308 report_bug(regs->ip, regs);
22309
22310 if (__die(str, regs, err))
22311 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22312 index 5abd4cd..c65733b 100644
22313 --- a/arch/x86/kernel/dumpstack_32.c
22314 +++ b/arch/x86/kernel/dumpstack_32.c
22315 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22316 bp = stack_frame(task, regs);
22317
22318 for (;;) {
22319 - struct thread_info *context;
22320 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22321 void *end_stack;
22322
22323 end_stack = is_hardirq_stack(stack, cpu);
22324 if (!end_stack)
22325 end_stack = is_softirq_stack(stack, cpu);
22326
22327 - context = task_thread_info(task);
22328 - bp = ops->walk_stack(context, stack, bp, ops, data,
22329 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22330 end_stack, &graph);
22331
22332 /* Stop if not on irq stack */
22333 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22334 int i;
22335
22336 show_regs_print_info(KERN_EMERG);
22337 - __show_regs(regs, !user_mode_vm(regs));
22338 + __show_regs(regs, !user_mode(regs));
22339
22340 /*
22341 * When in-kernel, we also print out the stack and code at the
22342 * time of the fault..
22343 */
22344 - if (!user_mode_vm(regs)) {
22345 + if (!user_mode(regs)) {
22346 unsigned int code_prologue = code_bytes * 43 / 64;
22347 unsigned int code_len = code_bytes;
22348 unsigned char c;
22349 u8 *ip;
22350 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22351
22352 pr_emerg("Stack:\n");
22353 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22354
22355 pr_emerg("Code:");
22356
22357 - ip = (u8 *)regs->ip - code_prologue;
22358 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22359 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22360 /* try starting at IP */
22361 - ip = (u8 *)regs->ip;
22362 + ip = (u8 *)regs->ip + cs_base;
22363 code_len = code_len - code_prologue + 1;
22364 }
22365 for (i = 0; i < code_len; i++, ip++) {
22366 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22367 pr_cont(" Bad EIP value.");
22368 break;
22369 }
22370 - if (ip == (u8 *)regs->ip)
22371 + if (ip == (u8 *)regs->ip + cs_base)
22372 pr_cont(" <%02x>", c);
22373 else
22374 pr_cont(" %02x", c);
22375 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22376 {
22377 unsigned short ud2;
22378
22379 + ip = ktla_ktva(ip);
22380 if (ip < PAGE_OFFSET)
22381 return 0;
22382 if (probe_kernel_address((unsigned short *)ip, ud2))
22383 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22384
22385 return ud2 == 0x0b0f;
22386 }
22387 +
22388 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22389 +void pax_check_alloca(unsigned long size)
22390 +{
22391 + unsigned long sp = (unsigned long)&sp, stack_left;
22392 +
22393 + /* all kernel stacks are of the same size */
22394 + stack_left = sp & (THREAD_SIZE - 1);
22395 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22396 +}
22397 +EXPORT_SYMBOL(pax_check_alloca);
22398 +#endif
22399 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22400 index 1abcb50..6c8d702 100644
22401 --- a/arch/x86/kernel/dumpstack_64.c
22402 +++ b/arch/x86/kernel/dumpstack_64.c
22403 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22404 const struct stacktrace_ops *ops, void *data)
22405 {
22406 const unsigned cpu = get_cpu();
22407 - struct thread_info *tinfo;
22408 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22409 unsigned long dummy;
22410 unsigned used = 0;
22411 int graph = 0;
22412 int done = 0;
22413 + void *stack_start;
22414
22415 if (!task)
22416 task = current;
22417 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22418 * current stack address. If the stacks consist of nested
22419 * exceptions
22420 */
22421 - tinfo = task_thread_info(task);
22422 while (!done) {
22423 unsigned long *stack_end;
22424 enum stack_type stype;
22425 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22426 if (ops->stack(data, id) < 0)
22427 break;
22428
22429 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22430 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22431 data, stack_end, &graph);
22432 ops->stack(data, "<EOE>");
22433 /*
22434 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22435 * second-to-last pointer (index -2 to end) in the
22436 * exception stack:
22437 */
22438 + if ((u16)stack_end[-1] != __KERNEL_DS)
22439 + goto out;
22440 stack = (unsigned long *) stack_end[-2];
22441 done = 0;
22442 break;
22443 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22444
22445 if (ops->stack(data, "IRQ") < 0)
22446 break;
22447 - bp = ops->walk_stack(tinfo, stack, bp,
22448 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22449 ops, data, stack_end, &graph);
22450 /*
22451 * We link to the next stack (which would be
22452 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22453 /*
22454 * This handles the process stack:
22455 */
22456 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22457 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22458 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22459 +out:
22460 put_cpu();
22461 }
22462 EXPORT_SYMBOL(dump_trace);
22463 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22464
22465 return ud2 == 0x0b0f;
22466 }
22467 +
22468 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22469 +void pax_check_alloca(unsigned long size)
22470 +{
22471 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22472 + unsigned cpu, used;
22473 + char *id;
22474 +
22475 + /* check the process stack first */
22476 + stack_start = (unsigned long)task_stack_page(current);
22477 + stack_end = stack_start + THREAD_SIZE;
22478 + if (likely(stack_start <= sp && sp < stack_end)) {
22479 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22480 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22481 + return;
22482 + }
22483 +
22484 + cpu = get_cpu();
22485 +
22486 + /* check the irq stacks */
22487 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22488 + stack_start = stack_end - IRQ_STACK_SIZE;
22489 + if (stack_start <= sp && sp < stack_end) {
22490 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22491 + put_cpu();
22492 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22493 + return;
22494 + }
22495 +
22496 + /* check the exception stacks */
22497 + used = 0;
22498 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22499 + stack_start = stack_end - EXCEPTION_STKSZ;
22500 + if (stack_end && stack_start <= sp && sp < stack_end) {
22501 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22502 + put_cpu();
22503 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22504 + return;
22505 + }
22506 +
22507 + put_cpu();
22508 +
22509 + /* unknown stack */
22510 + BUG();
22511 +}
22512 +EXPORT_SYMBOL(pax_check_alloca);
22513 +#endif
22514 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22515 index 988c00a..4f673b6 100644
22516 --- a/arch/x86/kernel/e820.c
22517 +++ b/arch/x86/kernel/e820.c
22518 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22519
22520 static void early_panic(char *msg)
22521 {
22522 - early_printk(msg);
22523 - panic(msg);
22524 + early_printk("%s", msg);
22525 + panic("%s", msg);
22526 }
22527
22528 static int userdef __initdata;
22529 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22530 index 01d1c18..8073693 100644
22531 --- a/arch/x86/kernel/early_printk.c
22532 +++ b/arch/x86/kernel/early_printk.c
22533 @@ -7,6 +7,7 @@
22534 #include <linux/pci_regs.h>
22535 #include <linux/pci_ids.h>
22536 #include <linux/errno.h>
22537 +#include <linux/sched.h>
22538 #include <asm/io.h>
22539 #include <asm/processor.h>
22540 #include <asm/fcntl.h>
22541 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22542 index 0d0c9d4..f65b4f6 100644
22543 --- a/arch/x86/kernel/entry_32.S
22544 +++ b/arch/x86/kernel/entry_32.S
22545 @@ -177,13 +177,153 @@
22546 /*CFI_REL_OFFSET gs, PT_GS*/
22547 .endm
22548 .macro SET_KERNEL_GS reg
22549 +
22550 +#ifdef CONFIG_CC_STACKPROTECTOR
22551 movl $(__KERNEL_STACK_CANARY), \reg
22552 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22553 + movl $(__USER_DS), \reg
22554 +#else
22555 + xorl \reg, \reg
22556 +#endif
22557 +
22558 movl \reg, %gs
22559 .endm
22560
22561 #endif /* CONFIG_X86_32_LAZY_GS */
22562
22563 -.macro SAVE_ALL
22564 +.macro pax_enter_kernel
22565 +#ifdef CONFIG_PAX_KERNEXEC
22566 + call pax_enter_kernel
22567 +#endif
22568 +.endm
22569 +
22570 +.macro pax_exit_kernel
22571 +#ifdef CONFIG_PAX_KERNEXEC
22572 + call pax_exit_kernel
22573 +#endif
22574 +.endm
22575 +
22576 +#ifdef CONFIG_PAX_KERNEXEC
22577 +ENTRY(pax_enter_kernel)
22578 +#ifdef CONFIG_PARAVIRT
22579 + pushl %eax
22580 + pushl %ecx
22581 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22582 + mov %eax, %esi
22583 +#else
22584 + mov %cr0, %esi
22585 +#endif
22586 + bts $16, %esi
22587 + jnc 1f
22588 + mov %cs, %esi
22589 + cmp $__KERNEL_CS, %esi
22590 + jz 3f
22591 + ljmp $__KERNEL_CS, $3f
22592 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22593 +2:
22594 +#ifdef CONFIG_PARAVIRT
22595 + mov %esi, %eax
22596 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22597 +#else
22598 + mov %esi, %cr0
22599 +#endif
22600 +3:
22601 +#ifdef CONFIG_PARAVIRT
22602 + popl %ecx
22603 + popl %eax
22604 +#endif
22605 + ret
22606 +ENDPROC(pax_enter_kernel)
22607 +
22608 +ENTRY(pax_exit_kernel)
22609 +#ifdef CONFIG_PARAVIRT
22610 + pushl %eax
22611 + pushl %ecx
22612 +#endif
22613 + mov %cs, %esi
22614 + cmp $__KERNEXEC_KERNEL_CS, %esi
22615 + jnz 2f
22616 +#ifdef CONFIG_PARAVIRT
22617 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22618 + mov %eax, %esi
22619 +#else
22620 + mov %cr0, %esi
22621 +#endif
22622 + btr $16, %esi
22623 + ljmp $__KERNEL_CS, $1f
22624 +1:
22625 +#ifdef CONFIG_PARAVIRT
22626 + mov %esi, %eax
22627 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22628 +#else
22629 + mov %esi, %cr0
22630 +#endif
22631 +2:
22632 +#ifdef CONFIG_PARAVIRT
22633 + popl %ecx
22634 + popl %eax
22635 +#endif
22636 + ret
22637 +ENDPROC(pax_exit_kernel)
22638 +#endif
22639 +
22640 + .macro pax_erase_kstack
22641 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22642 + call pax_erase_kstack
22643 +#endif
22644 + .endm
22645 +
22646 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22647 +/*
22648 + * ebp: thread_info
22649 + */
22650 +ENTRY(pax_erase_kstack)
22651 + pushl %edi
22652 + pushl %ecx
22653 + pushl %eax
22654 +
22655 + mov TI_lowest_stack(%ebp), %edi
22656 + mov $-0xBEEF, %eax
22657 + std
22658 +
22659 +1: mov %edi, %ecx
22660 + and $THREAD_SIZE_asm - 1, %ecx
22661 + shr $2, %ecx
22662 + repne scasl
22663 + jecxz 2f
22664 +
22665 + cmp $2*16, %ecx
22666 + jc 2f
22667 +
22668 + mov $2*16, %ecx
22669 + repe scasl
22670 + jecxz 2f
22671 + jne 1b
22672 +
22673 +2: cld
22674 + mov %esp, %ecx
22675 + sub %edi, %ecx
22676 +
22677 + cmp $THREAD_SIZE_asm, %ecx
22678 + jb 3f
22679 + ud2
22680 +3:
22681 +
22682 + shr $2, %ecx
22683 + rep stosl
22684 +
22685 + mov TI_task_thread_sp0(%ebp), %edi
22686 + sub $128, %edi
22687 + mov %edi, TI_lowest_stack(%ebp)
22688 +
22689 + popl %eax
22690 + popl %ecx
22691 + popl %edi
22692 + ret
22693 +ENDPROC(pax_erase_kstack)
22694 +#endif
22695 +
22696 +.macro __SAVE_ALL _DS
22697 cld
22698 PUSH_GS
22699 pushl_cfi %fs
22700 @@ -206,7 +346,7 @@
22701 CFI_REL_OFFSET ecx, 0
22702 pushl_cfi %ebx
22703 CFI_REL_OFFSET ebx, 0
22704 - movl $(__USER_DS), %edx
22705 + movl $\_DS, %edx
22706 movl %edx, %ds
22707 movl %edx, %es
22708 movl $(__KERNEL_PERCPU), %edx
22709 @@ -214,6 +354,15 @@
22710 SET_KERNEL_GS %edx
22711 .endm
22712
22713 +.macro SAVE_ALL
22714 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22715 + __SAVE_ALL __KERNEL_DS
22716 + pax_enter_kernel
22717 +#else
22718 + __SAVE_ALL __USER_DS
22719 +#endif
22720 +.endm
22721 +
22722 .macro RESTORE_INT_REGS
22723 popl_cfi %ebx
22724 CFI_RESTORE ebx
22725 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22726 popfl_cfi
22727 jmp syscall_exit
22728 CFI_ENDPROC
22729 -END(ret_from_fork)
22730 +ENDPROC(ret_from_fork)
22731
22732 ENTRY(ret_from_kernel_thread)
22733 CFI_STARTPROC
22734 @@ -340,7 +489,15 @@ ret_from_intr:
22735 andl $SEGMENT_RPL_MASK, %eax
22736 #endif
22737 cmpl $USER_RPL, %eax
22738 +
22739 +#ifdef CONFIG_PAX_KERNEXEC
22740 + jae resume_userspace
22741 +
22742 + pax_exit_kernel
22743 + jmp resume_kernel
22744 +#else
22745 jb resume_kernel # not returning to v8086 or userspace
22746 +#endif
22747
22748 ENTRY(resume_userspace)
22749 LOCKDEP_SYS_EXIT
22750 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22751 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22752 # int/exception return?
22753 jne work_pending
22754 - jmp restore_all
22755 -END(ret_from_exception)
22756 + jmp restore_all_pax
22757 +ENDPROC(ret_from_exception)
22758
22759 #ifdef CONFIG_PREEMPT
22760 ENTRY(resume_kernel)
22761 @@ -365,7 +522,7 @@ need_resched:
22762 jz restore_all
22763 call preempt_schedule_irq
22764 jmp need_resched
22765 -END(resume_kernel)
22766 +ENDPROC(resume_kernel)
22767 #endif
22768 CFI_ENDPROC
22769
22770 @@ -395,30 +552,45 @@ sysenter_past_esp:
22771 /*CFI_REL_OFFSET cs, 0*/
22772 /*
22773 * Push current_thread_info()->sysenter_return to the stack.
22774 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22775 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22776 */
22777 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22778 + pushl_cfi $0
22779 CFI_REL_OFFSET eip, 0
22780
22781 pushl_cfi %eax
22782 SAVE_ALL
22783 + GET_THREAD_INFO(%ebp)
22784 + movl TI_sysenter_return(%ebp),%ebp
22785 + movl %ebp,PT_EIP(%esp)
22786 ENABLE_INTERRUPTS(CLBR_NONE)
22787
22788 /*
22789 * Load the potential sixth argument from user stack.
22790 * Careful about security.
22791 */
22792 + movl PT_OLDESP(%esp),%ebp
22793 +
22794 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22795 + mov PT_OLDSS(%esp),%ds
22796 +1: movl %ds:(%ebp),%ebp
22797 + push %ss
22798 + pop %ds
22799 +#else
22800 cmpl $__PAGE_OFFSET-3,%ebp
22801 jae syscall_fault
22802 ASM_STAC
22803 1: movl (%ebp),%ebp
22804 ASM_CLAC
22805 +#endif
22806 +
22807 movl %ebp,PT_EBP(%esp)
22808 _ASM_EXTABLE(1b,syscall_fault)
22809
22810 GET_THREAD_INFO(%ebp)
22811
22812 +#ifdef CONFIG_PAX_RANDKSTACK
22813 + pax_erase_kstack
22814 +#endif
22815 +
22816 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22817 jnz sysenter_audit
22818 sysenter_do_call:
22819 @@ -434,12 +606,24 @@ sysenter_after_call:
22820 testl $_TIF_ALLWORK_MASK, %ecx
22821 jne sysexit_audit
22822 sysenter_exit:
22823 +
22824 +#ifdef CONFIG_PAX_RANDKSTACK
22825 + pushl_cfi %eax
22826 + movl %esp, %eax
22827 + call pax_randomize_kstack
22828 + popl_cfi %eax
22829 +#endif
22830 +
22831 + pax_erase_kstack
22832 +
22833 /* if something modifies registers it must also disable sysexit */
22834 movl PT_EIP(%esp), %edx
22835 movl PT_OLDESP(%esp), %ecx
22836 xorl %ebp,%ebp
22837 TRACE_IRQS_ON
22838 1: mov PT_FS(%esp), %fs
22839 +2: mov PT_DS(%esp), %ds
22840 +3: mov PT_ES(%esp), %es
22841 PTGS_TO_GS
22842 ENABLE_INTERRUPTS_SYSEXIT
22843
22844 @@ -456,6 +640,9 @@ sysenter_audit:
22845 movl %eax,%edx /* 2nd arg: syscall number */
22846 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22847 call __audit_syscall_entry
22848 +
22849 + pax_erase_kstack
22850 +
22851 pushl_cfi %ebx
22852 movl PT_EAX(%esp),%eax /* reload syscall number */
22853 jmp sysenter_do_call
22854 @@ -481,10 +668,16 @@ sysexit_audit:
22855
22856 CFI_ENDPROC
22857 .pushsection .fixup,"ax"
22858 -2: movl $0,PT_FS(%esp)
22859 +4: movl $0,PT_FS(%esp)
22860 + jmp 1b
22861 +5: movl $0,PT_DS(%esp)
22862 + jmp 1b
22863 +6: movl $0,PT_ES(%esp)
22864 jmp 1b
22865 .popsection
22866 - _ASM_EXTABLE(1b,2b)
22867 + _ASM_EXTABLE(1b,4b)
22868 + _ASM_EXTABLE(2b,5b)
22869 + _ASM_EXTABLE(3b,6b)
22870 PTGS_TO_GS_EX
22871 ENDPROC(ia32_sysenter_target)
22872
22873 @@ -495,6 +688,11 @@ ENTRY(system_call)
22874 pushl_cfi %eax # save orig_eax
22875 SAVE_ALL
22876 GET_THREAD_INFO(%ebp)
22877 +
22878 +#ifdef CONFIG_PAX_RANDKSTACK
22879 + pax_erase_kstack
22880 +#endif
22881 +
22882 # system call tracing in operation / emulation
22883 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22884 jnz syscall_trace_entry
22885 @@ -514,6 +712,15 @@ syscall_exit:
22886 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22887 jne syscall_exit_work
22888
22889 +restore_all_pax:
22890 +
22891 +#ifdef CONFIG_PAX_RANDKSTACK
22892 + movl %esp, %eax
22893 + call pax_randomize_kstack
22894 +#endif
22895 +
22896 + pax_erase_kstack
22897 +
22898 restore_all:
22899 TRACE_IRQS_IRET
22900 restore_all_notrace:
22901 @@ -568,14 +775,34 @@ ldt_ss:
22902 * compensating for the offset by changing to the ESPFIX segment with
22903 * a base address that matches for the difference.
22904 */
22905 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22906 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22907 mov %esp, %edx /* load kernel esp */
22908 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22909 mov %dx, %ax /* eax: new kernel esp */
22910 sub %eax, %edx /* offset (low word is 0) */
22911 +#ifdef CONFIG_SMP
22912 + movl PER_CPU_VAR(cpu_number), %ebx
22913 + shll $PAGE_SHIFT_asm, %ebx
22914 + addl $cpu_gdt_table, %ebx
22915 +#else
22916 + movl $cpu_gdt_table, %ebx
22917 +#endif
22918 shr $16, %edx
22919 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22920 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22921 +
22922 +#ifdef CONFIG_PAX_KERNEXEC
22923 + mov %cr0, %esi
22924 + btr $16, %esi
22925 + mov %esi, %cr0
22926 +#endif
22927 +
22928 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22929 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22930 +
22931 +#ifdef CONFIG_PAX_KERNEXEC
22932 + bts $16, %esi
22933 + mov %esi, %cr0
22934 +#endif
22935 +
22936 pushl_cfi $__ESPFIX_SS
22937 pushl_cfi %eax /* new kernel esp */
22938 /* Disable interrupts, but do not irqtrace this section: we
22939 @@ -605,20 +832,18 @@ work_resched:
22940 movl TI_flags(%ebp), %ecx
22941 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22942 # than syscall tracing?
22943 - jz restore_all
22944 + jz restore_all_pax
22945 testb $_TIF_NEED_RESCHED, %cl
22946 jnz work_resched
22947
22948 work_notifysig: # deal with pending signals and
22949 # notify-resume requests
22950 + movl %esp, %eax
22951 #ifdef CONFIG_VM86
22952 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22953 - movl %esp, %eax
22954 jne work_notifysig_v86 # returning to kernel-space or
22955 # vm86-space
22956 1:
22957 -#else
22958 - movl %esp, %eax
22959 #endif
22960 TRACE_IRQS_ON
22961 ENABLE_INTERRUPTS(CLBR_NONE)
22962 @@ -639,7 +864,7 @@ work_notifysig_v86:
22963 movl %eax, %esp
22964 jmp 1b
22965 #endif
22966 -END(work_pending)
22967 +ENDPROC(work_pending)
22968
22969 # perform syscall exit tracing
22970 ALIGN
22971 @@ -647,11 +872,14 @@ syscall_trace_entry:
22972 movl $-ENOSYS,PT_EAX(%esp)
22973 movl %esp, %eax
22974 call syscall_trace_enter
22975 +
22976 + pax_erase_kstack
22977 +
22978 /* What it returned is what we'll actually use. */
22979 cmpl $(NR_syscalls), %eax
22980 jnae syscall_call
22981 jmp syscall_exit
22982 -END(syscall_trace_entry)
22983 +ENDPROC(syscall_trace_entry)
22984
22985 # perform syscall exit tracing
22986 ALIGN
22987 @@ -664,26 +892,30 @@ syscall_exit_work:
22988 movl %esp, %eax
22989 call syscall_trace_leave
22990 jmp resume_userspace
22991 -END(syscall_exit_work)
22992 +ENDPROC(syscall_exit_work)
22993 CFI_ENDPROC
22994
22995 RING0_INT_FRAME # can't unwind into user space anyway
22996 syscall_fault:
22997 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22998 + push %ss
22999 + pop %ds
23000 +#endif
23001 ASM_CLAC
23002 GET_THREAD_INFO(%ebp)
23003 movl $-EFAULT,PT_EAX(%esp)
23004 jmp resume_userspace
23005 -END(syscall_fault)
23006 +ENDPROC(syscall_fault)
23007
23008 syscall_badsys:
23009 movl $-ENOSYS,%eax
23010 jmp syscall_after_call
23011 -END(syscall_badsys)
23012 +ENDPROC(syscall_badsys)
23013
23014 sysenter_badsys:
23015 movl $-ENOSYS,%eax
23016 jmp sysenter_after_call
23017 -END(syscall_badsys)
23018 +ENDPROC(sysenter_badsys)
23019 CFI_ENDPROC
23020
23021 .macro FIXUP_ESPFIX_STACK
23022 @@ -696,8 +928,15 @@ END(syscall_badsys)
23023 */
23024 #ifdef CONFIG_X86_ESPFIX32
23025 /* fixup the stack */
23026 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23027 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23028 +#ifdef CONFIG_SMP
23029 + movl PER_CPU_VAR(cpu_number), %ebx
23030 + shll $PAGE_SHIFT_asm, %ebx
23031 + addl $cpu_gdt_table, %ebx
23032 +#else
23033 + movl $cpu_gdt_table, %ebx
23034 +#endif
23035 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23036 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23037 shl $16, %eax
23038 addl %esp, %eax /* the adjusted stack pointer */
23039 pushl_cfi $__KERNEL_DS
23040 @@ -753,7 +992,7 @@ vector=vector+1
23041 .endr
23042 2: jmp common_interrupt
23043 .endr
23044 -END(irq_entries_start)
23045 +ENDPROC(irq_entries_start)
23046
23047 .previous
23048 END(interrupt)
23049 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23050 pushl_cfi $do_coprocessor_error
23051 jmp error_code
23052 CFI_ENDPROC
23053 -END(coprocessor_error)
23054 +ENDPROC(coprocessor_error)
23055
23056 ENTRY(simd_coprocessor_error)
23057 RING0_INT_FRAME
23058 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23059 .section .altinstructions,"a"
23060 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23061 .previous
23062 -.section .altinstr_replacement,"ax"
23063 +.section .altinstr_replacement,"a"
23064 663: pushl $do_simd_coprocessor_error
23065 664:
23066 .previous
23067 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23068 #endif
23069 jmp error_code
23070 CFI_ENDPROC
23071 -END(simd_coprocessor_error)
23072 +ENDPROC(simd_coprocessor_error)
23073
23074 ENTRY(device_not_available)
23075 RING0_INT_FRAME
23076 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23077 pushl_cfi $do_device_not_available
23078 jmp error_code
23079 CFI_ENDPROC
23080 -END(device_not_available)
23081 +ENDPROC(device_not_available)
23082
23083 #ifdef CONFIG_PARAVIRT
23084 ENTRY(native_iret)
23085 iret
23086 _ASM_EXTABLE(native_iret, iret_exc)
23087 -END(native_iret)
23088 +ENDPROC(native_iret)
23089
23090 ENTRY(native_irq_enable_sysexit)
23091 sti
23092 sysexit
23093 -END(native_irq_enable_sysexit)
23094 +ENDPROC(native_irq_enable_sysexit)
23095 #endif
23096
23097 ENTRY(overflow)
23098 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23099 pushl_cfi $do_overflow
23100 jmp error_code
23101 CFI_ENDPROC
23102 -END(overflow)
23103 +ENDPROC(overflow)
23104
23105 ENTRY(bounds)
23106 RING0_INT_FRAME
23107 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23108 pushl_cfi $do_bounds
23109 jmp error_code
23110 CFI_ENDPROC
23111 -END(bounds)
23112 +ENDPROC(bounds)
23113
23114 ENTRY(invalid_op)
23115 RING0_INT_FRAME
23116 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23117 pushl_cfi $do_invalid_op
23118 jmp error_code
23119 CFI_ENDPROC
23120 -END(invalid_op)
23121 +ENDPROC(invalid_op)
23122
23123 ENTRY(coprocessor_segment_overrun)
23124 RING0_INT_FRAME
23125 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23126 pushl_cfi $do_coprocessor_segment_overrun
23127 jmp error_code
23128 CFI_ENDPROC
23129 -END(coprocessor_segment_overrun)
23130 +ENDPROC(coprocessor_segment_overrun)
23131
23132 ENTRY(invalid_TSS)
23133 RING0_EC_FRAME
23134 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23135 pushl_cfi $do_invalid_TSS
23136 jmp error_code
23137 CFI_ENDPROC
23138 -END(invalid_TSS)
23139 +ENDPROC(invalid_TSS)
23140
23141 ENTRY(segment_not_present)
23142 RING0_EC_FRAME
23143 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23144 pushl_cfi $do_segment_not_present
23145 jmp error_code
23146 CFI_ENDPROC
23147 -END(segment_not_present)
23148 +ENDPROC(segment_not_present)
23149
23150 ENTRY(stack_segment)
23151 RING0_EC_FRAME
23152 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23153 pushl_cfi $do_stack_segment
23154 jmp error_code
23155 CFI_ENDPROC
23156 -END(stack_segment)
23157 +ENDPROC(stack_segment)
23158
23159 ENTRY(alignment_check)
23160 RING0_EC_FRAME
23161 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23162 pushl_cfi $do_alignment_check
23163 jmp error_code
23164 CFI_ENDPROC
23165 -END(alignment_check)
23166 +ENDPROC(alignment_check)
23167
23168 ENTRY(divide_error)
23169 RING0_INT_FRAME
23170 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23171 pushl_cfi $do_divide_error
23172 jmp error_code
23173 CFI_ENDPROC
23174 -END(divide_error)
23175 +ENDPROC(divide_error)
23176
23177 #ifdef CONFIG_X86_MCE
23178 ENTRY(machine_check)
23179 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23180 pushl_cfi machine_check_vector
23181 jmp error_code
23182 CFI_ENDPROC
23183 -END(machine_check)
23184 +ENDPROC(machine_check)
23185 #endif
23186
23187 ENTRY(spurious_interrupt_bug)
23188 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23189 pushl_cfi $do_spurious_interrupt_bug
23190 jmp error_code
23191 CFI_ENDPROC
23192 -END(spurious_interrupt_bug)
23193 +ENDPROC(spurious_interrupt_bug)
23194
23195 #ifdef CONFIG_XEN
23196 /* Xen doesn't set %esp to be precisely what the normal sysenter
23197 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23198
23199 ENTRY(mcount)
23200 ret
23201 -END(mcount)
23202 +ENDPROC(mcount)
23203
23204 ENTRY(ftrace_caller)
23205 cmpl $0, function_trace_stop
23206 @@ -1089,7 +1328,7 @@ ftrace_graph_call:
23207 .globl ftrace_stub
23208 ftrace_stub:
23209 ret
23210 -END(ftrace_caller)
23211 +ENDPROC(ftrace_caller)
23212
23213 ENTRY(ftrace_regs_caller)
23214 pushf /* push flags before compare (in cs location) */
23215 @@ -1193,7 +1432,7 @@ trace:
23216 popl %ecx
23217 popl %eax
23218 jmp ftrace_stub
23219 -END(mcount)
23220 +ENDPROC(mcount)
23221 #endif /* CONFIG_DYNAMIC_FTRACE */
23222 #endif /* CONFIG_FUNCTION_TRACER */
23223
23224 @@ -1211,7 +1450,7 @@ ENTRY(ftrace_graph_caller)
23225 popl %ecx
23226 popl %eax
23227 ret
23228 -END(ftrace_graph_caller)
23229 +ENDPROC(ftrace_graph_caller)
23230
23231 .globl return_to_handler
23232 return_to_handler:
23233 @@ -1272,15 +1511,18 @@ error_code:
23234 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23235 REG_TO_PTGS %ecx
23236 SET_KERNEL_GS %ecx
23237 - movl $(__USER_DS), %ecx
23238 + movl $(__KERNEL_DS), %ecx
23239 movl %ecx, %ds
23240 movl %ecx, %es
23241 +
23242 + pax_enter_kernel
23243 +
23244 TRACE_IRQS_OFF
23245 movl %esp,%eax # pt_regs pointer
23246 call *%edi
23247 jmp ret_from_exception
23248 CFI_ENDPROC
23249 -END(page_fault)
23250 +ENDPROC(page_fault)
23251
23252 /*
23253 * Debug traps and NMI can happen at the one SYSENTER instruction
23254 @@ -1323,7 +1565,7 @@ debug_stack_correct:
23255 call do_debug
23256 jmp ret_from_exception
23257 CFI_ENDPROC
23258 -END(debug)
23259 +ENDPROC(debug)
23260
23261 /*
23262 * NMI is doubly nasty. It can happen _while_ we're handling
23263 @@ -1363,6 +1605,9 @@ nmi_stack_correct:
23264 xorl %edx,%edx # zero error code
23265 movl %esp,%eax # pt_regs pointer
23266 call do_nmi
23267 +
23268 + pax_exit_kernel
23269 +
23270 jmp restore_all_notrace
23271 CFI_ENDPROC
23272
23273 @@ -1400,13 +1645,16 @@ nmi_espfix_stack:
23274 FIXUP_ESPFIX_STACK # %eax == %esp
23275 xorl %edx,%edx # zero error code
23276 call do_nmi
23277 +
23278 + pax_exit_kernel
23279 +
23280 RESTORE_REGS
23281 lss 12+4(%esp), %esp # back to espfix stack
23282 CFI_ADJUST_CFA_OFFSET -24
23283 jmp irq_return
23284 #endif
23285 CFI_ENDPROC
23286 -END(nmi)
23287 +ENDPROC(nmi)
23288
23289 ENTRY(int3)
23290 RING0_INT_FRAME
23291 @@ -1419,14 +1667,14 @@ ENTRY(int3)
23292 call do_int3
23293 jmp ret_from_exception
23294 CFI_ENDPROC
23295 -END(int3)
23296 +ENDPROC(int3)
23297
23298 ENTRY(general_protection)
23299 RING0_EC_FRAME
23300 pushl_cfi $do_general_protection
23301 jmp error_code
23302 CFI_ENDPROC
23303 -END(general_protection)
23304 +ENDPROC(general_protection)
23305
23306 #ifdef CONFIG_KVM_GUEST
23307 ENTRY(async_page_fault)
23308 @@ -1435,6 +1683,6 @@ ENTRY(async_page_fault)
23309 pushl_cfi $do_async_page_fault
23310 jmp error_code
23311 CFI_ENDPROC
23312 -END(async_page_fault)
23313 +ENDPROC(async_page_fault)
23314 #endif
23315
23316 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23317 index c844f08..966a50e 100644
23318 --- a/arch/x86/kernel/entry_64.S
23319 +++ b/arch/x86/kernel/entry_64.S
23320 @@ -59,6 +59,8 @@
23321 #include <asm/smap.h>
23322 #include <asm/pgtable_types.h>
23323 #include <linux/err.h>
23324 +#include <asm/pgtable.h>
23325 +#include <asm/alternative-asm.h>
23326
23327 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23328 #include <linux/elf-em.h>
23329 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23330 ENDPROC(native_usergs_sysret64)
23331 #endif /* CONFIG_PARAVIRT */
23332
23333 + .macro ljmpq sel, off
23334 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23335 + .byte 0x48; ljmp *1234f(%rip)
23336 + .pushsection .rodata
23337 + .align 16
23338 + 1234: .quad \off; .word \sel
23339 + .popsection
23340 +#else
23341 + pushq $\sel
23342 + pushq $\off
23343 + lretq
23344 +#endif
23345 + .endm
23346 +
23347 + .macro pax_enter_kernel
23348 + pax_set_fptr_mask
23349 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23350 + call pax_enter_kernel
23351 +#endif
23352 + .endm
23353 +
23354 + .macro pax_exit_kernel
23355 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23356 + call pax_exit_kernel
23357 +#endif
23358 +
23359 + .endm
23360 +
23361 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23362 +ENTRY(pax_enter_kernel)
23363 + pushq %rdi
23364 +
23365 +#ifdef CONFIG_PARAVIRT
23366 + PV_SAVE_REGS(CLBR_RDI)
23367 +#endif
23368 +
23369 +#ifdef CONFIG_PAX_KERNEXEC
23370 + GET_CR0_INTO_RDI
23371 + bts $16,%rdi
23372 + jnc 3f
23373 + mov %cs,%edi
23374 + cmp $__KERNEL_CS,%edi
23375 + jnz 2f
23376 +1:
23377 +#endif
23378 +
23379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23380 + 661: jmp 111f
23381 + .pushsection .altinstr_replacement, "a"
23382 + 662: ASM_NOP2
23383 + .popsection
23384 + .pushsection .altinstructions, "a"
23385 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23386 + .popsection
23387 + GET_CR3_INTO_RDI
23388 + cmp $0,%dil
23389 + jnz 112f
23390 + mov $__KERNEL_DS,%edi
23391 + mov %edi,%ss
23392 + jmp 111f
23393 +112: cmp $1,%dil
23394 + jz 113f
23395 + ud2
23396 +113: sub $4097,%rdi
23397 + bts $63,%rdi
23398 + SET_RDI_INTO_CR3
23399 + mov $__UDEREF_KERNEL_DS,%edi
23400 + mov %edi,%ss
23401 +111:
23402 +#endif
23403 +
23404 +#ifdef CONFIG_PARAVIRT
23405 + PV_RESTORE_REGS(CLBR_RDI)
23406 +#endif
23407 +
23408 + popq %rdi
23409 + pax_force_retaddr
23410 + retq
23411 +
23412 +#ifdef CONFIG_PAX_KERNEXEC
23413 +2: ljmpq __KERNEL_CS,1b
23414 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23415 +4: SET_RDI_INTO_CR0
23416 + jmp 1b
23417 +#endif
23418 +ENDPROC(pax_enter_kernel)
23419 +
23420 +ENTRY(pax_exit_kernel)
23421 + pushq %rdi
23422 +
23423 +#ifdef CONFIG_PARAVIRT
23424 + PV_SAVE_REGS(CLBR_RDI)
23425 +#endif
23426 +
23427 +#ifdef CONFIG_PAX_KERNEXEC
23428 + mov %cs,%rdi
23429 + cmp $__KERNEXEC_KERNEL_CS,%edi
23430 + jz 2f
23431 + GET_CR0_INTO_RDI
23432 + bts $16,%rdi
23433 + jnc 4f
23434 +1:
23435 +#endif
23436 +
23437 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23438 + 661: jmp 111f
23439 + .pushsection .altinstr_replacement, "a"
23440 + 662: ASM_NOP2
23441 + .popsection
23442 + .pushsection .altinstructions, "a"
23443 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23444 + .popsection
23445 + mov %ss,%edi
23446 + cmp $__UDEREF_KERNEL_DS,%edi
23447 + jnz 111f
23448 + GET_CR3_INTO_RDI
23449 + cmp $0,%dil
23450 + jz 112f
23451 + ud2
23452 +112: add $4097,%rdi
23453 + bts $63,%rdi
23454 + SET_RDI_INTO_CR3
23455 + mov $__KERNEL_DS,%edi
23456 + mov %edi,%ss
23457 +111:
23458 +#endif
23459 +
23460 +#ifdef CONFIG_PARAVIRT
23461 + PV_RESTORE_REGS(CLBR_RDI);
23462 +#endif
23463 +
23464 + popq %rdi
23465 + pax_force_retaddr
23466 + retq
23467 +
23468 +#ifdef CONFIG_PAX_KERNEXEC
23469 +2: GET_CR0_INTO_RDI
23470 + btr $16,%rdi
23471 + jnc 4f
23472 + ljmpq __KERNEL_CS,3f
23473 +3: SET_RDI_INTO_CR0
23474 + jmp 1b
23475 +4: ud2
23476 + jmp 4b
23477 +#endif
23478 +ENDPROC(pax_exit_kernel)
23479 +#endif
23480 +
23481 + .macro pax_enter_kernel_user
23482 + pax_set_fptr_mask
23483 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23484 + call pax_enter_kernel_user
23485 +#endif
23486 + .endm
23487 +
23488 + .macro pax_exit_kernel_user
23489 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23490 + call pax_exit_kernel_user
23491 +#endif
23492 +#ifdef CONFIG_PAX_RANDKSTACK
23493 + pushq %rax
23494 + pushq %r11
23495 + call pax_randomize_kstack
23496 + popq %r11
23497 + popq %rax
23498 +#endif
23499 + .endm
23500 +
23501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23502 +ENTRY(pax_enter_kernel_user)
23503 + pushq %rdi
23504 + pushq %rbx
23505 +
23506 +#ifdef CONFIG_PARAVIRT
23507 + PV_SAVE_REGS(CLBR_RDI)
23508 +#endif
23509 +
23510 + 661: jmp 111f
23511 + .pushsection .altinstr_replacement, "a"
23512 + 662: ASM_NOP2
23513 + .popsection
23514 + .pushsection .altinstructions, "a"
23515 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23516 + .popsection
23517 + GET_CR3_INTO_RDI
23518 + cmp $1,%dil
23519 + jnz 4f
23520 + sub $4097,%rdi
23521 + bts $63,%rdi
23522 + SET_RDI_INTO_CR3
23523 + jmp 3f
23524 +111:
23525 +
23526 + GET_CR3_INTO_RDI
23527 + mov %rdi,%rbx
23528 + add $__START_KERNEL_map,%rbx
23529 + sub phys_base(%rip),%rbx
23530 +
23531 +#ifdef CONFIG_PARAVIRT
23532 + cmpl $0, pv_info+PARAVIRT_enabled
23533 + jz 1f
23534 + pushq %rdi
23535 + i = 0
23536 + .rept USER_PGD_PTRS
23537 + mov i*8(%rbx),%rsi
23538 + mov $0,%sil
23539 + lea i*8(%rbx),%rdi
23540 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23541 + i = i + 1
23542 + .endr
23543 + popq %rdi
23544 + jmp 2f
23545 +1:
23546 +#endif
23547 +
23548 + i = 0
23549 + .rept USER_PGD_PTRS
23550 + movb $0,i*8(%rbx)
23551 + i = i + 1
23552 + .endr
23553 +
23554 +2: SET_RDI_INTO_CR3
23555 +
23556 +#ifdef CONFIG_PAX_KERNEXEC
23557 + GET_CR0_INTO_RDI
23558 + bts $16,%rdi
23559 + SET_RDI_INTO_CR0
23560 +#endif
23561 +
23562 +3:
23563 +
23564 +#ifdef CONFIG_PARAVIRT
23565 + PV_RESTORE_REGS(CLBR_RDI)
23566 +#endif
23567 +
23568 + popq %rbx
23569 + popq %rdi
23570 + pax_force_retaddr
23571 + retq
23572 +4: ud2
23573 +ENDPROC(pax_enter_kernel_user)
23574 +
23575 +ENTRY(pax_exit_kernel_user)
23576 + pushq %rdi
23577 + pushq %rbx
23578 +
23579 +#ifdef CONFIG_PARAVIRT
23580 + PV_SAVE_REGS(CLBR_RDI)
23581 +#endif
23582 +
23583 + GET_CR3_INTO_RDI
23584 + 661: jmp 1f
23585 + .pushsection .altinstr_replacement, "a"
23586 + 662: ASM_NOP2
23587 + .popsection
23588 + .pushsection .altinstructions, "a"
23589 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23590 + .popsection
23591 + cmp $0,%dil
23592 + jnz 3f
23593 + add $4097,%rdi
23594 + bts $63,%rdi
23595 + SET_RDI_INTO_CR3
23596 + jmp 2f
23597 +1:
23598 +
23599 + mov %rdi,%rbx
23600 +
23601 +#ifdef CONFIG_PAX_KERNEXEC
23602 + GET_CR0_INTO_RDI
23603 + btr $16,%rdi
23604 + jnc 3f
23605 + SET_RDI_INTO_CR0
23606 +#endif
23607 +
23608 + add $__START_KERNEL_map,%rbx
23609 + sub phys_base(%rip),%rbx
23610 +
23611 +#ifdef CONFIG_PARAVIRT
23612 + cmpl $0, pv_info+PARAVIRT_enabled
23613 + jz 1f
23614 + i = 0
23615 + .rept USER_PGD_PTRS
23616 + mov i*8(%rbx),%rsi
23617 + mov $0x67,%sil
23618 + lea i*8(%rbx),%rdi
23619 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23620 + i = i + 1
23621 + .endr
23622 + jmp 2f
23623 +1:
23624 +#endif
23625 +
23626 + i = 0
23627 + .rept USER_PGD_PTRS
23628 + movb $0x67,i*8(%rbx)
23629 + i = i + 1
23630 + .endr
23631 +2:
23632 +
23633 +#ifdef CONFIG_PARAVIRT
23634 + PV_RESTORE_REGS(CLBR_RDI)
23635 +#endif
23636 +
23637 + popq %rbx
23638 + popq %rdi
23639 + pax_force_retaddr
23640 + retq
23641 +3: ud2
23642 +ENDPROC(pax_exit_kernel_user)
23643 +#endif
23644 +
23645 + .macro pax_enter_kernel_nmi
23646 + pax_set_fptr_mask
23647 +
23648 +#ifdef CONFIG_PAX_KERNEXEC
23649 + GET_CR0_INTO_RDI
23650 + bts $16,%rdi
23651 + jc 110f
23652 + SET_RDI_INTO_CR0
23653 + or $2,%ebx
23654 +110:
23655 +#endif
23656 +
23657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23658 + 661: jmp 111f
23659 + .pushsection .altinstr_replacement, "a"
23660 + 662: ASM_NOP2
23661 + .popsection
23662 + .pushsection .altinstructions, "a"
23663 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23664 + .popsection
23665 + GET_CR3_INTO_RDI
23666 + cmp $0,%dil
23667 + jz 111f
23668 + sub $4097,%rdi
23669 + or $4,%ebx
23670 + bts $63,%rdi
23671 + SET_RDI_INTO_CR3
23672 + mov $__UDEREF_KERNEL_DS,%edi
23673 + mov %edi,%ss
23674 +111:
23675 +#endif
23676 + .endm
23677 +
23678 + .macro pax_exit_kernel_nmi
23679 +#ifdef CONFIG_PAX_KERNEXEC
23680 + btr $1,%ebx
23681 + jnc 110f
23682 + GET_CR0_INTO_RDI
23683 + btr $16,%rdi
23684 + SET_RDI_INTO_CR0
23685 +110:
23686 +#endif
23687 +
23688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23689 + btr $2,%ebx
23690 + jnc 111f
23691 + GET_CR3_INTO_RDI
23692 + add $4097,%rdi
23693 + bts $63,%rdi
23694 + SET_RDI_INTO_CR3
23695 + mov $__KERNEL_DS,%edi
23696 + mov %edi,%ss
23697 +111:
23698 +#endif
23699 + .endm
23700 +
23701 + .macro pax_erase_kstack
23702 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23703 + call pax_erase_kstack
23704 +#endif
23705 + .endm
23706 +
23707 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23708 +ENTRY(pax_erase_kstack)
23709 + pushq %rdi
23710 + pushq %rcx
23711 + pushq %rax
23712 + pushq %r11
23713 +
23714 + GET_THREAD_INFO(%r11)
23715 + mov TI_lowest_stack(%r11), %rdi
23716 + mov $-0xBEEF, %rax
23717 + std
23718 +
23719 +1: mov %edi, %ecx
23720 + and $THREAD_SIZE_asm - 1, %ecx
23721 + shr $3, %ecx
23722 + repne scasq
23723 + jecxz 2f
23724 +
23725 + cmp $2*8, %ecx
23726 + jc 2f
23727 +
23728 + mov $2*8, %ecx
23729 + repe scasq
23730 + jecxz 2f
23731 + jne 1b
23732 +
23733 +2: cld
23734 + mov %esp, %ecx
23735 + sub %edi, %ecx
23736 +
23737 + cmp $THREAD_SIZE_asm, %rcx
23738 + jb 3f
23739 + ud2
23740 +3:
23741 +
23742 + shr $3, %ecx
23743 + rep stosq
23744 +
23745 + mov TI_task_thread_sp0(%r11), %rdi
23746 + sub $256, %rdi
23747 + mov %rdi, TI_lowest_stack(%r11)
23748 +
23749 + popq %r11
23750 + popq %rax
23751 + popq %rcx
23752 + popq %rdi
23753 + pax_force_retaddr
23754 + ret
23755 +ENDPROC(pax_erase_kstack)
23756 +#endif
23757
23758 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23759 #ifdef CONFIG_TRACE_IRQFLAGS
23760 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23761 .endm
23762
23763 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23764 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23765 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23766 jnc 1f
23767 TRACE_IRQS_ON_DEBUG
23768 1:
23769 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23770 movq \tmp,R11+\offset(%rsp)
23771 .endm
23772
23773 - .macro FAKE_STACK_FRAME child_rip
23774 - /* push in order ss, rsp, eflags, cs, rip */
23775 - xorl %eax, %eax
23776 - pushq_cfi $__KERNEL_DS /* ss */
23777 - /*CFI_REL_OFFSET ss,0*/
23778 - pushq_cfi %rax /* rsp */
23779 - CFI_REL_OFFSET rsp,0
23780 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23781 - /*CFI_REL_OFFSET rflags,0*/
23782 - pushq_cfi $__KERNEL_CS /* cs */
23783 - /*CFI_REL_OFFSET cs,0*/
23784 - pushq_cfi \child_rip /* rip */
23785 - CFI_REL_OFFSET rip,0
23786 - pushq_cfi %rax /* orig rax */
23787 - .endm
23788 -
23789 - .macro UNFAKE_STACK_FRAME
23790 - addq $8*6, %rsp
23791 - CFI_ADJUST_CFA_OFFSET -(6*8)
23792 - .endm
23793 -
23794 /*
23795 * initial frame state for interrupts (and exceptions without error code)
23796 */
23797 @@ -242,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23798 /* save partial stack frame */
23799 .macro SAVE_ARGS_IRQ
23800 cld
23801 - /* start from rbp in pt_regs and jump over */
23802 - movq_cfi rdi, (RDI-RBP)
23803 - movq_cfi rsi, (RSI-RBP)
23804 - movq_cfi rdx, (RDX-RBP)
23805 - movq_cfi rcx, (RCX-RBP)
23806 - movq_cfi rax, (RAX-RBP)
23807 - movq_cfi r8, (R8-RBP)
23808 - movq_cfi r9, (R9-RBP)
23809 - movq_cfi r10, (R10-RBP)
23810 - movq_cfi r11, (R11-RBP)
23811 + /* start from r15 in pt_regs and jump over */
23812 + movq_cfi rdi, RDI
23813 + movq_cfi rsi, RSI
23814 + movq_cfi rdx, RDX
23815 + movq_cfi rcx, RCX
23816 + movq_cfi rax, RAX
23817 + movq_cfi r8, R8
23818 + movq_cfi r9, R9
23819 + movq_cfi r10, R10
23820 + movq_cfi r11, R11
23821 + movq_cfi r12, R12
23822
23823 /* Save rbp so that we can unwind from get_irq_regs() */
23824 - movq_cfi rbp, 0
23825 + movq_cfi rbp, RBP
23826
23827 /* Save previous stack value */
23828 movq %rsp, %rsi
23829
23830 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23831 - testl $3, CS-RBP(%rsi)
23832 + movq %rsp,%rdi /* arg1 for handler */
23833 + testb $3, CS(%rsi)
23834 je 1f
23835 SWAPGS
23836 /*
23837 @@ -280,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23838 0x06 /* DW_OP_deref */, \
23839 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23840 0x22 /* DW_OP_plus */
23841 +
23842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23843 + testb $3, CS(%rdi)
23844 + jnz 1f
23845 + pax_enter_kernel
23846 + jmp 2f
23847 +1: pax_enter_kernel_user
23848 +2:
23849 +#else
23850 + pax_enter_kernel
23851 +#endif
23852 +
23853 /* We entered an interrupt context - irqs are off: */
23854 TRACE_IRQS_OFF
23855 .endm
23856 @@ -309,9 +727,52 @@ ENTRY(save_paranoid)
23857 js 1f /* negative -> in kernel */
23858 SWAPGS
23859 xorl %ebx,%ebx
23860 -1: ret
23861 +1:
23862 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23863 + testb $3, CS+8(%rsp)
23864 + jnz 1f
23865 + pax_enter_kernel
23866 + jmp 2f
23867 +1: pax_enter_kernel_user
23868 +2:
23869 +#else
23870 + pax_enter_kernel
23871 +#endif
23872 + pax_force_retaddr
23873 + ret
23874 CFI_ENDPROC
23875 -END(save_paranoid)
23876 +ENDPROC(save_paranoid)
23877 +
23878 +ENTRY(save_paranoid_nmi)
23879 + XCPT_FRAME 1 RDI+8
23880 + cld
23881 + movq_cfi rdi, RDI+8
23882 + movq_cfi rsi, RSI+8
23883 + movq_cfi rdx, RDX+8
23884 + movq_cfi rcx, RCX+8
23885 + movq_cfi rax, RAX+8
23886 + movq_cfi r8, R8+8
23887 + movq_cfi r9, R9+8
23888 + movq_cfi r10, R10+8
23889 + movq_cfi r11, R11+8
23890 + movq_cfi rbx, RBX+8
23891 + movq_cfi rbp, RBP+8
23892 + movq_cfi r12, R12+8
23893 + movq_cfi r13, R13+8
23894 + movq_cfi r14, R14+8
23895 + movq_cfi r15, R15+8
23896 + movl $1,%ebx
23897 + movl $MSR_GS_BASE,%ecx
23898 + rdmsr
23899 + testl %edx,%edx
23900 + js 1f /* negative -> in kernel */
23901 + SWAPGS
23902 + xorl %ebx,%ebx
23903 +1: pax_enter_kernel_nmi
23904 + pax_force_retaddr
23905 + ret
23906 + CFI_ENDPROC
23907 +ENDPROC(save_paranoid_nmi)
23908
23909 /*
23910 * A newly forked process directly context switches into this address.
23911 @@ -332,7 +793,7 @@ ENTRY(ret_from_fork)
23912
23913 RESTORE_REST
23914
23915 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23916 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23917 jz 1f
23918
23919 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23920 @@ -342,15 +803,13 @@ ENTRY(ret_from_fork)
23921 jmp ret_from_sys_call # go to the SYSRET fastpath
23922
23923 1:
23924 - subq $REST_SKIP, %rsp # leave space for volatiles
23925 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23926 movq %rbp, %rdi
23927 call *%rbx
23928 movl $0, RAX(%rsp)
23929 RESTORE_REST
23930 jmp int_ret_from_sys_call
23931 CFI_ENDPROC
23932 -END(ret_from_fork)
23933 +ENDPROC(ret_from_fork)
23934
23935 /*
23936 * System call entry. Up to 6 arguments in registers are supported.
23937 @@ -387,7 +846,7 @@ END(ret_from_fork)
23938 ENTRY(system_call)
23939 CFI_STARTPROC simple
23940 CFI_SIGNAL_FRAME
23941 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23942 + CFI_DEF_CFA rsp,0
23943 CFI_REGISTER rip,rcx
23944 /*CFI_REGISTER rflags,r11*/
23945 SWAPGS_UNSAFE_STACK
23946 @@ -400,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23947
23948 movq %rsp,PER_CPU_VAR(old_rsp)
23949 movq PER_CPU_VAR(kernel_stack),%rsp
23950 + SAVE_ARGS 8*6,0
23951 + pax_enter_kernel_user
23952 +
23953 +#ifdef CONFIG_PAX_RANDKSTACK
23954 + pax_erase_kstack
23955 +#endif
23956 +
23957 /*
23958 * No need to follow this irqs off/on section - it's straight
23959 * and short:
23960 */
23961 ENABLE_INTERRUPTS(CLBR_NONE)
23962 - SAVE_ARGS 8,0
23963 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23964 movq %rcx,RIP-ARGOFFSET(%rsp)
23965 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23966 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23967 + GET_THREAD_INFO(%rcx)
23968 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23969 jnz tracesys
23970 system_call_fastpath:
23971 #if __SYSCALL_MASK == ~0
23972 @@ -433,10 +899,13 @@ sysret_check:
23973 LOCKDEP_SYS_EXIT
23974 DISABLE_INTERRUPTS(CLBR_NONE)
23975 TRACE_IRQS_OFF
23976 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23977 + GET_THREAD_INFO(%rcx)
23978 + movl TI_flags(%rcx),%edx
23979 andl %edi,%edx
23980 jnz sysret_careful
23981 CFI_REMEMBER_STATE
23982 + pax_exit_kernel_user
23983 + pax_erase_kstack
23984 /*
23985 * sysretq will re-enable interrupts:
23986 */
23987 @@ -495,6 +964,9 @@ auditsys:
23988 movq %rax,%rsi /* 2nd arg: syscall number */
23989 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23990 call __audit_syscall_entry
23991 +
23992 + pax_erase_kstack
23993 +
23994 LOAD_ARGS 0 /* reload call-clobbered registers */
23995 jmp system_call_fastpath
23996
23997 @@ -516,7 +988,7 @@ sysret_audit:
23998 /* Do syscall tracing */
23999 tracesys:
24000 #ifdef CONFIG_AUDITSYSCALL
24001 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24002 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24003 jz auditsys
24004 #endif
24005 SAVE_REST
24006 @@ -524,12 +996,15 @@ tracesys:
24007 FIXUP_TOP_OF_STACK %rdi
24008 movq %rsp,%rdi
24009 call syscall_trace_enter
24010 +
24011 + pax_erase_kstack
24012 +
24013 /*
24014 * Reload arg registers from stack in case ptrace changed them.
24015 * We don't reload %rax because syscall_trace_enter() returned
24016 * the value it wants us to use in the table lookup.
24017 */
24018 - LOAD_ARGS ARGOFFSET, 1
24019 + LOAD_ARGS 1
24020 RESTORE_REST
24021 #if __SYSCALL_MASK == ~0
24022 cmpq $__NR_syscall_max,%rax
24023 @@ -559,7 +1034,9 @@ GLOBAL(int_with_check)
24024 andl %edi,%edx
24025 jnz int_careful
24026 andl $~TS_COMPAT,TI_status(%rcx)
24027 - jmp retint_swapgs
24028 + pax_exit_kernel_user
24029 + pax_erase_kstack
24030 + jmp retint_swapgs_pax
24031
24032 /* Either reschedule or signal or syscall exit tracking needed. */
24033 /* First do a reschedule test. */
24034 @@ -605,7 +1082,7 @@ int_restore_rest:
24035 TRACE_IRQS_OFF
24036 jmp int_with_check
24037 CFI_ENDPROC
24038 -END(system_call)
24039 +ENDPROC(system_call)
24040
24041 .macro FORK_LIKE func
24042 ENTRY(stub_\func)
24043 @@ -618,9 +1095,10 @@ ENTRY(stub_\func)
24044 DEFAULT_FRAME 0 8 /* offset 8: return address */
24045 call sys_\func
24046 RESTORE_TOP_OF_STACK %r11, 8
24047 - ret $REST_SKIP /* pop extended registers */
24048 + pax_force_retaddr
24049 + ret
24050 CFI_ENDPROC
24051 -END(stub_\func)
24052 +ENDPROC(stub_\func)
24053 .endm
24054
24055 .macro FIXED_FRAME label,func
24056 @@ -630,9 +1108,10 @@ ENTRY(\label)
24057 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24058 call \func
24059 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24060 + pax_force_retaddr
24061 ret
24062 CFI_ENDPROC
24063 -END(\label)
24064 +ENDPROC(\label)
24065 .endm
24066
24067 FORK_LIKE clone
24068 @@ -640,19 +1119,6 @@ END(\label)
24069 FORK_LIKE vfork
24070 FIXED_FRAME stub_iopl, sys_iopl
24071
24072 -ENTRY(ptregscall_common)
24073 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24074 - RESTORE_TOP_OF_STACK %r11, 8
24075 - movq_cfi_restore R15+8, r15
24076 - movq_cfi_restore R14+8, r14
24077 - movq_cfi_restore R13+8, r13
24078 - movq_cfi_restore R12+8, r12
24079 - movq_cfi_restore RBP+8, rbp
24080 - movq_cfi_restore RBX+8, rbx
24081 - ret $REST_SKIP /* pop extended registers */
24082 - CFI_ENDPROC
24083 -END(ptregscall_common)
24084 -
24085 ENTRY(stub_execve)
24086 CFI_STARTPROC
24087 addq $8, %rsp
24088 @@ -664,7 +1130,7 @@ ENTRY(stub_execve)
24089 RESTORE_REST
24090 jmp int_ret_from_sys_call
24091 CFI_ENDPROC
24092 -END(stub_execve)
24093 +ENDPROC(stub_execve)
24094
24095 /*
24096 * sigreturn is special because it needs to restore all registers on return.
24097 @@ -681,7 +1147,7 @@ ENTRY(stub_rt_sigreturn)
24098 RESTORE_REST
24099 jmp int_ret_from_sys_call
24100 CFI_ENDPROC
24101 -END(stub_rt_sigreturn)
24102 +ENDPROC(stub_rt_sigreturn)
24103
24104 #ifdef CONFIG_X86_X32_ABI
24105 ENTRY(stub_x32_rt_sigreturn)
24106 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_rt_sigreturn)
24107 RESTORE_REST
24108 jmp int_ret_from_sys_call
24109 CFI_ENDPROC
24110 -END(stub_x32_rt_sigreturn)
24111 +ENDPROC(stub_x32_rt_sigreturn)
24112
24113 ENTRY(stub_x32_execve)
24114 CFI_STARTPROC
24115 @@ -709,7 +1175,7 @@ ENTRY(stub_x32_execve)
24116 RESTORE_REST
24117 jmp int_ret_from_sys_call
24118 CFI_ENDPROC
24119 -END(stub_x32_execve)
24120 +ENDPROC(stub_x32_execve)
24121
24122 #endif
24123
24124 @@ -746,7 +1212,7 @@ vector=vector+1
24125 2: jmp common_interrupt
24126 .endr
24127 CFI_ENDPROC
24128 -END(irq_entries_start)
24129 +ENDPROC(irq_entries_start)
24130
24131 .previous
24132 END(interrupt)
24133 @@ -763,8 +1229,8 @@ END(interrupt)
24134 /* 0(%rsp): ~(interrupt number) */
24135 .macro interrupt func
24136 /* reserve pt_regs for scratch regs and rbp */
24137 - subq $ORIG_RAX-RBP, %rsp
24138 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24139 + subq $ORIG_RAX, %rsp
24140 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24141 SAVE_ARGS_IRQ
24142 call \func
24143 .endm
24144 @@ -787,14 +1253,14 @@ ret_from_intr:
24145
24146 /* Restore saved previous stack */
24147 popq %rsi
24148 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24149 - leaq ARGOFFSET-RBP(%rsi), %rsp
24150 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24151 + movq %rsi, %rsp
24152 CFI_DEF_CFA_REGISTER rsp
24153 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24154 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24155
24156 exit_intr:
24157 GET_THREAD_INFO(%rcx)
24158 - testl $3,CS-ARGOFFSET(%rsp)
24159 + testb $3,CS-ARGOFFSET(%rsp)
24160 je retint_kernel
24161
24162 /* Interrupt came from user space */
24163 @@ -816,12 +1282,35 @@ retint_swapgs: /* return to user-space */
24164 * The iretq could re-enable interrupts:
24165 */
24166 DISABLE_INTERRUPTS(CLBR_ANY)
24167 + pax_exit_kernel_user
24168 +retint_swapgs_pax:
24169 TRACE_IRQS_IRETQ
24170 SWAPGS
24171 jmp restore_args
24172
24173 retint_restore_args: /* return to kernel space */
24174 DISABLE_INTERRUPTS(CLBR_ANY)
24175 + pax_exit_kernel
24176 +
24177 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24178 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24179 + * namely calling EFI runtime services with a phys mapping. We're
24180 + * starting off with NOPs and patch in the real instrumentation
24181 + * (BTS/OR) before starting any userland process; even before starting
24182 + * up the APs.
24183 + */
24184 + .pushsection .altinstr_replacement, "a"
24185 + 601: pax_force_retaddr (RIP-ARGOFFSET)
24186 + 602:
24187 + .popsection
24188 + 603: .fill 602b-601b, 1, 0x90
24189 + .pushsection .altinstructions, "a"
24190 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24191 + .popsection
24192 +#else
24193 + pax_force_retaddr (RIP-ARGOFFSET)
24194 +#endif
24195 +
24196 /*
24197 * The iretq could re-enable interrupts:
24198 */
24199 @@ -934,7 +1423,7 @@ ENTRY(retint_kernel)
24200 jmp exit_intr
24201 #endif
24202 CFI_ENDPROC
24203 -END(common_interrupt)
24204 +ENDPROC(common_interrupt)
24205
24206 /*
24207 * If IRET takes a fault on the espfix stack, then we
24208 @@ -956,13 +1445,13 @@ __do_double_fault:
24209 cmpq $native_irq_return_iret,%rax
24210 jne do_double_fault /* This shouldn't happen... */
24211 movq PER_CPU_VAR(kernel_stack),%rax
24212 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24213 + subq $(6*8),%rax /* Reset to original stack */
24214 movq %rax,RSP(%rdi)
24215 movq $0,(%rax) /* Missing (lost) #GP error code */
24216 movq $general_protection,RIP(%rdi)
24217 retq
24218 CFI_ENDPROC
24219 -END(__do_double_fault)
24220 +ENDPROC(__do_double_fault)
24221 #else
24222 # define __do_double_fault do_double_fault
24223 #endif
24224 @@ -979,7 +1468,7 @@ ENTRY(\sym)
24225 interrupt \do_sym
24226 jmp ret_from_intr
24227 CFI_ENDPROC
24228 -END(\sym)
24229 +ENDPROC(\sym)
24230 .endm
24231
24232 #ifdef CONFIG_TRACING
24233 @@ -1052,7 +1541,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24234 /*
24235 * Exception entry points.
24236 */
24237 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24238 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24239
24240 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24241 ENTRY(\sym)
24242 @@ -1103,6 +1592,12 @@ ENTRY(\sym)
24243 .endif
24244
24245 .if \shift_ist != -1
24246 +#ifdef CONFIG_SMP
24247 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24248 + lea init_tss(%r13), %r13
24249 +#else
24250 + lea init_tss(%rip), %r13
24251 +#endif
24252 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24253 .endif
24254
24255 @@ -1119,7 +1614,7 @@ ENTRY(\sym)
24256 .endif
24257
24258 CFI_ENDPROC
24259 -END(\sym)
24260 +ENDPROC(\sym)
24261 .endm
24262
24263 #ifdef CONFIG_TRACING
24264 @@ -1160,9 +1655,10 @@ gs_change:
24265 2: mfence /* workaround */
24266 SWAPGS
24267 popfq_cfi
24268 + pax_force_retaddr
24269 ret
24270 CFI_ENDPROC
24271 -END(native_load_gs_index)
24272 +ENDPROC(native_load_gs_index)
24273
24274 _ASM_EXTABLE(gs_change,bad_gs)
24275 .section .fixup,"ax"
24276 @@ -1190,9 +1686,10 @@ ENTRY(do_softirq_own_stack)
24277 CFI_DEF_CFA_REGISTER rsp
24278 CFI_ADJUST_CFA_OFFSET -8
24279 decl PER_CPU_VAR(irq_count)
24280 + pax_force_retaddr
24281 ret
24282 CFI_ENDPROC
24283 -END(do_softirq_own_stack)
24284 +ENDPROC(do_softirq_own_stack)
24285
24286 #ifdef CONFIG_XEN
24287 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24288 @@ -1230,7 +1727,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24289 decl PER_CPU_VAR(irq_count)
24290 jmp error_exit
24291 CFI_ENDPROC
24292 -END(xen_do_hypervisor_callback)
24293 +ENDPROC(xen_do_hypervisor_callback)
24294
24295 /*
24296 * Hypervisor uses this for application faults while it executes.
24297 @@ -1289,7 +1786,7 @@ ENTRY(xen_failsafe_callback)
24298 SAVE_ALL
24299 jmp error_exit
24300 CFI_ENDPROC
24301 -END(xen_failsafe_callback)
24302 +ENDPROC(xen_failsafe_callback)
24303
24304 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24305 xen_hvm_callback_vector xen_evtchn_do_upcall
24306 @@ -1336,18 +1833,33 @@ ENTRY(paranoid_exit)
24307 DEFAULT_FRAME
24308 DISABLE_INTERRUPTS(CLBR_NONE)
24309 TRACE_IRQS_OFF_DEBUG
24310 - testl %ebx,%ebx /* swapgs needed? */
24311 + testl $1,%ebx /* swapgs needed? */
24312 jnz paranoid_restore
24313 - testl $3,CS(%rsp)
24314 + testb $3,CS(%rsp)
24315 jnz paranoid_userspace
24316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24317 + pax_exit_kernel
24318 + TRACE_IRQS_IRETQ 0
24319 + SWAPGS_UNSAFE_STACK
24320 + RESTORE_ALL 8
24321 + pax_force_retaddr_bts
24322 + jmp irq_return
24323 +#endif
24324 paranoid_swapgs:
24325 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24326 + pax_exit_kernel_user
24327 +#else
24328 + pax_exit_kernel
24329 +#endif
24330 TRACE_IRQS_IRETQ 0
24331 SWAPGS_UNSAFE_STACK
24332 RESTORE_ALL 8
24333 jmp irq_return
24334 paranoid_restore:
24335 + pax_exit_kernel
24336 TRACE_IRQS_IRETQ_DEBUG 0
24337 RESTORE_ALL 8
24338 + pax_force_retaddr_bts
24339 jmp irq_return
24340 paranoid_userspace:
24341 GET_THREAD_INFO(%rcx)
24342 @@ -1376,7 +1888,7 @@ paranoid_schedule:
24343 TRACE_IRQS_OFF
24344 jmp paranoid_userspace
24345 CFI_ENDPROC
24346 -END(paranoid_exit)
24347 +ENDPROC(paranoid_exit)
24348
24349 /*
24350 * Exception entry point. This expects an error code/orig_rax on the stack.
24351 @@ -1403,12 +1915,23 @@ ENTRY(error_entry)
24352 movq_cfi r14, R14+8
24353 movq_cfi r15, R15+8
24354 xorl %ebx,%ebx
24355 - testl $3,CS+8(%rsp)
24356 + testb $3,CS+8(%rsp)
24357 je error_kernelspace
24358 error_swapgs:
24359 SWAPGS
24360 error_sti:
24361 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24362 + testb $3, CS+8(%rsp)
24363 + jnz 1f
24364 + pax_enter_kernel
24365 + jmp 2f
24366 +1: pax_enter_kernel_user
24367 +2:
24368 +#else
24369 + pax_enter_kernel
24370 +#endif
24371 TRACE_IRQS_OFF
24372 + pax_force_retaddr
24373 ret
24374
24375 /*
24376 @@ -1435,7 +1958,7 @@ bstep_iret:
24377 movq %rcx,RIP+8(%rsp)
24378 jmp error_swapgs
24379 CFI_ENDPROC
24380 -END(error_entry)
24381 +ENDPROC(error_entry)
24382
24383
24384 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24385 @@ -1446,7 +1969,7 @@ ENTRY(error_exit)
24386 DISABLE_INTERRUPTS(CLBR_NONE)
24387 TRACE_IRQS_OFF
24388 GET_THREAD_INFO(%rcx)
24389 - testl %eax,%eax
24390 + testl $1,%eax
24391 jne retint_kernel
24392 LOCKDEP_SYS_EXIT_IRQ
24393 movl TI_flags(%rcx),%edx
24394 @@ -1455,7 +1978,7 @@ ENTRY(error_exit)
24395 jnz retint_careful
24396 jmp retint_swapgs
24397 CFI_ENDPROC
24398 -END(error_exit)
24399 +ENDPROC(error_exit)
24400
24401 /*
24402 * Test if a given stack is an NMI stack or not.
24403 @@ -1513,9 +2036,11 @@ ENTRY(nmi)
24404 * If %cs was not the kernel segment, then the NMI triggered in user
24405 * space, which means it is definitely not nested.
24406 */
24407 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24408 + je 1f
24409 cmpl $__KERNEL_CS, 16(%rsp)
24410 jne first_nmi
24411 -
24412 +1:
24413 /*
24414 * Check the special variable on the stack to see if NMIs are
24415 * executing.
24416 @@ -1549,8 +2074,7 @@ nested_nmi:
24417
24418 1:
24419 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24420 - leaq -1*8(%rsp), %rdx
24421 - movq %rdx, %rsp
24422 + subq $8, %rsp
24423 CFI_ADJUST_CFA_OFFSET 1*8
24424 leaq -10*8(%rsp), %rdx
24425 pushq_cfi $__KERNEL_DS
24426 @@ -1568,6 +2092,7 @@ nested_nmi_out:
24427 CFI_RESTORE rdx
24428
24429 /* No need to check faults here */
24430 +# pax_force_retaddr_bts
24431 INTERRUPT_RETURN
24432
24433 CFI_RESTORE_STATE
24434 @@ -1664,13 +2189,13 @@ end_repeat_nmi:
24435 subq $ORIG_RAX-R15, %rsp
24436 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24437 /*
24438 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24439 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24440 * as we should not be calling schedule in NMI context.
24441 * Even with normal interrupts enabled. An NMI should not be
24442 * setting NEED_RESCHED or anything that normal interrupts and
24443 * exceptions might do.
24444 */
24445 - call save_paranoid
24446 + call save_paranoid_nmi
24447 DEFAULT_FRAME 0
24448
24449 /*
24450 @@ -1680,9 +2205,9 @@ end_repeat_nmi:
24451 * NMI itself takes a page fault, the page fault that was preempted
24452 * will read the information from the NMI page fault and not the
24453 * origin fault. Save it off and restore it if it changes.
24454 - * Use the r12 callee-saved register.
24455 + * Use the r13 callee-saved register.
24456 */
24457 - movq %cr2, %r12
24458 + movq %cr2, %r13
24459
24460 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24461 movq %rsp,%rdi
24462 @@ -1691,29 +2216,34 @@ end_repeat_nmi:
24463
24464 /* Did the NMI take a page fault? Restore cr2 if it did */
24465 movq %cr2, %rcx
24466 - cmpq %rcx, %r12
24467 + cmpq %rcx, %r13
24468 je 1f
24469 - movq %r12, %cr2
24470 + movq %r13, %cr2
24471 1:
24472
24473 - testl %ebx,%ebx /* swapgs needed? */
24474 + testl $1,%ebx /* swapgs needed? */
24475 jnz nmi_restore
24476 nmi_swapgs:
24477 SWAPGS_UNSAFE_STACK
24478 nmi_restore:
24479 + pax_exit_kernel_nmi
24480 /* Pop the extra iret frame at once */
24481 RESTORE_ALL 6*8
24482 + testb $3, 8(%rsp)
24483 + jnz 1f
24484 + pax_force_retaddr_bts
24485 +1:
24486
24487 /* Clear the NMI executing stack variable */
24488 movq $0, 5*8(%rsp)
24489 jmp irq_return
24490 CFI_ENDPROC
24491 -END(nmi)
24492 +ENDPROC(nmi)
24493
24494 ENTRY(ignore_sysret)
24495 CFI_STARTPROC
24496 mov $-ENOSYS,%eax
24497 sysret
24498 CFI_ENDPROC
24499 -END(ignore_sysret)
24500 +ENDPROC(ignore_sysret)
24501
24502 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24503 index 94d857f..bf1f0bf 100644
24504 --- a/arch/x86/kernel/espfix_64.c
24505 +++ b/arch/x86/kernel/espfix_64.c
24506 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24507 set_pte(&pte_p[n*PTE_STRIDE], pte);
24508
24509 /* Job is done for this CPU and any CPU which shares this page */
24510 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24511 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24512
24513 unlock_done:
24514 mutex_unlock(&espfix_init_mutex);
24515 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24516 index cbc4a91..b38ee45 100644
24517 --- a/arch/x86/kernel/ftrace.c
24518 +++ b/arch/x86/kernel/ftrace.c
24519 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24520 * kernel identity mapping to modify code.
24521 */
24522 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24523 - ip = (unsigned long)__va(__pa_symbol(ip));
24524 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24525
24526 return ip;
24527 }
24528 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24529 {
24530 unsigned char replaced[MCOUNT_INSN_SIZE];
24531
24532 + ip = ktla_ktva(ip);
24533 +
24534 /*
24535 * Note: Due to modules and __init, code can
24536 * disappear and change, we need to protect against faulting
24537 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24538 unsigned char old[MCOUNT_INSN_SIZE];
24539 int ret;
24540
24541 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24542 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24543
24544 ftrace_update_func = ip;
24545 /* Make sure the breakpoints see the ftrace_update_func update */
24546 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24547 unsigned char replaced[MCOUNT_INSN_SIZE];
24548 unsigned char brk = BREAKPOINT_INSTRUCTION;
24549
24550 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24551 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24552 return -EFAULT;
24553
24554 /* Make sure it is what we expect it to be */
24555 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24556 index eda1a86..8f6df48 100644
24557 --- a/arch/x86/kernel/head64.c
24558 +++ b/arch/x86/kernel/head64.c
24559 @@ -67,12 +67,12 @@ again:
24560 pgd = *pgd_p;
24561
24562 /*
24563 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24564 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24565 + * The use of __early_va rather than __va here is critical:
24566 + * __va would point us back into the dynamic
24567 * range and we might end up looping forever...
24568 */
24569 if (pgd)
24570 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24571 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24572 else {
24573 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24574 reset_early_page_tables();
24575 @@ -82,13 +82,13 @@ again:
24576 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24577 for (i = 0; i < PTRS_PER_PUD; i++)
24578 pud_p[i] = 0;
24579 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24580 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24581 }
24582 pud_p += pud_index(address);
24583 pud = *pud_p;
24584
24585 if (pud)
24586 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24587 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24588 else {
24589 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24590 reset_early_page_tables();
24591 @@ -98,7 +98,7 @@ again:
24592 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24593 for (i = 0; i < PTRS_PER_PMD; i++)
24594 pmd_p[i] = 0;
24595 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24596 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24597 }
24598 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24599 pmd_p[pmd_index(address)] = pmd;
24600 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24601 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24602 early_printk("Kernel alive\n");
24603
24604 - clear_page(init_level4_pgt);
24605 /* set init_level4_pgt kernel high mapping*/
24606 init_level4_pgt[511] = early_level4_pgt[511];
24607
24608 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24609 index f36bd42..0ab4474 100644
24610 --- a/arch/x86/kernel/head_32.S
24611 +++ b/arch/x86/kernel/head_32.S
24612 @@ -26,6 +26,12 @@
24613 /* Physical address */
24614 #define pa(X) ((X) - __PAGE_OFFSET)
24615
24616 +#ifdef CONFIG_PAX_KERNEXEC
24617 +#define ta(X) (X)
24618 +#else
24619 +#define ta(X) ((X) - __PAGE_OFFSET)
24620 +#endif
24621 +
24622 /*
24623 * References to members of the new_cpu_data structure.
24624 */
24625 @@ -55,11 +61,7 @@
24626 * and small than max_low_pfn, otherwise will waste some page table entries
24627 */
24628
24629 -#if PTRS_PER_PMD > 1
24630 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24631 -#else
24632 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24633 -#endif
24634 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24635
24636 /* Number of possible pages in the lowmem region */
24637 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24638 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24639 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24640
24641 /*
24642 + * Real beginning of normal "text" segment
24643 + */
24644 +ENTRY(stext)
24645 +ENTRY(_stext)
24646 +
24647 +/*
24648 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24649 * %esi points to the real-mode code as a 32-bit pointer.
24650 * CS and DS must be 4 GB flat segments, but we don't depend on
24651 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24652 * can.
24653 */
24654 __HEAD
24655 +
24656 +#ifdef CONFIG_PAX_KERNEXEC
24657 + jmp startup_32
24658 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24659 +.fill PAGE_SIZE-5,1,0xcc
24660 +#endif
24661 +
24662 ENTRY(startup_32)
24663 movl pa(stack_start),%ecx
24664
24665 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24666 2:
24667 leal -__PAGE_OFFSET(%ecx),%esp
24668
24669 +#ifdef CONFIG_SMP
24670 + movl $pa(cpu_gdt_table),%edi
24671 + movl $__per_cpu_load,%eax
24672 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24673 + rorl $16,%eax
24674 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24675 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24676 + movl $__per_cpu_end - 1,%eax
24677 + subl $__per_cpu_start,%eax
24678 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24679 +#endif
24680 +
24681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24682 + movl $NR_CPUS,%ecx
24683 + movl $pa(cpu_gdt_table),%edi
24684 +1:
24685 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24686 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24687 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24688 + addl $PAGE_SIZE_asm,%edi
24689 + loop 1b
24690 +#endif
24691 +
24692 +#ifdef CONFIG_PAX_KERNEXEC
24693 + movl $pa(boot_gdt),%edi
24694 + movl $__LOAD_PHYSICAL_ADDR,%eax
24695 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24696 + rorl $16,%eax
24697 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24698 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24699 + rorl $16,%eax
24700 +
24701 + ljmp $(__BOOT_CS),$1f
24702 +1:
24703 +
24704 + movl $NR_CPUS,%ecx
24705 + movl $pa(cpu_gdt_table),%edi
24706 + addl $__PAGE_OFFSET,%eax
24707 +1:
24708 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24709 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24710 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24711 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24712 + rorl $16,%eax
24713 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24714 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24715 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24716 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24717 + rorl $16,%eax
24718 + addl $PAGE_SIZE_asm,%edi
24719 + loop 1b
24720 +#endif
24721 +
24722 /*
24723 * Clear BSS first so that there are no surprises...
24724 */
24725 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24726 movl %eax, pa(max_pfn_mapped)
24727
24728 /* Do early initialization of the fixmap area */
24729 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24730 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24731 +#ifdef CONFIG_COMPAT_VDSO
24732 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24733 +#else
24734 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24735 +#endif
24736 #else /* Not PAE */
24737
24738 page_pde_offset = (__PAGE_OFFSET >> 20);
24739 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24740 movl %eax, pa(max_pfn_mapped)
24741
24742 /* Do early initialization of the fixmap area */
24743 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24744 - movl %eax,pa(initial_page_table+0xffc)
24745 +#ifdef CONFIG_COMPAT_VDSO
24746 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24747 +#else
24748 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24749 +#endif
24750 #endif
24751
24752 #ifdef CONFIG_PARAVIRT
24753 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24754 cmpl $num_subarch_entries, %eax
24755 jae bad_subarch
24756
24757 - movl pa(subarch_entries)(,%eax,4), %eax
24758 - subl $__PAGE_OFFSET, %eax
24759 - jmp *%eax
24760 + jmp *pa(subarch_entries)(,%eax,4)
24761
24762 bad_subarch:
24763 WEAK(lguest_entry)
24764 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24765 __INITDATA
24766
24767 subarch_entries:
24768 - .long default_entry /* normal x86/PC */
24769 - .long lguest_entry /* lguest hypervisor */
24770 - .long xen_entry /* Xen hypervisor */
24771 - .long default_entry /* Moorestown MID */
24772 + .long ta(default_entry) /* normal x86/PC */
24773 + .long ta(lguest_entry) /* lguest hypervisor */
24774 + .long ta(xen_entry) /* Xen hypervisor */
24775 + .long ta(default_entry) /* Moorestown MID */
24776 num_subarch_entries = (. - subarch_entries) / 4
24777 .previous
24778 #else
24779 @@ -354,6 +426,7 @@ default_entry:
24780 movl pa(mmu_cr4_features),%eax
24781 movl %eax,%cr4
24782
24783 +#ifdef CONFIG_X86_PAE
24784 testb $X86_CR4_PAE, %al # check if PAE is enabled
24785 jz enable_paging
24786
24787 @@ -382,6 +455,9 @@ default_entry:
24788 /* Make changes effective */
24789 wrmsr
24790
24791 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24792 +#endif
24793 +
24794 enable_paging:
24795
24796 /*
24797 @@ -449,14 +525,20 @@ is486:
24798 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24799 movl %eax,%ss # after changing gdt.
24800
24801 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24802 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24803 movl %eax,%ds
24804 movl %eax,%es
24805
24806 movl $(__KERNEL_PERCPU), %eax
24807 movl %eax,%fs # set this cpu's percpu
24808
24809 +#ifdef CONFIG_CC_STACKPROTECTOR
24810 movl $(__KERNEL_STACK_CANARY),%eax
24811 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24812 + movl $(__USER_DS),%eax
24813 +#else
24814 + xorl %eax,%eax
24815 +#endif
24816 movl %eax,%gs
24817
24818 xorl %eax,%eax # Clear LDT
24819 @@ -512,8 +594,11 @@ setup_once:
24820 * relocation. Manually set base address in stack canary
24821 * segment descriptor.
24822 */
24823 - movl $gdt_page,%eax
24824 + movl $cpu_gdt_table,%eax
24825 movl $stack_canary,%ecx
24826 +#ifdef CONFIG_SMP
24827 + addl $__per_cpu_load,%ecx
24828 +#endif
24829 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24830 shrl $16, %ecx
24831 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24832 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24833 cmpl $2,(%esp) # X86_TRAP_NMI
24834 je is_nmi # Ignore NMI
24835
24836 - cmpl $2,%ss:early_recursion_flag
24837 + cmpl $1,%ss:early_recursion_flag
24838 je hlt_loop
24839 incl %ss:early_recursion_flag
24840
24841 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24842 pushl (20+6*4)(%esp) /* trapno */
24843 pushl $fault_msg
24844 call printk
24845 -#endif
24846 call dump_stack
24847 +#endif
24848 hlt_loop:
24849 hlt
24850 jmp hlt_loop
24851 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24852 /* This is the default interrupt "handler" :-) */
24853 ALIGN
24854 ignore_int:
24855 - cld
24856 #ifdef CONFIG_PRINTK
24857 + cmpl $2,%ss:early_recursion_flag
24858 + je hlt_loop
24859 + incl %ss:early_recursion_flag
24860 + cld
24861 pushl %eax
24862 pushl %ecx
24863 pushl %edx
24864 @@ -617,9 +705,6 @@ ignore_int:
24865 movl $(__KERNEL_DS),%eax
24866 movl %eax,%ds
24867 movl %eax,%es
24868 - cmpl $2,early_recursion_flag
24869 - je hlt_loop
24870 - incl early_recursion_flag
24871 pushl 16(%esp)
24872 pushl 24(%esp)
24873 pushl 32(%esp)
24874 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24875 /*
24876 * BSS section
24877 */
24878 -__PAGE_ALIGNED_BSS
24879 - .align PAGE_SIZE
24880 #ifdef CONFIG_X86_PAE
24881 +.section .initial_pg_pmd,"a",@progbits
24882 initial_pg_pmd:
24883 .fill 1024*KPMDS,4,0
24884 #else
24885 +.section .initial_page_table,"a",@progbits
24886 ENTRY(initial_page_table)
24887 .fill 1024,4,0
24888 #endif
24889 +.section .initial_pg_fixmap,"a",@progbits
24890 initial_pg_fixmap:
24891 .fill 1024,4,0
24892 +.section .empty_zero_page,"a",@progbits
24893 ENTRY(empty_zero_page)
24894 .fill 4096,1,0
24895 +.section .swapper_pg_dir,"a",@progbits
24896 ENTRY(swapper_pg_dir)
24897 +#ifdef CONFIG_X86_PAE
24898 + .fill 4,8,0
24899 +#else
24900 .fill 1024,4,0
24901 +#endif
24902
24903 /*
24904 * This starts the data section.
24905 */
24906 #ifdef CONFIG_X86_PAE
24907 -__PAGE_ALIGNED_DATA
24908 - /* Page-aligned for the benefit of paravirt? */
24909 - .align PAGE_SIZE
24910 +.section .initial_page_table,"a",@progbits
24911 ENTRY(initial_page_table)
24912 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24913 # if KPMDS == 3
24914 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24915 # error "Kernel PMDs should be 1, 2 or 3"
24916 # endif
24917 .align PAGE_SIZE /* needs to be page-sized too */
24918 +
24919 +#ifdef CONFIG_PAX_PER_CPU_PGD
24920 +ENTRY(cpu_pgd)
24921 + .rept 2*NR_CPUS
24922 + .fill 4,8,0
24923 + .endr
24924 +#endif
24925 +
24926 #endif
24927
24928 .data
24929 .balign 4
24930 ENTRY(stack_start)
24931 - .long init_thread_union+THREAD_SIZE
24932 + .long init_thread_union+THREAD_SIZE-8
24933
24934 __INITRODATA
24935 int_msg:
24936 @@ -727,7 +825,7 @@ fault_msg:
24937 * segment size, and 32-bit linear address value:
24938 */
24939
24940 - .data
24941 +.section .rodata,"a",@progbits
24942 .globl boot_gdt_descr
24943 .globl idt_descr
24944
24945 @@ -736,7 +834,7 @@ fault_msg:
24946 .word 0 # 32 bit align gdt_desc.address
24947 boot_gdt_descr:
24948 .word __BOOT_DS+7
24949 - .long boot_gdt - __PAGE_OFFSET
24950 + .long pa(boot_gdt)
24951
24952 .word 0 # 32-bit align idt_desc.address
24953 idt_descr:
24954 @@ -747,7 +845,7 @@ idt_descr:
24955 .word 0 # 32 bit align gdt_desc.address
24956 ENTRY(early_gdt_descr)
24957 .word GDT_ENTRIES*8-1
24958 - .long gdt_page /* Overwritten for secondary CPUs */
24959 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24960
24961 /*
24962 * The boot_gdt must mirror the equivalent in setup.S and is
24963 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24964 .align L1_CACHE_BYTES
24965 ENTRY(boot_gdt)
24966 .fill GDT_ENTRY_BOOT_CS,8,0
24967 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24968 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24969 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24970 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24971 +
24972 + .align PAGE_SIZE_asm
24973 +ENTRY(cpu_gdt_table)
24974 + .rept NR_CPUS
24975 + .quad 0x0000000000000000 /* NULL descriptor */
24976 + .quad 0x0000000000000000 /* 0x0b reserved */
24977 + .quad 0x0000000000000000 /* 0x13 reserved */
24978 + .quad 0x0000000000000000 /* 0x1b reserved */
24979 +
24980 +#ifdef CONFIG_PAX_KERNEXEC
24981 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24982 +#else
24983 + .quad 0x0000000000000000 /* 0x20 unused */
24984 +#endif
24985 +
24986 + .quad 0x0000000000000000 /* 0x28 unused */
24987 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24988 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24989 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24990 + .quad 0x0000000000000000 /* 0x4b reserved */
24991 + .quad 0x0000000000000000 /* 0x53 reserved */
24992 + .quad 0x0000000000000000 /* 0x5b reserved */
24993 +
24994 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24995 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24996 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24997 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24998 +
24999 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25000 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25001 +
25002 + /*
25003 + * Segments used for calling PnP BIOS have byte granularity.
25004 + * The code segments and data segments have fixed 64k limits,
25005 + * the transfer segment sizes are set at run time.
25006 + */
25007 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
25008 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
25009 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
25010 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
25011 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
25012 +
25013 + /*
25014 + * The APM segments have byte granularity and their bases
25015 + * are set at run time. All have 64k limits.
25016 + */
25017 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25018 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25019 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
25020 +
25021 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25022 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25023 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25024 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25025 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25026 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25027 +
25028 + /* Be sure this is zeroed to avoid false validations in Xen */
25029 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25030 + .endr
25031 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25032 index a468c0a..c7dec74 100644
25033 --- a/arch/x86/kernel/head_64.S
25034 +++ b/arch/x86/kernel/head_64.S
25035 @@ -20,6 +20,8 @@
25036 #include <asm/processor-flags.h>
25037 #include <asm/percpu.h>
25038 #include <asm/nops.h>
25039 +#include <asm/cpufeature.h>
25040 +#include <asm/alternative-asm.h>
25041
25042 #ifdef CONFIG_PARAVIRT
25043 #include <asm/asm-offsets.h>
25044 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25045 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25046 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25047 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25048 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
25049 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25050 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25051 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25052 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25053 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25054
25055 .text
25056 __HEAD
25057 @@ -89,11 +97,24 @@ startup_64:
25058 * Fixup the physical addresses in the page table
25059 */
25060 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25061 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25062 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25063 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25064 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25065 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25066
25067 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25068 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25069 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25070 +#ifndef CONFIG_XEN
25071 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25072 +#endif
25073 +
25074 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25075 +
25076 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25077 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25078
25079 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25080 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25081
25082 /*
25083 * Set up the identity mapping for the switchover. These
25084 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
25085 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25086 1:
25087
25088 - /* Enable PAE mode and PGE */
25089 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25090 + /* Enable PAE mode and PSE/PGE */
25091 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25092 movq %rcx, %cr4
25093
25094 /* Setup early boot stage 4 level pagetables. */
25095 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
25096 movl $MSR_EFER, %ecx
25097 rdmsr
25098 btsl $_EFER_SCE, %eax /* Enable System Call */
25099 - btl $20,%edi /* No Execute supported? */
25100 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25101 jnc 1f
25102 btsl $_EFER_NX, %eax
25103 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25104 +#ifndef CONFIG_EFI
25105 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25106 +#endif
25107 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25108 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25109 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25110 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25111 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25112 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25113 1: wrmsr /* Make changes effective */
25114
25115 /* Setup cr0 */
25116 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
25117 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25118 * address given in m16:64.
25119 */
25120 + pax_set_fptr_mask
25121 movq initial_code(%rip),%rax
25122 pushq $0 # fake return address to stop unwinder
25123 pushq $__KERNEL_CS # set correct cs
25124 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
25125 .quad INIT_PER_CPU_VAR(irq_stack_union)
25126
25127 GLOBAL(stack_start)
25128 - .quad init_thread_union+THREAD_SIZE-8
25129 + .quad init_thread_union+THREAD_SIZE-16
25130 .word 0
25131 __FINITDATA
25132
25133 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
25134 call dump_stack
25135 #ifdef CONFIG_KALLSYMS
25136 leaq early_idt_ripmsg(%rip),%rdi
25137 - movq 40(%rsp),%rsi # %rip again
25138 + movq 88(%rsp),%rsi # %rip again
25139 call __print_symbol
25140 #endif
25141 #endif /* EARLY_PRINTK */
25142 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
25143 early_recursion_flag:
25144 .long 0
25145
25146 + .section .rodata,"a",@progbits
25147 #ifdef CONFIG_EARLY_PRINTK
25148 early_idt_msg:
25149 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25150 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
25151 NEXT_PAGE(early_dynamic_pgts)
25152 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25153
25154 - .data
25155 + .section .rodata,"a",@progbits
25156
25157 -#ifndef CONFIG_XEN
25158 NEXT_PAGE(init_level4_pgt)
25159 - .fill 512,8,0
25160 -#else
25161 -NEXT_PAGE(init_level4_pgt)
25162 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25163 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25164 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25165 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25166 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25167 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25168 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25169 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25170 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25171 .org init_level4_pgt + L4_START_KERNEL*8, 0
25172 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25173 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25174
25175 +#ifdef CONFIG_PAX_PER_CPU_PGD
25176 +NEXT_PAGE(cpu_pgd)
25177 + .rept 2*NR_CPUS
25178 + .fill 512,8,0
25179 + .endr
25180 +#endif
25181 +
25182 NEXT_PAGE(level3_ident_pgt)
25183 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25184 +#ifdef CONFIG_XEN
25185 .fill 511, 8, 0
25186 +#else
25187 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25188 + .fill 510,8,0
25189 +#endif
25190 +
25191 +NEXT_PAGE(level3_vmalloc_start_pgt)
25192 + .fill 512,8,0
25193 +
25194 +NEXT_PAGE(level3_vmalloc_end_pgt)
25195 + .fill 512,8,0
25196 +
25197 +NEXT_PAGE(level3_vmemmap_pgt)
25198 + .fill L3_VMEMMAP_START,8,0
25199 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25200 +
25201 NEXT_PAGE(level2_ident_pgt)
25202 - /* Since I easily can, map the first 1G.
25203 + /* Since I easily can, map the first 2G.
25204 * Don't set NX because code runs from these pages.
25205 */
25206 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25207 -#endif
25208 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25209
25210 NEXT_PAGE(level3_kernel_pgt)
25211 .fill L3_START_KERNEL,8,0
25212 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25213 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25214 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25215
25216 +NEXT_PAGE(level2_vmemmap_pgt)
25217 + .fill 512,8,0
25218 +
25219 NEXT_PAGE(level2_kernel_pgt)
25220 /*
25221 * 512 MB kernel mapping. We spend a full page on this pagetable
25222 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25223 NEXT_PAGE(level2_fixmap_pgt)
25224 .fill 506,8,0
25225 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25226 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25227 - .fill 5,8,0
25228 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25229 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25230 + .fill 4,8,0
25231
25232 NEXT_PAGE(level1_fixmap_pgt)
25233 .fill 512,8,0
25234
25235 +NEXT_PAGE(level1_vsyscall_pgt)
25236 + .fill 512,8,0
25237 +
25238 #undef PMDS
25239
25240 - .data
25241 + .align PAGE_SIZE
25242 +ENTRY(cpu_gdt_table)
25243 + .rept NR_CPUS
25244 + .quad 0x0000000000000000 /* NULL descriptor */
25245 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25246 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25247 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25248 + .quad 0x00cffb000000ffff /* __USER32_CS */
25249 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25250 + .quad 0x00affb000000ffff /* __USER_CS */
25251 +
25252 +#ifdef CONFIG_PAX_KERNEXEC
25253 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25254 +#else
25255 + .quad 0x0 /* unused */
25256 +#endif
25257 +
25258 + .quad 0,0 /* TSS */
25259 + .quad 0,0 /* LDT */
25260 + .quad 0,0,0 /* three TLS descriptors */
25261 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25262 + /* asm/segment.h:GDT_ENTRIES must match this */
25263 +
25264 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25265 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25266 +#else
25267 + .quad 0x0 /* unused */
25268 +#endif
25269 +
25270 + /* zero the remaining page */
25271 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25272 + .endr
25273 +
25274 .align 16
25275 .globl early_gdt_descr
25276 early_gdt_descr:
25277 .word GDT_ENTRIES*8-1
25278 early_gdt_descr_base:
25279 - .quad INIT_PER_CPU_VAR(gdt_page)
25280 + .quad cpu_gdt_table
25281
25282 ENTRY(phys_base)
25283 /* This must match the first entry in level2_kernel_pgt */
25284 .quad 0x0000000000000000
25285
25286 #include "../../x86/xen/xen-head.S"
25287 -
25288 - __PAGE_ALIGNED_BSS
25289 +
25290 + .section .rodata,"a",@progbits
25291 NEXT_PAGE(empty_zero_page)
25292 .skip PAGE_SIZE
25293 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25294 index 05fd74f..c3548b1 100644
25295 --- a/arch/x86/kernel/i386_ksyms_32.c
25296 +++ b/arch/x86/kernel/i386_ksyms_32.c
25297 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25298 EXPORT_SYMBOL(cmpxchg8b_emu);
25299 #endif
25300
25301 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25302 +
25303 /* Networking helper routines. */
25304 EXPORT_SYMBOL(csum_partial_copy_generic);
25305 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25306 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25307
25308 EXPORT_SYMBOL(__get_user_1);
25309 EXPORT_SYMBOL(__get_user_2);
25310 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25311 EXPORT_SYMBOL(___preempt_schedule_context);
25312 #endif
25313 #endif
25314 +
25315 +#ifdef CONFIG_PAX_KERNEXEC
25316 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25317 +#endif
25318 +
25319 +#ifdef CONFIG_PAX_PER_CPU_PGD
25320 +EXPORT_SYMBOL(cpu_pgd);
25321 +#endif
25322 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25323 index d5dd808..b6432cf 100644
25324 --- a/arch/x86/kernel/i387.c
25325 +++ b/arch/x86/kernel/i387.c
25326 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25327 static inline bool interrupted_user_mode(void)
25328 {
25329 struct pt_regs *regs = get_irq_regs();
25330 - return regs && user_mode_vm(regs);
25331 + return regs && user_mode(regs);
25332 }
25333
25334 /*
25335 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25336 index 8af8171..f8c1169 100644
25337 --- a/arch/x86/kernel/i8259.c
25338 +++ b/arch/x86/kernel/i8259.c
25339 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25340 static void make_8259A_irq(unsigned int irq)
25341 {
25342 disable_irq_nosync(irq);
25343 - io_apic_irqs &= ~(1<<irq);
25344 + io_apic_irqs &= ~(1UL<<irq);
25345 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25346 i8259A_chip.name);
25347 enable_irq(irq);
25348 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25349 "spurious 8259A interrupt: IRQ%d.\n", irq);
25350 spurious_irq_mask |= irqmask;
25351 }
25352 - atomic_inc(&irq_err_count);
25353 + atomic_inc_unchecked(&irq_err_count);
25354 /*
25355 * Theoretically we do not have to handle this IRQ,
25356 * but in Linux this does not cause problems and is
25357 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25358 /* (slave's support for AEOI in flat mode is to be investigated) */
25359 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25360
25361 + pax_open_kernel();
25362 if (auto_eoi)
25363 /*
25364 * In AEOI mode we just have to mask the interrupt
25365 * when acking.
25366 */
25367 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25368 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25369 else
25370 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25371 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25372 + pax_close_kernel();
25373
25374 udelay(100); /* wait for 8259A to initialize */
25375
25376 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25377 index a979b5b..1d6db75 100644
25378 --- a/arch/x86/kernel/io_delay.c
25379 +++ b/arch/x86/kernel/io_delay.c
25380 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25381 * Quirk table for systems that misbehave (lock up, etc.) if port
25382 * 0x80 is used:
25383 */
25384 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25385 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25386 {
25387 .callback = dmi_io_delay_0xed_port,
25388 .ident = "Compaq Presario V6000",
25389 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25390 index 4ddaf66..49d5c18 100644
25391 --- a/arch/x86/kernel/ioport.c
25392 +++ b/arch/x86/kernel/ioport.c
25393 @@ -6,6 +6,7 @@
25394 #include <linux/sched.h>
25395 #include <linux/kernel.h>
25396 #include <linux/capability.h>
25397 +#include <linux/security.h>
25398 #include <linux/errno.h>
25399 #include <linux/types.h>
25400 #include <linux/ioport.h>
25401 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25402 return -EINVAL;
25403 if (turn_on && !capable(CAP_SYS_RAWIO))
25404 return -EPERM;
25405 +#ifdef CONFIG_GRKERNSEC_IO
25406 + if (turn_on && grsec_disable_privio) {
25407 + gr_handle_ioperm();
25408 + return -ENODEV;
25409 + }
25410 +#endif
25411
25412 /*
25413 * If it's the first ioperm() call in this thread's lifetime, set the
25414 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25415 * because the ->io_bitmap_max value must match the bitmap
25416 * contents:
25417 */
25418 - tss = &per_cpu(init_tss, get_cpu());
25419 + tss = init_tss + get_cpu();
25420
25421 if (turn_on)
25422 bitmap_clear(t->io_bitmap_ptr, from, num);
25423 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25424 if (level > old) {
25425 if (!capable(CAP_SYS_RAWIO))
25426 return -EPERM;
25427 +#ifdef CONFIG_GRKERNSEC_IO
25428 + if (grsec_disable_privio) {
25429 + gr_handle_iopl();
25430 + return -ENODEV;
25431 + }
25432 +#endif
25433 }
25434 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25435 t->iopl = level << 12;
25436 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25437 index 922d285..6d20692 100644
25438 --- a/arch/x86/kernel/irq.c
25439 +++ b/arch/x86/kernel/irq.c
25440 @@ -22,7 +22,7 @@
25441 #define CREATE_TRACE_POINTS
25442 #include <asm/trace/irq_vectors.h>
25443
25444 -atomic_t irq_err_count;
25445 +atomic_unchecked_t irq_err_count;
25446
25447 /* Function pointer for generic interrupt vector handling */
25448 void (*x86_platform_ipi_callback)(void) = NULL;
25449 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25450 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25451 seq_printf(p, " Hypervisor callback interrupts\n");
25452 #endif
25453 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25454 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25455 #if defined(CONFIG_X86_IO_APIC)
25456 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25457 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25458 #endif
25459 return 0;
25460 }
25461 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25462
25463 u64 arch_irq_stat(void)
25464 {
25465 - u64 sum = atomic_read(&irq_err_count);
25466 + u64 sum = atomic_read_unchecked(&irq_err_count);
25467 return sum;
25468 }
25469
25470 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25471 index 63ce838..2ea3e06 100644
25472 --- a/arch/x86/kernel/irq_32.c
25473 +++ b/arch/x86/kernel/irq_32.c
25474 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25475
25476 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25477
25478 +extern void gr_handle_kernel_exploit(void);
25479 +
25480 int sysctl_panic_on_stackoverflow __read_mostly;
25481
25482 /* Debugging check for stack overflow: is there less than 1KB free? */
25483 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25484 __asm__ __volatile__("andl %%esp,%0" :
25485 "=r" (sp) : "0" (THREAD_SIZE - 1));
25486
25487 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25488 + return sp < STACK_WARN;
25489 }
25490
25491 static void print_stack_overflow(void)
25492 {
25493 printk(KERN_WARNING "low stack detected by irq handler\n");
25494 dump_stack();
25495 + gr_handle_kernel_exploit();
25496 if (sysctl_panic_on_stackoverflow)
25497 panic("low stack detected by irq handler - check messages\n");
25498 }
25499 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25500 static inline int
25501 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25502 {
25503 - struct irq_stack *curstk, *irqstk;
25504 + struct irq_stack *irqstk;
25505 u32 *isp, *prev_esp, arg1, arg2;
25506
25507 - curstk = (struct irq_stack *) current_stack();
25508 irqstk = __this_cpu_read(hardirq_stack);
25509
25510 /*
25511 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25512 * handler) we can't do that and just have to keep using the
25513 * current stack (which is the irq stack already after all)
25514 */
25515 - if (unlikely(curstk == irqstk))
25516 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25517 return 0;
25518
25519 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25520 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25521
25522 /* Save the next esp at the bottom of the stack */
25523 prev_esp = (u32 *)irqstk;
25524 *prev_esp = current_stack_pointer;
25525
25526 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25527 + __set_fs(MAKE_MM_SEG(0));
25528 +#endif
25529 +
25530 if (unlikely(overflow))
25531 call_on_stack(print_stack_overflow, isp);
25532
25533 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25534 : "0" (irq), "1" (desc), "2" (isp),
25535 "D" (desc->handle_irq)
25536 : "memory", "cc", "ecx");
25537 +
25538 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25539 + __set_fs(current_thread_info()->addr_limit);
25540 +#endif
25541 +
25542 return 1;
25543 }
25544
25545 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25546 */
25547 void irq_ctx_init(int cpu)
25548 {
25549 - struct irq_stack *irqstk;
25550 -
25551 if (per_cpu(hardirq_stack, cpu))
25552 return;
25553
25554 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25555 - THREADINFO_GFP,
25556 - THREAD_SIZE_ORDER));
25557 - per_cpu(hardirq_stack, cpu) = irqstk;
25558 -
25559 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25560 - THREADINFO_GFP,
25561 - THREAD_SIZE_ORDER));
25562 - per_cpu(softirq_stack, cpu) = irqstk;
25563 -
25564 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25565 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25566 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25567 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25568 }
25569
25570 void do_softirq_own_stack(void)
25571 {
25572 - struct thread_info *curstk;
25573 struct irq_stack *irqstk;
25574 u32 *isp, *prev_esp;
25575
25576 - curstk = current_stack();
25577 irqstk = __this_cpu_read(softirq_stack);
25578
25579 /* build the stack frame on the softirq stack */
25580 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25581 prev_esp = (u32 *)irqstk;
25582 *prev_esp = current_stack_pointer;
25583
25584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25585 + __set_fs(MAKE_MM_SEG(0));
25586 +#endif
25587 +
25588 call_on_stack(__do_softirq, isp);
25589 +
25590 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25591 + __set_fs(current_thread_info()->addr_limit);
25592 +#endif
25593 +
25594 }
25595
25596 bool handle_irq(unsigned irq, struct pt_regs *regs)
25597 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25598 if (unlikely(!desc))
25599 return false;
25600
25601 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25602 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25603 if (unlikely(overflow))
25604 print_stack_overflow();
25605 desc->handle_irq(irq, desc);
25606 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25607 index 4d1c746..55a22d6 100644
25608 --- a/arch/x86/kernel/irq_64.c
25609 +++ b/arch/x86/kernel/irq_64.c
25610 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25611 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25612 EXPORT_PER_CPU_SYMBOL(irq_regs);
25613
25614 +extern void gr_handle_kernel_exploit(void);
25615 +
25616 int sysctl_panic_on_stackoverflow;
25617
25618 /*
25619 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25620 u64 estack_top, estack_bottom;
25621 u64 curbase = (u64)task_stack_page(current);
25622
25623 - if (user_mode_vm(regs))
25624 + if (user_mode(regs))
25625 return;
25626
25627 if (regs->sp >= curbase + sizeof(struct thread_info) +
25628 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25629 irq_stack_top, irq_stack_bottom,
25630 estack_top, estack_bottom);
25631
25632 + gr_handle_kernel_exploit();
25633 +
25634 if (sysctl_panic_on_stackoverflow)
25635 panic("low stack detected by irq handler - check messages\n");
25636 #endif
25637 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25638 index 26d5a55..a01160a 100644
25639 --- a/arch/x86/kernel/jump_label.c
25640 +++ b/arch/x86/kernel/jump_label.c
25641 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25642 * Jump label is enabled for the first time.
25643 * So we expect a default_nop...
25644 */
25645 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25646 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25647 != 0))
25648 bug_at((void *)entry->code, __LINE__);
25649 } else {
25650 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25651 * ...otherwise expect an ideal_nop. Otherwise
25652 * something went horribly wrong.
25653 */
25654 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25655 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25656 != 0))
25657 bug_at((void *)entry->code, __LINE__);
25658 }
25659 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25660 * are converting the default nop to the ideal nop.
25661 */
25662 if (init) {
25663 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25664 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25665 bug_at((void *)entry->code, __LINE__);
25666 } else {
25667 code.jump = 0xe9;
25668 code.offset = entry->target -
25669 (entry->code + JUMP_LABEL_NOP_SIZE);
25670 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25671 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25672 bug_at((void *)entry->code, __LINE__);
25673 }
25674 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25675 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25676 index 7ec1d5f..5a7d130 100644
25677 --- a/arch/x86/kernel/kgdb.c
25678 +++ b/arch/x86/kernel/kgdb.c
25679 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25680 #ifdef CONFIG_X86_32
25681 switch (regno) {
25682 case GDB_SS:
25683 - if (!user_mode_vm(regs))
25684 + if (!user_mode(regs))
25685 *(unsigned long *)mem = __KERNEL_DS;
25686 break;
25687 case GDB_SP:
25688 - if (!user_mode_vm(regs))
25689 + if (!user_mode(regs))
25690 *(unsigned long *)mem = kernel_stack_pointer(regs);
25691 break;
25692 case GDB_GS:
25693 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25694 bp->attr.bp_addr = breakinfo[breakno].addr;
25695 bp->attr.bp_len = breakinfo[breakno].len;
25696 bp->attr.bp_type = breakinfo[breakno].type;
25697 - info->address = breakinfo[breakno].addr;
25698 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25699 + info->address = ktla_ktva(breakinfo[breakno].addr);
25700 + else
25701 + info->address = breakinfo[breakno].addr;
25702 info->len = breakinfo[breakno].len;
25703 info->type = breakinfo[breakno].type;
25704 val = arch_install_hw_breakpoint(bp);
25705 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25706 case 'k':
25707 /* clear the trace bit */
25708 linux_regs->flags &= ~X86_EFLAGS_TF;
25709 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25710 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25711
25712 /* set the trace bit if we're stepping */
25713 if (remcomInBuffer[0] == 's') {
25714 linux_regs->flags |= X86_EFLAGS_TF;
25715 - atomic_set(&kgdb_cpu_doing_single_step,
25716 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25717 raw_smp_processor_id());
25718 }
25719
25720 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25721
25722 switch (cmd) {
25723 case DIE_DEBUG:
25724 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25725 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25726 if (user_mode(regs))
25727 return single_step_cont(regs, args);
25728 break;
25729 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25730 #endif /* CONFIG_DEBUG_RODATA */
25731
25732 bpt->type = BP_BREAKPOINT;
25733 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25734 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25735 BREAK_INSTR_SIZE);
25736 if (err)
25737 return err;
25738 - err = probe_kernel_write((char *)bpt->bpt_addr,
25739 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25740 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25741 #ifdef CONFIG_DEBUG_RODATA
25742 if (!err)
25743 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25744 return -EBUSY;
25745 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25746 BREAK_INSTR_SIZE);
25747 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25748 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25749 if (err)
25750 return err;
25751 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25752 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25753 if (mutex_is_locked(&text_mutex))
25754 goto knl_write;
25755 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25756 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25757 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25758 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25759 goto knl_write;
25760 return err;
25761 knl_write:
25762 #endif /* CONFIG_DEBUG_RODATA */
25763 - return probe_kernel_write((char *)bpt->bpt_addr,
25764 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25765 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25766 }
25767
25768 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25769 index 67e6d19..731ed28 100644
25770 --- a/arch/x86/kernel/kprobes/core.c
25771 +++ b/arch/x86/kernel/kprobes/core.c
25772 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25773 s32 raddr;
25774 } __packed *insn;
25775
25776 - insn = (struct __arch_relative_insn *)from;
25777 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25778 +
25779 + pax_open_kernel();
25780 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25781 insn->op = op;
25782 + pax_close_kernel();
25783 }
25784
25785 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25786 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25787 kprobe_opcode_t opcode;
25788 kprobe_opcode_t *orig_opcodes = opcodes;
25789
25790 - if (search_exception_tables((unsigned long)opcodes))
25791 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25792 return 0; /* Page fault may occur on this address. */
25793
25794 retry:
25795 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25796 * for the first byte, we can recover the original instruction
25797 * from it and kp->opcode.
25798 */
25799 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25800 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25801 buf[0] = kp->opcode;
25802 - return (unsigned long)buf;
25803 + return ktva_ktla((unsigned long)buf);
25804 }
25805
25806 /*
25807 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25808 /* Another subsystem puts a breakpoint, failed to recover */
25809 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25810 return 0;
25811 + pax_open_kernel();
25812 memcpy(dest, insn.kaddr, insn.length);
25813 + pax_close_kernel();
25814
25815 #ifdef CONFIG_X86_64
25816 if (insn_rip_relative(&insn)) {
25817 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25818 return 0;
25819 }
25820 disp = (u8 *) dest + insn_offset_displacement(&insn);
25821 + pax_open_kernel();
25822 *(s32 *) disp = (s32) newdisp;
25823 + pax_close_kernel();
25824 }
25825 #endif
25826 return insn.length;
25827 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25828 * nor set current_kprobe, because it doesn't use single
25829 * stepping.
25830 */
25831 - regs->ip = (unsigned long)p->ainsn.insn;
25832 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25833 preempt_enable_no_resched();
25834 return;
25835 }
25836 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25837 regs->flags &= ~X86_EFLAGS_IF;
25838 /* single step inline if the instruction is an int3 */
25839 if (p->opcode == BREAKPOINT_INSTRUCTION)
25840 - regs->ip = (unsigned long)p->addr;
25841 + regs->ip = ktla_ktva((unsigned long)p->addr);
25842 else
25843 - regs->ip = (unsigned long)p->ainsn.insn;
25844 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25845 }
25846 NOKPROBE_SYMBOL(setup_singlestep);
25847
25848 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25849 struct kprobe *p;
25850 struct kprobe_ctlblk *kcb;
25851
25852 - if (user_mode_vm(regs))
25853 + if (user_mode(regs))
25854 return 0;
25855
25856 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25857 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25858 setup_singlestep(p, regs, kcb, 0);
25859 return 1;
25860 }
25861 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25862 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25863 /*
25864 * The breakpoint instruction was removed right
25865 * after we hit it. Another cpu has removed
25866 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25867 " movq %rax, 152(%rsp)\n"
25868 RESTORE_REGS_STRING
25869 " popfq\n"
25870 +#ifdef KERNEXEC_PLUGIN
25871 + " btsq $63,(%rsp)\n"
25872 +#endif
25873 #else
25874 " pushf\n"
25875 SAVE_REGS_STRING
25876 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25877 struct kprobe_ctlblk *kcb)
25878 {
25879 unsigned long *tos = stack_addr(regs);
25880 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25881 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25882 unsigned long orig_ip = (unsigned long)p->addr;
25883 kprobe_opcode_t *insn = p->ainsn.insn;
25884
25885 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25886 struct die_args *args = data;
25887 int ret = NOTIFY_DONE;
25888
25889 - if (args->regs && user_mode_vm(args->regs))
25890 + if (args->regs && user_mode(args->regs))
25891 return ret;
25892
25893 if (val == DIE_GPF) {
25894 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25895 index f304773..551e63c 100644
25896 --- a/arch/x86/kernel/kprobes/opt.c
25897 +++ b/arch/x86/kernel/kprobes/opt.c
25898 @@ -79,6 +79,7 @@ found:
25899 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25900 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25901 {
25902 + pax_open_kernel();
25903 #ifdef CONFIG_X86_64
25904 *addr++ = 0x48;
25905 *addr++ = 0xbf;
25906 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25907 *addr++ = 0xb8;
25908 #endif
25909 *(unsigned long *)addr = val;
25910 + pax_close_kernel();
25911 }
25912
25913 asm (
25914 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25915 * Verify if the address gap is in 2GB range, because this uses
25916 * a relative jump.
25917 */
25918 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25919 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25920 if (abs(rel) > 0x7fffffff)
25921 return -ERANGE;
25922
25923 @@ -352,16 +354,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25924 op->optinsn.size = ret;
25925
25926 /* Copy arch-dep-instance from template */
25927 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25928 + pax_open_kernel();
25929 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25930 + pax_close_kernel();
25931
25932 /* Set probe information */
25933 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25934
25935 /* Set probe function call */
25936 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25937 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25938
25939 /* Set returning jmp instruction at the tail of out-of-line buffer */
25940 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25941 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25942 (u8 *)op->kp.addr + op->optinsn.size);
25943
25944 flush_icache_range((unsigned long) buf,
25945 @@ -386,7 +390,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25946 WARN_ON(kprobe_disabled(&op->kp));
25947
25948 /* Backup instructions which will be replaced by jump address */
25949 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25950 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25951 RELATIVE_ADDR_SIZE);
25952
25953 insn_buf[0] = RELATIVEJUMP_OPCODE;
25954 @@ -434,7 +438,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25955 /* This kprobe is really able to run optimized path. */
25956 op = container_of(p, struct optimized_kprobe, kp);
25957 /* Detour through copied instructions */
25958 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25959 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25960 if (!reenter)
25961 reset_current_kprobe();
25962 preempt_enable_no_resched();
25963 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25964 index c2bedae..25e7ab60 100644
25965 --- a/arch/x86/kernel/ksysfs.c
25966 +++ b/arch/x86/kernel/ksysfs.c
25967 @@ -184,7 +184,7 @@ out:
25968
25969 static struct kobj_attribute type_attr = __ATTR_RO(type);
25970
25971 -static struct bin_attribute data_attr = {
25972 +static bin_attribute_no_const data_attr __read_only = {
25973 .attr = {
25974 .name = "data",
25975 .mode = S_IRUGO,
25976 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25977 index c37886d..d851d32 100644
25978 --- a/arch/x86/kernel/ldt.c
25979 +++ b/arch/x86/kernel/ldt.c
25980 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25981 if (reload) {
25982 #ifdef CONFIG_SMP
25983 preempt_disable();
25984 - load_LDT(pc);
25985 + load_LDT_nolock(pc);
25986 if (!cpumask_equal(mm_cpumask(current->mm),
25987 cpumask_of(smp_processor_id())))
25988 smp_call_function(flush_ldt, current->mm, 1);
25989 preempt_enable();
25990 #else
25991 - load_LDT(pc);
25992 + load_LDT_nolock(pc);
25993 #endif
25994 }
25995 if (oldsize) {
25996 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25997 return err;
25998
25999 for (i = 0; i < old->size; i++)
26000 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26001 + write_ldt_entry(new->ldt, i, old->ldt + i);
26002 return 0;
26003 }
26004
26005 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26006 retval = copy_ldt(&mm->context, &old_mm->context);
26007 mutex_unlock(&old_mm->context.lock);
26008 }
26009 +
26010 + if (tsk == current) {
26011 + mm->context.vdso = 0;
26012 +
26013 +#ifdef CONFIG_X86_32
26014 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26015 + mm->context.user_cs_base = 0UL;
26016 + mm->context.user_cs_limit = ~0UL;
26017 +
26018 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26019 + cpus_clear(mm->context.cpu_user_cs_mask);
26020 +#endif
26021 +
26022 +#endif
26023 +#endif
26024 +
26025 + }
26026 +
26027 return retval;
26028 }
26029
26030 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26031 }
26032 }
26033
26034 +#ifdef CONFIG_PAX_SEGMEXEC
26035 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26036 + error = -EINVAL;
26037 + goto out_unlock;
26038 + }
26039 +#endif
26040 +
26041 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26042 error = -EINVAL;
26043 goto out_unlock;
26044 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26045 index 1667b1d..16492c5 100644
26046 --- a/arch/x86/kernel/machine_kexec_32.c
26047 +++ b/arch/x86/kernel/machine_kexec_32.c
26048 @@ -25,7 +25,7 @@
26049 #include <asm/cacheflush.h>
26050 #include <asm/debugreg.h>
26051
26052 -static void set_idt(void *newidt, __u16 limit)
26053 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26054 {
26055 struct desc_ptr curidt;
26056
26057 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26058 }
26059
26060
26061 -static void set_gdt(void *newgdt, __u16 limit)
26062 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26063 {
26064 struct desc_ptr curgdt;
26065
26066 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26067 }
26068
26069 control_page = page_address(image->control_code_page);
26070 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26071 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26072
26073 relocate_kernel_ptr = control_page;
26074 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26075 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26076 index c050a01..5774072 100644
26077 --- a/arch/x86/kernel/mcount_64.S
26078 +++ b/arch/x86/kernel/mcount_64.S
26079 @@ -7,7 +7,7 @@
26080 #include <linux/linkage.h>
26081 #include <asm/ptrace.h>
26082 #include <asm/ftrace.h>
26083 -
26084 +#include <asm/alternative-asm.h>
26085
26086 .code64
26087 .section .entry.text, "ax"
26088 @@ -24,8 +24,9 @@
26089 #ifdef CONFIG_DYNAMIC_FTRACE
26090
26091 ENTRY(function_hook)
26092 + pax_force_retaddr
26093 retq
26094 -END(function_hook)
26095 +ENDPROC(function_hook)
26096
26097 /* skip is set if stack has been adjusted */
26098 .macro ftrace_caller_setup skip=0
26099 @@ -66,8 +67,9 @@ GLOBAL(ftrace_graph_call)
26100 #endif
26101
26102 GLOBAL(ftrace_stub)
26103 + pax_force_retaddr
26104 retq
26105 -END(ftrace_caller)
26106 +ENDPROC(ftrace_caller)
26107
26108 ENTRY(ftrace_regs_caller)
26109 /* Save the current flags before compare (in SS location)*/
26110 @@ -135,7 +137,7 @@ ftrace_restore_flags:
26111 popfq
26112 jmp ftrace_stub
26113
26114 -END(ftrace_regs_caller)
26115 +ENDPROC(ftrace_regs_caller)
26116
26117
26118 #else /* ! CONFIG_DYNAMIC_FTRACE */
26119 @@ -156,6 +158,7 @@ ENTRY(function_hook)
26120 #endif
26121
26122 GLOBAL(ftrace_stub)
26123 + pax_force_retaddr
26124 retq
26125
26126 trace:
26127 @@ -169,12 +172,13 @@ trace:
26128 #endif
26129 subq $MCOUNT_INSN_SIZE, %rdi
26130
26131 + pax_force_fptr ftrace_trace_function
26132 call *ftrace_trace_function
26133
26134 MCOUNT_RESTORE_FRAME
26135
26136 jmp ftrace_stub
26137 -END(function_hook)
26138 +ENDPROC(function_hook)
26139 #endif /* CONFIG_DYNAMIC_FTRACE */
26140 #endif /* CONFIG_FUNCTION_TRACER */
26141
26142 @@ -196,8 +200,9 @@ ENTRY(ftrace_graph_caller)
26143
26144 MCOUNT_RESTORE_FRAME
26145
26146 + pax_force_retaddr
26147 retq
26148 -END(ftrace_graph_caller)
26149 +ENDPROC(ftrace_graph_caller)
26150
26151 GLOBAL(return_to_handler)
26152 subq $24, %rsp
26153 @@ -213,5 +218,7 @@ GLOBAL(return_to_handler)
26154 movq 8(%rsp), %rdx
26155 movq (%rsp), %rax
26156 addq $24, %rsp
26157 + pax_force_fptr %rdi
26158 jmp *%rdi
26159 +ENDPROC(return_to_handler)
26160 #endif
26161 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26162 index e69f988..da078ea 100644
26163 --- a/arch/x86/kernel/module.c
26164 +++ b/arch/x86/kernel/module.c
26165 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26166 }
26167 #endif
26168
26169 -void *module_alloc(unsigned long size)
26170 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26171 {
26172 - if (PAGE_ALIGN(size) > MODULES_LEN)
26173 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26174 return NULL;
26175 return __vmalloc_node_range(size, 1,
26176 MODULES_VADDR + get_module_load_offset(),
26177 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26178 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26179 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26180 + prot, NUMA_NO_NODE,
26181 __builtin_return_address(0));
26182 }
26183
26184 +void *module_alloc(unsigned long size)
26185 +{
26186 +
26187 +#ifdef CONFIG_PAX_KERNEXEC
26188 + return __module_alloc(size, PAGE_KERNEL);
26189 +#else
26190 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26191 +#endif
26192 +
26193 +}
26194 +
26195 +#ifdef CONFIG_PAX_KERNEXEC
26196 +#ifdef CONFIG_X86_32
26197 +void *module_alloc_exec(unsigned long size)
26198 +{
26199 + struct vm_struct *area;
26200 +
26201 + if (size == 0)
26202 + return NULL;
26203 +
26204 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26205 +return area ? area->addr : NULL;
26206 +}
26207 +EXPORT_SYMBOL(module_alloc_exec);
26208 +
26209 +void module_free_exec(struct module *mod, void *module_region)
26210 +{
26211 + vunmap(module_region);
26212 +}
26213 +EXPORT_SYMBOL(module_free_exec);
26214 +#else
26215 +void module_free_exec(struct module *mod, void *module_region)
26216 +{
26217 + module_free(mod, module_region);
26218 +}
26219 +EXPORT_SYMBOL(module_free_exec);
26220 +
26221 +void *module_alloc_exec(unsigned long size)
26222 +{
26223 + return __module_alloc(size, PAGE_KERNEL_RX);
26224 +}
26225 +EXPORT_SYMBOL(module_alloc_exec);
26226 +#endif
26227 +#endif
26228 +
26229 #ifdef CONFIG_X86_32
26230 int apply_relocate(Elf32_Shdr *sechdrs,
26231 const char *strtab,
26232 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26233 unsigned int i;
26234 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26235 Elf32_Sym *sym;
26236 - uint32_t *location;
26237 + uint32_t *plocation, location;
26238
26239 DEBUGP("Applying relocate section %u to %u\n",
26240 relsec, sechdrs[relsec].sh_info);
26241 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26242 /* This is where to make the change */
26243 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26244 - + rel[i].r_offset;
26245 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26246 + location = (uint32_t)plocation;
26247 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26248 + plocation = ktla_ktva((void *)plocation);
26249 /* This is the symbol it is referring to. Note that all
26250 undefined symbols have been resolved. */
26251 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26252 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26253 switch (ELF32_R_TYPE(rel[i].r_info)) {
26254 case R_386_32:
26255 /* We add the value into the location given */
26256 - *location += sym->st_value;
26257 + pax_open_kernel();
26258 + *plocation += sym->st_value;
26259 + pax_close_kernel();
26260 break;
26261 case R_386_PC32:
26262 /* Add the value, subtract its position */
26263 - *location += sym->st_value - (uint32_t)location;
26264 + pax_open_kernel();
26265 + *plocation += sym->st_value - location;
26266 + pax_close_kernel();
26267 break;
26268 default:
26269 pr_err("%s: Unknown relocation: %u\n",
26270 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26271 case R_X86_64_NONE:
26272 break;
26273 case R_X86_64_64:
26274 + pax_open_kernel();
26275 *(u64 *)loc = val;
26276 + pax_close_kernel();
26277 break;
26278 case R_X86_64_32:
26279 + pax_open_kernel();
26280 *(u32 *)loc = val;
26281 + pax_close_kernel();
26282 if (val != *(u32 *)loc)
26283 goto overflow;
26284 break;
26285 case R_X86_64_32S:
26286 + pax_open_kernel();
26287 *(s32 *)loc = val;
26288 + pax_close_kernel();
26289 if ((s64)val != *(s32 *)loc)
26290 goto overflow;
26291 break;
26292 case R_X86_64_PC32:
26293 val -= (u64)loc;
26294 + pax_open_kernel();
26295 *(u32 *)loc = val;
26296 + pax_close_kernel();
26297 +
26298 #if 0
26299 if ((s64)val != *(s32 *)loc)
26300 goto overflow;
26301 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26302 index c9603ac..9f88728 100644
26303 --- a/arch/x86/kernel/msr.c
26304 +++ b/arch/x86/kernel/msr.c
26305 @@ -37,6 +37,7 @@
26306 #include <linux/notifier.h>
26307 #include <linux/uaccess.h>
26308 #include <linux/gfp.h>
26309 +#include <linux/grsecurity.h>
26310
26311 #include <asm/processor.h>
26312 #include <asm/msr.h>
26313 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26314 int err = 0;
26315 ssize_t bytes = 0;
26316
26317 +#ifdef CONFIG_GRKERNSEC_KMEM
26318 + gr_handle_msr_write();
26319 + return -EPERM;
26320 +#endif
26321 +
26322 if (count % 8)
26323 return -EINVAL; /* Invalid chunk size */
26324
26325 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26326 err = -EBADF;
26327 break;
26328 }
26329 +#ifdef CONFIG_GRKERNSEC_KMEM
26330 + gr_handle_msr_write();
26331 + return -EPERM;
26332 +#endif
26333 if (copy_from_user(&regs, uregs, sizeof regs)) {
26334 err = -EFAULT;
26335 break;
26336 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26337 return notifier_from_errno(err);
26338 }
26339
26340 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26341 +static struct notifier_block msr_class_cpu_notifier = {
26342 .notifier_call = msr_class_cpu_callback,
26343 };
26344
26345 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26346 index c3e985d..110a36a 100644
26347 --- a/arch/x86/kernel/nmi.c
26348 +++ b/arch/x86/kernel/nmi.c
26349 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26350
26351 static void nmi_max_handler(struct irq_work *w)
26352 {
26353 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26354 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26355 int remainder_ns, decimal_msecs;
26356 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26357 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26358
26359 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26360 decimal_msecs = remainder_ns / 1000;
26361
26362 printk_ratelimited(KERN_INFO
26363 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26364 - a->handler, whole_msecs, decimal_msecs);
26365 + n->action->handler, whole_msecs, decimal_msecs);
26366 }
26367
26368 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26369 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26370 delta = sched_clock() - delta;
26371 trace_nmi_handler(a->handler, (int)delta, thishandled);
26372
26373 - if (delta < nmi_longest_ns || delta < a->max_duration)
26374 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26375 continue;
26376
26377 - a->max_duration = delta;
26378 - irq_work_queue(&a->irq_work);
26379 + a->work->max_duration = delta;
26380 + irq_work_queue(&a->work->irq_work);
26381 }
26382
26383 rcu_read_unlock();
26384 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26385 }
26386 NOKPROBE_SYMBOL(nmi_handle);
26387
26388 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26389 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26390 {
26391 struct nmi_desc *desc = nmi_to_desc(type);
26392 unsigned long flags;
26393 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26394 if (!action->handler)
26395 return -EINVAL;
26396
26397 - init_irq_work(&action->irq_work, nmi_max_handler);
26398 + action->work->action = action;
26399 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26400
26401 spin_lock_irqsave(&desc->lock, flags);
26402
26403 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26404 * event confuses some handlers (kdump uses this flag)
26405 */
26406 if (action->flags & NMI_FLAG_FIRST)
26407 - list_add_rcu(&action->list, &desc->head);
26408 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26409 else
26410 - list_add_tail_rcu(&action->list, &desc->head);
26411 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26412
26413 spin_unlock_irqrestore(&desc->lock, flags);
26414 return 0;
26415 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26416 if (!strcmp(n->name, name)) {
26417 WARN(in_nmi(),
26418 "Trying to free NMI (%s) from NMI context!\n", n->name);
26419 - list_del_rcu(&n->list);
26420 + pax_list_del_rcu((struct list_head *)&n->list);
26421 break;
26422 }
26423 }
26424 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26425 dotraplinkage notrace void
26426 do_nmi(struct pt_regs *regs, long error_code)
26427 {
26428 +
26429 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26430 + if (!user_mode(regs)) {
26431 + unsigned long cs = regs->cs & 0xFFFF;
26432 + unsigned long ip = ktva_ktla(regs->ip);
26433 +
26434 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26435 + regs->ip = ip;
26436 + }
26437 +#endif
26438 +
26439 nmi_nesting_preprocess(regs);
26440
26441 nmi_enter();
26442 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26443 index 6d9582e..f746287 100644
26444 --- a/arch/x86/kernel/nmi_selftest.c
26445 +++ b/arch/x86/kernel/nmi_selftest.c
26446 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26447 {
26448 /* trap all the unknown NMIs we may generate */
26449 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26450 - __initdata);
26451 + __initconst);
26452 }
26453
26454 static void __init cleanup_nmi_testsuite(void)
26455 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26456 unsigned long timeout;
26457
26458 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26459 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26460 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26461 nmi_fail = FAILURE;
26462 return;
26463 }
26464 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26465 index bbb6c73..24a58ef 100644
26466 --- a/arch/x86/kernel/paravirt-spinlocks.c
26467 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26468 @@ -8,7 +8,7 @@
26469
26470 #include <asm/paravirt.h>
26471
26472 -struct pv_lock_ops pv_lock_ops = {
26473 +struct pv_lock_ops pv_lock_ops __read_only = {
26474 #ifdef CONFIG_SMP
26475 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26476 .unlock_kick = paravirt_nop,
26477 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26478 index 548d25f..f8fb99c 100644
26479 --- a/arch/x86/kernel/paravirt.c
26480 +++ b/arch/x86/kernel/paravirt.c
26481 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26482 {
26483 return x;
26484 }
26485 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26486 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26487 +#endif
26488
26489 void __init default_banner(void)
26490 {
26491 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26492
26493 if (opfunc == NULL)
26494 /* If there's no function, patch it with a ud2a (BUG) */
26495 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26496 - else if (opfunc == _paravirt_nop)
26497 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26498 + else if (opfunc == (void *)_paravirt_nop)
26499 /* If the operation is a nop, then nop the callsite */
26500 ret = paravirt_patch_nop();
26501
26502 /* identity functions just return their single argument */
26503 - else if (opfunc == _paravirt_ident_32)
26504 + else if (opfunc == (void *)_paravirt_ident_32)
26505 ret = paravirt_patch_ident_32(insnbuf, len);
26506 - else if (opfunc == _paravirt_ident_64)
26507 + else if (opfunc == (void *)_paravirt_ident_64)
26508 ret = paravirt_patch_ident_64(insnbuf, len);
26509 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26510 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26511 + ret = paravirt_patch_ident_64(insnbuf, len);
26512 +#endif
26513
26514 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26515 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26516 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26517 if (insn_len > len || start == NULL)
26518 insn_len = len;
26519 else
26520 - memcpy(insnbuf, start, insn_len);
26521 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26522
26523 return insn_len;
26524 }
26525 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26526 return this_cpu_read(paravirt_lazy_mode);
26527 }
26528
26529 -struct pv_info pv_info = {
26530 +struct pv_info pv_info __read_only = {
26531 .name = "bare hardware",
26532 .paravirt_enabled = 0,
26533 .kernel_rpl = 0,
26534 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26535 #endif
26536 };
26537
26538 -struct pv_init_ops pv_init_ops = {
26539 +struct pv_init_ops pv_init_ops __read_only = {
26540 .patch = native_patch,
26541 };
26542
26543 -struct pv_time_ops pv_time_ops = {
26544 +struct pv_time_ops pv_time_ops __read_only = {
26545 .sched_clock = native_sched_clock,
26546 .steal_clock = native_steal_clock,
26547 };
26548
26549 -__visible struct pv_irq_ops pv_irq_ops = {
26550 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26551 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26552 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26553 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26554 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26555 #endif
26556 };
26557
26558 -__visible struct pv_cpu_ops pv_cpu_ops = {
26559 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26560 .cpuid = native_cpuid,
26561 .get_debugreg = native_get_debugreg,
26562 .set_debugreg = native_set_debugreg,
26563 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26564 NOKPROBE_SYMBOL(native_set_debugreg);
26565 NOKPROBE_SYMBOL(native_load_idt);
26566
26567 -struct pv_apic_ops pv_apic_ops = {
26568 +struct pv_apic_ops pv_apic_ops __read_only= {
26569 #ifdef CONFIG_X86_LOCAL_APIC
26570 .startup_ipi_hook = paravirt_nop,
26571 #endif
26572 };
26573
26574 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26575 +#ifdef CONFIG_X86_32
26576 +#ifdef CONFIG_X86_PAE
26577 +/* 64-bit pagetable entries */
26578 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26579 +#else
26580 /* 32-bit pagetable entries */
26581 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26582 +#endif
26583 #else
26584 /* 64-bit pagetable entries */
26585 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26586 #endif
26587
26588 -struct pv_mmu_ops pv_mmu_ops = {
26589 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26590
26591 .read_cr2 = native_read_cr2,
26592 .write_cr2 = native_write_cr2,
26593 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26594 .make_pud = PTE_IDENT,
26595
26596 .set_pgd = native_set_pgd,
26597 + .set_pgd_batched = native_set_pgd_batched,
26598 #endif
26599 #endif /* PAGETABLE_LEVELS >= 3 */
26600
26601 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26602 },
26603
26604 .set_fixmap = native_set_fixmap,
26605 +
26606 +#ifdef CONFIG_PAX_KERNEXEC
26607 + .pax_open_kernel = native_pax_open_kernel,
26608 + .pax_close_kernel = native_pax_close_kernel,
26609 +#endif
26610 +
26611 };
26612
26613 EXPORT_SYMBOL_GPL(pv_time_ops);
26614 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26615 index 0497f71..7186c0d 100644
26616 --- a/arch/x86/kernel/pci-calgary_64.c
26617 +++ b/arch/x86/kernel/pci-calgary_64.c
26618 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26619 tce_space = be64_to_cpu(readq(target));
26620 tce_space = tce_space & TAR_SW_BITS;
26621
26622 - tce_space = tce_space & (~specified_table_size);
26623 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26624 info->tce_space = (u64 *)__va(tce_space);
26625 }
26626 }
26627 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26628 index 35ccf75..7a15747 100644
26629 --- a/arch/x86/kernel/pci-iommu_table.c
26630 +++ b/arch/x86/kernel/pci-iommu_table.c
26631 @@ -2,7 +2,7 @@
26632 #include <asm/iommu_table.h>
26633 #include <linux/string.h>
26634 #include <linux/kallsyms.h>
26635 -
26636 +#include <linux/sched.h>
26637
26638 #define DEBUG 1
26639
26640 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26641 index 77dd0ad..9ec4723 100644
26642 --- a/arch/x86/kernel/pci-swiotlb.c
26643 +++ b/arch/x86/kernel/pci-swiotlb.c
26644 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26645 struct dma_attrs *attrs)
26646 {
26647 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26648 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26649 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26650 else
26651 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26652 }
26653 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26654 index ca7f0d5..8996469 100644
26655 --- a/arch/x86/kernel/preempt.S
26656 +++ b/arch/x86/kernel/preempt.S
26657 @@ -3,12 +3,14 @@
26658 #include <asm/dwarf2.h>
26659 #include <asm/asm.h>
26660 #include <asm/calling.h>
26661 +#include <asm/alternative-asm.h>
26662
26663 ENTRY(___preempt_schedule)
26664 CFI_STARTPROC
26665 SAVE_ALL
26666 call preempt_schedule
26667 RESTORE_ALL
26668 + pax_force_retaddr
26669 ret
26670 CFI_ENDPROC
26671
26672 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26673 SAVE_ALL
26674 call preempt_schedule_context
26675 RESTORE_ALL
26676 + pax_force_retaddr
26677 ret
26678 CFI_ENDPROC
26679
26680 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26681 index 4505e2a..ae28b0d 100644
26682 --- a/arch/x86/kernel/process.c
26683 +++ b/arch/x86/kernel/process.c
26684 @@ -36,7 +36,8 @@
26685 * section. Since TSS's are completely CPU-local, we want them
26686 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26687 */
26688 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26689 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26690 +EXPORT_SYMBOL(init_tss);
26691
26692 #ifdef CONFIG_X86_64
26693 static DEFINE_PER_CPU(unsigned char, is_idle);
26694 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26695 task_xstate_cachep =
26696 kmem_cache_create("task_xstate", xstate_size,
26697 __alignof__(union thread_xstate),
26698 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26699 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26700 }
26701
26702 /*
26703 @@ -105,7 +106,7 @@ void exit_thread(void)
26704 unsigned long *bp = t->io_bitmap_ptr;
26705
26706 if (bp) {
26707 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26708 + struct tss_struct *tss = init_tss + get_cpu();
26709
26710 t->io_bitmap_ptr = NULL;
26711 clear_thread_flag(TIF_IO_BITMAP);
26712 @@ -125,6 +126,9 @@ void flush_thread(void)
26713 {
26714 struct task_struct *tsk = current;
26715
26716 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26717 + loadsegment(gs, 0);
26718 +#endif
26719 flush_ptrace_hw_breakpoint(tsk);
26720 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26721 drop_init_fpu(tsk);
26722 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26723 void exit_idle(void)
26724 {
26725 /* idle loop has pid 0 */
26726 - if (current->pid)
26727 + if (task_pid_nr(current))
26728 return;
26729 __exit_idle();
26730 }
26731 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26732 return ret;
26733 }
26734 #endif
26735 -void stop_this_cpu(void *dummy)
26736 +__noreturn void stop_this_cpu(void *dummy)
26737 {
26738 local_irq_disable();
26739 /*
26740 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26741 }
26742 early_param("idle", idle_setup);
26743
26744 -unsigned long arch_align_stack(unsigned long sp)
26745 +#ifdef CONFIG_PAX_RANDKSTACK
26746 +void pax_randomize_kstack(struct pt_regs *regs)
26747 {
26748 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26749 - sp -= get_random_int() % 8192;
26750 - return sp & ~0xf;
26751 -}
26752 + struct thread_struct *thread = &current->thread;
26753 + unsigned long time;
26754
26755 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26756 -{
26757 - unsigned long range_end = mm->brk + 0x02000000;
26758 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26759 -}
26760 + if (!randomize_va_space)
26761 + return;
26762 +
26763 + if (v8086_mode(regs))
26764 + return;
26765
26766 + rdtscl(time);
26767 +
26768 + /* P4 seems to return a 0 LSB, ignore it */
26769 +#ifdef CONFIG_MPENTIUM4
26770 + time &= 0x3EUL;
26771 + time <<= 2;
26772 +#elif defined(CONFIG_X86_64)
26773 + time &= 0xFUL;
26774 + time <<= 4;
26775 +#else
26776 + time &= 0x1FUL;
26777 + time <<= 3;
26778 +#endif
26779 +
26780 + thread->sp0 ^= time;
26781 + load_sp0(init_tss + smp_processor_id(), thread);
26782 +
26783 +#ifdef CONFIG_X86_64
26784 + this_cpu_write(kernel_stack, thread->sp0);
26785 +#endif
26786 +}
26787 +#endif
26788 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26789 index 7bc86bb..0ea06e8 100644
26790 --- a/arch/x86/kernel/process_32.c
26791 +++ b/arch/x86/kernel/process_32.c
26792 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26793 unsigned long thread_saved_pc(struct task_struct *tsk)
26794 {
26795 return ((unsigned long *)tsk->thread.sp)[3];
26796 +//XXX return tsk->thread.eip;
26797 }
26798
26799 void __show_regs(struct pt_regs *regs, int all)
26800 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26801 unsigned long sp;
26802 unsigned short ss, gs;
26803
26804 - if (user_mode_vm(regs)) {
26805 + if (user_mode(regs)) {
26806 sp = regs->sp;
26807 ss = regs->ss & 0xffff;
26808 - gs = get_user_gs(regs);
26809 } else {
26810 sp = kernel_stack_pointer(regs);
26811 savesegment(ss, ss);
26812 - savesegment(gs, gs);
26813 }
26814 + gs = get_user_gs(regs);
26815
26816 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26817 (u16)regs->cs, regs->ip, regs->flags,
26818 - smp_processor_id());
26819 + raw_smp_processor_id());
26820 print_symbol("EIP is at %s\n", regs->ip);
26821
26822 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26823 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26824 int copy_thread(unsigned long clone_flags, unsigned long sp,
26825 unsigned long arg, struct task_struct *p)
26826 {
26827 - struct pt_regs *childregs = task_pt_regs(p);
26828 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26829 struct task_struct *tsk;
26830 int err;
26831
26832 p->thread.sp = (unsigned long) childregs;
26833 p->thread.sp0 = (unsigned long) (childregs+1);
26834 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26835
26836 if (unlikely(p->flags & PF_KTHREAD)) {
26837 /* kernel thread */
26838 memset(childregs, 0, sizeof(struct pt_regs));
26839 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26840 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26841 - childregs->ds = __USER_DS;
26842 - childregs->es = __USER_DS;
26843 + savesegment(gs, childregs->gs);
26844 + childregs->ds = __KERNEL_DS;
26845 + childregs->es = __KERNEL_DS;
26846 childregs->fs = __KERNEL_PERCPU;
26847 childregs->bx = sp; /* function */
26848 childregs->bp = arg;
26849 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26850 struct thread_struct *prev = &prev_p->thread,
26851 *next = &next_p->thread;
26852 int cpu = smp_processor_id();
26853 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26854 + struct tss_struct *tss = init_tss + cpu;
26855 fpu_switch_t fpu;
26856
26857 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26858 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26859 */
26860 lazy_save_gs(prev->gs);
26861
26862 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26863 + __set_fs(task_thread_info(next_p)->addr_limit);
26864 +#endif
26865 +
26866 /*
26867 * Load the per-thread Thread-Local Storage descriptor.
26868 */
26869 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26870 */
26871 arch_end_context_switch(next_p);
26872
26873 - this_cpu_write(kernel_stack,
26874 - (unsigned long)task_stack_page(next_p) +
26875 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26876 + this_cpu_write(current_task, next_p);
26877 + this_cpu_write(current_tinfo, &next_p->tinfo);
26878 + this_cpu_write(kernel_stack, next->sp0);
26879
26880 /*
26881 * Restore %gs if needed (which is common)
26882 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26883
26884 switch_fpu_finish(next_p, fpu);
26885
26886 - this_cpu_write(current_task, next_p);
26887 -
26888 return prev_p;
26889 }
26890
26891 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26892 } while (count++ < 16);
26893 return 0;
26894 }
26895 -
26896 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26897 index ca5b02d..c0b2f6a 100644
26898 --- a/arch/x86/kernel/process_64.c
26899 +++ b/arch/x86/kernel/process_64.c
26900 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26901 struct pt_regs *childregs;
26902 struct task_struct *me = current;
26903
26904 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26905 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26906 childregs = task_pt_regs(p);
26907 p->thread.sp = (unsigned long) childregs;
26908 p->thread.usersp = me->thread.usersp;
26909 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26910 set_tsk_thread_flag(p, TIF_FORK);
26911 p->thread.fpu_counter = 0;
26912 p->thread.io_bitmap_ptr = NULL;
26913 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26914 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26915 savesegment(es, p->thread.es);
26916 savesegment(ds, p->thread.ds);
26917 + savesegment(ss, p->thread.ss);
26918 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26919 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26920
26921 if (unlikely(p->flags & PF_KTHREAD)) {
26922 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26923 struct thread_struct *prev = &prev_p->thread;
26924 struct thread_struct *next = &next_p->thread;
26925 int cpu = smp_processor_id();
26926 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26927 + struct tss_struct *tss = init_tss + cpu;
26928 unsigned fsindex, gsindex;
26929 fpu_switch_t fpu;
26930
26931 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26932 if (unlikely(next->ds | prev->ds))
26933 loadsegment(ds, next->ds);
26934
26935 + savesegment(ss, prev->ss);
26936 + if (unlikely(next->ss != prev->ss))
26937 + loadsegment(ss, next->ss);
26938
26939 /* We must save %fs and %gs before load_TLS() because
26940 * %fs and %gs may be cleared by load_TLS().
26941 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26942 prev->usersp = this_cpu_read(old_rsp);
26943 this_cpu_write(old_rsp, next->usersp);
26944 this_cpu_write(current_task, next_p);
26945 + this_cpu_write(current_tinfo, &next_p->tinfo);
26946
26947 /*
26948 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26949 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26950 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26951 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26952
26953 - this_cpu_write(kernel_stack,
26954 - (unsigned long)task_stack_page(next_p) +
26955 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26956 + this_cpu_write(kernel_stack, next->sp0);
26957
26958 /*
26959 * Now maybe reload the debug registers and handle I/O bitmaps
26960 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
26961 if (!p || p == current || p->state == TASK_RUNNING)
26962 return 0;
26963 stack = (unsigned long)task_stack_page(p);
26964 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26965 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26966 return 0;
26967 fp = *(u64 *)(p->thread.sp);
26968 do {
26969 - if (fp < (unsigned long)stack ||
26970 - fp >= (unsigned long)stack+THREAD_SIZE)
26971 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26972 return 0;
26973 ip = *(u64 *)(fp+8);
26974 if (!in_sched_functions(ip))
26975 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26976 index 678c0ad..2fc2a7b 100644
26977 --- a/arch/x86/kernel/ptrace.c
26978 +++ b/arch/x86/kernel/ptrace.c
26979 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26980 unsigned long sp = (unsigned long)&regs->sp;
26981 u32 *prev_esp;
26982
26983 - if (context == (sp & ~(THREAD_SIZE - 1)))
26984 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26985 return sp;
26986
26987 - prev_esp = (u32 *)(context);
26988 + prev_esp = *(u32 **)(context);
26989 if (prev_esp)
26990 return (unsigned long)prev_esp;
26991
26992 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26993 if (child->thread.gs != value)
26994 return do_arch_prctl(child, ARCH_SET_GS, value);
26995 return 0;
26996 +
26997 + case offsetof(struct user_regs_struct,ip):
26998 + /*
26999 + * Protect against any attempt to set ip to an
27000 + * impossible address. There are dragons lurking if the
27001 + * address is noncanonical. (This explicitly allows
27002 + * setting ip to TASK_SIZE_MAX, because user code can do
27003 + * that all by itself by running off the end of its
27004 + * address space.
27005 + */
27006 + if (value > TASK_SIZE_MAX)
27007 + return -EIO;
27008 + break;
27009 +
27010 #endif
27011 }
27012
27013 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27014 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27015 {
27016 int i;
27017 - int dr7 = 0;
27018 + unsigned long dr7 = 0;
27019 struct arch_hw_breakpoint *info;
27020
27021 for (i = 0; i < HBP_NUM; i++) {
27022 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27023 unsigned long addr, unsigned long data)
27024 {
27025 int ret;
27026 - unsigned long __user *datap = (unsigned long __user *)data;
27027 + unsigned long __user *datap = (__force unsigned long __user *)data;
27028
27029 switch (request) {
27030 /* read the word at location addr in the USER area. */
27031 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27032 if ((int) addr < 0)
27033 return -EIO;
27034 ret = do_get_thread_area(child, addr,
27035 - (struct user_desc __user *)data);
27036 + (__force struct user_desc __user *) data);
27037 break;
27038
27039 case PTRACE_SET_THREAD_AREA:
27040 if ((int) addr < 0)
27041 return -EIO;
27042 ret = do_set_thread_area(child, addr,
27043 - (struct user_desc __user *)data, 0);
27044 + (__force struct user_desc __user *) data, 0);
27045 break;
27046 #endif
27047
27048 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27049
27050 #ifdef CONFIG_X86_64
27051
27052 -static struct user_regset x86_64_regsets[] __read_mostly = {
27053 +static user_regset_no_const x86_64_regsets[] __read_only = {
27054 [REGSET_GENERAL] = {
27055 .core_note_type = NT_PRSTATUS,
27056 .n = sizeof(struct user_regs_struct) / sizeof(long),
27057 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27058 #endif /* CONFIG_X86_64 */
27059
27060 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27061 -static struct user_regset x86_32_regsets[] __read_mostly = {
27062 +static user_regset_no_const x86_32_regsets[] __read_only = {
27063 [REGSET_GENERAL] = {
27064 .core_note_type = NT_PRSTATUS,
27065 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27066 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27067 */
27068 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27069
27070 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27071 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27072 {
27073 #ifdef CONFIG_X86_64
27074 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27075 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27076 memset(info, 0, sizeof(*info));
27077 info->si_signo = SIGTRAP;
27078 info->si_code = si_code;
27079 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27080 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27081 }
27082
27083 void user_single_step_siginfo(struct task_struct *tsk,
27084 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27085 # define IS_IA32 0
27086 #endif
27087
27088 +#ifdef CONFIG_GRKERNSEC_SETXID
27089 +extern void gr_delayed_cred_worker(void);
27090 +#endif
27091 +
27092 /*
27093 * We must return the syscall number to actually look up in the table.
27094 * This can be -1L to skip running any syscall at all.
27095 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27096
27097 user_exit();
27098
27099 +#ifdef CONFIG_GRKERNSEC_SETXID
27100 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27101 + gr_delayed_cred_worker();
27102 +#endif
27103 +
27104 /*
27105 * If we stepped into a sysenter/syscall insn, it trapped in
27106 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27107 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27108 */
27109 user_exit();
27110
27111 +#ifdef CONFIG_GRKERNSEC_SETXID
27112 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27113 + gr_delayed_cred_worker();
27114 +#endif
27115 +
27116 audit_syscall_exit(regs);
27117
27118 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27119 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27120 index 2f355d2..e75ed0a 100644
27121 --- a/arch/x86/kernel/pvclock.c
27122 +++ b/arch/x86/kernel/pvclock.c
27123 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27124 reset_hung_task_detector();
27125 }
27126
27127 -static atomic64_t last_value = ATOMIC64_INIT(0);
27128 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27129
27130 void pvclock_resume(void)
27131 {
27132 - atomic64_set(&last_value, 0);
27133 + atomic64_set_unchecked(&last_value, 0);
27134 }
27135
27136 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27137 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27138 * updating at the same time, and one of them could be slightly behind,
27139 * making the assumption that last_value always go forward fail to hold.
27140 */
27141 - last = atomic64_read(&last_value);
27142 + last = atomic64_read_unchecked(&last_value);
27143 do {
27144 if (ret < last)
27145 return last;
27146 - last = atomic64_cmpxchg(&last_value, last, ret);
27147 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27148 } while (unlikely(last != ret));
27149
27150 return ret;
27151 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27152 index 52b1157..c6e67c4 100644
27153 --- a/arch/x86/kernel/reboot.c
27154 +++ b/arch/x86/kernel/reboot.c
27155 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27156
27157 void __noreturn machine_real_restart(unsigned int type)
27158 {
27159 +
27160 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27161 + struct desc_struct *gdt;
27162 +#endif
27163 +
27164 local_irq_disable();
27165
27166 /*
27167 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
27168
27169 /* Jump to the identity-mapped low memory code */
27170 #ifdef CONFIG_X86_32
27171 - asm volatile("jmpl *%0" : :
27172 +
27173 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27174 + gdt = get_cpu_gdt_table(smp_processor_id());
27175 + pax_open_kernel();
27176 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27177 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27178 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27179 + loadsegment(ds, __KERNEL_DS);
27180 + loadsegment(es, __KERNEL_DS);
27181 + loadsegment(ss, __KERNEL_DS);
27182 +#endif
27183 +#ifdef CONFIG_PAX_KERNEXEC
27184 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27185 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27186 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27187 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27188 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27189 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27190 +#endif
27191 + pax_close_kernel();
27192 +#endif
27193 +
27194 + asm volatile("ljmpl *%0" : :
27195 "rm" (real_mode_header->machine_real_restart_asm),
27196 "a" (type));
27197 #else
27198 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27199 * This means that this function can never return, it can misbehave
27200 * by not rebooting properly and hanging.
27201 */
27202 -static void native_machine_emergency_restart(void)
27203 +static void __noreturn native_machine_emergency_restart(void)
27204 {
27205 int i;
27206 int attempt = 0;
27207 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
27208 #endif
27209 }
27210
27211 -static void __machine_emergency_restart(int emergency)
27212 +static void __noreturn __machine_emergency_restart(int emergency)
27213 {
27214 reboot_emergency = emergency;
27215 machine_ops.emergency_restart();
27216 }
27217
27218 -static void native_machine_restart(char *__unused)
27219 +static void __noreturn native_machine_restart(char *__unused)
27220 {
27221 pr_notice("machine restart\n");
27222
27223 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
27224 __machine_emergency_restart(0);
27225 }
27226
27227 -static void native_machine_halt(void)
27228 +static void __noreturn native_machine_halt(void)
27229 {
27230 /* Stop other cpus and apics */
27231 machine_shutdown();
27232 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
27233 stop_this_cpu(NULL);
27234 }
27235
27236 -static void native_machine_power_off(void)
27237 +static void __noreturn native_machine_power_off(void)
27238 {
27239 if (pm_power_off) {
27240 if (!reboot_force)
27241 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
27242 }
27243 /* A fallback in case there is no PM info available */
27244 tboot_shutdown(TB_SHUTDOWN_HALT);
27245 + unreachable();
27246 }
27247
27248 -struct machine_ops machine_ops = {
27249 +struct machine_ops machine_ops __read_only = {
27250 .power_off = native_machine_power_off,
27251 .shutdown = native_machine_shutdown,
27252 .emergency_restart = native_machine_emergency_restart,
27253 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27254 index c8e41e9..64049ef 100644
27255 --- a/arch/x86/kernel/reboot_fixups_32.c
27256 +++ b/arch/x86/kernel/reboot_fixups_32.c
27257 @@ -57,7 +57,7 @@ struct device_fixup {
27258 unsigned int vendor;
27259 unsigned int device;
27260 void (*reboot_fixup)(struct pci_dev *);
27261 -};
27262 +} __do_const;
27263
27264 /*
27265 * PCI ids solely used for fixups_table go here
27266 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27267 index 3fd2c69..a444264 100644
27268 --- a/arch/x86/kernel/relocate_kernel_64.S
27269 +++ b/arch/x86/kernel/relocate_kernel_64.S
27270 @@ -96,8 +96,7 @@ relocate_kernel:
27271
27272 /* jump to identity mapped page */
27273 addq $(identity_mapped - relocate_kernel), %r8
27274 - pushq %r8
27275 - ret
27276 + jmp *%r8
27277
27278 identity_mapped:
27279 /* set return address to 0 if not preserving context */
27280 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27281 index 78a0e62..5c2e510 100644
27282 --- a/arch/x86/kernel/setup.c
27283 +++ b/arch/x86/kernel/setup.c
27284 @@ -110,6 +110,7 @@
27285 #include <asm/mce.h>
27286 #include <asm/alternative.h>
27287 #include <asm/prom.h>
27288 +#include <asm/boot.h>
27289
27290 /*
27291 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27292 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27293 #endif
27294
27295
27296 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27297 -__visible unsigned long mmu_cr4_features;
27298 +#ifdef CONFIG_X86_64
27299 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27300 +#elif defined(CONFIG_X86_PAE)
27301 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27302 #else
27303 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27304 +__visible unsigned long mmu_cr4_features __read_only;
27305 #endif
27306
27307 +void set_in_cr4(unsigned long mask)
27308 +{
27309 + unsigned long cr4 = read_cr4();
27310 +
27311 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27312 + return;
27313 +
27314 + pax_open_kernel();
27315 + mmu_cr4_features |= mask;
27316 + pax_close_kernel();
27317 +
27318 + if (trampoline_cr4_features)
27319 + *trampoline_cr4_features = mmu_cr4_features;
27320 + cr4 |= mask;
27321 + write_cr4(cr4);
27322 +}
27323 +EXPORT_SYMBOL(set_in_cr4);
27324 +
27325 +void clear_in_cr4(unsigned long mask)
27326 +{
27327 + unsigned long cr4 = read_cr4();
27328 +
27329 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27330 + return;
27331 +
27332 + pax_open_kernel();
27333 + mmu_cr4_features &= ~mask;
27334 + pax_close_kernel();
27335 +
27336 + if (trampoline_cr4_features)
27337 + *trampoline_cr4_features = mmu_cr4_features;
27338 + cr4 &= ~mask;
27339 + write_cr4(cr4);
27340 +}
27341 +EXPORT_SYMBOL(clear_in_cr4);
27342 +
27343 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27344 int bootloader_type, bootloader_version;
27345
27346 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27347 * area (640->1Mb) as ram even though it is not.
27348 * take them out.
27349 */
27350 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27351 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27352
27353 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27354 }
27355 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27356 /* called before trim_bios_range() to spare extra sanitize */
27357 static void __init e820_add_kernel_range(void)
27358 {
27359 - u64 start = __pa_symbol(_text);
27360 + u64 start = __pa_symbol(ktla_ktva(_text));
27361 u64 size = __pa_symbol(_end) - start;
27362
27363 /*
27364 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27365
27366 void __init setup_arch(char **cmdline_p)
27367 {
27368 +#ifdef CONFIG_X86_32
27369 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27370 +#else
27371 memblock_reserve(__pa_symbol(_text),
27372 (unsigned long)__bss_stop - (unsigned long)_text);
27373 +#endif
27374
27375 early_reserve_initrd();
27376
27377 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27378
27379 if (!boot_params.hdr.root_flags)
27380 root_mountflags &= ~MS_RDONLY;
27381 - init_mm.start_code = (unsigned long) _text;
27382 - init_mm.end_code = (unsigned long) _etext;
27383 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27384 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27385 init_mm.end_data = (unsigned long) _edata;
27386 init_mm.brk = _brk_end;
27387
27388 - code_resource.start = __pa_symbol(_text);
27389 - code_resource.end = __pa_symbol(_etext)-1;
27390 - data_resource.start = __pa_symbol(_etext);
27391 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27392 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27393 + data_resource.start = __pa_symbol(_sdata);
27394 data_resource.end = __pa_symbol(_edata)-1;
27395 bss_resource.start = __pa_symbol(__bss_start);
27396 bss_resource.end = __pa_symbol(__bss_stop)-1;
27397 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27398 index 5cdff03..80fa283 100644
27399 --- a/arch/x86/kernel/setup_percpu.c
27400 +++ b/arch/x86/kernel/setup_percpu.c
27401 @@ -21,19 +21,17 @@
27402 #include <asm/cpu.h>
27403 #include <asm/stackprotector.h>
27404
27405 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27406 +#ifdef CONFIG_SMP
27407 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27408 EXPORT_PER_CPU_SYMBOL(cpu_number);
27409 +#endif
27410
27411 -#ifdef CONFIG_X86_64
27412 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27413 -#else
27414 -#define BOOT_PERCPU_OFFSET 0
27415 -#endif
27416
27417 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27418 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27419
27420 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27421 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27422 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27423 };
27424 EXPORT_SYMBOL(__per_cpu_offset);
27425 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27426 {
27427 #ifdef CONFIG_NEED_MULTIPLE_NODES
27428 pg_data_t *last = NULL;
27429 - unsigned int cpu;
27430 + int cpu;
27431
27432 for_each_possible_cpu(cpu) {
27433 int node = early_cpu_to_node(cpu);
27434 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27435 {
27436 #ifdef CONFIG_X86_32
27437 struct desc_struct gdt;
27438 + unsigned long base = per_cpu_offset(cpu);
27439
27440 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27441 - 0x2 | DESCTYPE_S, 0x8);
27442 - gdt.s = 1;
27443 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27444 + 0x83 | DESCTYPE_S, 0xC);
27445 write_gdt_entry(get_cpu_gdt_table(cpu),
27446 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27447 #endif
27448 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27449 /* alrighty, percpu areas up and running */
27450 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27451 for_each_possible_cpu(cpu) {
27452 +#ifdef CONFIG_CC_STACKPROTECTOR
27453 +#ifdef CONFIG_X86_32
27454 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27455 +#endif
27456 +#endif
27457 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27458 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27459 per_cpu(cpu_number, cpu) = cpu;
27460 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27461 */
27462 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27463 #endif
27464 +#ifdef CONFIG_CC_STACKPROTECTOR
27465 +#ifdef CONFIG_X86_32
27466 + if (!cpu)
27467 + per_cpu(stack_canary.canary, cpu) = canary;
27468 +#endif
27469 +#endif
27470 /*
27471 * Up to this point, the boot CPU has been using .init.data
27472 * area. Reload any changed state for the boot CPU.
27473 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27474 index 2851d63..83bf567 100644
27475 --- a/arch/x86/kernel/signal.c
27476 +++ b/arch/x86/kernel/signal.c
27477 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27478 * Align the stack pointer according to the i386 ABI,
27479 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27480 */
27481 - sp = ((sp + 4) & -16ul) - 4;
27482 + sp = ((sp - 12) & -16ul) - 4;
27483 #else /* !CONFIG_X86_32 */
27484 sp = round_down(sp, 16) - 8;
27485 #endif
27486 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27487 }
27488
27489 if (current->mm->context.vdso)
27490 - restorer = current->mm->context.vdso +
27491 - selected_vdso32->sym___kernel_sigreturn;
27492 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27493 else
27494 - restorer = &frame->retcode;
27495 + restorer = (void __user *)&frame->retcode;
27496 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27497 restorer = ksig->ka.sa.sa_restorer;
27498
27499 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27500 * reasons and because gdb uses it as a signature to notice
27501 * signal handler stack frames.
27502 */
27503 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27504 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27505
27506 if (err)
27507 return -EFAULT;
27508 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27509 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27510
27511 /* Set up to return from userspace. */
27512 - restorer = current->mm->context.vdso +
27513 - selected_vdso32->sym___kernel_rt_sigreturn;
27514 + if (current->mm->context.vdso)
27515 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27516 + else
27517 + restorer = (void __user *)&frame->retcode;
27518 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27519 restorer = ksig->ka.sa.sa_restorer;
27520 put_user_ex(restorer, &frame->pretcode);
27521 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27522 * reasons and because gdb uses it as a signature to notice
27523 * signal handler stack frames.
27524 */
27525 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27526 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27527 } put_user_catch(err);
27528
27529 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27530 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27531 {
27532 int usig = signr_convert(ksig->sig);
27533 sigset_t *set = sigmask_to_save();
27534 - compat_sigset_t *cset = (compat_sigset_t *) set;
27535 + sigset_t sigcopy;
27536 + compat_sigset_t *cset;
27537 +
27538 + sigcopy = *set;
27539 +
27540 + cset = (compat_sigset_t *) &sigcopy;
27541
27542 /* Set up the stack frame */
27543 if (is_ia32_frame()) {
27544 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27545 } else if (is_x32_frame()) {
27546 return x32_setup_rt_frame(ksig, cset, regs);
27547 } else {
27548 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27549 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27550 }
27551 }
27552
27553 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27554 index be8e1bd..a3d93fa 100644
27555 --- a/arch/x86/kernel/smp.c
27556 +++ b/arch/x86/kernel/smp.c
27557 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27558
27559 __setup("nonmi_ipi", nonmi_ipi_setup);
27560
27561 -struct smp_ops smp_ops = {
27562 +struct smp_ops smp_ops __read_only = {
27563 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27564 .smp_prepare_cpus = native_smp_prepare_cpus,
27565 .smp_cpus_done = native_smp_cpus_done,
27566 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27567 index 5492798..a3bd4f2 100644
27568 --- a/arch/x86/kernel/smpboot.c
27569 +++ b/arch/x86/kernel/smpboot.c
27570 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27571
27572 enable_start_cpu0 = 0;
27573
27574 -#ifdef CONFIG_X86_32
27575 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27576 + barrier();
27577 +
27578 /* switch away from the initial page table */
27579 +#ifdef CONFIG_PAX_PER_CPU_PGD
27580 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27581 +#else
27582 load_cr3(swapper_pg_dir);
27583 +#endif
27584 __flush_tlb_all();
27585 -#endif
27586
27587 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27588 - barrier();
27589 /*
27590 * Check TSC synchronization with the BP:
27591 */
27592 @@ -764,8 +767,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27593 alternatives_enable_smp();
27594
27595 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27596 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27597 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27598 per_cpu(current_task, cpu) = idle;
27599 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27600
27601 #ifdef CONFIG_X86_32
27602 /* Stack for startup_32 can be just as for start_secondary onwards */
27603 @@ -774,10 +778,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27604 clear_tsk_thread_flag(idle, TIF_FORK);
27605 initial_gs = per_cpu_offset(cpu);
27606 #endif
27607 - per_cpu(kernel_stack, cpu) =
27608 - (unsigned long)task_stack_page(idle) -
27609 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27610 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27611 + pax_open_kernel();
27612 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27613 + pax_close_kernel();
27614 initial_code = (unsigned long)start_secondary;
27615 stack_start = idle->thread.sp;
27616
27617 @@ -923,6 +927,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27618 /* the FPU context is blank, nobody can own it */
27619 __cpu_disable_lazy_restore(cpu);
27620
27621 +#ifdef CONFIG_PAX_PER_CPU_PGD
27622 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27623 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27624 + KERNEL_PGD_PTRS);
27625 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27626 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27627 + KERNEL_PGD_PTRS);
27628 +#endif
27629 +
27630 err = do_boot_cpu(apicid, cpu, tidle);
27631 if (err) {
27632 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27633 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27634 index 9b4d51d..5d28b58 100644
27635 --- a/arch/x86/kernel/step.c
27636 +++ b/arch/x86/kernel/step.c
27637 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27638 struct desc_struct *desc;
27639 unsigned long base;
27640
27641 - seg &= ~7UL;
27642 + seg >>= 3;
27643
27644 mutex_lock(&child->mm->context.lock);
27645 - if (unlikely((seg >> 3) >= child->mm->context.size))
27646 + if (unlikely(seg >= child->mm->context.size))
27647 addr = -1L; /* bogus selector, access would fault */
27648 else {
27649 desc = child->mm->context.ldt + seg;
27650 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27651 addr += base;
27652 }
27653 mutex_unlock(&child->mm->context.lock);
27654 - }
27655 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27656 + addr = ktla_ktva(addr);
27657
27658 return addr;
27659 }
27660 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27661 unsigned char opcode[15];
27662 unsigned long addr = convert_ip_to_linear(child, regs);
27663
27664 + if (addr == -EINVAL)
27665 + return 0;
27666 +
27667 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27668 for (i = 0; i < copied; i++) {
27669 switch (opcode[i]) {
27670 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27671 new file mode 100644
27672 index 0000000..5877189
27673 --- /dev/null
27674 +++ b/arch/x86/kernel/sys_i386_32.c
27675 @@ -0,0 +1,189 @@
27676 +/*
27677 + * This file contains various random system calls that
27678 + * have a non-standard calling sequence on the Linux/i386
27679 + * platform.
27680 + */
27681 +
27682 +#include <linux/errno.h>
27683 +#include <linux/sched.h>
27684 +#include <linux/mm.h>
27685 +#include <linux/fs.h>
27686 +#include <linux/smp.h>
27687 +#include <linux/sem.h>
27688 +#include <linux/msg.h>
27689 +#include <linux/shm.h>
27690 +#include <linux/stat.h>
27691 +#include <linux/syscalls.h>
27692 +#include <linux/mman.h>
27693 +#include <linux/file.h>
27694 +#include <linux/utsname.h>
27695 +#include <linux/ipc.h>
27696 +#include <linux/elf.h>
27697 +
27698 +#include <linux/uaccess.h>
27699 +#include <linux/unistd.h>
27700 +
27701 +#include <asm/syscalls.h>
27702 +
27703 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27704 +{
27705 + unsigned long pax_task_size = TASK_SIZE;
27706 +
27707 +#ifdef CONFIG_PAX_SEGMEXEC
27708 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27709 + pax_task_size = SEGMEXEC_TASK_SIZE;
27710 +#endif
27711 +
27712 + if (flags & MAP_FIXED)
27713 + if (len > pax_task_size || addr > pax_task_size - len)
27714 + return -EINVAL;
27715 +
27716 + return 0;
27717 +}
27718 +
27719 +/*
27720 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27721 + */
27722 +static unsigned long get_align_mask(void)
27723 +{
27724 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27725 + return 0;
27726 +
27727 + if (!(current->flags & PF_RANDOMIZE))
27728 + return 0;
27729 +
27730 + return va_align.mask;
27731 +}
27732 +
27733 +unsigned long
27734 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27735 + unsigned long len, unsigned long pgoff, unsigned long flags)
27736 +{
27737 + struct mm_struct *mm = current->mm;
27738 + struct vm_area_struct *vma;
27739 + unsigned long pax_task_size = TASK_SIZE;
27740 + struct vm_unmapped_area_info info;
27741 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27742 +
27743 +#ifdef CONFIG_PAX_SEGMEXEC
27744 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27745 + pax_task_size = SEGMEXEC_TASK_SIZE;
27746 +#endif
27747 +
27748 + pax_task_size -= PAGE_SIZE;
27749 +
27750 + if (len > pax_task_size)
27751 + return -ENOMEM;
27752 +
27753 + if (flags & MAP_FIXED)
27754 + return addr;
27755 +
27756 +#ifdef CONFIG_PAX_RANDMMAP
27757 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27758 +#endif
27759 +
27760 + if (addr) {
27761 + addr = PAGE_ALIGN(addr);
27762 + if (pax_task_size - len >= addr) {
27763 + vma = find_vma(mm, addr);
27764 + if (check_heap_stack_gap(vma, addr, len, offset))
27765 + return addr;
27766 + }
27767 + }
27768 +
27769 + info.flags = 0;
27770 + info.length = len;
27771 + info.align_mask = filp ? get_align_mask() : 0;
27772 + info.align_offset = pgoff << PAGE_SHIFT;
27773 + info.threadstack_offset = offset;
27774 +
27775 +#ifdef CONFIG_PAX_PAGEEXEC
27776 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27777 + info.low_limit = 0x00110000UL;
27778 + info.high_limit = mm->start_code;
27779 +
27780 +#ifdef CONFIG_PAX_RANDMMAP
27781 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27782 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27783 +#endif
27784 +
27785 + if (info.low_limit < info.high_limit) {
27786 + addr = vm_unmapped_area(&info);
27787 + if (!IS_ERR_VALUE(addr))
27788 + return addr;
27789 + }
27790 + } else
27791 +#endif
27792 +
27793 + info.low_limit = mm->mmap_base;
27794 + info.high_limit = pax_task_size;
27795 +
27796 + return vm_unmapped_area(&info);
27797 +}
27798 +
27799 +unsigned long
27800 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27801 + const unsigned long len, const unsigned long pgoff,
27802 + const unsigned long flags)
27803 +{
27804 + struct vm_area_struct *vma;
27805 + struct mm_struct *mm = current->mm;
27806 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27807 + struct vm_unmapped_area_info info;
27808 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27809 +
27810 +#ifdef CONFIG_PAX_SEGMEXEC
27811 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27812 + pax_task_size = SEGMEXEC_TASK_SIZE;
27813 +#endif
27814 +
27815 + pax_task_size -= PAGE_SIZE;
27816 +
27817 + /* requested length too big for entire address space */
27818 + if (len > pax_task_size)
27819 + return -ENOMEM;
27820 +
27821 + if (flags & MAP_FIXED)
27822 + return addr;
27823 +
27824 +#ifdef CONFIG_PAX_PAGEEXEC
27825 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27826 + goto bottomup;
27827 +#endif
27828 +
27829 +#ifdef CONFIG_PAX_RANDMMAP
27830 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27831 +#endif
27832 +
27833 + /* requesting a specific address */
27834 + if (addr) {
27835 + addr = PAGE_ALIGN(addr);
27836 + if (pax_task_size - len >= addr) {
27837 + vma = find_vma(mm, addr);
27838 + if (check_heap_stack_gap(vma, addr, len, offset))
27839 + return addr;
27840 + }
27841 + }
27842 +
27843 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27844 + info.length = len;
27845 + info.low_limit = PAGE_SIZE;
27846 + info.high_limit = mm->mmap_base;
27847 + info.align_mask = filp ? get_align_mask() : 0;
27848 + info.align_offset = pgoff << PAGE_SHIFT;
27849 + info.threadstack_offset = offset;
27850 +
27851 + addr = vm_unmapped_area(&info);
27852 + if (!(addr & ~PAGE_MASK))
27853 + return addr;
27854 + VM_BUG_ON(addr != -ENOMEM);
27855 +
27856 +bottomup:
27857 + /*
27858 + * A failed mmap() very likely causes application failure,
27859 + * so fall back to the bottom-up function here. This scenario
27860 + * can happen with large stack limits and large mmap()
27861 + * allocations.
27862 + */
27863 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27864 +}
27865 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27866 index 30277e2..5664a29 100644
27867 --- a/arch/x86/kernel/sys_x86_64.c
27868 +++ b/arch/x86/kernel/sys_x86_64.c
27869 @@ -81,8 +81,8 @@ out:
27870 return error;
27871 }
27872
27873 -static void find_start_end(unsigned long flags, unsigned long *begin,
27874 - unsigned long *end)
27875 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27876 + unsigned long *begin, unsigned long *end)
27877 {
27878 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27879 unsigned long new_begin;
27880 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27881 *begin = new_begin;
27882 }
27883 } else {
27884 - *begin = current->mm->mmap_legacy_base;
27885 + *begin = mm->mmap_legacy_base;
27886 *end = TASK_SIZE;
27887 }
27888 }
27889 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27890 struct vm_area_struct *vma;
27891 struct vm_unmapped_area_info info;
27892 unsigned long begin, end;
27893 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27894
27895 if (flags & MAP_FIXED)
27896 return addr;
27897
27898 - find_start_end(flags, &begin, &end);
27899 + find_start_end(mm, flags, &begin, &end);
27900
27901 if (len > end)
27902 return -ENOMEM;
27903
27904 +#ifdef CONFIG_PAX_RANDMMAP
27905 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27906 +#endif
27907 +
27908 if (addr) {
27909 addr = PAGE_ALIGN(addr);
27910 vma = find_vma(mm, addr);
27911 - if (end - len >= addr &&
27912 - (!vma || addr + len <= vma->vm_start))
27913 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27914 return addr;
27915 }
27916
27917 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27918 info.high_limit = end;
27919 info.align_mask = filp ? get_align_mask() : 0;
27920 info.align_offset = pgoff << PAGE_SHIFT;
27921 + info.threadstack_offset = offset;
27922 return vm_unmapped_area(&info);
27923 }
27924
27925 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27926 struct mm_struct *mm = current->mm;
27927 unsigned long addr = addr0;
27928 struct vm_unmapped_area_info info;
27929 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27930
27931 /* requested length too big for entire address space */
27932 if (len > TASK_SIZE)
27933 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27934 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27935 goto bottomup;
27936
27937 +#ifdef CONFIG_PAX_RANDMMAP
27938 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27939 +#endif
27940 +
27941 /* requesting a specific address */
27942 if (addr) {
27943 addr = PAGE_ALIGN(addr);
27944 vma = find_vma(mm, addr);
27945 - if (TASK_SIZE - len >= addr &&
27946 - (!vma || addr + len <= vma->vm_start))
27947 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27948 return addr;
27949 }
27950
27951 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27952 info.high_limit = mm->mmap_base;
27953 info.align_mask = filp ? get_align_mask() : 0;
27954 info.align_offset = pgoff << PAGE_SHIFT;
27955 + info.threadstack_offset = offset;
27956 addr = vm_unmapped_area(&info);
27957 if (!(addr & ~PAGE_MASK))
27958 return addr;
27959 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27960 index 91a4496..bb87552 100644
27961 --- a/arch/x86/kernel/tboot.c
27962 +++ b/arch/x86/kernel/tboot.c
27963 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27964
27965 void tboot_shutdown(u32 shutdown_type)
27966 {
27967 - void (*shutdown)(void);
27968 + void (* __noreturn shutdown)(void);
27969
27970 if (!tboot_enabled())
27971 return;
27972 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27973
27974 switch_to_tboot_pt();
27975
27976 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27977 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27978 shutdown();
27979
27980 /* should not reach here */
27981 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27982 return -ENODEV;
27983 }
27984
27985 -static atomic_t ap_wfs_count;
27986 +static atomic_unchecked_t ap_wfs_count;
27987
27988 static int tboot_wait_for_aps(int num_aps)
27989 {
27990 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27991 {
27992 switch (action) {
27993 case CPU_DYING:
27994 - atomic_inc(&ap_wfs_count);
27995 + atomic_inc_unchecked(&ap_wfs_count);
27996 if (num_online_cpus() == 1)
27997 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27998 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27999 return NOTIFY_BAD;
28000 break;
28001 }
28002 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28003
28004 tboot_create_trampoline();
28005
28006 - atomic_set(&ap_wfs_count, 0);
28007 + atomic_set_unchecked(&ap_wfs_count, 0);
28008 register_hotcpu_notifier(&tboot_cpu_notifier);
28009
28010 #ifdef CONFIG_DEBUG_FS
28011 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28012 index bf7ef5c..59d0ac9 100644
28013 --- a/arch/x86/kernel/time.c
28014 +++ b/arch/x86/kernel/time.c
28015 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28016 {
28017 unsigned long pc = instruction_pointer(regs);
28018
28019 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28020 + if (!user_mode(regs) && in_lock_functions(pc)) {
28021 #ifdef CONFIG_FRAME_POINTER
28022 - return *(unsigned long *)(regs->bp + sizeof(long));
28023 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28024 #else
28025 unsigned long *sp =
28026 (unsigned long *)kernel_stack_pointer(regs);
28027 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28028 * or above a saved flags. Eflags has bits 22-31 zero,
28029 * kernel addresses don't.
28030 */
28031 +
28032 +#ifdef CONFIG_PAX_KERNEXEC
28033 + return ktla_ktva(sp[0]);
28034 +#else
28035 if (sp[0] >> 22)
28036 return sp[0];
28037 if (sp[1] >> 22)
28038 return sp[1];
28039 #endif
28040 +
28041 +#endif
28042 }
28043 return pc;
28044 }
28045 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28046 index f7fec09..9991981 100644
28047 --- a/arch/x86/kernel/tls.c
28048 +++ b/arch/x86/kernel/tls.c
28049 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28050 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28051 return -EINVAL;
28052
28053 +#ifdef CONFIG_PAX_SEGMEXEC
28054 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28055 + return -EINVAL;
28056 +#endif
28057 +
28058 set_tls_desc(p, idx, &info, 1);
28059
28060 return 0;
28061 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28062
28063 if (kbuf)
28064 info = kbuf;
28065 - else if (__copy_from_user(infobuf, ubuf, count))
28066 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28067 return -EFAULT;
28068 else
28069 info = infobuf;
28070 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28071 index 1c113db..287b42e 100644
28072 --- a/arch/x86/kernel/tracepoint.c
28073 +++ b/arch/x86/kernel/tracepoint.c
28074 @@ -9,11 +9,11 @@
28075 #include <linux/atomic.h>
28076
28077 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28078 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28079 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28080 (unsigned long) trace_idt_table };
28081
28082 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28083 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28084 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28085
28086 static int trace_irq_vector_refcount;
28087 static DEFINE_MUTEX(irq_vector_mutex);
28088 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28089 index 0d0e922..0886373 100644
28090 --- a/arch/x86/kernel/traps.c
28091 +++ b/arch/x86/kernel/traps.c
28092 @@ -67,7 +67,7 @@
28093 #include <asm/proto.h>
28094
28095 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28096 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28097 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28098 #else
28099 #include <asm/processor-flags.h>
28100 #include <asm/setup.h>
28101 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28102 #endif
28103
28104 /* Must be page-aligned because the real IDT is used in a fixmap. */
28105 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28106 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28107
28108 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28109 EXPORT_SYMBOL_GPL(used_vectors);
28110 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28111 }
28112
28113 static nokprobe_inline int
28114 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28115 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28116 struct pt_regs *regs, long error_code)
28117 {
28118 #ifdef CONFIG_X86_32
28119 - if (regs->flags & X86_VM_MASK) {
28120 + if (v8086_mode(regs)) {
28121 /*
28122 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28123 * On nmi (interrupt 2), do_trap should not be called.
28124 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28125 return -1;
28126 }
28127 #endif
28128 - if (!user_mode(regs)) {
28129 + if (!user_mode_novm(regs)) {
28130 if (!fixup_exception(regs)) {
28131 tsk->thread.error_code = error_code;
28132 tsk->thread.trap_nr = trapnr;
28133 +
28134 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28135 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28136 + str = "PAX: suspicious stack segment fault";
28137 +#endif
28138 +
28139 die(str, regs, error_code);
28140 }
28141 +
28142 +#ifdef CONFIG_PAX_REFCOUNT
28143 + if (trapnr == X86_TRAP_OF)
28144 + pax_report_refcount_overflow(regs);
28145 +#endif
28146 +
28147 return 0;
28148 }
28149
28150 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28151 }
28152
28153 static void
28154 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28155 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28156 long error_code, siginfo_t *info)
28157 {
28158 struct task_struct *tsk = current;
28159 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28160 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28161 printk_ratelimit()) {
28162 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28163 - tsk->comm, tsk->pid, str,
28164 + tsk->comm, task_pid_nr(tsk), str,
28165 regs->ip, regs->sp, error_code);
28166 print_vma_addr(" in ", regs->ip);
28167 pr_cont("\n");
28168 @@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28169 tsk->thread.error_code = error_code;
28170 tsk->thread.trap_nr = X86_TRAP_DF;
28171
28172 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28173 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28174 + die("grsec: kernel stack overflow detected", regs, error_code);
28175 +#endif
28176 +
28177 #ifdef CONFIG_DOUBLEFAULT
28178 df_debug(regs, error_code);
28179 #endif
28180 @@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28181 conditional_sti(regs);
28182
28183 #ifdef CONFIG_X86_32
28184 - if (regs->flags & X86_VM_MASK) {
28185 + if (v8086_mode(regs)) {
28186 local_irq_enable();
28187 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28188 goto exit;
28189 @@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28190 #endif
28191
28192 tsk = current;
28193 - if (!user_mode(regs)) {
28194 + if (!user_mode_novm(regs)) {
28195 if (fixup_exception(regs))
28196 goto exit;
28197
28198 tsk->thread.error_code = error_code;
28199 tsk->thread.trap_nr = X86_TRAP_GP;
28200 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28201 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28202 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28203 +
28204 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28205 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28206 + die("PAX: suspicious general protection fault", regs, error_code);
28207 + else
28208 +#endif
28209 +
28210 die("general protection fault", regs, error_code);
28211 + }
28212 goto exit;
28213 }
28214
28215 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28216 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28217 + struct mm_struct *mm = tsk->mm;
28218 + unsigned long limit;
28219 +
28220 + down_write(&mm->mmap_sem);
28221 + limit = mm->context.user_cs_limit;
28222 + if (limit < TASK_SIZE) {
28223 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28224 + up_write(&mm->mmap_sem);
28225 + return;
28226 + }
28227 + up_write(&mm->mmap_sem);
28228 + }
28229 +#endif
28230 +
28231 tsk->thread.error_code = error_code;
28232 tsk->thread.trap_nr = X86_TRAP_GP;
28233
28234 @@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28235 /* It's safe to allow irq's after DR6 has been saved */
28236 preempt_conditional_sti(regs);
28237
28238 - if (regs->flags & X86_VM_MASK) {
28239 + if (v8086_mode(regs)) {
28240 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28241 X86_TRAP_DB);
28242 preempt_conditional_cli(regs);
28243 @@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28244 * We already checked v86 mode above, so we can check for kernel mode
28245 * by just checking the CPL of CS.
28246 */
28247 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28248 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28249 tsk->thread.debugreg6 &= ~DR_STEP;
28250 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28251 regs->flags &= ~X86_EFLAGS_TF;
28252 @@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28253 return;
28254 conditional_sti(regs);
28255
28256 - if (!user_mode_vm(regs))
28257 + if (!user_mode(regs))
28258 {
28259 if (!fixup_exception(regs)) {
28260 task->thread.error_code = error_code;
28261 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28262 index ea03031..34a5cdda 100644
28263 --- a/arch/x86/kernel/tsc.c
28264 +++ b/arch/x86/kernel/tsc.c
28265 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28266 */
28267 smp_wmb();
28268
28269 - ACCESS_ONCE(c2n->head) = data;
28270 + ACCESS_ONCE_RW(c2n->head) = data;
28271 }
28272
28273 /*
28274 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28275 index 5d1cbfe..2a21feb 100644
28276 --- a/arch/x86/kernel/uprobes.c
28277 +++ b/arch/x86/kernel/uprobes.c
28278 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28279 int ret = NOTIFY_DONE;
28280
28281 /* We are only interested in userspace traps */
28282 - if (regs && !user_mode_vm(regs))
28283 + if (regs && !user_mode(regs))
28284 return NOTIFY_DONE;
28285
28286 switch (val) {
28287 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28288
28289 if (nleft != rasize) {
28290 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28291 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28292 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28293
28294 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28295 }
28296 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28297 index b9242ba..50c5edd 100644
28298 --- a/arch/x86/kernel/verify_cpu.S
28299 +++ b/arch/x86/kernel/verify_cpu.S
28300 @@ -20,6 +20,7 @@
28301 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28302 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28303 * arch/x86/kernel/head_32.S: processor startup
28304 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28305 *
28306 * verify_cpu, returns the status of longmode and SSE in register %eax.
28307 * 0: Success 1: Failure
28308 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28309 index e8edcf5..27f9344 100644
28310 --- a/arch/x86/kernel/vm86_32.c
28311 +++ b/arch/x86/kernel/vm86_32.c
28312 @@ -44,6 +44,7 @@
28313 #include <linux/ptrace.h>
28314 #include <linux/audit.h>
28315 #include <linux/stddef.h>
28316 +#include <linux/grsecurity.h>
28317
28318 #include <asm/uaccess.h>
28319 #include <asm/io.h>
28320 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28321 do_exit(SIGSEGV);
28322 }
28323
28324 - tss = &per_cpu(init_tss, get_cpu());
28325 + tss = init_tss + get_cpu();
28326 current->thread.sp0 = current->thread.saved_sp0;
28327 current->thread.sysenter_cs = __KERNEL_CS;
28328 load_sp0(tss, &current->thread);
28329 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28330
28331 if (tsk->thread.saved_sp0)
28332 return -EPERM;
28333 +
28334 +#ifdef CONFIG_GRKERNSEC_VM86
28335 + if (!capable(CAP_SYS_RAWIO)) {
28336 + gr_handle_vm86();
28337 + return -EPERM;
28338 + }
28339 +#endif
28340 +
28341 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28342 offsetof(struct kernel_vm86_struct, vm86plus) -
28343 sizeof(info.regs));
28344 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28345 int tmp;
28346 struct vm86plus_struct __user *v86;
28347
28348 +#ifdef CONFIG_GRKERNSEC_VM86
28349 + if (!capable(CAP_SYS_RAWIO)) {
28350 + gr_handle_vm86();
28351 + return -EPERM;
28352 + }
28353 +#endif
28354 +
28355 tsk = current;
28356 switch (cmd) {
28357 case VM86_REQUEST_IRQ:
28358 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28359 tsk->thread.saved_fs = info->regs32->fs;
28360 tsk->thread.saved_gs = get_user_gs(info->regs32);
28361
28362 - tss = &per_cpu(init_tss, get_cpu());
28363 + tss = init_tss + get_cpu();
28364 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28365 if (cpu_has_sep)
28366 tsk->thread.sysenter_cs = 0;
28367 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28368 goto cannot_handle;
28369 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28370 goto cannot_handle;
28371 - intr_ptr = (unsigned long __user *) (i << 2);
28372 + intr_ptr = (__force unsigned long __user *) (i << 2);
28373 if (get_user(segoffs, intr_ptr))
28374 goto cannot_handle;
28375 if ((segoffs >> 16) == BIOSSEG)
28376 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28377 index 49edf2d..c0d1362 100644
28378 --- a/arch/x86/kernel/vmlinux.lds.S
28379 +++ b/arch/x86/kernel/vmlinux.lds.S
28380 @@ -26,6 +26,13 @@
28381 #include <asm/page_types.h>
28382 #include <asm/cache.h>
28383 #include <asm/boot.h>
28384 +#include <asm/segment.h>
28385 +
28386 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28387 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28388 +#else
28389 +#define __KERNEL_TEXT_OFFSET 0
28390 +#endif
28391
28392 #undef i386 /* in case the preprocessor is a 32bit one */
28393
28394 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28395
28396 PHDRS {
28397 text PT_LOAD FLAGS(5); /* R_E */
28398 +#ifdef CONFIG_X86_32
28399 + module PT_LOAD FLAGS(5); /* R_E */
28400 +#endif
28401 +#ifdef CONFIG_XEN
28402 + rodata PT_LOAD FLAGS(5); /* R_E */
28403 +#else
28404 + rodata PT_LOAD FLAGS(4); /* R__ */
28405 +#endif
28406 data PT_LOAD FLAGS(6); /* RW_ */
28407 -#ifdef CONFIG_X86_64
28408 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28409 #ifdef CONFIG_SMP
28410 percpu PT_LOAD FLAGS(6); /* RW_ */
28411 #endif
28412 + text.init PT_LOAD FLAGS(5); /* R_E */
28413 + text.exit PT_LOAD FLAGS(5); /* R_E */
28414 init PT_LOAD FLAGS(7); /* RWE */
28415 -#endif
28416 note PT_NOTE FLAGS(0); /* ___ */
28417 }
28418
28419 SECTIONS
28420 {
28421 #ifdef CONFIG_X86_32
28422 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28423 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28424 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28425 #else
28426 - . = __START_KERNEL;
28427 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28428 + . = __START_KERNEL;
28429 #endif
28430
28431 /* Text and read-only data */
28432 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28433 - _text = .;
28434 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28435 /* bootstrapping code */
28436 +#ifdef CONFIG_X86_32
28437 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28438 +#else
28439 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28440 +#endif
28441 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28442 + _text = .;
28443 HEAD_TEXT
28444 . = ALIGN(8);
28445 _stext = .;
28446 @@ -104,13 +124,47 @@ SECTIONS
28447 IRQENTRY_TEXT
28448 *(.fixup)
28449 *(.gnu.warning)
28450 - /* End of text section */
28451 - _etext = .;
28452 } :text = 0x9090
28453
28454 - NOTES :text :note
28455 + . += __KERNEL_TEXT_OFFSET;
28456
28457 - EXCEPTION_TABLE(16) :text = 0x9090
28458 +#ifdef CONFIG_X86_32
28459 + . = ALIGN(PAGE_SIZE);
28460 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28461 +
28462 +#ifdef CONFIG_PAX_KERNEXEC
28463 + MODULES_EXEC_VADDR = .;
28464 + BYTE(0)
28465 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28466 + . = ALIGN(HPAGE_SIZE) - 1;
28467 + MODULES_EXEC_END = .;
28468 +#endif
28469 +
28470 + } :module
28471 +#endif
28472 +
28473 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28474 + /* End of text section */
28475 + BYTE(0)
28476 + _etext = . - __KERNEL_TEXT_OFFSET;
28477 + }
28478 +
28479 +#ifdef CONFIG_X86_32
28480 + . = ALIGN(PAGE_SIZE);
28481 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28482 + . = ALIGN(PAGE_SIZE);
28483 + *(.empty_zero_page)
28484 + *(.initial_pg_fixmap)
28485 + *(.initial_pg_pmd)
28486 + *(.initial_page_table)
28487 + *(.swapper_pg_dir)
28488 + } :rodata
28489 +#endif
28490 +
28491 + . = ALIGN(PAGE_SIZE);
28492 + NOTES :rodata :note
28493 +
28494 + EXCEPTION_TABLE(16) :rodata
28495
28496 #if defined(CONFIG_DEBUG_RODATA)
28497 /* .text should occupy whole number of pages */
28498 @@ -122,16 +176,20 @@ SECTIONS
28499
28500 /* Data */
28501 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28502 +
28503 +#ifdef CONFIG_PAX_KERNEXEC
28504 + . = ALIGN(HPAGE_SIZE);
28505 +#else
28506 + . = ALIGN(PAGE_SIZE);
28507 +#endif
28508 +
28509 /* Start of data section */
28510 _sdata = .;
28511
28512 /* init_task */
28513 INIT_TASK_DATA(THREAD_SIZE)
28514
28515 -#ifdef CONFIG_X86_32
28516 - /* 32 bit has nosave before _edata */
28517 NOSAVE_DATA
28518 -#endif
28519
28520 PAGE_ALIGNED_DATA(PAGE_SIZE)
28521
28522 @@ -174,12 +232,19 @@ SECTIONS
28523 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28524
28525 /* Init code and data - will be freed after init */
28526 - . = ALIGN(PAGE_SIZE);
28527 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28528 + BYTE(0)
28529 +
28530 +#ifdef CONFIG_PAX_KERNEXEC
28531 + . = ALIGN(HPAGE_SIZE);
28532 +#else
28533 + . = ALIGN(PAGE_SIZE);
28534 +#endif
28535 +
28536 __init_begin = .; /* paired with __init_end */
28537 - }
28538 + } :init.begin
28539
28540 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28541 +#ifdef CONFIG_SMP
28542 /*
28543 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28544 * output PHDR, so the next output section - .init.text - should
28545 @@ -188,12 +253,27 @@ SECTIONS
28546 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28547 #endif
28548
28549 - INIT_TEXT_SECTION(PAGE_SIZE)
28550 -#ifdef CONFIG_X86_64
28551 - :init
28552 -#endif
28553 + . = ALIGN(PAGE_SIZE);
28554 + init_begin = .;
28555 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28556 + VMLINUX_SYMBOL(_sinittext) = .;
28557 + INIT_TEXT
28558 + VMLINUX_SYMBOL(_einittext) = .;
28559 + . = ALIGN(PAGE_SIZE);
28560 + } :text.init
28561
28562 - INIT_DATA_SECTION(16)
28563 + /*
28564 + * .exit.text is discard at runtime, not link time, to deal with
28565 + * references from .altinstructions and .eh_frame
28566 + */
28567 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28568 + EXIT_TEXT
28569 + . = ALIGN(16);
28570 + } :text.exit
28571 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28572 +
28573 + . = ALIGN(PAGE_SIZE);
28574 + INIT_DATA_SECTION(16) :init
28575
28576 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28577 __x86_cpu_dev_start = .;
28578 @@ -264,19 +344,12 @@ SECTIONS
28579 }
28580
28581 . = ALIGN(8);
28582 - /*
28583 - * .exit.text is discard at runtime, not link time, to deal with
28584 - * references from .altinstructions and .eh_frame
28585 - */
28586 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28587 - EXIT_TEXT
28588 - }
28589
28590 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28591 EXIT_DATA
28592 }
28593
28594 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28595 +#ifndef CONFIG_SMP
28596 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28597 #endif
28598
28599 @@ -295,16 +368,10 @@ SECTIONS
28600 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28601 __smp_locks = .;
28602 *(.smp_locks)
28603 - . = ALIGN(PAGE_SIZE);
28604 __smp_locks_end = .;
28605 + . = ALIGN(PAGE_SIZE);
28606 }
28607
28608 -#ifdef CONFIG_X86_64
28609 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28610 - NOSAVE_DATA
28611 - }
28612 -#endif
28613 -
28614 /* BSS */
28615 . = ALIGN(PAGE_SIZE);
28616 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28617 @@ -320,6 +387,7 @@ SECTIONS
28618 __brk_base = .;
28619 . += 64 * 1024; /* 64k alignment slop space */
28620 *(.brk_reservation) /* areas brk users have reserved */
28621 + . = ALIGN(HPAGE_SIZE);
28622 __brk_limit = .;
28623 }
28624
28625 @@ -346,13 +414,12 @@ SECTIONS
28626 * for the boot processor.
28627 */
28628 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28629 -INIT_PER_CPU(gdt_page);
28630 INIT_PER_CPU(irq_stack_union);
28631
28632 /*
28633 * Build-time check on the image size:
28634 */
28635 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28636 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28637 "kernel image bigger than KERNEL_IMAGE_SIZE");
28638
28639 #ifdef CONFIG_SMP
28640 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28641 index e1e1e80..1400089 100644
28642 --- a/arch/x86/kernel/vsyscall_64.c
28643 +++ b/arch/x86/kernel/vsyscall_64.c
28644 @@ -54,15 +54,13 @@
28645
28646 DEFINE_VVAR(int, vgetcpu_mode);
28647
28648 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28649 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28650
28651 static int __init vsyscall_setup(char *str)
28652 {
28653 if (str) {
28654 if (!strcmp("emulate", str))
28655 vsyscall_mode = EMULATE;
28656 - else if (!strcmp("native", str))
28657 - vsyscall_mode = NATIVE;
28658 else if (!strcmp("none", str))
28659 vsyscall_mode = NONE;
28660 else
28661 @@ -279,8 +277,7 @@ do_ret:
28662 return true;
28663
28664 sigsegv:
28665 - force_sig(SIGSEGV, current);
28666 - return true;
28667 + do_group_exit(SIGKILL);
28668 }
28669
28670 /*
28671 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28672 extern char __vsyscall_page;
28673 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28674
28675 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28676 - vsyscall_mode == NATIVE
28677 - ? PAGE_KERNEL_VSYSCALL
28678 - : PAGE_KERNEL_VVAR);
28679 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28680 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28681 (unsigned long)VSYSCALL_ADDR);
28682 }
28683 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28684 index 04068192..4d75aa6 100644
28685 --- a/arch/x86/kernel/x8664_ksyms_64.c
28686 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28687 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28688 EXPORT_SYMBOL(copy_user_generic_unrolled);
28689 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28690 EXPORT_SYMBOL(__copy_user_nocache);
28691 -EXPORT_SYMBOL(_copy_from_user);
28692 -EXPORT_SYMBOL(_copy_to_user);
28693
28694 EXPORT_SYMBOL(copy_page);
28695 EXPORT_SYMBOL(clear_page);
28696 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28697 EXPORT_SYMBOL(___preempt_schedule_context);
28698 #endif
28699 #endif
28700 +
28701 +#ifdef CONFIG_PAX_PER_CPU_PGD
28702 +EXPORT_SYMBOL(cpu_pgd);
28703 +#endif
28704 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28705 index e48b674..a451dd9 100644
28706 --- a/arch/x86/kernel/x86_init.c
28707 +++ b/arch/x86/kernel/x86_init.c
28708 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28709 static void default_nmi_init(void) { };
28710 static int default_i8042_detect(void) { return 1; };
28711
28712 -struct x86_platform_ops x86_platform = {
28713 +struct x86_platform_ops x86_platform __read_only = {
28714 .calibrate_tsc = native_calibrate_tsc,
28715 .get_wallclock = mach_get_cmos_time,
28716 .set_wallclock = mach_set_rtc_mmss,
28717 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28718 EXPORT_SYMBOL_GPL(x86_platform);
28719
28720 #if defined(CONFIG_PCI_MSI)
28721 -struct x86_msi_ops x86_msi = {
28722 +struct x86_msi_ops x86_msi __read_only = {
28723 .setup_msi_irqs = native_setup_msi_irqs,
28724 .compose_msi_msg = native_compose_msi_msg,
28725 .teardown_msi_irq = native_teardown_msi_irq,
28726 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28727 }
28728 #endif
28729
28730 -struct x86_io_apic_ops x86_io_apic_ops = {
28731 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28732 .init = native_io_apic_init_mappings,
28733 .read = native_io_apic_read,
28734 .write = native_io_apic_write,
28735 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28736 index a4b451c..8dfe1ad 100644
28737 --- a/arch/x86/kernel/xsave.c
28738 +++ b/arch/x86/kernel/xsave.c
28739 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28740
28741 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28742 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28743 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28744 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28745
28746 if (!use_xsave())
28747 return err;
28748
28749 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28750 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28751
28752 /*
28753 * Read the xstate_bv which we copied (directly from the cpu or
28754 * from the state in task struct) to the user buffers.
28755 */
28756 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28757 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28758
28759 /*
28760 * For legacy compatible, we always set FP/SSE bits in the bit
28761 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28762 */
28763 xstate_bv |= XSTATE_FPSSE;
28764
28765 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28766 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28767
28768 return err;
28769 }
28770 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28771 {
28772 int err;
28773
28774 + buf = (struct xsave_struct __user *)____m(buf);
28775 if (use_xsave())
28776 err = xsave_user(buf);
28777 else if (use_fxsr())
28778 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28779 */
28780 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28781 {
28782 + buf = (void __user *)____m(buf);
28783 if (use_xsave()) {
28784 if ((unsigned long)buf % 64 || fx_only) {
28785 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28786 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28787 index 38a0afe..94421a9 100644
28788 --- a/arch/x86/kvm/cpuid.c
28789 +++ b/arch/x86/kvm/cpuid.c
28790 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28791 struct kvm_cpuid2 *cpuid,
28792 struct kvm_cpuid_entry2 __user *entries)
28793 {
28794 - int r;
28795 + int r, i;
28796
28797 r = -E2BIG;
28798 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28799 goto out;
28800 r = -EFAULT;
28801 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28802 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28803 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28804 goto out;
28805 + for (i = 0; i < cpuid->nent; ++i) {
28806 + struct kvm_cpuid_entry2 cpuid_entry;
28807 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28808 + goto out;
28809 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28810 + }
28811 vcpu->arch.cpuid_nent = cpuid->nent;
28812 kvm_apic_set_version(vcpu);
28813 kvm_x86_ops->cpuid_update(vcpu);
28814 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28815 struct kvm_cpuid2 *cpuid,
28816 struct kvm_cpuid_entry2 __user *entries)
28817 {
28818 - int r;
28819 + int r, i;
28820
28821 r = -E2BIG;
28822 if (cpuid->nent < vcpu->arch.cpuid_nent)
28823 goto out;
28824 r = -EFAULT;
28825 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28826 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28827 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28828 goto out;
28829 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28830 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28831 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28832 + goto out;
28833 + }
28834 return 0;
28835
28836 out:
28837 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28838 index 453e5fb..214168f 100644
28839 --- a/arch/x86/kvm/lapic.c
28840 +++ b/arch/x86/kvm/lapic.c
28841 @@ -55,7 +55,7 @@
28842 #define APIC_BUS_CYCLE_NS 1
28843
28844 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28845 -#define apic_debug(fmt, arg...)
28846 +#define apic_debug(fmt, arg...) do {} while (0)
28847
28848 #define APIC_LVT_NUM 6
28849 /* 14 is the version for Xeon and Pentium 8.4.8*/
28850 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28851 index 4107765..d9eb358 100644
28852 --- a/arch/x86/kvm/paging_tmpl.h
28853 +++ b/arch/x86/kvm/paging_tmpl.h
28854 @@ -331,7 +331,7 @@ retry_walk:
28855 if (unlikely(kvm_is_error_hva(host_addr)))
28856 goto error;
28857
28858 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28859 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28860 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28861 goto error;
28862 walker->ptep_user[walker->level - 1] = ptep_user;
28863 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28864 index b5e994a..35b5866 100644
28865 --- a/arch/x86/kvm/svm.c
28866 +++ b/arch/x86/kvm/svm.c
28867 @@ -3541,7 +3541,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28868 int cpu = raw_smp_processor_id();
28869
28870 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28871 +
28872 + pax_open_kernel();
28873 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28874 + pax_close_kernel();
28875 +
28876 load_TR_desc();
28877 }
28878
28879 @@ -3942,6 +3946,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28880 #endif
28881 #endif
28882
28883 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28884 + __set_fs(current_thread_info()->addr_limit);
28885 +#endif
28886 +
28887 reload_tss(vcpu);
28888
28889 local_irq_disable();
28890 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28891 index 801332e..eeff1cc 100644
28892 --- a/arch/x86/kvm/vmx.c
28893 +++ b/arch/x86/kvm/vmx.c
28894 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28895 #endif
28896 }
28897
28898 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28899 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28900 {
28901 vmcs_writel(field, vmcs_readl(field) & ~mask);
28902 }
28903
28904 -static void vmcs_set_bits(unsigned long field, u32 mask)
28905 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28906 {
28907 vmcs_writel(field, vmcs_readl(field) | mask);
28908 }
28909 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28910 struct desc_struct *descs;
28911
28912 descs = (void *)gdt->address;
28913 +
28914 + pax_open_kernel();
28915 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28916 + pax_close_kernel();
28917 +
28918 load_TR_desc();
28919 }
28920
28921 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28922 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28923 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28924
28925 +#ifdef CONFIG_PAX_PER_CPU_PGD
28926 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28927 +#endif
28928 +
28929 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28930 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28931 vmx->loaded_vmcs->cpu = cpu;
28932 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28933 * reads and returns guest's timestamp counter "register"
28934 * guest_tsc = host_tsc + tsc_offset -- 21.3
28935 */
28936 -static u64 guest_read_tsc(void)
28937 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28938 {
28939 u64 host_tsc, tsc_offset;
28940
28941 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28942 if (!cpu_has_vmx_flexpriority())
28943 flexpriority_enabled = 0;
28944
28945 - if (!cpu_has_vmx_tpr_shadow())
28946 - kvm_x86_ops->update_cr8_intercept = NULL;
28947 + if (!cpu_has_vmx_tpr_shadow()) {
28948 + pax_open_kernel();
28949 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28950 + pax_close_kernel();
28951 + }
28952
28953 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28954 kvm_disable_largepages();
28955 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28956 if (!cpu_has_vmx_apicv())
28957 enable_apicv = 0;
28958
28959 + pax_open_kernel();
28960 if (enable_apicv)
28961 - kvm_x86_ops->update_cr8_intercept = NULL;
28962 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28963 else {
28964 - kvm_x86_ops->hwapic_irr_update = NULL;
28965 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28966 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28967 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28968 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28969 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28970 }
28971 + pax_close_kernel();
28972
28973 if (nested)
28974 nested_vmx_setup_ctls_msrs();
28975 @@ -4221,7 +4234,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28976
28977 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28978 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28979 +
28980 +#ifndef CONFIG_PAX_PER_CPU_PGD
28981 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28982 +#endif
28983
28984 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28985 #ifdef CONFIG_X86_64
28986 @@ -4243,7 +4259,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28987 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28988 vmx->host_idt_base = dt.address;
28989
28990 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28991 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28992
28993 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28994 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28995 @@ -7413,6 +7429,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28996 "jmp 2f \n\t"
28997 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28998 "2: "
28999 +
29000 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29001 + "ljmp %[cs],$3f\n\t"
29002 + "3: "
29003 +#endif
29004 +
29005 /* Save guest registers, load host registers, keep flags */
29006 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29007 "pop %0 \n\t"
29008 @@ -7465,6 +7487,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29009 #endif
29010 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29011 [wordsize]"i"(sizeof(ulong))
29012 +
29013 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29014 + ,[cs]"i"(__KERNEL_CS)
29015 +#endif
29016 +
29017 : "cc", "memory"
29018 #ifdef CONFIG_X86_64
29019 , "rax", "rbx", "rdi", "rsi"
29020 @@ -7478,7 +7505,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29021 if (debugctlmsr)
29022 update_debugctlmsr(debugctlmsr);
29023
29024 -#ifndef CONFIG_X86_64
29025 +#ifdef CONFIG_X86_32
29026 /*
29027 * The sysexit path does not restore ds/es, so we must set them to
29028 * a reasonable value ourselves.
29029 @@ -7487,8 +7514,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29030 * may be executed in interrupt context, which saves and restore segments
29031 * around it, nullifying its effect.
29032 */
29033 - loadsegment(ds, __USER_DS);
29034 - loadsegment(es, __USER_DS);
29035 + loadsegment(ds, __KERNEL_DS);
29036 + loadsegment(es, __KERNEL_DS);
29037 + loadsegment(ss, __KERNEL_DS);
29038 +
29039 +#ifdef CONFIG_PAX_KERNEXEC
29040 + loadsegment(fs, __KERNEL_PERCPU);
29041 +#endif
29042 +
29043 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29044 + __set_fs(current_thread_info()->addr_limit);
29045 +#endif
29046 +
29047 #endif
29048
29049 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29050 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29051 index ef432f8..a630659 100644
29052 --- a/arch/x86/kvm/x86.c
29053 +++ b/arch/x86/kvm/x86.c
29054 @@ -1808,8 +1808,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29055 {
29056 struct kvm *kvm = vcpu->kvm;
29057 int lm = is_long_mode(vcpu);
29058 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29059 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29060 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29061 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29062 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29063 : kvm->arch.xen_hvm_config.blob_size_32;
29064 u32 page_num = data & ~PAGE_MASK;
29065 @@ -2729,6 +2729,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29066 if (n < msr_list.nmsrs)
29067 goto out;
29068 r = -EFAULT;
29069 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29070 + goto out;
29071 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29072 num_msrs_to_save * sizeof(u32)))
29073 goto out;
29074 @@ -5567,7 +5569,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29075 };
29076 #endif
29077
29078 -int kvm_arch_init(void *opaque)
29079 +int kvm_arch_init(const void *opaque)
29080 {
29081 int r;
29082 struct kvm_x86_ops *ops = opaque;
29083 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29084 index aae9413..d11e829 100644
29085 --- a/arch/x86/lguest/boot.c
29086 +++ b/arch/x86/lguest/boot.c
29087 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29088 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29089 * Launcher to reboot us.
29090 */
29091 -static void lguest_restart(char *reason)
29092 +static __noreturn void lguest_restart(char *reason)
29093 {
29094 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29095 + BUG();
29096 }
29097
29098 /*G:050
29099 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29100 index 00933d5..3a64af9 100644
29101 --- a/arch/x86/lib/atomic64_386_32.S
29102 +++ b/arch/x86/lib/atomic64_386_32.S
29103 @@ -48,6 +48,10 @@ BEGIN(read)
29104 movl (v), %eax
29105 movl 4(v), %edx
29106 RET_ENDP
29107 +BEGIN(read_unchecked)
29108 + movl (v), %eax
29109 + movl 4(v), %edx
29110 +RET_ENDP
29111 #undef v
29112
29113 #define v %esi
29114 @@ -55,6 +59,10 @@ BEGIN(set)
29115 movl %ebx, (v)
29116 movl %ecx, 4(v)
29117 RET_ENDP
29118 +BEGIN(set_unchecked)
29119 + movl %ebx, (v)
29120 + movl %ecx, 4(v)
29121 +RET_ENDP
29122 #undef v
29123
29124 #define v %esi
29125 @@ -70,6 +78,20 @@ RET_ENDP
29126 BEGIN(add)
29127 addl %eax, (v)
29128 adcl %edx, 4(v)
29129 +
29130 +#ifdef CONFIG_PAX_REFCOUNT
29131 + jno 0f
29132 + subl %eax, (v)
29133 + sbbl %edx, 4(v)
29134 + int $4
29135 +0:
29136 + _ASM_EXTABLE(0b, 0b)
29137 +#endif
29138 +
29139 +RET_ENDP
29140 +BEGIN(add_unchecked)
29141 + addl %eax, (v)
29142 + adcl %edx, 4(v)
29143 RET_ENDP
29144 #undef v
29145
29146 @@ -77,6 +99,24 @@ RET_ENDP
29147 BEGIN(add_return)
29148 addl (v), %eax
29149 adcl 4(v), %edx
29150 +
29151 +#ifdef CONFIG_PAX_REFCOUNT
29152 + into
29153 +1234:
29154 + _ASM_EXTABLE(1234b, 2f)
29155 +#endif
29156 +
29157 + movl %eax, (v)
29158 + movl %edx, 4(v)
29159 +
29160 +#ifdef CONFIG_PAX_REFCOUNT
29161 +2:
29162 +#endif
29163 +
29164 +RET_ENDP
29165 +BEGIN(add_return_unchecked)
29166 + addl (v), %eax
29167 + adcl 4(v), %edx
29168 movl %eax, (v)
29169 movl %edx, 4(v)
29170 RET_ENDP
29171 @@ -86,6 +126,20 @@ RET_ENDP
29172 BEGIN(sub)
29173 subl %eax, (v)
29174 sbbl %edx, 4(v)
29175 +
29176 +#ifdef CONFIG_PAX_REFCOUNT
29177 + jno 0f
29178 + addl %eax, (v)
29179 + adcl %edx, 4(v)
29180 + int $4
29181 +0:
29182 + _ASM_EXTABLE(0b, 0b)
29183 +#endif
29184 +
29185 +RET_ENDP
29186 +BEGIN(sub_unchecked)
29187 + subl %eax, (v)
29188 + sbbl %edx, 4(v)
29189 RET_ENDP
29190 #undef v
29191
29192 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29193 sbbl $0, %edx
29194 addl (v), %eax
29195 adcl 4(v), %edx
29196 +
29197 +#ifdef CONFIG_PAX_REFCOUNT
29198 + into
29199 +1234:
29200 + _ASM_EXTABLE(1234b, 2f)
29201 +#endif
29202 +
29203 + movl %eax, (v)
29204 + movl %edx, 4(v)
29205 +
29206 +#ifdef CONFIG_PAX_REFCOUNT
29207 +2:
29208 +#endif
29209 +
29210 +RET_ENDP
29211 +BEGIN(sub_return_unchecked)
29212 + negl %edx
29213 + negl %eax
29214 + sbbl $0, %edx
29215 + addl (v), %eax
29216 + adcl 4(v), %edx
29217 movl %eax, (v)
29218 movl %edx, 4(v)
29219 RET_ENDP
29220 @@ -105,6 +180,20 @@ RET_ENDP
29221 BEGIN(inc)
29222 addl $1, (v)
29223 adcl $0, 4(v)
29224 +
29225 +#ifdef CONFIG_PAX_REFCOUNT
29226 + jno 0f
29227 + subl $1, (v)
29228 + sbbl $0, 4(v)
29229 + int $4
29230 +0:
29231 + _ASM_EXTABLE(0b, 0b)
29232 +#endif
29233 +
29234 +RET_ENDP
29235 +BEGIN(inc_unchecked)
29236 + addl $1, (v)
29237 + adcl $0, 4(v)
29238 RET_ENDP
29239 #undef v
29240
29241 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29242 movl 4(v), %edx
29243 addl $1, %eax
29244 adcl $0, %edx
29245 +
29246 +#ifdef CONFIG_PAX_REFCOUNT
29247 + into
29248 +1234:
29249 + _ASM_EXTABLE(1234b, 2f)
29250 +#endif
29251 +
29252 + movl %eax, (v)
29253 + movl %edx, 4(v)
29254 +
29255 +#ifdef CONFIG_PAX_REFCOUNT
29256 +2:
29257 +#endif
29258 +
29259 +RET_ENDP
29260 +BEGIN(inc_return_unchecked)
29261 + movl (v), %eax
29262 + movl 4(v), %edx
29263 + addl $1, %eax
29264 + adcl $0, %edx
29265 movl %eax, (v)
29266 movl %edx, 4(v)
29267 RET_ENDP
29268 @@ -123,6 +232,20 @@ RET_ENDP
29269 BEGIN(dec)
29270 subl $1, (v)
29271 sbbl $0, 4(v)
29272 +
29273 +#ifdef CONFIG_PAX_REFCOUNT
29274 + jno 0f
29275 + addl $1, (v)
29276 + adcl $0, 4(v)
29277 + int $4
29278 +0:
29279 + _ASM_EXTABLE(0b, 0b)
29280 +#endif
29281 +
29282 +RET_ENDP
29283 +BEGIN(dec_unchecked)
29284 + subl $1, (v)
29285 + sbbl $0, 4(v)
29286 RET_ENDP
29287 #undef v
29288
29289 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29290 movl 4(v), %edx
29291 subl $1, %eax
29292 sbbl $0, %edx
29293 +
29294 +#ifdef CONFIG_PAX_REFCOUNT
29295 + into
29296 +1234:
29297 + _ASM_EXTABLE(1234b, 2f)
29298 +#endif
29299 +
29300 + movl %eax, (v)
29301 + movl %edx, 4(v)
29302 +
29303 +#ifdef CONFIG_PAX_REFCOUNT
29304 +2:
29305 +#endif
29306 +
29307 +RET_ENDP
29308 +BEGIN(dec_return_unchecked)
29309 + movl (v), %eax
29310 + movl 4(v), %edx
29311 + subl $1, %eax
29312 + sbbl $0, %edx
29313 movl %eax, (v)
29314 movl %edx, 4(v)
29315 RET_ENDP
29316 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29317 adcl %edx, %edi
29318 addl (v), %eax
29319 adcl 4(v), %edx
29320 +
29321 +#ifdef CONFIG_PAX_REFCOUNT
29322 + into
29323 +1234:
29324 + _ASM_EXTABLE(1234b, 2f)
29325 +#endif
29326 +
29327 cmpl %eax, %ecx
29328 je 3f
29329 1:
29330 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29331 1:
29332 addl $1, %eax
29333 adcl $0, %edx
29334 +
29335 +#ifdef CONFIG_PAX_REFCOUNT
29336 + into
29337 +1234:
29338 + _ASM_EXTABLE(1234b, 2f)
29339 +#endif
29340 +
29341 movl %eax, (v)
29342 movl %edx, 4(v)
29343 movl $1, %eax
29344 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29345 movl 4(v), %edx
29346 subl $1, %eax
29347 sbbl $0, %edx
29348 +
29349 +#ifdef CONFIG_PAX_REFCOUNT
29350 + into
29351 +1234:
29352 + _ASM_EXTABLE(1234b, 1f)
29353 +#endif
29354 +
29355 js 1f
29356 movl %eax, (v)
29357 movl %edx, 4(v)
29358 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29359 index f5cc9eb..51fa319 100644
29360 --- a/arch/x86/lib/atomic64_cx8_32.S
29361 +++ b/arch/x86/lib/atomic64_cx8_32.S
29362 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29363 CFI_STARTPROC
29364
29365 read64 %ecx
29366 + pax_force_retaddr
29367 ret
29368 CFI_ENDPROC
29369 ENDPROC(atomic64_read_cx8)
29370
29371 +ENTRY(atomic64_read_unchecked_cx8)
29372 + CFI_STARTPROC
29373 +
29374 + read64 %ecx
29375 + pax_force_retaddr
29376 + ret
29377 + CFI_ENDPROC
29378 +ENDPROC(atomic64_read_unchecked_cx8)
29379 +
29380 ENTRY(atomic64_set_cx8)
29381 CFI_STARTPROC
29382
29383 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29384 cmpxchg8b (%esi)
29385 jne 1b
29386
29387 + pax_force_retaddr
29388 ret
29389 CFI_ENDPROC
29390 ENDPROC(atomic64_set_cx8)
29391
29392 +ENTRY(atomic64_set_unchecked_cx8)
29393 + CFI_STARTPROC
29394 +
29395 +1:
29396 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29397 + * are atomic on 586 and newer */
29398 + cmpxchg8b (%esi)
29399 + jne 1b
29400 +
29401 + pax_force_retaddr
29402 + ret
29403 + CFI_ENDPROC
29404 +ENDPROC(atomic64_set_unchecked_cx8)
29405 +
29406 ENTRY(atomic64_xchg_cx8)
29407 CFI_STARTPROC
29408
29409 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29410 cmpxchg8b (%esi)
29411 jne 1b
29412
29413 + pax_force_retaddr
29414 ret
29415 CFI_ENDPROC
29416 ENDPROC(atomic64_xchg_cx8)
29417
29418 -.macro addsub_return func ins insc
29419 -ENTRY(atomic64_\func\()_return_cx8)
29420 +.macro addsub_return func ins insc unchecked=""
29421 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29422 CFI_STARTPROC
29423 SAVE ebp
29424 SAVE ebx
29425 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29426 movl %edx, %ecx
29427 \ins\()l %esi, %ebx
29428 \insc\()l %edi, %ecx
29429 +
29430 +.ifb \unchecked
29431 +#ifdef CONFIG_PAX_REFCOUNT
29432 + into
29433 +2:
29434 + _ASM_EXTABLE(2b, 3f)
29435 +#endif
29436 +.endif
29437 +
29438 LOCK_PREFIX
29439 cmpxchg8b (%ebp)
29440 jne 1b
29441 -
29442 -10:
29443 movl %ebx, %eax
29444 movl %ecx, %edx
29445 +
29446 +.ifb \unchecked
29447 +#ifdef CONFIG_PAX_REFCOUNT
29448 +3:
29449 +#endif
29450 +.endif
29451 +
29452 RESTORE edi
29453 RESTORE esi
29454 RESTORE ebx
29455 RESTORE ebp
29456 + pax_force_retaddr
29457 ret
29458 CFI_ENDPROC
29459 -ENDPROC(atomic64_\func\()_return_cx8)
29460 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29461 .endm
29462
29463 addsub_return add add adc
29464 addsub_return sub sub sbb
29465 +addsub_return add add adc _unchecked
29466 +addsub_return sub sub sbb _unchecked
29467
29468 -.macro incdec_return func ins insc
29469 -ENTRY(atomic64_\func\()_return_cx8)
29470 +.macro incdec_return func ins insc unchecked=""
29471 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29472 CFI_STARTPROC
29473 SAVE ebx
29474
29475 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29476 movl %edx, %ecx
29477 \ins\()l $1, %ebx
29478 \insc\()l $0, %ecx
29479 +
29480 +.ifb \unchecked
29481 +#ifdef CONFIG_PAX_REFCOUNT
29482 + into
29483 +2:
29484 + _ASM_EXTABLE(2b, 3f)
29485 +#endif
29486 +.endif
29487 +
29488 LOCK_PREFIX
29489 cmpxchg8b (%esi)
29490 jne 1b
29491
29492 -10:
29493 movl %ebx, %eax
29494 movl %ecx, %edx
29495 +
29496 +.ifb \unchecked
29497 +#ifdef CONFIG_PAX_REFCOUNT
29498 +3:
29499 +#endif
29500 +.endif
29501 +
29502 RESTORE ebx
29503 + pax_force_retaddr
29504 ret
29505 CFI_ENDPROC
29506 -ENDPROC(atomic64_\func\()_return_cx8)
29507 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29508 .endm
29509
29510 incdec_return inc add adc
29511 incdec_return dec sub sbb
29512 +incdec_return inc add adc _unchecked
29513 +incdec_return dec sub sbb _unchecked
29514
29515 ENTRY(atomic64_dec_if_positive_cx8)
29516 CFI_STARTPROC
29517 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29518 movl %edx, %ecx
29519 subl $1, %ebx
29520 sbb $0, %ecx
29521 +
29522 +#ifdef CONFIG_PAX_REFCOUNT
29523 + into
29524 +1234:
29525 + _ASM_EXTABLE(1234b, 2f)
29526 +#endif
29527 +
29528 js 2f
29529 LOCK_PREFIX
29530 cmpxchg8b (%esi)
29531 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29532 movl %ebx, %eax
29533 movl %ecx, %edx
29534 RESTORE ebx
29535 + pax_force_retaddr
29536 ret
29537 CFI_ENDPROC
29538 ENDPROC(atomic64_dec_if_positive_cx8)
29539 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29540 movl %edx, %ecx
29541 addl %ebp, %ebx
29542 adcl %edi, %ecx
29543 +
29544 +#ifdef CONFIG_PAX_REFCOUNT
29545 + into
29546 +1234:
29547 + _ASM_EXTABLE(1234b, 3f)
29548 +#endif
29549 +
29550 LOCK_PREFIX
29551 cmpxchg8b (%esi)
29552 jne 1b
29553 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29554 CFI_ADJUST_CFA_OFFSET -8
29555 RESTORE ebx
29556 RESTORE ebp
29557 + pax_force_retaddr
29558 ret
29559 4:
29560 cmpl %edx, 4(%esp)
29561 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29562 xorl %ecx, %ecx
29563 addl $1, %ebx
29564 adcl %edx, %ecx
29565 +
29566 +#ifdef CONFIG_PAX_REFCOUNT
29567 + into
29568 +1234:
29569 + _ASM_EXTABLE(1234b, 3f)
29570 +#endif
29571 +
29572 LOCK_PREFIX
29573 cmpxchg8b (%esi)
29574 jne 1b
29575 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29576 movl $1, %eax
29577 3:
29578 RESTORE ebx
29579 + pax_force_retaddr
29580 ret
29581 CFI_ENDPROC
29582 ENDPROC(atomic64_inc_not_zero_cx8)
29583 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29584 index e78b8eee..7e173a8 100644
29585 --- a/arch/x86/lib/checksum_32.S
29586 +++ b/arch/x86/lib/checksum_32.S
29587 @@ -29,7 +29,8 @@
29588 #include <asm/dwarf2.h>
29589 #include <asm/errno.h>
29590 #include <asm/asm.h>
29591 -
29592 +#include <asm/segment.h>
29593 +
29594 /*
29595 * computes a partial checksum, e.g. for TCP/UDP fragments
29596 */
29597 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29598
29599 #define ARGBASE 16
29600 #define FP 12
29601 -
29602 -ENTRY(csum_partial_copy_generic)
29603 +
29604 +ENTRY(csum_partial_copy_generic_to_user)
29605 CFI_STARTPROC
29606 +
29607 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29608 + pushl_cfi %gs
29609 + popl_cfi %es
29610 + jmp csum_partial_copy_generic
29611 +#endif
29612 +
29613 +ENTRY(csum_partial_copy_generic_from_user)
29614 +
29615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29616 + pushl_cfi %gs
29617 + popl_cfi %ds
29618 +#endif
29619 +
29620 +ENTRY(csum_partial_copy_generic)
29621 subl $4,%esp
29622 CFI_ADJUST_CFA_OFFSET 4
29623 pushl_cfi %edi
29624 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29625 jmp 4f
29626 SRC(1: movw (%esi), %bx )
29627 addl $2, %esi
29628 -DST( movw %bx, (%edi) )
29629 +DST( movw %bx, %es:(%edi) )
29630 addl $2, %edi
29631 addw %bx, %ax
29632 adcl $0, %eax
29633 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29634 SRC(1: movl (%esi), %ebx )
29635 SRC( movl 4(%esi), %edx )
29636 adcl %ebx, %eax
29637 -DST( movl %ebx, (%edi) )
29638 +DST( movl %ebx, %es:(%edi) )
29639 adcl %edx, %eax
29640 -DST( movl %edx, 4(%edi) )
29641 +DST( movl %edx, %es:4(%edi) )
29642
29643 SRC( movl 8(%esi), %ebx )
29644 SRC( movl 12(%esi), %edx )
29645 adcl %ebx, %eax
29646 -DST( movl %ebx, 8(%edi) )
29647 +DST( movl %ebx, %es:8(%edi) )
29648 adcl %edx, %eax
29649 -DST( movl %edx, 12(%edi) )
29650 +DST( movl %edx, %es:12(%edi) )
29651
29652 SRC( movl 16(%esi), %ebx )
29653 SRC( movl 20(%esi), %edx )
29654 adcl %ebx, %eax
29655 -DST( movl %ebx, 16(%edi) )
29656 +DST( movl %ebx, %es:16(%edi) )
29657 adcl %edx, %eax
29658 -DST( movl %edx, 20(%edi) )
29659 +DST( movl %edx, %es:20(%edi) )
29660
29661 SRC( movl 24(%esi), %ebx )
29662 SRC( movl 28(%esi), %edx )
29663 adcl %ebx, %eax
29664 -DST( movl %ebx, 24(%edi) )
29665 +DST( movl %ebx, %es:24(%edi) )
29666 adcl %edx, %eax
29667 -DST( movl %edx, 28(%edi) )
29668 +DST( movl %edx, %es:28(%edi) )
29669
29670 lea 32(%esi), %esi
29671 lea 32(%edi), %edi
29672 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29673 shrl $2, %edx # This clears CF
29674 SRC(3: movl (%esi), %ebx )
29675 adcl %ebx, %eax
29676 -DST( movl %ebx, (%edi) )
29677 +DST( movl %ebx, %es:(%edi) )
29678 lea 4(%esi), %esi
29679 lea 4(%edi), %edi
29680 dec %edx
29681 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29682 jb 5f
29683 SRC( movw (%esi), %cx )
29684 leal 2(%esi), %esi
29685 -DST( movw %cx, (%edi) )
29686 +DST( movw %cx, %es:(%edi) )
29687 leal 2(%edi), %edi
29688 je 6f
29689 shll $16,%ecx
29690 SRC(5: movb (%esi), %cl )
29691 -DST( movb %cl, (%edi) )
29692 +DST( movb %cl, %es:(%edi) )
29693 6: addl %ecx, %eax
29694 adcl $0, %eax
29695 7:
29696 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29697
29698 6001:
29699 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29700 - movl $-EFAULT, (%ebx)
29701 + movl $-EFAULT, %ss:(%ebx)
29702
29703 # zero the complete destination - computing the rest
29704 # is too much work
29705 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29706
29707 6002:
29708 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29709 - movl $-EFAULT,(%ebx)
29710 + movl $-EFAULT,%ss:(%ebx)
29711 jmp 5000b
29712
29713 .previous
29714
29715 + pushl_cfi %ss
29716 + popl_cfi %ds
29717 + pushl_cfi %ss
29718 + popl_cfi %es
29719 popl_cfi %ebx
29720 CFI_RESTORE ebx
29721 popl_cfi %esi
29722 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29723 popl_cfi %ecx # equivalent to addl $4,%esp
29724 ret
29725 CFI_ENDPROC
29726 -ENDPROC(csum_partial_copy_generic)
29727 +ENDPROC(csum_partial_copy_generic_to_user)
29728
29729 #else
29730
29731 /* Version for PentiumII/PPro */
29732
29733 #define ROUND1(x) \
29734 + nop; nop; nop; \
29735 SRC(movl x(%esi), %ebx ) ; \
29736 addl %ebx, %eax ; \
29737 - DST(movl %ebx, x(%edi) ) ;
29738 + DST(movl %ebx, %es:x(%edi)) ;
29739
29740 #define ROUND(x) \
29741 + nop; nop; nop; \
29742 SRC(movl x(%esi), %ebx ) ; \
29743 adcl %ebx, %eax ; \
29744 - DST(movl %ebx, x(%edi) ) ;
29745 + DST(movl %ebx, %es:x(%edi)) ;
29746
29747 #define ARGBASE 12
29748 -
29749 -ENTRY(csum_partial_copy_generic)
29750 +
29751 +ENTRY(csum_partial_copy_generic_to_user)
29752 CFI_STARTPROC
29753 +
29754 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29755 + pushl_cfi %gs
29756 + popl_cfi %es
29757 + jmp csum_partial_copy_generic
29758 +#endif
29759 +
29760 +ENTRY(csum_partial_copy_generic_from_user)
29761 +
29762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29763 + pushl_cfi %gs
29764 + popl_cfi %ds
29765 +#endif
29766 +
29767 +ENTRY(csum_partial_copy_generic)
29768 pushl_cfi %ebx
29769 CFI_REL_OFFSET ebx, 0
29770 pushl_cfi %edi
29771 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29772 subl %ebx, %edi
29773 lea -1(%esi),%edx
29774 andl $-32,%edx
29775 - lea 3f(%ebx,%ebx), %ebx
29776 + lea 3f(%ebx,%ebx,2), %ebx
29777 testl %esi, %esi
29778 jmp *%ebx
29779 1: addl $64,%esi
29780 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29781 jb 5f
29782 SRC( movw (%esi), %dx )
29783 leal 2(%esi), %esi
29784 -DST( movw %dx, (%edi) )
29785 +DST( movw %dx, %es:(%edi) )
29786 leal 2(%edi), %edi
29787 je 6f
29788 shll $16,%edx
29789 5:
29790 SRC( movb (%esi), %dl )
29791 -DST( movb %dl, (%edi) )
29792 +DST( movb %dl, %es:(%edi) )
29793 6: addl %edx, %eax
29794 adcl $0, %eax
29795 7:
29796 .section .fixup, "ax"
29797 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29798 - movl $-EFAULT, (%ebx)
29799 + movl $-EFAULT, %ss:(%ebx)
29800 # zero the complete destination (computing the rest is too much work)
29801 movl ARGBASE+8(%esp),%edi # dst
29802 movl ARGBASE+12(%esp),%ecx # len
29803 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29804 rep; stosb
29805 jmp 7b
29806 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29807 - movl $-EFAULT, (%ebx)
29808 + movl $-EFAULT, %ss:(%ebx)
29809 jmp 7b
29810 .previous
29811
29812 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29813 + pushl_cfi %ss
29814 + popl_cfi %ds
29815 + pushl_cfi %ss
29816 + popl_cfi %es
29817 +#endif
29818 +
29819 popl_cfi %esi
29820 CFI_RESTORE esi
29821 popl_cfi %edi
29822 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29823 CFI_RESTORE ebx
29824 ret
29825 CFI_ENDPROC
29826 -ENDPROC(csum_partial_copy_generic)
29827 +ENDPROC(csum_partial_copy_generic_to_user)
29828
29829 #undef ROUND
29830 #undef ROUND1
29831 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29832 index f2145cf..cea889d 100644
29833 --- a/arch/x86/lib/clear_page_64.S
29834 +++ b/arch/x86/lib/clear_page_64.S
29835 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29836 movl $4096/8,%ecx
29837 xorl %eax,%eax
29838 rep stosq
29839 + pax_force_retaddr
29840 ret
29841 CFI_ENDPROC
29842 ENDPROC(clear_page_c)
29843 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29844 movl $4096,%ecx
29845 xorl %eax,%eax
29846 rep stosb
29847 + pax_force_retaddr
29848 ret
29849 CFI_ENDPROC
29850 ENDPROC(clear_page_c_e)
29851 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29852 leaq 64(%rdi),%rdi
29853 jnz .Lloop
29854 nop
29855 + pax_force_retaddr
29856 ret
29857 CFI_ENDPROC
29858 .Lclear_page_end:
29859 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29860
29861 #include <asm/cpufeature.h>
29862
29863 - .section .altinstr_replacement,"ax"
29864 + .section .altinstr_replacement,"a"
29865 1: .byte 0xeb /* jmp <disp8> */
29866 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29867 2: .byte 0xeb /* jmp <disp8> */
29868 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29869 index 1e572c5..2a162cd 100644
29870 --- a/arch/x86/lib/cmpxchg16b_emu.S
29871 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29872 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29873
29874 popf
29875 mov $1, %al
29876 + pax_force_retaddr
29877 ret
29878
29879 not_same:
29880 popf
29881 xor %al,%al
29882 + pax_force_retaddr
29883 ret
29884
29885 CFI_ENDPROC
29886 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29887 index 176cca6..e0d658e 100644
29888 --- a/arch/x86/lib/copy_page_64.S
29889 +++ b/arch/x86/lib/copy_page_64.S
29890 @@ -9,6 +9,7 @@ copy_page_rep:
29891 CFI_STARTPROC
29892 movl $4096/8, %ecx
29893 rep movsq
29894 + pax_force_retaddr
29895 ret
29896 CFI_ENDPROC
29897 ENDPROC(copy_page_rep)
29898 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29899 CFI_ADJUST_CFA_OFFSET 2*8
29900 movq %rbx, (%rsp)
29901 CFI_REL_OFFSET rbx, 0
29902 - movq %r12, 1*8(%rsp)
29903 - CFI_REL_OFFSET r12, 1*8
29904 + movq %r13, 1*8(%rsp)
29905 + CFI_REL_OFFSET r13, 1*8
29906
29907 movl $(4096/64)-5, %ecx
29908 .p2align 4
29909 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29910 movq 0x8*4(%rsi), %r9
29911 movq 0x8*5(%rsi), %r10
29912 movq 0x8*6(%rsi), %r11
29913 - movq 0x8*7(%rsi), %r12
29914 + movq 0x8*7(%rsi), %r13
29915
29916 prefetcht0 5*64(%rsi)
29917
29918 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29919 movq %r9, 0x8*4(%rdi)
29920 movq %r10, 0x8*5(%rdi)
29921 movq %r11, 0x8*6(%rdi)
29922 - movq %r12, 0x8*7(%rdi)
29923 + movq %r13, 0x8*7(%rdi)
29924
29925 leaq 64 (%rsi), %rsi
29926 leaq 64 (%rdi), %rdi
29927 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29928 movq 0x8*4(%rsi), %r9
29929 movq 0x8*5(%rsi), %r10
29930 movq 0x8*6(%rsi), %r11
29931 - movq 0x8*7(%rsi), %r12
29932 + movq 0x8*7(%rsi), %r13
29933
29934 movq %rax, 0x8*0(%rdi)
29935 movq %rbx, 0x8*1(%rdi)
29936 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29937 movq %r9, 0x8*4(%rdi)
29938 movq %r10, 0x8*5(%rdi)
29939 movq %r11, 0x8*6(%rdi)
29940 - movq %r12, 0x8*7(%rdi)
29941 + movq %r13, 0x8*7(%rdi)
29942
29943 leaq 64(%rdi), %rdi
29944 leaq 64(%rsi), %rsi
29945 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29946
29947 movq (%rsp), %rbx
29948 CFI_RESTORE rbx
29949 - movq 1*8(%rsp), %r12
29950 - CFI_RESTORE r12
29951 + movq 1*8(%rsp), %r13
29952 + CFI_RESTORE r13
29953 addq $2*8, %rsp
29954 CFI_ADJUST_CFA_OFFSET -2*8
29955 + pax_force_retaddr
29956 ret
29957 .Lcopy_page_end:
29958 CFI_ENDPROC
29959 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29960
29961 #include <asm/cpufeature.h>
29962
29963 - .section .altinstr_replacement,"ax"
29964 + .section .altinstr_replacement,"a"
29965 1: .byte 0xeb /* jmp <disp8> */
29966 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29967 2:
29968 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29969 index dee945d..a84067b 100644
29970 --- a/arch/x86/lib/copy_user_64.S
29971 +++ b/arch/x86/lib/copy_user_64.S
29972 @@ -18,31 +18,7 @@
29973 #include <asm/alternative-asm.h>
29974 #include <asm/asm.h>
29975 #include <asm/smap.h>
29976 -
29977 -/*
29978 - * By placing feature2 after feature1 in altinstructions section, we logically
29979 - * implement:
29980 - * If CPU has feature2, jmp to alt2 is used
29981 - * else if CPU has feature1, jmp to alt1 is used
29982 - * else jmp to orig is used.
29983 - */
29984 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29985 -0:
29986 - .byte 0xe9 /* 32bit jump */
29987 - .long \orig-1f /* by default jump to orig */
29988 -1:
29989 - .section .altinstr_replacement,"ax"
29990 -2: .byte 0xe9 /* near jump with 32bit immediate */
29991 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29992 -3: .byte 0xe9 /* near jump with 32bit immediate */
29993 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29994 - .previous
29995 -
29996 - .section .altinstructions,"a"
29997 - altinstruction_entry 0b,2b,\feature1,5,5
29998 - altinstruction_entry 0b,3b,\feature2,5,5
29999 - .previous
30000 - .endm
30001 +#include <asm/pgtable.h>
30002
30003 .macro ALIGN_DESTINATION
30004 #ifdef FIX_ALIGNMENT
30005 @@ -70,52 +46,6 @@
30006 #endif
30007 .endm
30008
30009 -/* Standard copy_to_user with segment limit checking */
30010 -ENTRY(_copy_to_user)
30011 - CFI_STARTPROC
30012 - GET_THREAD_INFO(%rax)
30013 - movq %rdi,%rcx
30014 - addq %rdx,%rcx
30015 - jc bad_to_user
30016 - cmpq TI_addr_limit(%rax),%rcx
30017 - ja bad_to_user
30018 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30019 - copy_user_generic_unrolled,copy_user_generic_string, \
30020 - copy_user_enhanced_fast_string
30021 - CFI_ENDPROC
30022 -ENDPROC(_copy_to_user)
30023 -
30024 -/* Standard copy_from_user with segment limit checking */
30025 -ENTRY(_copy_from_user)
30026 - CFI_STARTPROC
30027 - GET_THREAD_INFO(%rax)
30028 - movq %rsi,%rcx
30029 - addq %rdx,%rcx
30030 - jc bad_from_user
30031 - cmpq TI_addr_limit(%rax),%rcx
30032 - ja bad_from_user
30033 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30034 - copy_user_generic_unrolled,copy_user_generic_string, \
30035 - copy_user_enhanced_fast_string
30036 - CFI_ENDPROC
30037 -ENDPROC(_copy_from_user)
30038 -
30039 - .section .fixup,"ax"
30040 - /* must zero dest */
30041 -ENTRY(bad_from_user)
30042 -bad_from_user:
30043 - CFI_STARTPROC
30044 - movl %edx,%ecx
30045 - xorl %eax,%eax
30046 - rep
30047 - stosb
30048 -bad_to_user:
30049 - movl %edx,%eax
30050 - ret
30051 - CFI_ENDPROC
30052 -ENDPROC(bad_from_user)
30053 - .previous
30054 -
30055 /*
30056 * copy_user_generic_unrolled - memory copy with exception handling.
30057 * This version is for CPUs like P4 that don't have efficient micro
30058 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30059 */
30060 ENTRY(copy_user_generic_unrolled)
30061 CFI_STARTPROC
30062 + ASM_PAX_OPEN_USERLAND
30063 ASM_STAC
30064 cmpl $8,%edx
30065 jb 20f /* less then 8 bytes, go to byte copy loop */
30066 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30067 jnz 21b
30068 23: xor %eax,%eax
30069 ASM_CLAC
30070 + ASM_PAX_CLOSE_USERLAND
30071 + pax_force_retaddr
30072 ret
30073
30074 .section .fixup,"ax"
30075 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30076 */
30077 ENTRY(copy_user_generic_string)
30078 CFI_STARTPROC
30079 + ASM_PAX_OPEN_USERLAND
30080 ASM_STAC
30081 cmpl $8,%edx
30082 jb 2f /* less than 8 bytes, go to byte copy loop */
30083 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30084 movsb
30085 xorl %eax,%eax
30086 ASM_CLAC
30087 + ASM_PAX_CLOSE_USERLAND
30088 + pax_force_retaddr
30089 ret
30090
30091 .section .fixup,"ax"
30092 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30093 */
30094 ENTRY(copy_user_enhanced_fast_string)
30095 CFI_STARTPROC
30096 + ASM_PAX_OPEN_USERLAND
30097 ASM_STAC
30098 movl %edx,%ecx
30099 1: rep
30100 movsb
30101 xorl %eax,%eax
30102 ASM_CLAC
30103 + ASM_PAX_CLOSE_USERLAND
30104 + pax_force_retaddr
30105 ret
30106
30107 .section .fixup,"ax"
30108 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30109 index 6a4f43c..c70fb52 100644
30110 --- a/arch/x86/lib/copy_user_nocache_64.S
30111 +++ b/arch/x86/lib/copy_user_nocache_64.S
30112 @@ -8,6 +8,7 @@
30113
30114 #include <linux/linkage.h>
30115 #include <asm/dwarf2.h>
30116 +#include <asm/alternative-asm.h>
30117
30118 #define FIX_ALIGNMENT 1
30119
30120 @@ -16,6 +17,7 @@
30121 #include <asm/thread_info.h>
30122 #include <asm/asm.h>
30123 #include <asm/smap.h>
30124 +#include <asm/pgtable.h>
30125
30126 .macro ALIGN_DESTINATION
30127 #ifdef FIX_ALIGNMENT
30128 @@ -49,6 +51,16 @@
30129 */
30130 ENTRY(__copy_user_nocache)
30131 CFI_STARTPROC
30132 +
30133 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30134 + mov pax_user_shadow_base,%rcx
30135 + cmp %rcx,%rsi
30136 + jae 1f
30137 + add %rcx,%rsi
30138 +1:
30139 +#endif
30140 +
30141 + ASM_PAX_OPEN_USERLAND
30142 ASM_STAC
30143 cmpl $8,%edx
30144 jb 20f /* less then 8 bytes, go to byte copy loop */
30145 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30146 jnz 21b
30147 23: xorl %eax,%eax
30148 ASM_CLAC
30149 + ASM_PAX_CLOSE_USERLAND
30150 sfence
30151 + pax_force_retaddr
30152 ret
30153
30154 .section .fixup,"ax"
30155 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30156 index 2419d5f..fe52d0e 100644
30157 --- a/arch/x86/lib/csum-copy_64.S
30158 +++ b/arch/x86/lib/csum-copy_64.S
30159 @@ -9,6 +9,7 @@
30160 #include <asm/dwarf2.h>
30161 #include <asm/errno.h>
30162 #include <asm/asm.h>
30163 +#include <asm/alternative-asm.h>
30164
30165 /*
30166 * Checksum copy with exception handling.
30167 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30168 CFI_ADJUST_CFA_OFFSET 7*8
30169 movq %rbx, 2*8(%rsp)
30170 CFI_REL_OFFSET rbx, 2*8
30171 - movq %r12, 3*8(%rsp)
30172 - CFI_REL_OFFSET r12, 3*8
30173 + movq %r15, 3*8(%rsp)
30174 + CFI_REL_OFFSET r15, 3*8
30175 movq %r14, 4*8(%rsp)
30176 CFI_REL_OFFSET r14, 4*8
30177 movq %r13, 5*8(%rsp)
30178 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30179 movl %edx, %ecx
30180
30181 xorl %r9d, %r9d
30182 - movq %rcx, %r12
30183 + movq %rcx, %r15
30184
30185 - shrq $6, %r12
30186 + shrq $6, %r15
30187 jz .Lhandle_tail /* < 64 */
30188
30189 clc
30190
30191 /* main loop. clear in 64 byte blocks */
30192 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30193 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30194 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30195 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30196 .p2align 4
30197 .Lloop:
30198 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30199 adcq %r14, %rax
30200 adcq %r13, %rax
30201
30202 - decl %r12d
30203 + decl %r15d
30204
30205 dest
30206 movq %rbx, (%rsi)
30207 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30208 .Lende:
30209 movq 2*8(%rsp), %rbx
30210 CFI_RESTORE rbx
30211 - movq 3*8(%rsp), %r12
30212 - CFI_RESTORE r12
30213 + movq 3*8(%rsp), %r15
30214 + CFI_RESTORE r15
30215 movq 4*8(%rsp), %r14
30216 CFI_RESTORE r14
30217 movq 5*8(%rsp), %r13
30218 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30219 CFI_RESTORE rbp
30220 addq $7*8, %rsp
30221 CFI_ADJUST_CFA_OFFSET -7*8
30222 + pax_force_retaddr
30223 ret
30224 CFI_RESTORE_STATE
30225
30226 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30227 index 7609e0e..b449b98 100644
30228 --- a/arch/x86/lib/csum-wrappers_64.c
30229 +++ b/arch/x86/lib/csum-wrappers_64.c
30230 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30231 len -= 2;
30232 }
30233 }
30234 + pax_open_userland();
30235 stac();
30236 - isum = csum_partial_copy_generic((__force const void *)src,
30237 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30238 dst, len, isum, errp, NULL);
30239 clac();
30240 + pax_close_userland();
30241 if (unlikely(*errp))
30242 goto out_err;
30243
30244 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30245 }
30246
30247 *errp = 0;
30248 + pax_open_userland();
30249 stac();
30250 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30251 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30252 len, isum, NULL, errp);
30253 clac();
30254 + pax_close_userland();
30255 return ret;
30256 }
30257 EXPORT_SYMBOL(csum_partial_copy_to_user);
30258 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30259 index a451235..1daa956 100644
30260 --- a/arch/x86/lib/getuser.S
30261 +++ b/arch/x86/lib/getuser.S
30262 @@ -33,17 +33,40 @@
30263 #include <asm/thread_info.h>
30264 #include <asm/asm.h>
30265 #include <asm/smap.h>
30266 +#include <asm/segment.h>
30267 +#include <asm/pgtable.h>
30268 +#include <asm/alternative-asm.h>
30269 +
30270 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30271 +#define __copyuser_seg gs;
30272 +#else
30273 +#define __copyuser_seg
30274 +#endif
30275
30276 .text
30277 ENTRY(__get_user_1)
30278 CFI_STARTPROC
30279 +
30280 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30281 GET_THREAD_INFO(%_ASM_DX)
30282 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30283 jae bad_get_user
30284 ASM_STAC
30285 -1: movzbl (%_ASM_AX),%edx
30286 +
30287 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30288 + mov pax_user_shadow_base,%_ASM_DX
30289 + cmp %_ASM_DX,%_ASM_AX
30290 + jae 1234f
30291 + add %_ASM_DX,%_ASM_AX
30292 +1234:
30293 +#endif
30294 +
30295 +#endif
30296 +
30297 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30298 xor %eax,%eax
30299 ASM_CLAC
30300 + pax_force_retaddr
30301 ret
30302 CFI_ENDPROC
30303 ENDPROC(__get_user_1)
30304 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30305 ENTRY(__get_user_2)
30306 CFI_STARTPROC
30307 add $1,%_ASM_AX
30308 +
30309 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30310 jc bad_get_user
30311 GET_THREAD_INFO(%_ASM_DX)
30312 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30313 jae bad_get_user
30314 ASM_STAC
30315 -2: movzwl -1(%_ASM_AX),%edx
30316 +
30317 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30318 + mov pax_user_shadow_base,%_ASM_DX
30319 + cmp %_ASM_DX,%_ASM_AX
30320 + jae 1234f
30321 + add %_ASM_DX,%_ASM_AX
30322 +1234:
30323 +#endif
30324 +
30325 +#endif
30326 +
30327 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30328 xor %eax,%eax
30329 ASM_CLAC
30330 + pax_force_retaddr
30331 ret
30332 CFI_ENDPROC
30333 ENDPROC(__get_user_2)
30334 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30335 ENTRY(__get_user_4)
30336 CFI_STARTPROC
30337 add $3,%_ASM_AX
30338 +
30339 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30340 jc bad_get_user
30341 GET_THREAD_INFO(%_ASM_DX)
30342 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30343 jae bad_get_user
30344 ASM_STAC
30345 -3: movl -3(%_ASM_AX),%edx
30346 +
30347 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30348 + mov pax_user_shadow_base,%_ASM_DX
30349 + cmp %_ASM_DX,%_ASM_AX
30350 + jae 1234f
30351 + add %_ASM_DX,%_ASM_AX
30352 +1234:
30353 +#endif
30354 +
30355 +#endif
30356 +
30357 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30358 xor %eax,%eax
30359 ASM_CLAC
30360 + pax_force_retaddr
30361 ret
30362 CFI_ENDPROC
30363 ENDPROC(__get_user_4)
30364 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30365 GET_THREAD_INFO(%_ASM_DX)
30366 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30367 jae bad_get_user
30368 +
30369 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30370 + mov pax_user_shadow_base,%_ASM_DX
30371 + cmp %_ASM_DX,%_ASM_AX
30372 + jae 1234f
30373 + add %_ASM_DX,%_ASM_AX
30374 +1234:
30375 +#endif
30376 +
30377 ASM_STAC
30378 4: movq -7(%_ASM_AX),%rdx
30379 xor %eax,%eax
30380 ASM_CLAC
30381 + pax_force_retaddr
30382 ret
30383 #else
30384 add $7,%_ASM_AX
30385 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30386 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30387 jae bad_get_user_8
30388 ASM_STAC
30389 -4: movl -7(%_ASM_AX),%edx
30390 -5: movl -3(%_ASM_AX),%ecx
30391 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30392 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30393 xor %eax,%eax
30394 ASM_CLAC
30395 + pax_force_retaddr
30396 ret
30397 #endif
30398 CFI_ENDPROC
30399 @@ -113,6 +175,7 @@ bad_get_user:
30400 xor %edx,%edx
30401 mov $(-EFAULT),%_ASM_AX
30402 ASM_CLAC
30403 + pax_force_retaddr
30404 ret
30405 CFI_ENDPROC
30406 END(bad_get_user)
30407 @@ -124,6 +187,7 @@ bad_get_user_8:
30408 xor %ecx,%ecx
30409 mov $(-EFAULT),%_ASM_AX
30410 ASM_CLAC
30411 + pax_force_retaddr
30412 ret
30413 CFI_ENDPROC
30414 END(bad_get_user_8)
30415 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30416 index 54fcffe..7be149e 100644
30417 --- a/arch/x86/lib/insn.c
30418 +++ b/arch/x86/lib/insn.c
30419 @@ -20,8 +20,10 @@
30420
30421 #ifdef __KERNEL__
30422 #include <linux/string.h>
30423 +#include <asm/pgtable_types.h>
30424 #else
30425 #include <string.h>
30426 +#define ktla_ktva(addr) addr
30427 #endif
30428 #include <asm/inat.h>
30429 #include <asm/insn.h>
30430 @@ -53,8 +55,8 @@
30431 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30432 {
30433 memset(insn, 0, sizeof(*insn));
30434 - insn->kaddr = kaddr;
30435 - insn->next_byte = kaddr;
30436 + insn->kaddr = ktla_ktva(kaddr);
30437 + insn->next_byte = ktla_ktva(kaddr);
30438 insn->x86_64 = x86_64 ? 1 : 0;
30439 insn->opnd_bytes = 4;
30440 if (x86_64)
30441 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30442 index 05a95e7..326f2fa 100644
30443 --- a/arch/x86/lib/iomap_copy_64.S
30444 +++ b/arch/x86/lib/iomap_copy_64.S
30445 @@ -17,6 +17,7 @@
30446
30447 #include <linux/linkage.h>
30448 #include <asm/dwarf2.h>
30449 +#include <asm/alternative-asm.h>
30450
30451 /*
30452 * override generic version in lib/iomap_copy.c
30453 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30454 CFI_STARTPROC
30455 movl %edx,%ecx
30456 rep movsd
30457 + pax_force_retaddr
30458 ret
30459 CFI_ENDPROC
30460 ENDPROC(__iowrite32_copy)
30461 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30462 index 56313a3..0db417e 100644
30463 --- a/arch/x86/lib/memcpy_64.S
30464 +++ b/arch/x86/lib/memcpy_64.S
30465 @@ -24,7 +24,7 @@
30466 * This gets patched over the unrolled variant (below) via the
30467 * alternative instructions framework:
30468 */
30469 - .section .altinstr_replacement, "ax", @progbits
30470 + .section .altinstr_replacement, "a", @progbits
30471 .Lmemcpy_c:
30472 movq %rdi, %rax
30473 movq %rdx, %rcx
30474 @@ -33,6 +33,7 @@
30475 rep movsq
30476 movl %edx, %ecx
30477 rep movsb
30478 + pax_force_retaddr
30479 ret
30480 .Lmemcpy_e:
30481 .previous
30482 @@ -44,11 +45,12 @@
30483 * This gets patched over the unrolled variant (below) via the
30484 * alternative instructions framework:
30485 */
30486 - .section .altinstr_replacement, "ax", @progbits
30487 + .section .altinstr_replacement, "a", @progbits
30488 .Lmemcpy_c_e:
30489 movq %rdi, %rax
30490 movq %rdx, %rcx
30491 rep movsb
30492 + pax_force_retaddr
30493 ret
30494 .Lmemcpy_e_e:
30495 .previous
30496 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30497 movq %r9, 1*8(%rdi)
30498 movq %r10, -2*8(%rdi, %rdx)
30499 movq %r11, -1*8(%rdi, %rdx)
30500 + pax_force_retaddr
30501 retq
30502 .p2align 4
30503 .Lless_16bytes:
30504 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30505 movq -1*8(%rsi, %rdx), %r9
30506 movq %r8, 0*8(%rdi)
30507 movq %r9, -1*8(%rdi, %rdx)
30508 + pax_force_retaddr
30509 retq
30510 .p2align 4
30511 .Lless_8bytes:
30512 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30513 movl -4(%rsi, %rdx), %r8d
30514 movl %ecx, (%rdi)
30515 movl %r8d, -4(%rdi, %rdx)
30516 + pax_force_retaddr
30517 retq
30518 .p2align 4
30519 .Lless_3bytes:
30520 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30521 movb %cl, (%rdi)
30522
30523 .Lend:
30524 + pax_force_retaddr
30525 retq
30526 CFI_ENDPROC
30527 ENDPROC(memcpy)
30528 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30529 index 65268a6..dd1de11 100644
30530 --- a/arch/x86/lib/memmove_64.S
30531 +++ b/arch/x86/lib/memmove_64.S
30532 @@ -202,14 +202,16 @@ ENTRY(memmove)
30533 movb (%rsi), %r11b
30534 movb %r11b, (%rdi)
30535 13:
30536 + pax_force_retaddr
30537 retq
30538 CFI_ENDPROC
30539
30540 - .section .altinstr_replacement,"ax"
30541 + .section .altinstr_replacement,"a"
30542 .Lmemmove_begin_forward_efs:
30543 /* Forward moving data. */
30544 movq %rdx, %rcx
30545 rep movsb
30546 + pax_force_retaddr
30547 retq
30548 .Lmemmove_end_forward_efs:
30549 .previous
30550 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30551 index 2dcb380..2eb79fe 100644
30552 --- a/arch/x86/lib/memset_64.S
30553 +++ b/arch/x86/lib/memset_64.S
30554 @@ -16,7 +16,7 @@
30555 *
30556 * rax original destination
30557 */
30558 - .section .altinstr_replacement, "ax", @progbits
30559 + .section .altinstr_replacement, "a", @progbits
30560 .Lmemset_c:
30561 movq %rdi,%r9
30562 movq %rdx,%rcx
30563 @@ -30,6 +30,7 @@
30564 movl %edx,%ecx
30565 rep stosb
30566 movq %r9,%rax
30567 + pax_force_retaddr
30568 ret
30569 .Lmemset_e:
30570 .previous
30571 @@ -45,13 +46,14 @@
30572 *
30573 * rax original destination
30574 */
30575 - .section .altinstr_replacement, "ax", @progbits
30576 + .section .altinstr_replacement, "a", @progbits
30577 .Lmemset_c_e:
30578 movq %rdi,%r9
30579 movb %sil,%al
30580 movq %rdx,%rcx
30581 rep stosb
30582 movq %r9,%rax
30583 + pax_force_retaddr
30584 ret
30585 .Lmemset_e_e:
30586 .previous
30587 @@ -118,6 +120,7 @@ ENTRY(__memset)
30588
30589 .Lende:
30590 movq %r10,%rax
30591 + pax_force_retaddr
30592 ret
30593
30594 CFI_RESTORE_STATE
30595 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30596 index c9f2d9b..e7fd2c0 100644
30597 --- a/arch/x86/lib/mmx_32.c
30598 +++ b/arch/x86/lib/mmx_32.c
30599 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30600 {
30601 void *p;
30602 int i;
30603 + unsigned long cr0;
30604
30605 if (unlikely(in_interrupt()))
30606 return __memcpy(to, from, len);
30607 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30608 kernel_fpu_begin();
30609
30610 __asm__ __volatile__ (
30611 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30612 - " prefetch 64(%0)\n"
30613 - " prefetch 128(%0)\n"
30614 - " prefetch 192(%0)\n"
30615 - " prefetch 256(%0)\n"
30616 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30617 + " prefetch 64(%1)\n"
30618 + " prefetch 128(%1)\n"
30619 + " prefetch 192(%1)\n"
30620 + " prefetch 256(%1)\n"
30621 "2: \n"
30622 ".section .fixup, \"ax\"\n"
30623 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30624 + "3: \n"
30625 +
30626 +#ifdef CONFIG_PAX_KERNEXEC
30627 + " movl %%cr0, %0\n"
30628 + " movl %0, %%eax\n"
30629 + " andl $0xFFFEFFFF, %%eax\n"
30630 + " movl %%eax, %%cr0\n"
30631 +#endif
30632 +
30633 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30634 +
30635 +#ifdef CONFIG_PAX_KERNEXEC
30636 + " movl %0, %%cr0\n"
30637 +#endif
30638 +
30639 " jmp 2b\n"
30640 ".previous\n"
30641 _ASM_EXTABLE(1b, 3b)
30642 - : : "r" (from));
30643 + : "=&r" (cr0) : "r" (from) : "ax");
30644
30645 for ( ; i > 5; i--) {
30646 __asm__ __volatile__ (
30647 - "1: prefetch 320(%0)\n"
30648 - "2: movq (%0), %%mm0\n"
30649 - " movq 8(%0), %%mm1\n"
30650 - " movq 16(%0), %%mm2\n"
30651 - " movq 24(%0), %%mm3\n"
30652 - " movq %%mm0, (%1)\n"
30653 - " movq %%mm1, 8(%1)\n"
30654 - " movq %%mm2, 16(%1)\n"
30655 - " movq %%mm3, 24(%1)\n"
30656 - " movq 32(%0), %%mm0\n"
30657 - " movq 40(%0), %%mm1\n"
30658 - " movq 48(%0), %%mm2\n"
30659 - " movq 56(%0), %%mm3\n"
30660 - " movq %%mm0, 32(%1)\n"
30661 - " movq %%mm1, 40(%1)\n"
30662 - " movq %%mm2, 48(%1)\n"
30663 - " movq %%mm3, 56(%1)\n"
30664 + "1: prefetch 320(%1)\n"
30665 + "2: movq (%1), %%mm0\n"
30666 + " movq 8(%1), %%mm1\n"
30667 + " movq 16(%1), %%mm2\n"
30668 + " movq 24(%1), %%mm3\n"
30669 + " movq %%mm0, (%2)\n"
30670 + " movq %%mm1, 8(%2)\n"
30671 + " movq %%mm2, 16(%2)\n"
30672 + " movq %%mm3, 24(%2)\n"
30673 + " movq 32(%1), %%mm0\n"
30674 + " movq 40(%1), %%mm1\n"
30675 + " movq 48(%1), %%mm2\n"
30676 + " movq 56(%1), %%mm3\n"
30677 + " movq %%mm0, 32(%2)\n"
30678 + " movq %%mm1, 40(%2)\n"
30679 + " movq %%mm2, 48(%2)\n"
30680 + " movq %%mm3, 56(%2)\n"
30681 ".section .fixup, \"ax\"\n"
30682 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30683 + "3:\n"
30684 +
30685 +#ifdef CONFIG_PAX_KERNEXEC
30686 + " movl %%cr0, %0\n"
30687 + " movl %0, %%eax\n"
30688 + " andl $0xFFFEFFFF, %%eax\n"
30689 + " movl %%eax, %%cr0\n"
30690 +#endif
30691 +
30692 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30693 +
30694 +#ifdef CONFIG_PAX_KERNEXEC
30695 + " movl %0, %%cr0\n"
30696 +#endif
30697 +
30698 " jmp 2b\n"
30699 ".previous\n"
30700 _ASM_EXTABLE(1b, 3b)
30701 - : : "r" (from), "r" (to) : "memory");
30702 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30703
30704 from += 64;
30705 to += 64;
30706 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30707 static void fast_copy_page(void *to, void *from)
30708 {
30709 int i;
30710 + unsigned long cr0;
30711
30712 kernel_fpu_begin();
30713
30714 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30715 * but that is for later. -AV
30716 */
30717 __asm__ __volatile__(
30718 - "1: prefetch (%0)\n"
30719 - " prefetch 64(%0)\n"
30720 - " prefetch 128(%0)\n"
30721 - " prefetch 192(%0)\n"
30722 - " prefetch 256(%0)\n"
30723 + "1: prefetch (%1)\n"
30724 + " prefetch 64(%1)\n"
30725 + " prefetch 128(%1)\n"
30726 + " prefetch 192(%1)\n"
30727 + " prefetch 256(%1)\n"
30728 "2: \n"
30729 ".section .fixup, \"ax\"\n"
30730 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30731 + "3: \n"
30732 +
30733 +#ifdef CONFIG_PAX_KERNEXEC
30734 + " movl %%cr0, %0\n"
30735 + " movl %0, %%eax\n"
30736 + " andl $0xFFFEFFFF, %%eax\n"
30737 + " movl %%eax, %%cr0\n"
30738 +#endif
30739 +
30740 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30741 +
30742 +#ifdef CONFIG_PAX_KERNEXEC
30743 + " movl %0, %%cr0\n"
30744 +#endif
30745 +
30746 " jmp 2b\n"
30747 ".previous\n"
30748 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30749 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30750
30751 for (i = 0; i < (4096-320)/64; i++) {
30752 __asm__ __volatile__ (
30753 - "1: prefetch 320(%0)\n"
30754 - "2: movq (%0), %%mm0\n"
30755 - " movntq %%mm0, (%1)\n"
30756 - " movq 8(%0), %%mm1\n"
30757 - " movntq %%mm1, 8(%1)\n"
30758 - " movq 16(%0), %%mm2\n"
30759 - " movntq %%mm2, 16(%1)\n"
30760 - " movq 24(%0), %%mm3\n"
30761 - " movntq %%mm3, 24(%1)\n"
30762 - " movq 32(%0), %%mm4\n"
30763 - " movntq %%mm4, 32(%1)\n"
30764 - " movq 40(%0), %%mm5\n"
30765 - " movntq %%mm5, 40(%1)\n"
30766 - " movq 48(%0), %%mm6\n"
30767 - " movntq %%mm6, 48(%1)\n"
30768 - " movq 56(%0), %%mm7\n"
30769 - " movntq %%mm7, 56(%1)\n"
30770 + "1: prefetch 320(%1)\n"
30771 + "2: movq (%1), %%mm0\n"
30772 + " movntq %%mm0, (%2)\n"
30773 + " movq 8(%1), %%mm1\n"
30774 + " movntq %%mm1, 8(%2)\n"
30775 + " movq 16(%1), %%mm2\n"
30776 + " movntq %%mm2, 16(%2)\n"
30777 + " movq 24(%1), %%mm3\n"
30778 + " movntq %%mm3, 24(%2)\n"
30779 + " movq 32(%1), %%mm4\n"
30780 + " movntq %%mm4, 32(%2)\n"
30781 + " movq 40(%1), %%mm5\n"
30782 + " movntq %%mm5, 40(%2)\n"
30783 + " movq 48(%1), %%mm6\n"
30784 + " movntq %%mm6, 48(%2)\n"
30785 + " movq 56(%1), %%mm7\n"
30786 + " movntq %%mm7, 56(%2)\n"
30787 ".section .fixup, \"ax\"\n"
30788 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30789 + "3:\n"
30790 +
30791 +#ifdef CONFIG_PAX_KERNEXEC
30792 + " movl %%cr0, %0\n"
30793 + " movl %0, %%eax\n"
30794 + " andl $0xFFFEFFFF, %%eax\n"
30795 + " movl %%eax, %%cr0\n"
30796 +#endif
30797 +
30798 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30799 +
30800 +#ifdef CONFIG_PAX_KERNEXEC
30801 + " movl %0, %%cr0\n"
30802 +#endif
30803 +
30804 " jmp 2b\n"
30805 ".previous\n"
30806 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30807 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30808
30809 from += 64;
30810 to += 64;
30811 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30812 static void fast_copy_page(void *to, void *from)
30813 {
30814 int i;
30815 + unsigned long cr0;
30816
30817 kernel_fpu_begin();
30818
30819 __asm__ __volatile__ (
30820 - "1: prefetch (%0)\n"
30821 - " prefetch 64(%0)\n"
30822 - " prefetch 128(%0)\n"
30823 - " prefetch 192(%0)\n"
30824 - " prefetch 256(%0)\n"
30825 + "1: prefetch (%1)\n"
30826 + " prefetch 64(%1)\n"
30827 + " prefetch 128(%1)\n"
30828 + " prefetch 192(%1)\n"
30829 + " prefetch 256(%1)\n"
30830 "2: \n"
30831 ".section .fixup, \"ax\"\n"
30832 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30833 + "3: \n"
30834 +
30835 +#ifdef CONFIG_PAX_KERNEXEC
30836 + " movl %%cr0, %0\n"
30837 + " movl %0, %%eax\n"
30838 + " andl $0xFFFEFFFF, %%eax\n"
30839 + " movl %%eax, %%cr0\n"
30840 +#endif
30841 +
30842 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30843 +
30844 +#ifdef CONFIG_PAX_KERNEXEC
30845 + " movl %0, %%cr0\n"
30846 +#endif
30847 +
30848 " jmp 2b\n"
30849 ".previous\n"
30850 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30851 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30852
30853 for (i = 0; i < 4096/64; i++) {
30854 __asm__ __volatile__ (
30855 - "1: prefetch 320(%0)\n"
30856 - "2: movq (%0), %%mm0\n"
30857 - " movq 8(%0), %%mm1\n"
30858 - " movq 16(%0), %%mm2\n"
30859 - " movq 24(%0), %%mm3\n"
30860 - " movq %%mm0, (%1)\n"
30861 - " movq %%mm1, 8(%1)\n"
30862 - " movq %%mm2, 16(%1)\n"
30863 - " movq %%mm3, 24(%1)\n"
30864 - " movq 32(%0), %%mm0\n"
30865 - " movq 40(%0), %%mm1\n"
30866 - " movq 48(%0), %%mm2\n"
30867 - " movq 56(%0), %%mm3\n"
30868 - " movq %%mm0, 32(%1)\n"
30869 - " movq %%mm1, 40(%1)\n"
30870 - " movq %%mm2, 48(%1)\n"
30871 - " movq %%mm3, 56(%1)\n"
30872 + "1: prefetch 320(%1)\n"
30873 + "2: movq (%1), %%mm0\n"
30874 + " movq 8(%1), %%mm1\n"
30875 + " movq 16(%1), %%mm2\n"
30876 + " movq 24(%1), %%mm3\n"
30877 + " movq %%mm0, (%2)\n"
30878 + " movq %%mm1, 8(%2)\n"
30879 + " movq %%mm2, 16(%2)\n"
30880 + " movq %%mm3, 24(%2)\n"
30881 + " movq 32(%1), %%mm0\n"
30882 + " movq 40(%1), %%mm1\n"
30883 + " movq 48(%1), %%mm2\n"
30884 + " movq 56(%1), %%mm3\n"
30885 + " movq %%mm0, 32(%2)\n"
30886 + " movq %%mm1, 40(%2)\n"
30887 + " movq %%mm2, 48(%2)\n"
30888 + " movq %%mm3, 56(%2)\n"
30889 ".section .fixup, \"ax\"\n"
30890 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30891 + "3:\n"
30892 +
30893 +#ifdef CONFIG_PAX_KERNEXEC
30894 + " movl %%cr0, %0\n"
30895 + " movl %0, %%eax\n"
30896 + " andl $0xFFFEFFFF, %%eax\n"
30897 + " movl %%eax, %%cr0\n"
30898 +#endif
30899 +
30900 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30901 +
30902 +#ifdef CONFIG_PAX_KERNEXEC
30903 + " movl %0, %%cr0\n"
30904 +#endif
30905 +
30906 " jmp 2b\n"
30907 ".previous\n"
30908 _ASM_EXTABLE(1b, 3b)
30909 - : : "r" (from), "r" (to) : "memory");
30910 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30911
30912 from += 64;
30913 to += 64;
30914 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30915 index f6d13ee..d789440 100644
30916 --- a/arch/x86/lib/msr-reg.S
30917 +++ b/arch/x86/lib/msr-reg.S
30918 @@ -3,6 +3,7 @@
30919 #include <asm/dwarf2.h>
30920 #include <asm/asm.h>
30921 #include <asm/msr.h>
30922 +#include <asm/alternative-asm.h>
30923
30924 #ifdef CONFIG_X86_64
30925 /*
30926 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30927 movl %edi, 28(%r10)
30928 popq_cfi %rbp
30929 popq_cfi %rbx
30930 + pax_force_retaddr
30931 ret
30932 3:
30933 CFI_RESTORE_STATE
30934 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30935 index fc6ba17..d4d989d 100644
30936 --- a/arch/x86/lib/putuser.S
30937 +++ b/arch/x86/lib/putuser.S
30938 @@ -16,7 +16,9 @@
30939 #include <asm/errno.h>
30940 #include <asm/asm.h>
30941 #include <asm/smap.h>
30942 -
30943 +#include <asm/segment.h>
30944 +#include <asm/pgtable.h>
30945 +#include <asm/alternative-asm.h>
30946
30947 /*
30948 * __put_user_X
30949 @@ -30,57 +32,125 @@
30950 * as they get called from within inline assembly.
30951 */
30952
30953 -#define ENTER CFI_STARTPROC ; \
30954 - GET_THREAD_INFO(%_ASM_BX)
30955 -#define EXIT ASM_CLAC ; \
30956 - ret ; \
30957 +#define ENTER CFI_STARTPROC
30958 +#define EXIT ASM_CLAC ; \
30959 + pax_force_retaddr ; \
30960 + ret ; \
30961 CFI_ENDPROC
30962
30963 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30964 +#define _DEST %_ASM_CX,%_ASM_BX
30965 +#else
30966 +#define _DEST %_ASM_CX
30967 +#endif
30968 +
30969 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30970 +#define __copyuser_seg gs;
30971 +#else
30972 +#define __copyuser_seg
30973 +#endif
30974 +
30975 .text
30976 ENTRY(__put_user_1)
30977 ENTER
30978 +
30979 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30980 + GET_THREAD_INFO(%_ASM_BX)
30981 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30982 jae bad_put_user
30983 ASM_STAC
30984 -1: movb %al,(%_ASM_CX)
30985 +
30986 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30987 + mov pax_user_shadow_base,%_ASM_BX
30988 + cmp %_ASM_BX,%_ASM_CX
30989 + jb 1234f
30990 + xor %ebx,%ebx
30991 +1234:
30992 +#endif
30993 +
30994 +#endif
30995 +
30996 +1: __copyuser_seg movb %al,(_DEST)
30997 xor %eax,%eax
30998 EXIT
30999 ENDPROC(__put_user_1)
31000
31001 ENTRY(__put_user_2)
31002 ENTER
31003 +
31004 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31005 + GET_THREAD_INFO(%_ASM_BX)
31006 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31007 sub $1,%_ASM_BX
31008 cmp %_ASM_BX,%_ASM_CX
31009 jae bad_put_user
31010 ASM_STAC
31011 -2: movw %ax,(%_ASM_CX)
31012 +
31013 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31014 + mov pax_user_shadow_base,%_ASM_BX
31015 + cmp %_ASM_BX,%_ASM_CX
31016 + jb 1234f
31017 + xor %ebx,%ebx
31018 +1234:
31019 +#endif
31020 +
31021 +#endif
31022 +
31023 +2: __copyuser_seg movw %ax,(_DEST)
31024 xor %eax,%eax
31025 EXIT
31026 ENDPROC(__put_user_2)
31027
31028 ENTRY(__put_user_4)
31029 ENTER
31030 +
31031 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31032 + GET_THREAD_INFO(%_ASM_BX)
31033 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31034 sub $3,%_ASM_BX
31035 cmp %_ASM_BX,%_ASM_CX
31036 jae bad_put_user
31037 ASM_STAC
31038 -3: movl %eax,(%_ASM_CX)
31039 +
31040 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31041 + mov pax_user_shadow_base,%_ASM_BX
31042 + cmp %_ASM_BX,%_ASM_CX
31043 + jb 1234f
31044 + xor %ebx,%ebx
31045 +1234:
31046 +#endif
31047 +
31048 +#endif
31049 +
31050 +3: __copyuser_seg movl %eax,(_DEST)
31051 xor %eax,%eax
31052 EXIT
31053 ENDPROC(__put_user_4)
31054
31055 ENTRY(__put_user_8)
31056 ENTER
31057 +
31058 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31059 + GET_THREAD_INFO(%_ASM_BX)
31060 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31061 sub $7,%_ASM_BX
31062 cmp %_ASM_BX,%_ASM_CX
31063 jae bad_put_user
31064 ASM_STAC
31065 -4: mov %_ASM_AX,(%_ASM_CX)
31066 +
31067 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31068 + mov pax_user_shadow_base,%_ASM_BX
31069 + cmp %_ASM_BX,%_ASM_CX
31070 + jb 1234f
31071 + xor %ebx,%ebx
31072 +1234:
31073 +#endif
31074 +
31075 +#endif
31076 +
31077 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31078 #ifdef CONFIG_X86_32
31079 -5: movl %edx,4(%_ASM_CX)
31080 +5: __copyuser_seg movl %edx,4(_DEST)
31081 #endif
31082 xor %eax,%eax
31083 EXIT
31084 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31085 index 1cad221..de671ee 100644
31086 --- a/arch/x86/lib/rwlock.S
31087 +++ b/arch/x86/lib/rwlock.S
31088 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31089 FRAME
31090 0: LOCK_PREFIX
31091 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31092 +
31093 +#ifdef CONFIG_PAX_REFCOUNT
31094 + jno 1234f
31095 + LOCK_PREFIX
31096 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31097 + int $4
31098 +1234:
31099 + _ASM_EXTABLE(1234b, 1234b)
31100 +#endif
31101 +
31102 1: rep; nop
31103 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31104 jne 1b
31105 LOCK_PREFIX
31106 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31107 +
31108 +#ifdef CONFIG_PAX_REFCOUNT
31109 + jno 1234f
31110 + LOCK_PREFIX
31111 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31112 + int $4
31113 +1234:
31114 + _ASM_EXTABLE(1234b, 1234b)
31115 +#endif
31116 +
31117 jnz 0b
31118 ENDFRAME
31119 + pax_force_retaddr
31120 ret
31121 CFI_ENDPROC
31122 END(__write_lock_failed)
31123 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31124 FRAME
31125 0: LOCK_PREFIX
31126 READ_LOCK_SIZE(inc) (%__lock_ptr)
31127 +
31128 +#ifdef CONFIG_PAX_REFCOUNT
31129 + jno 1234f
31130 + LOCK_PREFIX
31131 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31132 + int $4
31133 +1234:
31134 + _ASM_EXTABLE(1234b, 1234b)
31135 +#endif
31136 +
31137 1: rep; nop
31138 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31139 js 1b
31140 LOCK_PREFIX
31141 READ_LOCK_SIZE(dec) (%__lock_ptr)
31142 +
31143 +#ifdef CONFIG_PAX_REFCOUNT
31144 + jno 1234f
31145 + LOCK_PREFIX
31146 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31147 + int $4
31148 +1234:
31149 + _ASM_EXTABLE(1234b, 1234b)
31150 +#endif
31151 +
31152 js 0b
31153 ENDFRAME
31154 + pax_force_retaddr
31155 ret
31156 CFI_ENDPROC
31157 END(__read_lock_failed)
31158 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31159 index 5dff5f0..cadebf4 100644
31160 --- a/arch/x86/lib/rwsem.S
31161 +++ b/arch/x86/lib/rwsem.S
31162 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31163 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31164 CFI_RESTORE __ASM_REG(dx)
31165 restore_common_regs
31166 + pax_force_retaddr
31167 ret
31168 CFI_ENDPROC
31169 ENDPROC(call_rwsem_down_read_failed)
31170 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31171 movq %rax,%rdi
31172 call rwsem_down_write_failed
31173 restore_common_regs
31174 + pax_force_retaddr
31175 ret
31176 CFI_ENDPROC
31177 ENDPROC(call_rwsem_down_write_failed)
31178 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31179 movq %rax,%rdi
31180 call rwsem_wake
31181 restore_common_regs
31182 -1: ret
31183 +1: pax_force_retaddr
31184 + ret
31185 CFI_ENDPROC
31186 ENDPROC(call_rwsem_wake)
31187
31188 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31189 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31190 CFI_RESTORE __ASM_REG(dx)
31191 restore_common_regs
31192 + pax_force_retaddr
31193 ret
31194 CFI_ENDPROC
31195 ENDPROC(call_rwsem_downgrade_wake)
31196 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31197 index 92d9fea..b2762c8 100644
31198 --- a/arch/x86/lib/thunk_64.S
31199 +++ b/arch/x86/lib/thunk_64.S
31200 @@ -9,6 +9,7 @@
31201 #include <asm/dwarf2.h>
31202 #include <asm/calling.h>
31203 #include <asm/asm.h>
31204 +#include <asm/alternative-asm.h>
31205
31206 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31207 .macro THUNK name, func, put_ret_addr_in_rdi=0
31208 @@ -16,11 +17,11 @@
31209 \name:
31210 CFI_STARTPROC
31211
31212 - /* this one pushes 9 elems, the next one would be %rIP */
31213 - SAVE_ARGS
31214 + /* this one pushes 15+1 elems, the next one would be %rIP */
31215 + SAVE_ARGS 8
31216
31217 .if \put_ret_addr_in_rdi
31218 - movq_cfi_restore 9*8, rdi
31219 + movq_cfi_restore RIP, rdi
31220 .endif
31221
31222 call \func
31223 @@ -40,9 +41,10 @@
31224
31225 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31226 CFI_STARTPROC
31227 - SAVE_ARGS
31228 + SAVE_ARGS 8
31229 restore:
31230 - RESTORE_ARGS
31231 + RESTORE_ARGS 1,8
31232 + pax_force_retaddr
31233 ret
31234 CFI_ENDPROC
31235 _ASM_NOKPROBE(restore)
31236 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31237 index e2f5e21..4b22130 100644
31238 --- a/arch/x86/lib/usercopy_32.c
31239 +++ b/arch/x86/lib/usercopy_32.c
31240 @@ -42,11 +42,13 @@ do { \
31241 int __d0; \
31242 might_fault(); \
31243 __asm__ __volatile__( \
31244 + __COPYUSER_SET_ES \
31245 ASM_STAC "\n" \
31246 "0: rep; stosl\n" \
31247 " movl %2,%0\n" \
31248 "1: rep; stosb\n" \
31249 "2: " ASM_CLAC "\n" \
31250 + __COPYUSER_RESTORE_ES \
31251 ".section .fixup,\"ax\"\n" \
31252 "3: lea 0(%2,%0,4),%0\n" \
31253 " jmp 2b\n" \
31254 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31255
31256 #ifdef CONFIG_X86_INTEL_USERCOPY
31257 static unsigned long
31258 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31259 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31260 {
31261 int d0, d1;
31262 __asm__ __volatile__(
31263 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31264 " .align 2,0x90\n"
31265 "3: movl 0(%4), %%eax\n"
31266 "4: movl 4(%4), %%edx\n"
31267 - "5: movl %%eax, 0(%3)\n"
31268 - "6: movl %%edx, 4(%3)\n"
31269 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31270 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31271 "7: movl 8(%4), %%eax\n"
31272 "8: movl 12(%4),%%edx\n"
31273 - "9: movl %%eax, 8(%3)\n"
31274 - "10: movl %%edx, 12(%3)\n"
31275 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31276 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31277 "11: movl 16(%4), %%eax\n"
31278 "12: movl 20(%4), %%edx\n"
31279 - "13: movl %%eax, 16(%3)\n"
31280 - "14: movl %%edx, 20(%3)\n"
31281 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31282 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31283 "15: movl 24(%4), %%eax\n"
31284 "16: movl 28(%4), %%edx\n"
31285 - "17: movl %%eax, 24(%3)\n"
31286 - "18: movl %%edx, 28(%3)\n"
31287 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31288 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31289 "19: movl 32(%4), %%eax\n"
31290 "20: movl 36(%4), %%edx\n"
31291 - "21: movl %%eax, 32(%3)\n"
31292 - "22: movl %%edx, 36(%3)\n"
31293 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31294 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31295 "23: movl 40(%4), %%eax\n"
31296 "24: movl 44(%4), %%edx\n"
31297 - "25: movl %%eax, 40(%3)\n"
31298 - "26: movl %%edx, 44(%3)\n"
31299 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31300 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31301 "27: movl 48(%4), %%eax\n"
31302 "28: movl 52(%4), %%edx\n"
31303 - "29: movl %%eax, 48(%3)\n"
31304 - "30: movl %%edx, 52(%3)\n"
31305 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31306 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31307 "31: movl 56(%4), %%eax\n"
31308 "32: movl 60(%4), %%edx\n"
31309 - "33: movl %%eax, 56(%3)\n"
31310 - "34: movl %%edx, 60(%3)\n"
31311 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31312 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31313 " addl $-64, %0\n"
31314 " addl $64, %4\n"
31315 " addl $64, %3\n"
31316 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31317 " shrl $2, %0\n"
31318 " andl $3, %%eax\n"
31319 " cld\n"
31320 + __COPYUSER_SET_ES
31321 "99: rep; movsl\n"
31322 "36: movl %%eax, %0\n"
31323 "37: rep; movsb\n"
31324 "100:\n"
31325 + __COPYUSER_RESTORE_ES
31326 + ".section .fixup,\"ax\"\n"
31327 + "101: lea 0(%%eax,%0,4),%0\n"
31328 + " jmp 100b\n"
31329 + ".previous\n"
31330 + _ASM_EXTABLE(1b,100b)
31331 + _ASM_EXTABLE(2b,100b)
31332 + _ASM_EXTABLE(3b,100b)
31333 + _ASM_EXTABLE(4b,100b)
31334 + _ASM_EXTABLE(5b,100b)
31335 + _ASM_EXTABLE(6b,100b)
31336 + _ASM_EXTABLE(7b,100b)
31337 + _ASM_EXTABLE(8b,100b)
31338 + _ASM_EXTABLE(9b,100b)
31339 + _ASM_EXTABLE(10b,100b)
31340 + _ASM_EXTABLE(11b,100b)
31341 + _ASM_EXTABLE(12b,100b)
31342 + _ASM_EXTABLE(13b,100b)
31343 + _ASM_EXTABLE(14b,100b)
31344 + _ASM_EXTABLE(15b,100b)
31345 + _ASM_EXTABLE(16b,100b)
31346 + _ASM_EXTABLE(17b,100b)
31347 + _ASM_EXTABLE(18b,100b)
31348 + _ASM_EXTABLE(19b,100b)
31349 + _ASM_EXTABLE(20b,100b)
31350 + _ASM_EXTABLE(21b,100b)
31351 + _ASM_EXTABLE(22b,100b)
31352 + _ASM_EXTABLE(23b,100b)
31353 + _ASM_EXTABLE(24b,100b)
31354 + _ASM_EXTABLE(25b,100b)
31355 + _ASM_EXTABLE(26b,100b)
31356 + _ASM_EXTABLE(27b,100b)
31357 + _ASM_EXTABLE(28b,100b)
31358 + _ASM_EXTABLE(29b,100b)
31359 + _ASM_EXTABLE(30b,100b)
31360 + _ASM_EXTABLE(31b,100b)
31361 + _ASM_EXTABLE(32b,100b)
31362 + _ASM_EXTABLE(33b,100b)
31363 + _ASM_EXTABLE(34b,100b)
31364 + _ASM_EXTABLE(35b,100b)
31365 + _ASM_EXTABLE(36b,100b)
31366 + _ASM_EXTABLE(37b,100b)
31367 + _ASM_EXTABLE(99b,101b)
31368 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31369 + : "1"(to), "2"(from), "0"(size)
31370 + : "eax", "edx", "memory");
31371 + return size;
31372 +}
31373 +
31374 +static unsigned long
31375 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31376 +{
31377 + int d0, d1;
31378 + __asm__ __volatile__(
31379 + " .align 2,0x90\n"
31380 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31381 + " cmpl $67, %0\n"
31382 + " jbe 3f\n"
31383 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31384 + " .align 2,0x90\n"
31385 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31386 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31387 + "5: movl %%eax, 0(%3)\n"
31388 + "6: movl %%edx, 4(%3)\n"
31389 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31390 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31391 + "9: movl %%eax, 8(%3)\n"
31392 + "10: movl %%edx, 12(%3)\n"
31393 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31394 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31395 + "13: movl %%eax, 16(%3)\n"
31396 + "14: movl %%edx, 20(%3)\n"
31397 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31398 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31399 + "17: movl %%eax, 24(%3)\n"
31400 + "18: movl %%edx, 28(%3)\n"
31401 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31402 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31403 + "21: movl %%eax, 32(%3)\n"
31404 + "22: movl %%edx, 36(%3)\n"
31405 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31406 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31407 + "25: movl %%eax, 40(%3)\n"
31408 + "26: movl %%edx, 44(%3)\n"
31409 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31410 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31411 + "29: movl %%eax, 48(%3)\n"
31412 + "30: movl %%edx, 52(%3)\n"
31413 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31414 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31415 + "33: movl %%eax, 56(%3)\n"
31416 + "34: movl %%edx, 60(%3)\n"
31417 + " addl $-64, %0\n"
31418 + " addl $64, %4\n"
31419 + " addl $64, %3\n"
31420 + " cmpl $63, %0\n"
31421 + " ja 1b\n"
31422 + "35: movl %0, %%eax\n"
31423 + " shrl $2, %0\n"
31424 + " andl $3, %%eax\n"
31425 + " cld\n"
31426 + "99: rep; "__copyuser_seg" movsl\n"
31427 + "36: movl %%eax, %0\n"
31428 + "37: rep; "__copyuser_seg" movsb\n"
31429 + "100:\n"
31430 ".section .fixup,\"ax\"\n"
31431 "101: lea 0(%%eax,%0,4),%0\n"
31432 " jmp 100b\n"
31433 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31434 int d0, d1;
31435 __asm__ __volatile__(
31436 " .align 2,0x90\n"
31437 - "0: movl 32(%4), %%eax\n"
31438 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31439 " cmpl $67, %0\n"
31440 " jbe 2f\n"
31441 - "1: movl 64(%4), %%eax\n"
31442 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31443 " .align 2,0x90\n"
31444 - "2: movl 0(%4), %%eax\n"
31445 - "21: movl 4(%4), %%edx\n"
31446 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31447 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31448 " movl %%eax, 0(%3)\n"
31449 " movl %%edx, 4(%3)\n"
31450 - "3: movl 8(%4), %%eax\n"
31451 - "31: movl 12(%4),%%edx\n"
31452 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31453 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31454 " movl %%eax, 8(%3)\n"
31455 " movl %%edx, 12(%3)\n"
31456 - "4: movl 16(%4), %%eax\n"
31457 - "41: movl 20(%4), %%edx\n"
31458 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31459 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31460 " movl %%eax, 16(%3)\n"
31461 " movl %%edx, 20(%3)\n"
31462 - "10: movl 24(%4), %%eax\n"
31463 - "51: movl 28(%4), %%edx\n"
31464 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31465 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31466 " movl %%eax, 24(%3)\n"
31467 " movl %%edx, 28(%3)\n"
31468 - "11: movl 32(%4), %%eax\n"
31469 - "61: movl 36(%4), %%edx\n"
31470 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31471 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31472 " movl %%eax, 32(%3)\n"
31473 " movl %%edx, 36(%3)\n"
31474 - "12: movl 40(%4), %%eax\n"
31475 - "71: movl 44(%4), %%edx\n"
31476 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31477 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31478 " movl %%eax, 40(%3)\n"
31479 " movl %%edx, 44(%3)\n"
31480 - "13: movl 48(%4), %%eax\n"
31481 - "81: movl 52(%4), %%edx\n"
31482 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31483 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31484 " movl %%eax, 48(%3)\n"
31485 " movl %%edx, 52(%3)\n"
31486 - "14: movl 56(%4), %%eax\n"
31487 - "91: movl 60(%4), %%edx\n"
31488 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31489 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31490 " movl %%eax, 56(%3)\n"
31491 " movl %%edx, 60(%3)\n"
31492 " addl $-64, %0\n"
31493 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31494 " shrl $2, %0\n"
31495 " andl $3, %%eax\n"
31496 " cld\n"
31497 - "6: rep; movsl\n"
31498 + "6: rep; "__copyuser_seg" movsl\n"
31499 " movl %%eax,%0\n"
31500 - "7: rep; movsb\n"
31501 + "7: rep; "__copyuser_seg" movsb\n"
31502 "8:\n"
31503 ".section .fixup,\"ax\"\n"
31504 "9: lea 0(%%eax,%0,4),%0\n"
31505 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31506
31507 __asm__ __volatile__(
31508 " .align 2,0x90\n"
31509 - "0: movl 32(%4), %%eax\n"
31510 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31511 " cmpl $67, %0\n"
31512 " jbe 2f\n"
31513 - "1: movl 64(%4), %%eax\n"
31514 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31515 " .align 2,0x90\n"
31516 - "2: movl 0(%4), %%eax\n"
31517 - "21: movl 4(%4), %%edx\n"
31518 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31519 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31520 " movnti %%eax, 0(%3)\n"
31521 " movnti %%edx, 4(%3)\n"
31522 - "3: movl 8(%4), %%eax\n"
31523 - "31: movl 12(%4),%%edx\n"
31524 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31525 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31526 " movnti %%eax, 8(%3)\n"
31527 " movnti %%edx, 12(%3)\n"
31528 - "4: movl 16(%4), %%eax\n"
31529 - "41: movl 20(%4), %%edx\n"
31530 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31531 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31532 " movnti %%eax, 16(%3)\n"
31533 " movnti %%edx, 20(%3)\n"
31534 - "10: movl 24(%4), %%eax\n"
31535 - "51: movl 28(%4), %%edx\n"
31536 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31537 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31538 " movnti %%eax, 24(%3)\n"
31539 " movnti %%edx, 28(%3)\n"
31540 - "11: movl 32(%4), %%eax\n"
31541 - "61: movl 36(%4), %%edx\n"
31542 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31543 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31544 " movnti %%eax, 32(%3)\n"
31545 " movnti %%edx, 36(%3)\n"
31546 - "12: movl 40(%4), %%eax\n"
31547 - "71: movl 44(%4), %%edx\n"
31548 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31549 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31550 " movnti %%eax, 40(%3)\n"
31551 " movnti %%edx, 44(%3)\n"
31552 - "13: movl 48(%4), %%eax\n"
31553 - "81: movl 52(%4), %%edx\n"
31554 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31555 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31556 " movnti %%eax, 48(%3)\n"
31557 " movnti %%edx, 52(%3)\n"
31558 - "14: movl 56(%4), %%eax\n"
31559 - "91: movl 60(%4), %%edx\n"
31560 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31561 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31562 " movnti %%eax, 56(%3)\n"
31563 " movnti %%edx, 60(%3)\n"
31564 " addl $-64, %0\n"
31565 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31566 " shrl $2, %0\n"
31567 " andl $3, %%eax\n"
31568 " cld\n"
31569 - "6: rep; movsl\n"
31570 + "6: rep; "__copyuser_seg" movsl\n"
31571 " movl %%eax,%0\n"
31572 - "7: rep; movsb\n"
31573 + "7: rep; "__copyuser_seg" movsb\n"
31574 "8:\n"
31575 ".section .fixup,\"ax\"\n"
31576 "9: lea 0(%%eax,%0,4),%0\n"
31577 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31578
31579 __asm__ __volatile__(
31580 " .align 2,0x90\n"
31581 - "0: movl 32(%4), %%eax\n"
31582 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31583 " cmpl $67, %0\n"
31584 " jbe 2f\n"
31585 - "1: movl 64(%4), %%eax\n"
31586 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31587 " .align 2,0x90\n"
31588 - "2: movl 0(%4), %%eax\n"
31589 - "21: movl 4(%4), %%edx\n"
31590 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31591 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31592 " movnti %%eax, 0(%3)\n"
31593 " movnti %%edx, 4(%3)\n"
31594 - "3: movl 8(%4), %%eax\n"
31595 - "31: movl 12(%4),%%edx\n"
31596 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31597 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31598 " movnti %%eax, 8(%3)\n"
31599 " movnti %%edx, 12(%3)\n"
31600 - "4: movl 16(%4), %%eax\n"
31601 - "41: movl 20(%4), %%edx\n"
31602 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31603 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31604 " movnti %%eax, 16(%3)\n"
31605 " movnti %%edx, 20(%3)\n"
31606 - "10: movl 24(%4), %%eax\n"
31607 - "51: movl 28(%4), %%edx\n"
31608 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31609 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31610 " movnti %%eax, 24(%3)\n"
31611 " movnti %%edx, 28(%3)\n"
31612 - "11: movl 32(%4), %%eax\n"
31613 - "61: movl 36(%4), %%edx\n"
31614 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31615 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31616 " movnti %%eax, 32(%3)\n"
31617 " movnti %%edx, 36(%3)\n"
31618 - "12: movl 40(%4), %%eax\n"
31619 - "71: movl 44(%4), %%edx\n"
31620 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31621 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31622 " movnti %%eax, 40(%3)\n"
31623 " movnti %%edx, 44(%3)\n"
31624 - "13: movl 48(%4), %%eax\n"
31625 - "81: movl 52(%4), %%edx\n"
31626 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31627 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31628 " movnti %%eax, 48(%3)\n"
31629 " movnti %%edx, 52(%3)\n"
31630 - "14: movl 56(%4), %%eax\n"
31631 - "91: movl 60(%4), %%edx\n"
31632 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31633 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31634 " movnti %%eax, 56(%3)\n"
31635 " movnti %%edx, 60(%3)\n"
31636 " addl $-64, %0\n"
31637 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31638 " shrl $2, %0\n"
31639 " andl $3, %%eax\n"
31640 " cld\n"
31641 - "6: rep; movsl\n"
31642 + "6: rep; "__copyuser_seg" movsl\n"
31643 " movl %%eax,%0\n"
31644 - "7: rep; movsb\n"
31645 + "7: rep; "__copyuser_seg" movsb\n"
31646 "8:\n"
31647 ".section .fixup,\"ax\"\n"
31648 "9: lea 0(%%eax,%0,4),%0\n"
31649 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31650 */
31651 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31652 unsigned long size);
31653 -unsigned long __copy_user_intel(void __user *to, const void *from,
31654 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31655 + unsigned long size);
31656 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31657 unsigned long size);
31658 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31659 const void __user *from, unsigned long size);
31660 #endif /* CONFIG_X86_INTEL_USERCOPY */
31661
31662 /* Generic arbitrary sized copy. */
31663 -#define __copy_user(to, from, size) \
31664 +#define __copy_user(to, from, size, prefix, set, restore) \
31665 do { \
31666 int __d0, __d1, __d2; \
31667 __asm__ __volatile__( \
31668 + set \
31669 " cmp $7,%0\n" \
31670 " jbe 1f\n" \
31671 " movl %1,%0\n" \
31672 " negl %0\n" \
31673 " andl $7,%0\n" \
31674 " subl %0,%3\n" \
31675 - "4: rep; movsb\n" \
31676 + "4: rep; "prefix"movsb\n" \
31677 " movl %3,%0\n" \
31678 " shrl $2,%0\n" \
31679 " andl $3,%3\n" \
31680 " .align 2,0x90\n" \
31681 - "0: rep; movsl\n" \
31682 + "0: rep; "prefix"movsl\n" \
31683 " movl %3,%0\n" \
31684 - "1: rep; movsb\n" \
31685 + "1: rep; "prefix"movsb\n" \
31686 "2:\n" \
31687 + restore \
31688 ".section .fixup,\"ax\"\n" \
31689 "5: addl %3,%0\n" \
31690 " jmp 2b\n" \
31691 @@ -538,14 +650,14 @@ do { \
31692 " negl %0\n" \
31693 " andl $7,%0\n" \
31694 " subl %0,%3\n" \
31695 - "4: rep; movsb\n" \
31696 + "4: rep; "__copyuser_seg"movsb\n" \
31697 " movl %3,%0\n" \
31698 " shrl $2,%0\n" \
31699 " andl $3,%3\n" \
31700 " .align 2,0x90\n" \
31701 - "0: rep; movsl\n" \
31702 + "0: rep; "__copyuser_seg"movsl\n" \
31703 " movl %3,%0\n" \
31704 - "1: rep; movsb\n" \
31705 + "1: rep; "__copyuser_seg"movsb\n" \
31706 "2:\n" \
31707 ".section .fixup,\"ax\"\n" \
31708 "5: addl %3,%0\n" \
31709 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31710 {
31711 stac();
31712 if (movsl_is_ok(to, from, n))
31713 - __copy_user(to, from, n);
31714 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31715 else
31716 - n = __copy_user_intel(to, from, n);
31717 + n = __generic_copy_to_user_intel(to, from, n);
31718 clac();
31719 return n;
31720 }
31721 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31722 {
31723 stac();
31724 if (movsl_is_ok(to, from, n))
31725 - __copy_user(to, from, n);
31726 + __copy_user(to, from, n, __copyuser_seg, "", "");
31727 else
31728 - n = __copy_user_intel((void __user *)to,
31729 - (const void *)from, n);
31730 + n = __generic_copy_from_user_intel(to, from, n);
31731 clac();
31732 return n;
31733 }
31734 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31735 if (n > 64 && cpu_has_xmm2)
31736 n = __copy_user_intel_nocache(to, from, n);
31737 else
31738 - __copy_user(to, from, n);
31739 + __copy_user(to, from, n, __copyuser_seg, "", "");
31740 #else
31741 - __copy_user(to, from, n);
31742 + __copy_user(to, from, n, __copyuser_seg, "", "");
31743 #endif
31744 clac();
31745 return n;
31746 }
31747 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31748
31749 -/**
31750 - * copy_to_user: - Copy a block of data into user space.
31751 - * @to: Destination address, in user space.
31752 - * @from: Source address, in kernel space.
31753 - * @n: Number of bytes to copy.
31754 - *
31755 - * Context: User context only. This function may sleep.
31756 - *
31757 - * Copy data from kernel space to user space.
31758 - *
31759 - * Returns number of bytes that could not be copied.
31760 - * On success, this will be zero.
31761 - */
31762 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31763 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31764 +void __set_fs(mm_segment_t x)
31765 {
31766 - if (access_ok(VERIFY_WRITE, to, n))
31767 - n = __copy_to_user(to, from, n);
31768 - return n;
31769 + switch (x.seg) {
31770 + case 0:
31771 + loadsegment(gs, 0);
31772 + break;
31773 + case TASK_SIZE_MAX:
31774 + loadsegment(gs, __USER_DS);
31775 + break;
31776 + case -1UL:
31777 + loadsegment(gs, __KERNEL_DS);
31778 + break;
31779 + default:
31780 + BUG();
31781 + }
31782 }
31783 -EXPORT_SYMBOL(_copy_to_user);
31784 +EXPORT_SYMBOL(__set_fs);
31785
31786 -/**
31787 - * copy_from_user: - Copy a block of data from user space.
31788 - * @to: Destination address, in kernel space.
31789 - * @from: Source address, in user space.
31790 - * @n: Number of bytes to copy.
31791 - *
31792 - * Context: User context only. This function may sleep.
31793 - *
31794 - * Copy data from user space to kernel space.
31795 - *
31796 - * Returns number of bytes that could not be copied.
31797 - * On success, this will be zero.
31798 - *
31799 - * If some data could not be copied, this function will pad the copied
31800 - * data to the requested size using zero bytes.
31801 - */
31802 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31803 +void set_fs(mm_segment_t x)
31804 {
31805 - if (access_ok(VERIFY_READ, from, n))
31806 - n = __copy_from_user(to, from, n);
31807 - else
31808 - memset(to, 0, n);
31809 - return n;
31810 + current_thread_info()->addr_limit = x;
31811 + __set_fs(x);
31812 }
31813 -EXPORT_SYMBOL(_copy_from_user);
31814 +EXPORT_SYMBOL(set_fs);
31815 +#endif
31816 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31817 index c905e89..01ab928 100644
31818 --- a/arch/x86/lib/usercopy_64.c
31819 +++ b/arch/x86/lib/usercopy_64.c
31820 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31821 might_fault();
31822 /* no memory constraint because it doesn't change any memory gcc knows
31823 about */
31824 + pax_open_userland();
31825 stac();
31826 asm volatile(
31827 " testq %[size8],%[size8]\n"
31828 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31829 _ASM_EXTABLE(0b,3b)
31830 _ASM_EXTABLE(1b,2b)
31831 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31832 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31833 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31834 [zero] "r" (0UL), [eight] "r" (8UL));
31835 clac();
31836 + pax_close_userland();
31837 return size;
31838 }
31839 EXPORT_SYMBOL(__clear_user);
31840 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31841 }
31842 EXPORT_SYMBOL(clear_user);
31843
31844 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31845 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31846 {
31847 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31848 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31849 - }
31850 - return len;
31851 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31852 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31853 + return len;
31854 }
31855 EXPORT_SYMBOL(copy_in_user);
31856
31857 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31858 * it is not necessary to optimize tail handling.
31859 */
31860 __visible unsigned long
31861 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31862 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31863 {
31864 char c;
31865 unsigned zero_len;
31866
31867 + clac();
31868 + pax_close_userland();
31869 for (; len; --len, to++) {
31870 if (__get_user_nocheck(c, from++, sizeof(char)))
31871 break;
31872 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31873 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31874 if (__put_user_nocheck(c, to++, sizeof(char)))
31875 break;
31876 - clac();
31877 return len;
31878 }
31879 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31880 index 6a19ad9..1c48f9a 100644
31881 --- a/arch/x86/mm/Makefile
31882 +++ b/arch/x86/mm/Makefile
31883 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31884 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31885
31886 obj-$(CONFIG_MEMTEST) += memtest.o
31887 +
31888 +quote:="
31889 +obj-$(CONFIG_X86_64) += uderef_64.o
31890 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31891 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31892 index 903ec1e..c4166b2 100644
31893 --- a/arch/x86/mm/extable.c
31894 +++ b/arch/x86/mm/extable.c
31895 @@ -6,12 +6,24 @@
31896 static inline unsigned long
31897 ex_insn_addr(const struct exception_table_entry *x)
31898 {
31899 - return (unsigned long)&x->insn + x->insn;
31900 + unsigned long reloc = 0;
31901 +
31902 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31903 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31904 +#endif
31905 +
31906 + return (unsigned long)&x->insn + x->insn + reloc;
31907 }
31908 static inline unsigned long
31909 ex_fixup_addr(const struct exception_table_entry *x)
31910 {
31911 - return (unsigned long)&x->fixup + x->fixup;
31912 + unsigned long reloc = 0;
31913 +
31914 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31915 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31916 +#endif
31917 +
31918 + return (unsigned long)&x->fixup + x->fixup + reloc;
31919 }
31920
31921 int fixup_exception(struct pt_regs *regs)
31922 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31923 unsigned long new_ip;
31924
31925 #ifdef CONFIG_PNPBIOS
31926 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31927 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31928 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31929 extern u32 pnp_bios_is_utter_crap;
31930 pnp_bios_is_utter_crap = 1;
31931 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31932 i += 4;
31933 p->fixup -= i;
31934 i += 4;
31935 +
31936 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31937 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31938 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31939 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31940 +#endif
31941 +
31942 }
31943 }
31944
31945 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31946 index 3664279..c6a7830 100644
31947 --- a/arch/x86/mm/fault.c
31948 +++ b/arch/x86/mm/fault.c
31949 @@ -14,12 +14,19 @@
31950 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31951 #include <linux/prefetch.h> /* prefetchw */
31952 #include <linux/context_tracking.h> /* exception_enter(), ... */
31953 +#include <linux/unistd.h>
31954 +#include <linux/compiler.h>
31955
31956 #include <asm/traps.h> /* dotraplinkage, ... */
31957 #include <asm/pgalloc.h> /* pgd_*(), ... */
31958 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31959 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31960 #include <asm/vsyscall.h> /* emulate_vsyscall */
31961 +#include <asm/tlbflush.h>
31962 +
31963 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31964 +#include <asm/stacktrace.h>
31965 +#endif
31966
31967 #define CREATE_TRACE_POINTS
31968 #include <asm/trace/exceptions.h>
31969 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31970 int ret = 0;
31971
31972 /* kprobe_running() needs smp_processor_id() */
31973 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31974 + if (kprobes_built_in() && !user_mode(regs)) {
31975 preempt_disable();
31976 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31977 ret = 1;
31978 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31979 return !instr_lo || (instr_lo>>1) == 1;
31980 case 0x00:
31981 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31982 - if (probe_kernel_address(instr, opcode))
31983 + if (user_mode(regs)) {
31984 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31985 + return 0;
31986 + } else if (probe_kernel_address(instr, opcode))
31987 return 0;
31988
31989 *prefetch = (instr_lo == 0xF) &&
31990 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31991 while (instr < max_instr) {
31992 unsigned char opcode;
31993
31994 - if (probe_kernel_address(instr, opcode))
31995 + if (user_mode(regs)) {
31996 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31997 + break;
31998 + } else if (probe_kernel_address(instr, opcode))
31999 break;
32000
32001 instr++;
32002 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32003 force_sig_info(si_signo, &info, tsk);
32004 }
32005
32006 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32007 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32008 +#endif
32009 +
32010 +#ifdef CONFIG_PAX_EMUTRAMP
32011 +static int pax_handle_fetch_fault(struct pt_regs *regs);
32012 +#endif
32013 +
32014 +#ifdef CONFIG_PAX_PAGEEXEC
32015 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32016 +{
32017 + pgd_t *pgd;
32018 + pud_t *pud;
32019 + pmd_t *pmd;
32020 +
32021 + pgd = pgd_offset(mm, address);
32022 + if (!pgd_present(*pgd))
32023 + return NULL;
32024 + pud = pud_offset(pgd, address);
32025 + if (!pud_present(*pud))
32026 + return NULL;
32027 + pmd = pmd_offset(pud, address);
32028 + if (!pmd_present(*pmd))
32029 + return NULL;
32030 + return pmd;
32031 +}
32032 +#endif
32033 +
32034 DEFINE_SPINLOCK(pgd_lock);
32035 LIST_HEAD(pgd_list);
32036
32037 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32038 for (address = VMALLOC_START & PMD_MASK;
32039 address >= TASK_SIZE && address < FIXADDR_TOP;
32040 address += PMD_SIZE) {
32041 +
32042 +#ifdef CONFIG_PAX_PER_CPU_PGD
32043 + unsigned long cpu;
32044 +#else
32045 struct page *page;
32046 +#endif
32047
32048 spin_lock(&pgd_lock);
32049 +
32050 +#ifdef CONFIG_PAX_PER_CPU_PGD
32051 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32052 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32053 + pmd_t *ret;
32054 +
32055 + ret = vmalloc_sync_one(pgd, address);
32056 + if (!ret)
32057 + break;
32058 + pgd = get_cpu_pgd(cpu, kernel);
32059 +#else
32060 list_for_each_entry(page, &pgd_list, lru) {
32061 + pgd_t *pgd;
32062 spinlock_t *pgt_lock;
32063 pmd_t *ret;
32064
32065 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32066 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32067
32068 spin_lock(pgt_lock);
32069 - ret = vmalloc_sync_one(page_address(page), address);
32070 + pgd = page_address(page);
32071 +#endif
32072 +
32073 + ret = vmalloc_sync_one(pgd, address);
32074 +
32075 +#ifndef CONFIG_PAX_PER_CPU_PGD
32076 spin_unlock(pgt_lock);
32077 +#endif
32078
32079 if (!ret)
32080 break;
32081 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32082 * an interrupt in the middle of a task switch..
32083 */
32084 pgd_paddr = read_cr3();
32085 +
32086 +#ifdef CONFIG_PAX_PER_CPU_PGD
32087 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32088 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32089 +#endif
32090 +
32091 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32092 if (!pmd_k)
32093 return -1;
32094 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32095 * happen within a race in page table update. In the later
32096 * case just flush:
32097 */
32098 - pgd = pgd_offset(current->active_mm, address);
32099 +
32100 pgd_ref = pgd_offset_k(address);
32101 if (pgd_none(*pgd_ref))
32102 return -1;
32103
32104 +#ifdef CONFIG_PAX_PER_CPU_PGD
32105 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32106 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32107 + if (pgd_none(*pgd)) {
32108 + set_pgd(pgd, *pgd_ref);
32109 + arch_flush_lazy_mmu_mode();
32110 + } else {
32111 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32112 + }
32113 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32114 +#else
32115 + pgd = pgd_offset(current->active_mm, address);
32116 +#endif
32117 +
32118 if (pgd_none(*pgd)) {
32119 set_pgd(pgd, *pgd_ref);
32120 arch_flush_lazy_mmu_mode();
32121 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32122 static int is_errata100(struct pt_regs *regs, unsigned long address)
32123 {
32124 #ifdef CONFIG_X86_64
32125 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32126 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32127 return 1;
32128 #endif
32129 return 0;
32130 @@ -576,7 +660,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32131 }
32132
32133 static const char nx_warning[] = KERN_CRIT
32134 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32135 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32136
32137 static void
32138 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32139 @@ -585,7 +669,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32140 if (!oops_may_print())
32141 return;
32142
32143 - if (error_code & PF_INSTR) {
32144 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32145 unsigned int level;
32146 pgd_t *pgd;
32147 pte_t *pte;
32148 @@ -596,9 +680,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32149 pte = lookup_address_in_pgd(pgd, address, &level);
32150
32151 if (pte && pte_present(*pte) && !pte_exec(*pte))
32152 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32153 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32154 }
32155
32156 +#ifdef CONFIG_PAX_KERNEXEC
32157 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32158 + if (current->signal->curr_ip)
32159 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32160 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32161 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32162 + else
32163 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32164 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32165 + }
32166 +#endif
32167 +
32168 printk(KERN_ALERT "BUG: unable to handle kernel ");
32169 if (address < PAGE_SIZE)
32170 printk(KERN_CONT "NULL pointer dereference");
32171 @@ -779,6 +875,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32172 return;
32173 }
32174 #endif
32175 +
32176 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32177 + if (pax_is_fetch_fault(regs, error_code, address)) {
32178 +
32179 +#ifdef CONFIG_PAX_EMUTRAMP
32180 + switch (pax_handle_fetch_fault(regs)) {
32181 + case 2:
32182 + return;
32183 + }
32184 +#endif
32185 +
32186 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32187 + do_group_exit(SIGKILL);
32188 + }
32189 +#endif
32190 +
32191 /* Kernel addresses are always protection faults: */
32192 if (address >= TASK_SIZE)
32193 error_code |= PF_PROT;
32194 @@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32195 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32196 printk(KERN_ERR
32197 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32198 - tsk->comm, tsk->pid, address);
32199 + tsk->comm, task_pid_nr(tsk), address);
32200 code = BUS_MCEERR_AR;
32201 }
32202 #endif
32203 @@ -918,6 +1030,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32204 return 1;
32205 }
32206
32207 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32208 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32209 +{
32210 + pte_t *pte;
32211 + pmd_t *pmd;
32212 + spinlock_t *ptl;
32213 + unsigned char pte_mask;
32214 +
32215 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32216 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32217 + return 0;
32218 +
32219 + /* PaX: it's our fault, let's handle it if we can */
32220 +
32221 + /* PaX: take a look at read faults before acquiring any locks */
32222 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32223 + /* instruction fetch attempt from a protected page in user mode */
32224 + up_read(&mm->mmap_sem);
32225 +
32226 +#ifdef CONFIG_PAX_EMUTRAMP
32227 + switch (pax_handle_fetch_fault(regs)) {
32228 + case 2:
32229 + return 1;
32230 + }
32231 +#endif
32232 +
32233 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32234 + do_group_exit(SIGKILL);
32235 + }
32236 +
32237 + pmd = pax_get_pmd(mm, address);
32238 + if (unlikely(!pmd))
32239 + return 0;
32240 +
32241 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32242 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32243 + pte_unmap_unlock(pte, ptl);
32244 + return 0;
32245 + }
32246 +
32247 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32248 + /* write attempt to a protected page in user mode */
32249 + pte_unmap_unlock(pte, ptl);
32250 + return 0;
32251 + }
32252 +
32253 +#ifdef CONFIG_SMP
32254 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32255 +#else
32256 + if (likely(address > get_limit(regs->cs)))
32257 +#endif
32258 + {
32259 + set_pte(pte, pte_mkread(*pte));
32260 + __flush_tlb_one(address);
32261 + pte_unmap_unlock(pte, ptl);
32262 + up_read(&mm->mmap_sem);
32263 + return 1;
32264 + }
32265 +
32266 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32267 +
32268 + /*
32269 + * PaX: fill DTLB with user rights and retry
32270 + */
32271 + __asm__ __volatile__ (
32272 + "orb %2,(%1)\n"
32273 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32274 +/*
32275 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32276 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32277 + * page fault when examined during a TLB load attempt. this is true not only
32278 + * for PTEs holding a non-present entry but also present entries that will
32279 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32280 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32281 + * for our target pages since their PTEs are simply not in the TLBs at all.
32282 +
32283 + * the best thing in omitting it is that we gain around 15-20% speed in the
32284 + * fast path of the page fault handler and can get rid of tracing since we
32285 + * can no longer flush unintended entries.
32286 + */
32287 + "invlpg (%0)\n"
32288 +#endif
32289 + __copyuser_seg"testb $0,(%0)\n"
32290 + "xorb %3,(%1)\n"
32291 + :
32292 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32293 + : "memory", "cc");
32294 + pte_unmap_unlock(pte, ptl);
32295 + up_read(&mm->mmap_sem);
32296 + return 1;
32297 +}
32298 +#endif
32299 +
32300 /*
32301 * Handle a spurious fault caused by a stale TLB entry.
32302 *
32303 @@ -985,6 +1190,9 @@ int show_unhandled_signals = 1;
32304 static inline int
32305 access_error(unsigned long error_code, struct vm_area_struct *vma)
32306 {
32307 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32308 + return 1;
32309 +
32310 if (error_code & PF_WRITE) {
32311 /* write, present and write, not present: */
32312 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32313 @@ -1019,7 +1227,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32314 if (error_code & PF_USER)
32315 return false;
32316
32317 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32318 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32319 return false;
32320
32321 return true;
32322 @@ -1047,6 +1255,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32323 tsk = current;
32324 mm = tsk->mm;
32325
32326 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32327 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32328 + if (!search_exception_tables(regs->ip)) {
32329 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32330 + bad_area_nosemaphore(regs, error_code, address);
32331 + return;
32332 + }
32333 + if (address < pax_user_shadow_base) {
32334 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32335 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32336 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32337 + } else
32338 + address -= pax_user_shadow_base;
32339 + }
32340 +#endif
32341 +
32342 /*
32343 * Detect and handle instructions that would cause a page fault for
32344 * both a tracked kernel page and a userspace page.
32345 @@ -1124,7 +1348,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32346 * User-mode registers count as a user access even for any
32347 * potential system fault or CPU buglet:
32348 */
32349 - if (user_mode_vm(regs)) {
32350 + if (user_mode(regs)) {
32351 local_irq_enable();
32352 error_code |= PF_USER;
32353 flags |= FAULT_FLAG_USER;
32354 @@ -1171,6 +1395,11 @@ retry:
32355 might_sleep();
32356 }
32357
32358 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32359 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32360 + return;
32361 +#endif
32362 +
32363 vma = find_vma(mm, address);
32364 if (unlikely(!vma)) {
32365 bad_area(regs, error_code, address);
32366 @@ -1182,18 +1411,24 @@ retry:
32367 bad_area(regs, error_code, address);
32368 return;
32369 }
32370 - if (error_code & PF_USER) {
32371 - /*
32372 - * Accessing the stack below %sp is always a bug.
32373 - * The large cushion allows instructions like enter
32374 - * and pusha to work. ("enter $65535, $31" pushes
32375 - * 32 pointers and then decrements %sp by 65535.)
32376 - */
32377 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32378 - bad_area(regs, error_code, address);
32379 - return;
32380 - }
32381 + /*
32382 + * Accessing the stack below %sp is always a bug.
32383 + * The large cushion allows instructions like enter
32384 + * and pusha to work. ("enter $65535, $31" pushes
32385 + * 32 pointers and then decrements %sp by 65535.)
32386 + */
32387 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32388 + bad_area(regs, error_code, address);
32389 + return;
32390 }
32391 +
32392 +#ifdef CONFIG_PAX_SEGMEXEC
32393 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32394 + bad_area(regs, error_code, address);
32395 + return;
32396 + }
32397 +#endif
32398 +
32399 if (unlikely(expand_stack(vma, address))) {
32400 bad_area(regs, error_code, address);
32401 return;
32402 @@ -1309,3 +1544,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32403 }
32404 NOKPROBE_SYMBOL(trace_do_page_fault);
32405 #endif /* CONFIG_TRACING */
32406 +
32407 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32408 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32409 +{
32410 + struct mm_struct *mm = current->mm;
32411 + unsigned long ip = regs->ip;
32412 +
32413 + if (v8086_mode(regs))
32414 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32415 +
32416 +#ifdef CONFIG_PAX_PAGEEXEC
32417 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32418 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32419 + return true;
32420 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32421 + return true;
32422 + return false;
32423 + }
32424 +#endif
32425 +
32426 +#ifdef CONFIG_PAX_SEGMEXEC
32427 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32428 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32429 + return true;
32430 + return false;
32431 + }
32432 +#endif
32433 +
32434 + return false;
32435 +}
32436 +#endif
32437 +
32438 +#ifdef CONFIG_PAX_EMUTRAMP
32439 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32440 +{
32441 + int err;
32442 +
32443 + do { /* PaX: libffi trampoline emulation */
32444 + unsigned char mov, jmp;
32445 + unsigned int addr1, addr2;
32446 +
32447 +#ifdef CONFIG_X86_64
32448 + if ((regs->ip + 9) >> 32)
32449 + break;
32450 +#endif
32451 +
32452 + err = get_user(mov, (unsigned char __user *)regs->ip);
32453 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32454 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32455 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32456 +
32457 + if (err)
32458 + break;
32459 +
32460 + if (mov == 0xB8 && jmp == 0xE9) {
32461 + regs->ax = addr1;
32462 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32463 + return 2;
32464 + }
32465 + } while (0);
32466 +
32467 + do { /* PaX: gcc trampoline emulation #1 */
32468 + unsigned char mov1, mov2;
32469 + unsigned short jmp;
32470 + unsigned int addr1, addr2;
32471 +
32472 +#ifdef CONFIG_X86_64
32473 + if ((regs->ip + 11) >> 32)
32474 + break;
32475 +#endif
32476 +
32477 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32478 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32479 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32480 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32481 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32482 +
32483 + if (err)
32484 + break;
32485 +
32486 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32487 + regs->cx = addr1;
32488 + regs->ax = addr2;
32489 + regs->ip = addr2;
32490 + return 2;
32491 + }
32492 + } while (0);
32493 +
32494 + do { /* PaX: gcc trampoline emulation #2 */
32495 + unsigned char mov, jmp;
32496 + unsigned int addr1, addr2;
32497 +
32498 +#ifdef CONFIG_X86_64
32499 + if ((regs->ip + 9) >> 32)
32500 + break;
32501 +#endif
32502 +
32503 + err = get_user(mov, (unsigned char __user *)regs->ip);
32504 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32505 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32506 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32507 +
32508 + if (err)
32509 + break;
32510 +
32511 + if (mov == 0xB9 && jmp == 0xE9) {
32512 + regs->cx = addr1;
32513 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32514 + return 2;
32515 + }
32516 + } while (0);
32517 +
32518 + return 1; /* PaX in action */
32519 +}
32520 +
32521 +#ifdef CONFIG_X86_64
32522 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32523 +{
32524 + int err;
32525 +
32526 + do { /* PaX: libffi trampoline emulation */
32527 + unsigned short mov1, mov2, jmp1;
32528 + unsigned char stcclc, jmp2;
32529 + unsigned long addr1, addr2;
32530 +
32531 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32532 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32533 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32534 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32535 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32536 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32537 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32538 +
32539 + if (err)
32540 + break;
32541 +
32542 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32543 + regs->r11 = addr1;
32544 + regs->r10 = addr2;
32545 + if (stcclc == 0xF8)
32546 + regs->flags &= ~X86_EFLAGS_CF;
32547 + else
32548 + regs->flags |= X86_EFLAGS_CF;
32549 + regs->ip = addr1;
32550 + return 2;
32551 + }
32552 + } while (0);
32553 +
32554 + do { /* PaX: gcc trampoline emulation #1 */
32555 + unsigned short mov1, mov2, jmp1;
32556 + unsigned char jmp2;
32557 + unsigned int addr1;
32558 + unsigned long addr2;
32559 +
32560 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32561 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32562 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32563 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32564 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32565 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32566 +
32567 + if (err)
32568 + break;
32569 +
32570 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32571 + regs->r11 = addr1;
32572 + regs->r10 = addr2;
32573 + regs->ip = addr1;
32574 + return 2;
32575 + }
32576 + } while (0);
32577 +
32578 + do { /* PaX: gcc trampoline emulation #2 */
32579 + unsigned short mov1, mov2, jmp1;
32580 + unsigned char jmp2;
32581 + unsigned long addr1, addr2;
32582 +
32583 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32584 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32585 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32586 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32587 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32588 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32589 +
32590 + if (err)
32591 + break;
32592 +
32593 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32594 + regs->r11 = addr1;
32595 + regs->r10 = addr2;
32596 + regs->ip = addr1;
32597 + return 2;
32598 + }
32599 + } while (0);
32600 +
32601 + return 1; /* PaX in action */
32602 +}
32603 +#endif
32604 +
32605 +/*
32606 + * PaX: decide what to do with offenders (regs->ip = fault address)
32607 + *
32608 + * returns 1 when task should be killed
32609 + * 2 when gcc trampoline was detected
32610 + */
32611 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32612 +{
32613 + if (v8086_mode(regs))
32614 + return 1;
32615 +
32616 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32617 + return 1;
32618 +
32619 +#ifdef CONFIG_X86_32
32620 + return pax_handle_fetch_fault_32(regs);
32621 +#else
32622 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32623 + return pax_handle_fetch_fault_32(regs);
32624 + else
32625 + return pax_handle_fetch_fault_64(regs);
32626 +#endif
32627 +}
32628 +#endif
32629 +
32630 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32631 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32632 +{
32633 + long i;
32634 +
32635 + printk(KERN_ERR "PAX: bytes at PC: ");
32636 + for (i = 0; i < 20; i++) {
32637 + unsigned char c;
32638 + if (get_user(c, (unsigned char __force_user *)pc+i))
32639 + printk(KERN_CONT "?? ");
32640 + else
32641 + printk(KERN_CONT "%02x ", c);
32642 + }
32643 + printk("\n");
32644 +
32645 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32646 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32647 + unsigned long c;
32648 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32649 +#ifdef CONFIG_X86_32
32650 + printk(KERN_CONT "???????? ");
32651 +#else
32652 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32653 + printk(KERN_CONT "???????? ???????? ");
32654 + else
32655 + printk(KERN_CONT "???????????????? ");
32656 +#endif
32657 + } else {
32658 +#ifdef CONFIG_X86_64
32659 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32660 + printk(KERN_CONT "%08x ", (unsigned int)c);
32661 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32662 + } else
32663 +#endif
32664 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32665 + }
32666 + }
32667 + printk("\n");
32668 +}
32669 +#endif
32670 +
32671 +/**
32672 + * probe_kernel_write(): safely attempt to write to a location
32673 + * @dst: address to write to
32674 + * @src: pointer to the data that shall be written
32675 + * @size: size of the data chunk
32676 + *
32677 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32678 + * happens, handle that and return -EFAULT.
32679 + */
32680 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32681 +{
32682 + long ret;
32683 + mm_segment_t old_fs = get_fs();
32684 +
32685 + set_fs(KERNEL_DS);
32686 + pagefault_disable();
32687 + pax_open_kernel();
32688 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32689 + pax_close_kernel();
32690 + pagefault_enable();
32691 + set_fs(old_fs);
32692 +
32693 + return ret ? -EFAULT : 0;
32694 +}
32695 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32696 index 207d9aef..69030980 100644
32697 --- a/arch/x86/mm/gup.c
32698 +++ b/arch/x86/mm/gup.c
32699 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32700 addr = start;
32701 len = (unsigned long) nr_pages << PAGE_SHIFT;
32702 end = start + len;
32703 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32704 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32705 (void __user *)start, len)))
32706 return 0;
32707
32708 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32709 goto slow_irqon;
32710 #endif
32711
32712 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32713 + (void __user *)start, len)))
32714 + return 0;
32715 +
32716 /*
32717 * XXX: batch / limit 'nr', to avoid large irq off latency
32718 * needs some instrumenting to determine the common sizes used by
32719 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32720 index 4500142..53a363c 100644
32721 --- a/arch/x86/mm/highmem_32.c
32722 +++ b/arch/x86/mm/highmem_32.c
32723 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32724 idx = type + KM_TYPE_NR*smp_processor_id();
32725 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32726 BUG_ON(!pte_none(*(kmap_pte-idx)));
32727 +
32728 + pax_open_kernel();
32729 set_pte(kmap_pte-idx, mk_pte(page, prot));
32730 + pax_close_kernel();
32731 +
32732 arch_flush_lazy_mmu_mode();
32733
32734 return (void *)vaddr;
32735 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32736 index 8b977eb..4732c33 100644
32737 --- a/arch/x86/mm/hugetlbpage.c
32738 +++ b/arch/x86/mm/hugetlbpage.c
32739 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32740 #ifdef CONFIG_HUGETLB_PAGE
32741 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32742 unsigned long addr, unsigned long len,
32743 - unsigned long pgoff, unsigned long flags)
32744 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32745 {
32746 struct hstate *h = hstate_file(file);
32747 struct vm_unmapped_area_info info;
32748 -
32749 +
32750 info.flags = 0;
32751 info.length = len;
32752 info.low_limit = current->mm->mmap_legacy_base;
32753 info.high_limit = TASK_SIZE;
32754 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32755 info.align_offset = 0;
32756 + info.threadstack_offset = offset;
32757 return vm_unmapped_area(&info);
32758 }
32759
32760 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32761 unsigned long addr0, unsigned long len,
32762 - unsigned long pgoff, unsigned long flags)
32763 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32764 {
32765 struct hstate *h = hstate_file(file);
32766 struct vm_unmapped_area_info info;
32767 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32768 info.high_limit = current->mm->mmap_base;
32769 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32770 info.align_offset = 0;
32771 + info.threadstack_offset = offset;
32772 addr = vm_unmapped_area(&info);
32773
32774 /*
32775 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32776 VM_BUG_ON(addr != -ENOMEM);
32777 info.flags = 0;
32778 info.low_limit = TASK_UNMAPPED_BASE;
32779 +
32780 +#ifdef CONFIG_PAX_RANDMMAP
32781 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32782 + info.low_limit += current->mm->delta_mmap;
32783 +#endif
32784 +
32785 info.high_limit = TASK_SIZE;
32786 addr = vm_unmapped_area(&info);
32787 }
32788 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32789 struct hstate *h = hstate_file(file);
32790 struct mm_struct *mm = current->mm;
32791 struct vm_area_struct *vma;
32792 + unsigned long pax_task_size = TASK_SIZE;
32793 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32794
32795 if (len & ~huge_page_mask(h))
32796 return -EINVAL;
32797 - if (len > TASK_SIZE)
32798 +
32799 +#ifdef CONFIG_PAX_SEGMEXEC
32800 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32801 + pax_task_size = SEGMEXEC_TASK_SIZE;
32802 +#endif
32803 +
32804 + pax_task_size -= PAGE_SIZE;
32805 +
32806 + if (len > pax_task_size)
32807 return -ENOMEM;
32808
32809 if (flags & MAP_FIXED) {
32810 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32811 return addr;
32812 }
32813
32814 +#ifdef CONFIG_PAX_RANDMMAP
32815 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32816 +#endif
32817 +
32818 if (addr) {
32819 addr = ALIGN(addr, huge_page_size(h));
32820 vma = find_vma(mm, addr);
32821 - if (TASK_SIZE - len >= addr &&
32822 - (!vma || addr + len <= vma->vm_start))
32823 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32824 return addr;
32825 }
32826 if (mm->get_unmapped_area == arch_get_unmapped_area)
32827 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32828 - pgoff, flags);
32829 + pgoff, flags, offset);
32830 else
32831 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32832 - pgoff, flags);
32833 + pgoff, flags, offset);
32834 }
32835 #endif /* CONFIG_HUGETLB_PAGE */
32836
32837 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32838 index f971306..e83e0f6 100644
32839 --- a/arch/x86/mm/init.c
32840 +++ b/arch/x86/mm/init.c
32841 @@ -4,6 +4,7 @@
32842 #include <linux/swap.h>
32843 #include <linux/memblock.h>
32844 #include <linux/bootmem.h> /* for max_low_pfn */
32845 +#include <linux/tboot.h>
32846
32847 #include <asm/cacheflush.h>
32848 #include <asm/e820.h>
32849 @@ -17,6 +18,8 @@
32850 #include <asm/proto.h>
32851 #include <asm/dma.h> /* for MAX_DMA_PFN */
32852 #include <asm/microcode.h>
32853 +#include <asm/desc.h>
32854 +#include <asm/bios_ebda.h>
32855
32856 #include "mm_internal.h"
32857
32858 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32859 early_ioremap_page_table_range_init();
32860 #endif
32861
32862 +#ifdef CONFIG_PAX_PER_CPU_PGD
32863 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32864 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32865 + KERNEL_PGD_PTRS);
32866 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32867 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32868 + KERNEL_PGD_PTRS);
32869 + load_cr3(get_cpu_pgd(0, kernel));
32870 +#else
32871 load_cr3(swapper_pg_dir);
32872 +#endif
32873 +
32874 __flush_tlb_all();
32875
32876 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32877 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32878 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32879 * mmio resources as well as potential bios/acpi data regions.
32880 */
32881 +
32882 +#ifdef CONFIG_GRKERNSEC_KMEM
32883 +static unsigned int ebda_start __read_only;
32884 +static unsigned int ebda_end __read_only;
32885 +#endif
32886 +
32887 int devmem_is_allowed(unsigned long pagenr)
32888 {
32889 - if (pagenr < 256)
32890 +#ifdef CONFIG_GRKERNSEC_KMEM
32891 + /* allow BDA */
32892 + if (!pagenr)
32893 return 1;
32894 + /* allow EBDA */
32895 + if (pagenr >= ebda_start && pagenr < ebda_end)
32896 + return 1;
32897 + /* if tboot is in use, allow access to its hardcoded serial log range */
32898 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32899 + return 1;
32900 +#else
32901 + if (!pagenr)
32902 + return 1;
32903 +#ifdef CONFIG_VM86
32904 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32905 + return 1;
32906 +#endif
32907 +#endif
32908 +
32909 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32910 + return 1;
32911 +#ifdef CONFIG_GRKERNSEC_KMEM
32912 + /* throw out everything else below 1MB */
32913 + if (pagenr <= 256)
32914 + return 0;
32915 +#endif
32916 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32917 return 0;
32918 if (!page_is_ram(pagenr))
32919 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32920 #endif
32921 }
32922
32923 +#ifdef CONFIG_GRKERNSEC_KMEM
32924 +static inline void gr_init_ebda(void)
32925 +{
32926 + unsigned int ebda_addr;
32927 + unsigned int ebda_size = 0;
32928 +
32929 + ebda_addr = get_bios_ebda();
32930 + if (ebda_addr) {
32931 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32932 + ebda_size <<= 10;
32933 + }
32934 + if (ebda_addr && ebda_size) {
32935 + ebda_start = ebda_addr >> PAGE_SHIFT;
32936 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32937 + } else {
32938 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32939 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32940 + }
32941 +}
32942 +#else
32943 +static inline void gr_init_ebda(void) { }
32944 +#endif
32945 +
32946 void free_initmem(void)
32947 {
32948 +#ifdef CONFIG_PAX_KERNEXEC
32949 +#ifdef CONFIG_X86_32
32950 + /* PaX: limit KERNEL_CS to actual size */
32951 + unsigned long addr, limit;
32952 + struct desc_struct d;
32953 + int cpu;
32954 +#else
32955 + pgd_t *pgd;
32956 + pud_t *pud;
32957 + pmd_t *pmd;
32958 + unsigned long addr, end;
32959 +#endif
32960 +#endif
32961 +
32962 + gr_init_ebda();
32963 +
32964 +#ifdef CONFIG_PAX_KERNEXEC
32965 +#ifdef CONFIG_X86_32
32966 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32967 + limit = (limit - 1UL) >> PAGE_SHIFT;
32968 +
32969 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32970 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32971 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32972 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32973 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32974 + }
32975 +
32976 + /* PaX: make KERNEL_CS read-only */
32977 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32978 + if (!paravirt_enabled())
32979 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32980 +/*
32981 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32982 + pgd = pgd_offset_k(addr);
32983 + pud = pud_offset(pgd, addr);
32984 + pmd = pmd_offset(pud, addr);
32985 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32986 + }
32987 +*/
32988 +#ifdef CONFIG_X86_PAE
32989 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32990 +/*
32991 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32992 + pgd = pgd_offset_k(addr);
32993 + pud = pud_offset(pgd, addr);
32994 + pmd = pmd_offset(pud, addr);
32995 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32996 + }
32997 +*/
32998 +#endif
32999 +
33000 +#ifdef CONFIG_MODULES
33001 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33002 +#endif
33003 +
33004 +#else
33005 + /* PaX: make kernel code/rodata read-only, rest non-executable */
33006 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33007 + pgd = pgd_offset_k(addr);
33008 + pud = pud_offset(pgd, addr);
33009 + pmd = pmd_offset(pud, addr);
33010 + if (!pmd_present(*pmd))
33011 + continue;
33012 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33013 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33014 + else
33015 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33016 + }
33017 +
33018 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33019 + end = addr + KERNEL_IMAGE_SIZE;
33020 + for (; addr < end; addr += PMD_SIZE) {
33021 + pgd = pgd_offset_k(addr);
33022 + pud = pud_offset(pgd, addr);
33023 + pmd = pmd_offset(pud, addr);
33024 + if (!pmd_present(*pmd))
33025 + continue;
33026 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33027 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33028 + }
33029 +#endif
33030 +
33031 + flush_tlb_all();
33032 +#endif
33033 +
33034 free_init_pages("unused kernel",
33035 (unsigned long)(&__init_begin),
33036 (unsigned long)(&__init_end));
33037 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33038 index e395048..cd38278 100644
33039 --- a/arch/x86/mm/init_32.c
33040 +++ b/arch/x86/mm/init_32.c
33041 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33042 bool __read_mostly __vmalloc_start_set = false;
33043
33044 /*
33045 - * Creates a middle page table and puts a pointer to it in the
33046 - * given global directory entry. This only returns the gd entry
33047 - * in non-PAE compilation mode, since the middle layer is folded.
33048 - */
33049 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33050 -{
33051 - pud_t *pud;
33052 - pmd_t *pmd_table;
33053 -
33054 -#ifdef CONFIG_X86_PAE
33055 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33056 - pmd_table = (pmd_t *)alloc_low_page();
33057 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33058 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33059 - pud = pud_offset(pgd, 0);
33060 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33061 -
33062 - return pmd_table;
33063 - }
33064 -#endif
33065 - pud = pud_offset(pgd, 0);
33066 - pmd_table = pmd_offset(pud, 0);
33067 -
33068 - return pmd_table;
33069 -}
33070 -
33071 -/*
33072 * Create a page table and place a pointer to it in a middle page
33073 * directory entry:
33074 */
33075 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33076 pte_t *page_table = (pte_t *)alloc_low_page();
33077
33078 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33079 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33080 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33081 +#else
33082 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33083 +#endif
33084 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33085 }
33086
33087 return pte_offset_kernel(pmd, 0);
33088 }
33089
33090 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33091 +{
33092 + pud_t *pud;
33093 + pmd_t *pmd_table;
33094 +
33095 + pud = pud_offset(pgd, 0);
33096 + pmd_table = pmd_offset(pud, 0);
33097 +
33098 + return pmd_table;
33099 +}
33100 +
33101 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33102 {
33103 int pgd_idx = pgd_index(vaddr);
33104 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33105 int pgd_idx, pmd_idx;
33106 unsigned long vaddr;
33107 pgd_t *pgd;
33108 + pud_t *pud;
33109 pmd_t *pmd;
33110 pte_t *pte = NULL;
33111 unsigned long count = page_table_range_init_count(start, end);
33112 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33113 pgd = pgd_base + pgd_idx;
33114
33115 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33116 - pmd = one_md_table_init(pgd);
33117 - pmd = pmd + pmd_index(vaddr);
33118 + pud = pud_offset(pgd, vaddr);
33119 + pmd = pmd_offset(pud, vaddr);
33120 +
33121 +#ifdef CONFIG_X86_PAE
33122 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33123 +#endif
33124 +
33125 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33126 pmd++, pmd_idx++) {
33127 pte = page_table_kmap_check(one_page_table_init(pmd),
33128 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33129 }
33130 }
33131
33132 -static inline int is_kernel_text(unsigned long addr)
33133 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33134 {
33135 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33136 - return 1;
33137 - return 0;
33138 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33139 + end <= ktla_ktva((unsigned long)_stext)) &&
33140 + (start >= ktla_ktva((unsigned long)_einittext) ||
33141 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33142 +
33143 +#ifdef CONFIG_ACPI_SLEEP
33144 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33145 +#endif
33146 +
33147 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33148 + return 0;
33149 + return 1;
33150 }
33151
33152 /*
33153 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33154 unsigned long last_map_addr = end;
33155 unsigned long start_pfn, end_pfn;
33156 pgd_t *pgd_base = swapper_pg_dir;
33157 - int pgd_idx, pmd_idx, pte_ofs;
33158 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33159 unsigned long pfn;
33160 pgd_t *pgd;
33161 + pud_t *pud;
33162 pmd_t *pmd;
33163 pte_t *pte;
33164 unsigned pages_2m, pages_4k;
33165 @@ -291,8 +295,13 @@ repeat:
33166 pfn = start_pfn;
33167 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33168 pgd = pgd_base + pgd_idx;
33169 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33170 - pmd = one_md_table_init(pgd);
33171 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33172 + pud = pud_offset(pgd, 0);
33173 + pmd = pmd_offset(pud, 0);
33174 +
33175 +#ifdef CONFIG_X86_PAE
33176 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33177 +#endif
33178
33179 if (pfn >= end_pfn)
33180 continue;
33181 @@ -304,14 +313,13 @@ repeat:
33182 #endif
33183 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33184 pmd++, pmd_idx++) {
33185 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33186 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33187
33188 /*
33189 * Map with big pages if possible, otherwise
33190 * create normal page tables:
33191 */
33192 if (use_pse) {
33193 - unsigned int addr2;
33194 pgprot_t prot = PAGE_KERNEL_LARGE;
33195 /*
33196 * first pass will use the same initial
33197 @@ -322,11 +330,7 @@ repeat:
33198 _PAGE_PSE);
33199
33200 pfn &= PMD_MASK >> PAGE_SHIFT;
33201 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33202 - PAGE_OFFSET + PAGE_SIZE-1;
33203 -
33204 - if (is_kernel_text(addr) ||
33205 - is_kernel_text(addr2))
33206 + if (is_kernel_text(address, address + PMD_SIZE))
33207 prot = PAGE_KERNEL_LARGE_EXEC;
33208
33209 pages_2m++;
33210 @@ -343,7 +347,7 @@ repeat:
33211 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33212 pte += pte_ofs;
33213 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33214 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33215 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33216 pgprot_t prot = PAGE_KERNEL;
33217 /*
33218 * first pass will use the same initial
33219 @@ -351,7 +355,7 @@ repeat:
33220 */
33221 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33222
33223 - if (is_kernel_text(addr))
33224 + if (is_kernel_text(address, address + PAGE_SIZE))
33225 prot = PAGE_KERNEL_EXEC;
33226
33227 pages_4k++;
33228 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33229
33230 pud = pud_offset(pgd, va);
33231 pmd = pmd_offset(pud, va);
33232 - if (!pmd_present(*pmd))
33233 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33234 break;
33235
33236 /* should not be large page here */
33237 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33238
33239 static void __init pagetable_init(void)
33240 {
33241 - pgd_t *pgd_base = swapper_pg_dir;
33242 -
33243 - permanent_kmaps_init(pgd_base);
33244 + permanent_kmaps_init(swapper_pg_dir);
33245 }
33246
33247 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33248 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33249 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33250
33251 /* user-defined highmem size */
33252 @@ -787,10 +789,10 @@ void __init mem_init(void)
33253 ((unsigned long)&__init_end -
33254 (unsigned long)&__init_begin) >> 10,
33255
33256 - (unsigned long)&_etext, (unsigned long)&_edata,
33257 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33258 + (unsigned long)&_sdata, (unsigned long)&_edata,
33259 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33260
33261 - (unsigned long)&_text, (unsigned long)&_etext,
33262 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33263 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33264
33265 /*
33266 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
33267 if (!kernel_set_to_readonly)
33268 return;
33269
33270 + start = ktla_ktva(start);
33271 pr_debug("Set kernel text: %lx - %lx for read write\n",
33272 start, start+size);
33273
33274 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
33275 if (!kernel_set_to_readonly)
33276 return;
33277
33278 + start = ktla_ktva(start);
33279 pr_debug("Set kernel text: %lx - %lx for read only\n",
33280 start, start+size);
33281
33282 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33283 unsigned long start = PFN_ALIGN(_text);
33284 unsigned long size = PFN_ALIGN(_etext) - start;
33285
33286 + start = ktla_ktva(start);
33287 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33288 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33289 size >> 10);
33290 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33291 index df1a992..94c272c 100644
33292 --- a/arch/x86/mm/init_64.c
33293 +++ b/arch/x86/mm/init_64.c
33294 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33295 * around without checking the pgd every time.
33296 */
33297
33298 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33299 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33300 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33301
33302 int force_personality32;
33303 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33304
33305 for (address = start; address <= end; address += PGDIR_SIZE) {
33306 const pgd_t *pgd_ref = pgd_offset_k(address);
33307 +
33308 +#ifdef CONFIG_PAX_PER_CPU_PGD
33309 + unsigned long cpu;
33310 +#else
33311 struct page *page;
33312 +#endif
33313
33314 if (pgd_none(*pgd_ref))
33315 continue;
33316
33317 spin_lock(&pgd_lock);
33318 +
33319 +#ifdef CONFIG_PAX_PER_CPU_PGD
33320 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33321 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33322 +
33323 + if (pgd_none(*pgd))
33324 + set_pgd(pgd, *pgd_ref);
33325 + else
33326 + BUG_ON(pgd_page_vaddr(*pgd)
33327 + != pgd_page_vaddr(*pgd_ref));
33328 + pgd = pgd_offset_cpu(cpu, kernel, address);
33329 +#else
33330 list_for_each_entry(page, &pgd_list, lru) {
33331 pgd_t *pgd;
33332 spinlock_t *pgt_lock;
33333 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33334 /* the pgt_lock only for Xen */
33335 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33336 spin_lock(pgt_lock);
33337 +#endif
33338
33339 if (pgd_none(*pgd))
33340 set_pgd(pgd, *pgd_ref);
33341 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33342 BUG_ON(pgd_page_vaddr(*pgd)
33343 != pgd_page_vaddr(*pgd_ref));
33344
33345 +#ifndef CONFIG_PAX_PER_CPU_PGD
33346 spin_unlock(pgt_lock);
33347 +#endif
33348 +
33349 }
33350 spin_unlock(&pgd_lock);
33351 }
33352 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33353 {
33354 if (pgd_none(*pgd)) {
33355 pud_t *pud = (pud_t *)spp_getpage();
33356 - pgd_populate(&init_mm, pgd, pud);
33357 + pgd_populate_kernel(&init_mm, pgd, pud);
33358 if (pud != pud_offset(pgd, 0))
33359 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33360 pud, pud_offset(pgd, 0));
33361 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33362 {
33363 if (pud_none(*pud)) {
33364 pmd_t *pmd = (pmd_t *) spp_getpage();
33365 - pud_populate(&init_mm, pud, pmd);
33366 + pud_populate_kernel(&init_mm, pud, pmd);
33367 if (pmd != pmd_offset(pud, 0))
33368 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33369 pmd, pmd_offset(pud, 0));
33370 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33371 pmd = fill_pmd(pud, vaddr);
33372 pte = fill_pte(pmd, vaddr);
33373
33374 + pax_open_kernel();
33375 set_pte(pte, new_pte);
33376 + pax_close_kernel();
33377
33378 /*
33379 * It's enough to flush this one mapping.
33380 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33381 pgd = pgd_offset_k((unsigned long)__va(phys));
33382 if (pgd_none(*pgd)) {
33383 pud = (pud_t *) spp_getpage();
33384 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33385 - _PAGE_USER));
33386 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33387 }
33388 pud = pud_offset(pgd, (unsigned long)__va(phys));
33389 if (pud_none(*pud)) {
33390 pmd = (pmd_t *) spp_getpage();
33391 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33392 - _PAGE_USER));
33393 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33394 }
33395 pmd = pmd_offset(pud, phys);
33396 BUG_ON(!pmd_none(*pmd));
33397 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33398 prot);
33399
33400 spin_lock(&init_mm.page_table_lock);
33401 - pud_populate(&init_mm, pud, pmd);
33402 + pud_populate_kernel(&init_mm, pud, pmd);
33403 spin_unlock(&init_mm.page_table_lock);
33404 }
33405 __flush_tlb_all();
33406 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33407 page_size_mask);
33408
33409 spin_lock(&init_mm.page_table_lock);
33410 - pgd_populate(&init_mm, pgd, pud);
33411 + pgd_populate_kernel(&init_mm, pgd, pud);
33412 spin_unlock(&init_mm.page_table_lock);
33413 pgd_changed = true;
33414 }
33415 @@ -1195,8 +1216,8 @@ static struct vm_operations_struct gate_vma_ops = {
33416 static struct vm_area_struct gate_vma = {
33417 .vm_start = VSYSCALL_ADDR,
33418 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33419 - .vm_page_prot = PAGE_READONLY_EXEC,
33420 - .vm_flags = VM_READ | VM_EXEC,
33421 + .vm_page_prot = PAGE_READONLY,
33422 + .vm_flags = VM_READ,
33423 .vm_ops = &gate_vma_ops,
33424 };
33425
33426 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33427 index 7b179b4..6bd17777 100644
33428 --- a/arch/x86/mm/iomap_32.c
33429 +++ b/arch/x86/mm/iomap_32.c
33430 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33431 type = kmap_atomic_idx_push();
33432 idx = type + KM_TYPE_NR * smp_processor_id();
33433 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33434 +
33435 + pax_open_kernel();
33436 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33437 + pax_close_kernel();
33438 +
33439 arch_flush_lazy_mmu_mode();
33440
33441 return (void *)vaddr;
33442 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33443 index baff1da..2816ef4 100644
33444 --- a/arch/x86/mm/ioremap.c
33445 +++ b/arch/x86/mm/ioremap.c
33446 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33447 unsigned long i;
33448
33449 for (i = 0; i < nr_pages; ++i)
33450 - if (pfn_valid(start_pfn + i) &&
33451 - !PageReserved(pfn_to_page(start_pfn + i)))
33452 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33453 + !PageReserved(pfn_to_page(start_pfn + i))))
33454 return 1;
33455
33456 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33457 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33458 *
33459 * Caller must ensure there is only one unmapping for the same pointer.
33460 */
33461 -void iounmap(volatile void __iomem *addr)
33462 +void iounmap(const volatile void __iomem *addr)
33463 {
33464 struct vm_struct *p, *o;
33465
33466 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33467
33468 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33469 if (page_is_ram(start >> PAGE_SHIFT))
33470 +#ifdef CONFIG_HIGHMEM
33471 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33472 +#endif
33473 return __va(phys);
33474
33475 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33476 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33477 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33478 {
33479 if (page_is_ram(phys >> PAGE_SHIFT))
33480 +#ifdef CONFIG_HIGHMEM
33481 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33482 +#endif
33483 return;
33484
33485 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33486 return;
33487 }
33488
33489 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33490 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33491
33492 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33493 {
33494 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33495 early_ioremap_setup();
33496
33497 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33498 - memset(bm_pte, 0, sizeof(bm_pte));
33499 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33500 + pmd_populate_user(&init_mm, pmd, bm_pte);
33501
33502 /*
33503 * The boot-ioremap range spans multiple pmds, for which
33504 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33505 index dd89a13..d77bdcc 100644
33506 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33507 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33508 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33509 * memory (e.g. tracked pages)? For now, we need this to avoid
33510 * invoking kmemcheck for PnP BIOS calls.
33511 */
33512 - if (regs->flags & X86_VM_MASK)
33513 + if (v8086_mode(regs))
33514 return false;
33515 - if (regs->cs != __KERNEL_CS)
33516 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33517 return false;
33518
33519 pte = kmemcheck_pte_lookup(address);
33520 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33521 index 25e7e13..1964579 100644
33522 --- a/arch/x86/mm/mmap.c
33523 +++ b/arch/x86/mm/mmap.c
33524 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33525 * Leave an at least ~128 MB hole with possible stack randomization.
33526 */
33527 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33528 -#define MAX_GAP (TASK_SIZE/6*5)
33529 +#define MAX_GAP (pax_task_size/6*5)
33530
33531 static int mmap_is_legacy(void)
33532 {
33533 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33534 return rnd << PAGE_SHIFT;
33535 }
33536
33537 -static unsigned long mmap_base(void)
33538 +static unsigned long mmap_base(struct mm_struct *mm)
33539 {
33540 unsigned long gap = rlimit(RLIMIT_STACK);
33541 + unsigned long pax_task_size = TASK_SIZE;
33542 +
33543 +#ifdef CONFIG_PAX_SEGMEXEC
33544 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33545 + pax_task_size = SEGMEXEC_TASK_SIZE;
33546 +#endif
33547
33548 if (gap < MIN_GAP)
33549 gap = MIN_GAP;
33550 else if (gap > MAX_GAP)
33551 gap = MAX_GAP;
33552
33553 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33554 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33555 }
33556
33557 /*
33558 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33559 * does, but not when emulating X86_32
33560 */
33561 -static unsigned long mmap_legacy_base(void)
33562 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33563 {
33564 - if (mmap_is_ia32())
33565 + if (mmap_is_ia32()) {
33566 +
33567 +#ifdef CONFIG_PAX_SEGMEXEC
33568 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33569 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33570 + else
33571 +#endif
33572 +
33573 return TASK_UNMAPPED_BASE;
33574 - else
33575 + } else
33576 return TASK_UNMAPPED_BASE + mmap_rnd();
33577 }
33578
33579 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33580 */
33581 void arch_pick_mmap_layout(struct mm_struct *mm)
33582 {
33583 - mm->mmap_legacy_base = mmap_legacy_base();
33584 - mm->mmap_base = mmap_base();
33585 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33586 + mm->mmap_base = mmap_base(mm);
33587 +
33588 +#ifdef CONFIG_PAX_RANDMMAP
33589 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33590 + mm->mmap_legacy_base += mm->delta_mmap;
33591 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33592 + }
33593 +#endif
33594
33595 if (mmap_is_legacy()) {
33596 mm->mmap_base = mm->mmap_legacy_base;
33597 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33598 index 0057a7a..95c7edd 100644
33599 --- a/arch/x86/mm/mmio-mod.c
33600 +++ b/arch/x86/mm/mmio-mod.c
33601 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33602 break;
33603 default:
33604 {
33605 - unsigned char *ip = (unsigned char *)instptr;
33606 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33607 my_trace->opcode = MMIO_UNKNOWN_OP;
33608 my_trace->width = 0;
33609 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33610 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33611 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33612 void __iomem *addr)
33613 {
33614 - static atomic_t next_id;
33615 + static atomic_unchecked_t next_id;
33616 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33617 /* These are page-unaligned. */
33618 struct mmiotrace_map map = {
33619 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33620 .private = trace
33621 },
33622 .phys = offset,
33623 - .id = atomic_inc_return(&next_id)
33624 + .id = atomic_inc_return_unchecked(&next_id)
33625 };
33626 map.map_id = trace->id;
33627
33628 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33629 ioremap_trace_core(offset, size, addr);
33630 }
33631
33632 -static void iounmap_trace_core(volatile void __iomem *addr)
33633 +static void iounmap_trace_core(const volatile void __iomem *addr)
33634 {
33635 struct mmiotrace_map map = {
33636 .phys = 0,
33637 @@ -328,7 +328,7 @@ not_enabled:
33638 }
33639 }
33640
33641 -void mmiotrace_iounmap(volatile void __iomem *addr)
33642 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33643 {
33644 might_sleep();
33645 if (is_enabled()) /* recheck and proper locking in *_core() */
33646 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33647 index a32b706..efb308b 100644
33648 --- a/arch/x86/mm/numa.c
33649 +++ b/arch/x86/mm/numa.c
33650 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33651 return true;
33652 }
33653
33654 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33655 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33656 {
33657 unsigned long uninitialized_var(pfn_align);
33658 int i, nid;
33659 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33660 index ae242a7..1c7998f 100644
33661 --- a/arch/x86/mm/pageattr.c
33662 +++ b/arch/x86/mm/pageattr.c
33663 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33664 */
33665 #ifdef CONFIG_PCI_BIOS
33666 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33667 - pgprot_val(forbidden) |= _PAGE_NX;
33668 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33669 #endif
33670
33671 /*
33672 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33673 * Does not cover __inittext since that is gone later on. On
33674 * 64bit we do not enforce !NX on the low mapping
33675 */
33676 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33677 - pgprot_val(forbidden) |= _PAGE_NX;
33678 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33679 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33680
33681 +#ifdef CONFIG_DEBUG_RODATA
33682 /*
33683 * The .rodata section needs to be read-only. Using the pfn
33684 * catches all aliases.
33685 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33686 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33687 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33688 pgprot_val(forbidden) |= _PAGE_RW;
33689 +#endif
33690
33691 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33692 /*
33693 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33694 }
33695 #endif
33696
33697 +#ifdef CONFIG_PAX_KERNEXEC
33698 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33699 + pgprot_val(forbidden) |= _PAGE_RW;
33700 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33701 + }
33702 +#endif
33703 +
33704 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33705
33706 return prot;
33707 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33708 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33709 {
33710 /* change init_mm */
33711 + pax_open_kernel();
33712 set_pte_atomic(kpte, pte);
33713 +
33714 #ifdef CONFIG_X86_32
33715 if (!SHARED_KERNEL_PMD) {
33716 +
33717 +#ifdef CONFIG_PAX_PER_CPU_PGD
33718 + unsigned long cpu;
33719 +#else
33720 struct page *page;
33721 +#endif
33722
33723 +#ifdef CONFIG_PAX_PER_CPU_PGD
33724 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33725 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33726 +#else
33727 list_for_each_entry(page, &pgd_list, lru) {
33728 - pgd_t *pgd;
33729 + pgd_t *pgd = (pgd_t *)page_address(page);
33730 +#endif
33731 +
33732 pud_t *pud;
33733 pmd_t *pmd;
33734
33735 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33736 + pgd += pgd_index(address);
33737 pud = pud_offset(pgd, address);
33738 pmd = pmd_offset(pud, address);
33739 set_pte_atomic((pte_t *)pmd, pte);
33740 }
33741 }
33742 #endif
33743 + pax_close_kernel();
33744 }
33745
33746 static int
33747 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33748 index 6574388..87e9bef 100644
33749 --- a/arch/x86/mm/pat.c
33750 +++ b/arch/x86/mm/pat.c
33751 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33752
33753 if (!entry) {
33754 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33755 - current->comm, current->pid, start, end - 1);
33756 + current->comm, task_pid_nr(current), start, end - 1);
33757 return -EINVAL;
33758 }
33759
33760 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33761
33762 while (cursor < to) {
33763 if (!devmem_is_allowed(pfn)) {
33764 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33765 - current->comm, from, to - 1);
33766 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33767 + current->comm, from, to - 1, cursor);
33768 return 0;
33769 }
33770 cursor += PAGE_SIZE;
33771 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33772 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33773 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33774 "for [mem %#010Lx-%#010Lx]\n",
33775 - current->comm, current->pid,
33776 + current->comm, task_pid_nr(current),
33777 cattr_name(flags),
33778 base, (unsigned long long)(base + size-1));
33779 return -EINVAL;
33780 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33781 flags = lookup_memtype(paddr);
33782 if (want_flags != flags) {
33783 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33784 - current->comm, current->pid,
33785 + current->comm, task_pid_nr(current),
33786 cattr_name(want_flags),
33787 (unsigned long long)paddr,
33788 (unsigned long long)(paddr + size - 1),
33789 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33790 free_memtype(paddr, paddr + size);
33791 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33792 " for [mem %#010Lx-%#010Lx], got %s\n",
33793 - current->comm, current->pid,
33794 + current->comm, task_pid_nr(current),
33795 cattr_name(want_flags),
33796 (unsigned long long)paddr,
33797 (unsigned long long)(paddr + size - 1),
33798 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33799 index 415f6c4..d319983 100644
33800 --- a/arch/x86/mm/pat_rbtree.c
33801 +++ b/arch/x86/mm/pat_rbtree.c
33802 @@ -160,7 +160,7 @@ success:
33803
33804 failure:
33805 printk(KERN_INFO "%s:%d conflicting memory types "
33806 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33807 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33808 end, cattr_name(found_type), cattr_name(match->type));
33809 return -EBUSY;
33810 }
33811 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33812 index 9f0614d..92ae64a 100644
33813 --- a/arch/x86/mm/pf_in.c
33814 +++ b/arch/x86/mm/pf_in.c
33815 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33816 int i;
33817 enum reason_type rv = OTHERS;
33818
33819 - p = (unsigned char *)ins_addr;
33820 + p = (unsigned char *)ktla_ktva(ins_addr);
33821 p += skip_prefix(p, &prf);
33822 p += get_opcode(p, &opcode);
33823
33824 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33825 struct prefix_bits prf;
33826 int i;
33827
33828 - p = (unsigned char *)ins_addr;
33829 + p = (unsigned char *)ktla_ktva(ins_addr);
33830 p += skip_prefix(p, &prf);
33831 p += get_opcode(p, &opcode);
33832
33833 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33834 struct prefix_bits prf;
33835 int i;
33836
33837 - p = (unsigned char *)ins_addr;
33838 + p = (unsigned char *)ktla_ktva(ins_addr);
33839 p += skip_prefix(p, &prf);
33840 p += get_opcode(p, &opcode);
33841
33842 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33843 struct prefix_bits prf;
33844 int i;
33845
33846 - p = (unsigned char *)ins_addr;
33847 + p = (unsigned char *)ktla_ktva(ins_addr);
33848 p += skip_prefix(p, &prf);
33849 p += get_opcode(p, &opcode);
33850 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33851 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33852 struct prefix_bits prf;
33853 int i;
33854
33855 - p = (unsigned char *)ins_addr;
33856 + p = (unsigned char *)ktla_ktva(ins_addr);
33857 p += skip_prefix(p, &prf);
33858 p += get_opcode(p, &opcode);
33859 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33860 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33861 index 6fb6927..4fc13c0 100644
33862 --- a/arch/x86/mm/pgtable.c
33863 +++ b/arch/x86/mm/pgtable.c
33864 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33865 list_del(&page->lru);
33866 }
33867
33868 -#define UNSHARED_PTRS_PER_PGD \
33869 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33870 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33871 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33872
33873 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33874 +{
33875 + unsigned int count = USER_PGD_PTRS;
33876
33877 + if (!pax_user_shadow_base)
33878 + return;
33879 +
33880 + while (count--)
33881 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33882 +}
33883 +#endif
33884 +
33885 +#ifdef CONFIG_PAX_PER_CPU_PGD
33886 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33887 +{
33888 + unsigned int count = USER_PGD_PTRS;
33889 +
33890 + while (count--) {
33891 + pgd_t pgd;
33892 +
33893 +#ifdef CONFIG_X86_64
33894 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33895 +#else
33896 + pgd = *src++;
33897 +#endif
33898 +
33899 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33900 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33901 +#endif
33902 +
33903 + *dst++ = pgd;
33904 + }
33905 +
33906 +}
33907 +#endif
33908 +
33909 +#ifdef CONFIG_X86_64
33910 +#define pxd_t pud_t
33911 +#define pyd_t pgd_t
33912 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33913 +#define pgtable_pxd_page_ctor(page) true
33914 +#define pgtable_pxd_page_dtor(page)
33915 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33916 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33917 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33918 +#define PYD_SIZE PGDIR_SIZE
33919 +#else
33920 +#define pxd_t pmd_t
33921 +#define pyd_t pud_t
33922 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33923 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33924 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33925 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33926 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33927 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33928 +#define PYD_SIZE PUD_SIZE
33929 +#endif
33930 +
33931 +#ifdef CONFIG_PAX_PER_CPU_PGD
33932 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33933 +static inline void pgd_dtor(pgd_t *pgd) {}
33934 +#else
33935 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33936 {
33937 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33938 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33939 pgd_list_del(pgd);
33940 spin_unlock(&pgd_lock);
33941 }
33942 +#endif
33943
33944 /*
33945 * List of all pgd's needed for non-PAE so it can invalidate entries
33946 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33947 * -- nyc
33948 */
33949
33950 -#ifdef CONFIG_X86_PAE
33951 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33952 /*
33953 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33954 * updating the top-level pagetable entries to guarantee the
33955 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33956 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33957 * and initialize the kernel pmds here.
33958 */
33959 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33960 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33961
33962 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33963 {
33964 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33965 */
33966 flush_tlb_mm(mm);
33967 }
33968 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33969 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33970 #else /* !CONFIG_X86_PAE */
33971
33972 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33973 -#define PREALLOCATED_PMDS 0
33974 +#define PREALLOCATED_PXDS 0
33975
33976 #endif /* CONFIG_X86_PAE */
33977
33978 -static void free_pmds(pmd_t *pmds[])
33979 +static void free_pxds(pxd_t *pxds[])
33980 {
33981 int i;
33982
33983 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33984 - if (pmds[i]) {
33985 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33986 - free_page((unsigned long)pmds[i]);
33987 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33988 + if (pxds[i]) {
33989 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33990 + free_page((unsigned long)pxds[i]);
33991 }
33992 }
33993
33994 -static int preallocate_pmds(pmd_t *pmds[])
33995 +static int preallocate_pxds(pxd_t *pxds[])
33996 {
33997 int i;
33998 bool failed = false;
33999
34000 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34001 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34002 - if (!pmd)
34003 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34004 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34005 + if (!pxd)
34006 failed = true;
34007 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34008 - free_page((unsigned long)pmd);
34009 - pmd = NULL;
34010 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34011 + free_page((unsigned long)pxd);
34012 + pxd = NULL;
34013 failed = true;
34014 }
34015 - pmds[i] = pmd;
34016 + pxds[i] = pxd;
34017 }
34018
34019 if (failed) {
34020 - free_pmds(pmds);
34021 + free_pxds(pxds);
34022 return -ENOMEM;
34023 }
34024
34025 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34026 * preallocate which never got a corresponding vma will need to be
34027 * freed manually.
34028 */
34029 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34030 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34031 {
34032 int i;
34033
34034 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34035 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34036 pgd_t pgd = pgdp[i];
34037
34038 if (pgd_val(pgd) != 0) {
34039 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34040 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34041
34042 - pgdp[i] = native_make_pgd(0);
34043 + set_pgd(pgdp + i, native_make_pgd(0));
34044
34045 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34046 - pmd_free(mm, pmd);
34047 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34048 + pxd_free(mm, pxd);
34049 }
34050 }
34051 }
34052
34053 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34054 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34055 {
34056 - pud_t *pud;
34057 + pyd_t *pyd;
34058 int i;
34059
34060 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34061 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34062 return;
34063
34064 - pud = pud_offset(pgd, 0);
34065 -
34066 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34067 - pmd_t *pmd = pmds[i];
34068 +#ifdef CONFIG_X86_64
34069 + pyd = pyd_offset(mm, 0L);
34070 +#else
34071 + pyd = pyd_offset(pgd, 0L);
34072 +#endif
34073
34074 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34075 + pxd_t *pxd = pxds[i];
34076 if (i >= KERNEL_PGD_BOUNDARY)
34077 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34078 - sizeof(pmd_t) * PTRS_PER_PMD);
34079 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34080 + sizeof(pxd_t) * PTRS_PER_PMD);
34081
34082 - pud_populate(mm, pud, pmd);
34083 + pyd_populate(mm, pyd, pxd);
34084 }
34085 }
34086
34087 pgd_t *pgd_alloc(struct mm_struct *mm)
34088 {
34089 pgd_t *pgd;
34090 - pmd_t *pmds[PREALLOCATED_PMDS];
34091 + pxd_t *pxds[PREALLOCATED_PXDS];
34092
34093 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34094
34095 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34096
34097 mm->pgd = pgd;
34098
34099 - if (preallocate_pmds(pmds) != 0)
34100 + if (preallocate_pxds(pxds) != 0)
34101 goto out_free_pgd;
34102
34103 if (paravirt_pgd_alloc(mm) != 0)
34104 - goto out_free_pmds;
34105 + goto out_free_pxds;
34106
34107 /*
34108 * Make sure that pre-populating the pmds is atomic with
34109 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34110 spin_lock(&pgd_lock);
34111
34112 pgd_ctor(mm, pgd);
34113 - pgd_prepopulate_pmd(mm, pgd, pmds);
34114 + pgd_prepopulate_pxd(mm, pgd, pxds);
34115
34116 spin_unlock(&pgd_lock);
34117
34118 return pgd;
34119
34120 -out_free_pmds:
34121 - free_pmds(pmds);
34122 +out_free_pxds:
34123 + free_pxds(pxds);
34124 out_free_pgd:
34125 free_page((unsigned long)pgd);
34126 out:
34127 @@ -313,7 +380,7 @@ out:
34128
34129 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34130 {
34131 - pgd_mop_up_pmds(mm, pgd);
34132 + pgd_mop_up_pxds(mm, pgd);
34133 pgd_dtor(pgd);
34134 paravirt_pgd_free(mm, pgd);
34135 free_page((unsigned long)pgd);
34136 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34137 index 4dd8cf6..f9d143e 100644
34138 --- a/arch/x86/mm/pgtable_32.c
34139 +++ b/arch/x86/mm/pgtable_32.c
34140 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34141 return;
34142 }
34143 pte = pte_offset_kernel(pmd, vaddr);
34144 +
34145 + pax_open_kernel();
34146 if (pte_val(pteval))
34147 set_pte_at(&init_mm, vaddr, pte, pteval);
34148 else
34149 pte_clear(&init_mm, vaddr, pte);
34150 + pax_close_kernel();
34151
34152 /*
34153 * It's enough to flush this one mapping.
34154 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34155 index e666cbb..61788c45 100644
34156 --- a/arch/x86/mm/physaddr.c
34157 +++ b/arch/x86/mm/physaddr.c
34158 @@ -10,7 +10,7 @@
34159 #ifdef CONFIG_X86_64
34160
34161 #ifdef CONFIG_DEBUG_VIRTUAL
34162 -unsigned long __phys_addr(unsigned long x)
34163 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34164 {
34165 unsigned long y = x - __START_KERNEL_map;
34166
34167 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34168 #else
34169
34170 #ifdef CONFIG_DEBUG_VIRTUAL
34171 -unsigned long __phys_addr(unsigned long x)
34172 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34173 {
34174 unsigned long phys_addr = x - PAGE_OFFSET;
34175 /* VMALLOC_* aren't constants */
34176 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34177 index 90555bf..f5f1828 100644
34178 --- a/arch/x86/mm/setup_nx.c
34179 +++ b/arch/x86/mm/setup_nx.c
34180 @@ -5,8 +5,10 @@
34181 #include <asm/pgtable.h>
34182 #include <asm/proto.h>
34183
34184 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34185 static int disable_nx;
34186
34187 +#ifndef CONFIG_PAX_PAGEEXEC
34188 /*
34189 * noexec = on|off
34190 *
34191 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34192 return 0;
34193 }
34194 early_param("noexec", noexec_setup);
34195 +#endif
34196 +
34197 +#endif
34198
34199 void x86_configure_nx(void)
34200 {
34201 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34202 if (cpu_has_nx && !disable_nx)
34203 __supported_pte_mask |= _PAGE_NX;
34204 else
34205 +#endif
34206 __supported_pte_mask &= ~_PAGE_NX;
34207 }
34208
34209 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34210 index dd8dda1..9e9b0f6 100644
34211 --- a/arch/x86/mm/tlb.c
34212 +++ b/arch/x86/mm/tlb.c
34213 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34214 BUG();
34215 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34216 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34217 +
34218 +#ifndef CONFIG_PAX_PER_CPU_PGD
34219 load_cr3(swapper_pg_dir);
34220 +#endif
34221 +
34222 }
34223 }
34224 EXPORT_SYMBOL_GPL(leave_mm);
34225 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34226 new file mode 100644
34227 index 0000000..dace51c
34228 --- /dev/null
34229 +++ b/arch/x86/mm/uderef_64.c
34230 @@ -0,0 +1,37 @@
34231 +#include <linux/mm.h>
34232 +#include <asm/pgtable.h>
34233 +#include <asm/uaccess.h>
34234 +
34235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34236 +/* PaX: due to the special call convention these functions must
34237 + * - remain leaf functions under all configurations,
34238 + * - never be called directly, only dereferenced from the wrappers.
34239 + */
34240 +void __pax_open_userland(void)
34241 +{
34242 + unsigned int cpu;
34243 +
34244 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34245 + return;
34246 +
34247 + cpu = raw_get_cpu();
34248 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34249 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34250 + raw_put_cpu_no_resched();
34251 +}
34252 +EXPORT_SYMBOL(__pax_open_userland);
34253 +
34254 +void __pax_close_userland(void)
34255 +{
34256 + unsigned int cpu;
34257 +
34258 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34259 + return;
34260 +
34261 + cpu = raw_get_cpu();
34262 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34263 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34264 + raw_put_cpu_no_resched();
34265 +}
34266 +EXPORT_SYMBOL(__pax_close_userland);
34267 +#endif
34268 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34269 index 6440221..f746de8 100644
34270 --- a/arch/x86/net/bpf_jit.S
34271 +++ b/arch/x86/net/bpf_jit.S
34272 @@ -9,19 +9,17 @@
34273 */
34274 #include <linux/linkage.h>
34275 #include <asm/dwarf2.h>
34276 +#include <asm/alternative-asm.h>
34277
34278 /*
34279 * Calling convention :
34280 - * rbx : skb pointer (callee saved)
34281 + * rdi : skb pointer
34282 * esi : offset of byte(s) to fetch in skb (can be scratched)
34283 - * r10 : copy of skb->data
34284 + * r8 : copy of skb->data
34285 * r9d : hlen = skb->len - skb->data_len
34286 */
34287 -#define SKBDATA %r10
34288 +#define SKBDATA %r8
34289 #define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
34290 -#define MAX_BPF_STACK (512 /* from filter.h */ + \
34291 - 32 /* space for rbx,r13,r14,r15 */ + \
34292 - 8 /* space for skb_copy_bits */)
34293
34294 sk_load_word:
34295 .globl sk_load_word
34296 @@ -38,6 +36,7 @@ sk_load_word_positive_offset:
34297 jle bpf_slow_path_word
34298 mov (SKBDATA,%rsi),%eax
34299 bswap %eax /* ntohl() */
34300 + pax_force_retaddr
34301 ret
34302
34303 sk_load_half:
34304 @@ -55,6 +54,7 @@ sk_load_half_positive_offset:
34305 jle bpf_slow_path_half
34306 movzwl (SKBDATA,%rsi),%eax
34307 rol $8,%ax # ntohs()
34308 + pax_force_retaddr
34309 ret
34310
34311 sk_load_byte:
34312 @@ -69,45 +69,83 @@ sk_load_byte_positive_offset:
34313 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34314 jle bpf_slow_path_byte
34315 movzbl (SKBDATA,%rsi),%eax
34316 + pax_force_retaddr
34317 + ret
34318 +
34319 +/**
34320 + * sk_load_byte_msh - BPF_S_LDX_B_MSH helper
34321 + *
34322 + * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf)
34323 + * Must preserve A accumulator (%eax)
34324 + * Inputs : %esi is the offset value
34325 + */
34326 +sk_load_byte_msh:
34327 + .globl sk_load_byte_msh
34328 + test %esi,%esi
34329 + js bpf_slow_path_byte_msh_neg
34330 +
34331 +sk_load_byte_msh_positive_offset:
34332 + .globl sk_load_byte_msh_positive_offset
34333 + cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
34334 + jle bpf_slow_path_byte_msh
34335 + movzbl (SKBDATA,%rsi),%ebx
34336 + and $15,%bl
34337 + shl $2,%bl
34338 + pax_force_retaddr
34339 ret
34340
34341 /* rsi contains offset and can be scratched */
34342 #define bpf_slow_path_common(LEN) \
34343 - mov %rbx, %rdi; /* arg1 == skb */ \
34344 + push %rdi; /* save skb */ \
34345 push %r9; \
34346 push SKBDATA; \
34347 /* rsi already has offset */ \
34348 mov $LEN,%ecx; /* len */ \
34349 - lea - MAX_BPF_STACK + 32(%rbp),%rdx; \
34350 + lea -12(%rbp),%rdx; \
34351 call skb_copy_bits; \
34352 test %eax,%eax; \
34353 pop SKBDATA; \
34354 - pop %r9;
34355 + pop %r9; \
34356 + pop %rdi
34357
34358
34359 bpf_slow_path_word:
34360 bpf_slow_path_common(4)
34361 js bpf_error
34362 - mov - MAX_BPF_STACK + 32(%rbp),%eax
34363 + mov -12(%rbp),%eax
34364 bswap %eax
34365 + pax_force_retaddr
34366 ret
34367
34368 bpf_slow_path_half:
34369 bpf_slow_path_common(2)
34370 js bpf_error
34371 - mov - MAX_BPF_STACK + 32(%rbp),%ax
34372 + mov -12(%rbp),%ax
34373 rol $8,%ax
34374 movzwl %ax,%eax
34375 + pax_force_retaddr
34376 ret
34377
34378 bpf_slow_path_byte:
34379 bpf_slow_path_common(1)
34380 js bpf_error
34381 - movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34382 + movzbl -12(%rbp),%eax
34383 + pax_force_retaddr
34384 + ret
34385 +
34386 +bpf_slow_path_byte_msh:
34387 + xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34388 + bpf_slow_path_common(1)
34389 + js bpf_error
34390 + movzbl -12(%rbp),%eax
34391 + and $15,%al
34392 + shl $2,%al
34393 + xchg %eax,%ebx
34394 + pax_force_retaddr
34395 ret
34396
34397 #define sk_negative_common(SIZE) \
34398 - mov %rbx, %rdi; /* arg1 == skb */ \
34399 + push %rdi; /* save skb */ \
34400 push %r9; \
34401 push SKBDATA; \
34402 /* rsi already has offset */ \
34403 @@ -116,8 +154,10 @@ bpf_slow_path_byte:
34404 test %rax,%rax; \
34405 pop SKBDATA; \
34406 pop %r9; \
34407 + pop %rdi; \
34408 jz bpf_error
34409
34410 +
34411 bpf_slow_path_word_neg:
34412 cmp SKF_MAX_NEG_OFF, %esi /* test range */
34413 jl bpf_error /* offset lower -> error */
34414 @@ -126,6 +166,7 @@ sk_load_word_negative_offset:
34415 sk_negative_common(4)
34416 mov (%rax), %eax
34417 bswap %eax
34418 + pax_force_retaddr
34419 ret
34420
34421 bpf_slow_path_half_neg:
34422 @@ -137,6 +178,7 @@ sk_load_half_negative_offset:
34423 mov (%rax),%ax
34424 rol $8,%ax
34425 movzwl %ax,%eax
34426 + pax_force_retaddr
34427 ret
34428
34429 bpf_slow_path_byte_neg:
34430 @@ -146,14 +188,27 @@ sk_load_byte_negative_offset:
34431 .globl sk_load_byte_negative_offset
34432 sk_negative_common(1)
34433 movzbl (%rax), %eax
34434 + pax_force_retaddr
34435 + ret
34436 +
34437 +bpf_slow_path_byte_msh_neg:
34438 + cmp SKF_MAX_NEG_OFF, %esi
34439 + jl bpf_error
34440 +sk_load_byte_msh_negative_offset:
34441 + .globl sk_load_byte_msh_negative_offset
34442 + xchg %eax,%ebx /* dont lose A , X is about to be scratched */
34443 + sk_negative_common(1)
34444 + movzbl (%rax),%eax
34445 + and $15,%al
34446 + shl $2,%al
34447 + xchg %eax,%ebx
34448 + pax_force_retaddr
34449 ret
34450
34451 bpf_error:
34452 # force a return 0 from jit handler
34453 - xor %eax,%eax
34454 - mov - MAX_BPF_STACK(%rbp),%rbx
34455 - mov - MAX_BPF_STACK + 8(%rbp),%r13
34456 - mov - MAX_BPF_STACK + 16(%rbp),%r14
34457 - mov - MAX_BPF_STACK + 24(%rbp),%r15
34458 + xor %eax,%eax
34459 + mov -8(%rbp),%rbx
34460 leaveq
34461 + pax_force_retaddr
34462 ret
34463 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34464 index 99bef86..bdfb5c6 100644
34465 --- a/arch/x86/net/bpf_jit_comp.c
34466 +++ b/arch/x86/net/bpf_jit_comp.c
34467 @@ -1,7 +1,6 @@
34468 /* bpf_jit_comp.c : BPF JIT compiler
34469 *
34470 * Copyright (C) 2011-2013 Eric Dumazet (eric.dumazet@gmail.com)
34471 - * Internal BPF Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
34472 *
34473 * This program is free software; you can redistribute it and/or
34474 * modify it under the terms of the GNU General Public License
34475 @@ -15,16 +14,28 @@
34476 #include <linux/if_vlan.h>
34477 #include <linux/random.h>
34478
34479 +/*
34480 + * Conventions :
34481 + * EAX : BPF A accumulator
34482 + * EBX : BPF X accumulator
34483 + * RDI : pointer to skb (first argument given to JIT function)
34484 + * RBP : frame pointer (even if CONFIG_FRAME_POINTER=n)
34485 + * ECX,EDX,ESI : scratch registers
34486 + * r9d : skb->len - skb->data_len (headlen)
34487 + * r8 : skb->data
34488 + * -8(RBP) : saved RBX value
34489 + * -16(RBP)..-80(RBP) : BPF_MEMWORDS values
34490 + */
34491 int bpf_jit_enable __read_mostly;
34492
34493 /*
34494 * assembly code in arch/x86/net/bpf_jit.S
34495 */
34496 -extern u8 sk_load_word[], sk_load_half[], sk_load_byte[];
34497 +extern u8 sk_load_word[], sk_load_half[], sk_load_byte[], sk_load_byte_msh[];
34498 extern u8 sk_load_word_positive_offset[], sk_load_half_positive_offset[];
34499 -extern u8 sk_load_byte_positive_offset[];
34500 +extern u8 sk_load_byte_positive_offset[], sk_load_byte_msh_positive_offset[];
34501 extern u8 sk_load_word_negative_offset[], sk_load_half_negative_offset[];
34502 -extern u8 sk_load_byte_negative_offset[];
34503 +extern u8 sk_load_byte_negative_offset[], sk_load_byte_msh_negative_offset[];
34504
34505 static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34506 {
34507 @@ -39,50 +50,113 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34508 return ptr + len;
34509 }
34510
34511 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34512 +#define MAX_INSTR_CODE_SIZE 96
34513 +#else
34514 +#define MAX_INSTR_CODE_SIZE 64
34515 +#endif
34516 +
34517 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34518
34519 #define EMIT1(b1) EMIT(b1, 1)
34520 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34521 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34522 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34523 -#define EMIT1_off32(b1, off) \
34524 - do {EMIT1(b1); EMIT(off, 4); } while (0)
34525 -#define EMIT2_off32(b1, b2, off) \
34526 - do {EMIT2(b1, b2); EMIT(off, 4); } while (0)
34527 -#define EMIT3_off32(b1, b2, b3, off) \
34528 - do {EMIT3(b1, b2, b3); EMIT(off, 4); } while (0)
34529 -#define EMIT4_off32(b1, b2, b3, b4, off) \
34530 - do {EMIT4(b1, b2, b3, b4); EMIT(off, 4); } while (0)
34531 +
34532 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34533 +/* original constant will appear in ecx */
34534 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
34535 +do { \
34536 + /* mov ecx, randkey */ \
34537 + EMIT1(0xb9); \
34538 + EMIT(_key, 4); \
34539 + /* xor ecx, randkey ^ off */ \
34540 + EMIT2(0x81, 0xf1); \
34541 + EMIT((_key) ^ (_off), 4); \
34542 +} while (0)
34543 +
34544 +#define EMIT1_off32(b1, _off) \
34545 +do { \
34546 + switch (b1) { \
34547 + case 0x05: /* add eax, imm32 */ \
34548 + case 0x2d: /* sub eax, imm32 */ \
34549 + case 0x25: /* and eax, imm32 */ \
34550 + case 0x0d: /* or eax, imm32 */ \
34551 + case 0xb8: /* mov eax, imm32 */ \
34552 + case 0x35: /* xor eax, imm32 */ \
34553 + case 0x3d: /* cmp eax, imm32 */ \
34554 + case 0xa9: /* test eax, imm32 */ \
34555 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34556 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34557 + break; \
34558 + case 0xbb: /* mov ebx, imm32 */ \
34559 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34560 + /* mov ebx, ecx */ \
34561 + EMIT2(0x89, 0xcb); \
34562 + break; \
34563 + case 0xbe: /* mov esi, imm32 */ \
34564 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34565 + /* mov esi, ecx */ \
34566 + EMIT2(0x89, 0xce); \
34567 + break; \
34568 + case 0xe8: /* call rel imm32, always to known funcs */ \
34569 + EMIT1(b1); \
34570 + EMIT(_off, 4); \
34571 + break; \
34572 + case 0xe9: /* jmp rel imm32 */ \
34573 + EMIT1(b1); \
34574 + EMIT(_off, 4); \
34575 + /* prevent fall-through, we're not called if off = 0 */ \
34576 + EMIT(0xcccccccc, 4); \
34577 + EMIT(0xcccccccc, 4); \
34578 + break; \
34579 + default: \
34580 + BUILD_BUG(); \
34581 + } \
34582 +} while (0)
34583 +
34584 +#define EMIT2_off32(b1, b2, _off) \
34585 +do { \
34586 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34587 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34588 + EMIT(randkey, 4); \
34589 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34590 + EMIT((_off) - randkey, 4); \
34591 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34592 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34593 + /* imul eax, ecx */ \
34594 + EMIT3(0x0f, 0xaf, 0xc1); \
34595 + } else { \
34596 + BUILD_BUG(); \
34597 + } \
34598 +} while (0)
34599 +#else
34600 +#define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34601 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34602 +#endif
34603 +
34604 +#define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34605 +#define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34606
34607 static inline bool is_imm8(int value)
34608 {
34609 return value <= 127 && value >= -128;
34610 }
34611
34612 -static inline bool is_simm32(s64 value)
34613 +static inline bool is_near(int offset)
34614 {
34615 - return value == (s64) (s32) value;
34616 + return offset <= 127 && offset >= -128;
34617 }
34618
34619 -/* mov dst, src */
34620 -#define EMIT_mov(DST, SRC) \
34621 - do {if (DST != SRC) \
34622 - EMIT3(add_2mod(0x48, DST, SRC), 0x89, add_2reg(0xC0, DST, SRC)); \
34623 - } while (0)
34624 -
34625 -static int bpf_size_to_x86_bytes(int bpf_size)
34626 -{
34627 - if (bpf_size == BPF_W)
34628 - return 4;
34629 - else if (bpf_size == BPF_H)
34630 - return 2;
34631 - else if (bpf_size == BPF_B)
34632 - return 1;
34633 - else if (bpf_size == BPF_DW)
34634 - return 4; /* imm32 */
34635 - else
34636 - return 0;
34637 -}
34638 +#define EMIT_JMP(offset) \
34639 +do { \
34640 + if (offset) { \
34641 + if (is_near(offset)) \
34642 + EMIT2(0xeb, offset); /* jmp .+off8 */ \
34643 + else \
34644 + EMIT1_off32(0xe9, offset); /* jmp .+off32 */ \
34645 + } \
34646 +} while (0)
34647
34648 /* list of x86 cond jumps opcodes (. + s8)
34649 * Add 0x10 (and an extra 0x0f) to generate far jumps (. + s32)
34650 @@ -93,8 +167,46 @@ static int bpf_size_to_x86_bytes(int bpf_size)
34651 #define X86_JNE 0x75
34652 #define X86_JBE 0x76
34653 #define X86_JA 0x77
34654 -#define X86_JGE 0x7D
34655 -#define X86_JG 0x7F
34656 +
34657 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34658 +#define APPEND_FLOW_VERIFY() \
34659 +do { \
34660 + /* mov ecx, randkey */ \
34661 + EMIT1(0xb9); \
34662 + EMIT(randkey, 4); \
34663 + /* cmp ecx, randkey */ \
34664 + EMIT2(0x81, 0xf9); \
34665 + EMIT(randkey, 4); \
34666 + /* jz after 8 int 3s */ \
34667 + EMIT2(0x74, 0x08); \
34668 + EMIT(0xcccccccc, 4); \
34669 + EMIT(0xcccccccc, 4); \
34670 +} while (0)
34671 +#else
34672 +#define APPEND_FLOW_VERIFY() do { } while (0)
34673 +#endif
34674 +
34675 +#define EMIT_COND_JMP(op, offset) \
34676 +do { \
34677 + if (is_near(offset)) \
34678 + EMIT2(op, offset); /* jxx .+off8 */ \
34679 + else { \
34680 + EMIT2(0x0f, op + 0x10); \
34681 + EMIT(offset, 4); /* jxx .+off32 */ \
34682 + APPEND_FLOW_VERIFY(); \
34683 + } \
34684 +} while (0)
34685 +
34686 +#define COND_SEL(CODE, TOP, FOP) \
34687 + case CODE: \
34688 + t_op = TOP; \
34689 + f_op = FOP; \
34690 + goto cond_branch
34691 +
34692 +
34693 +#define SEEN_DATAREF 1 /* might call external helpers */
34694 +#define SEEN_XREG 2 /* ebx is used */
34695 +#define SEEN_MEM 4 /* use mem[] for temporary storage */
34696
34697 static inline void bpf_flush_icache(void *start, void *end)
34698 {
34699 @@ -109,804 +221,646 @@ static inline void bpf_flush_icache(void *start, void *end)
34700 #define CHOOSE_LOAD_FUNC(K, func) \
34701 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34702
34703 -struct bpf_binary_header {
34704 - unsigned int pages;
34705 - /* Note : for security reasons, bpf code will follow a randomly
34706 - * sized amount of int3 instructions
34707 - */
34708 - u8 image[];
34709 -};
34710 +/* Helper to find the offset of pkt_type in sk_buff
34711 + * We want to make sure its still a 3bit field starting at a byte boundary.
34712 + */
34713 +#define PKT_TYPE_MAX 7
34714 +static int pkt_type_offset(void)
34715 +{
34716 + struct sk_buff skb_probe = {
34717 + .pkt_type = ~0,
34718 + };
34719 + char *ct = (char *)&skb_probe;
34720 + unsigned int off;
34721
34722 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34723 + for (off = 0; off < sizeof(struct sk_buff); off++) {
34724 + if (ct[off] == PKT_TYPE_MAX)
34725 + return off;
34726 + }
34727 + pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n");
34728 + return -1;
34729 +}
34730 +
34731 +/* Note : for security reasons, bpf code will follow a randomly
34732 + * sized amount of int3 instructions
34733 + */
34734 +static u8 *bpf_alloc_binary(unsigned int proglen,
34735 u8 **image_ptr)
34736 {
34737 unsigned int sz, hole;
34738 - struct bpf_binary_header *header;
34739 + u8 *header;
34740
34741 /* Most of BPF filters are really small,
34742 * but if some of them fill a page, allow at least
34743 * 128 extra bytes to insert a random section of int3
34744 */
34745 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34746 - header = module_alloc(sz);
34747 + sz = round_up(proglen + 128, PAGE_SIZE);
34748 + header = module_alloc_exec(sz);
34749 if (!header)
34750 return NULL;
34751
34752 + pax_open_kernel();
34753 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34754 + pax_close_kernel();
34755
34756 - header->pages = sz / PAGE_SIZE;
34757 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34758 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34759
34760 /* insert a random number of int3 instructions before BPF code */
34761 - *image_ptr = &header->image[prandom_u32() % hole];
34762 + *image_ptr = &header[prandom_u32() % hole];
34763 return header;
34764 }
34765
34766 -/* pick a register outside of BPF range for JIT internal work */
34767 -#define AUX_REG (MAX_BPF_REG + 1)
34768 -
34769 -/* the following table maps BPF registers to x64 registers.
34770 - * x64 register r12 is unused, since if used as base address register
34771 - * in load/store instructions, it always needs an extra byte of encoding
34772 - */
34773 -static const int reg2hex[] = {
34774 - [BPF_REG_0] = 0, /* rax */
34775 - [BPF_REG_1] = 7, /* rdi */
34776 - [BPF_REG_2] = 6, /* rsi */
34777 - [BPF_REG_3] = 2, /* rdx */
34778 - [BPF_REG_4] = 1, /* rcx */
34779 - [BPF_REG_5] = 0, /* r8 */
34780 - [BPF_REG_6] = 3, /* rbx callee saved */
34781 - [BPF_REG_7] = 5, /* r13 callee saved */
34782 - [BPF_REG_8] = 6, /* r14 callee saved */
34783 - [BPF_REG_9] = 7, /* r15 callee saved */
34784 - [BPF_REG_FP] = 5, /* rbp readonly */
34785 - [AUX_REG] = 3, /* r11 temp register */
34786 -};
34787 -
34788 -/* is_ereg() == true if BPF register 'reg' maps to x64 r8..r15
34789 - * which need extra byte of encoding.
34790 - * rax,rcx,...,rbp have simpler encoding
34791 - */
34792 -static inline bool is_ereg(u32 reg)
34793 -{
34794 - if (reg == BPF_REG_5 || reg == AUX_REG ||
34795 - (reg >= BPF_REG_7 && reg <= BPF_REG_9))
34796 - return true;
34797 - else
34798 - return false;
34799 -}
34800 -
34801 -/* add modifiers if 'reg' maps to x64 registers r8..r15 */
34802 -static inline u8 add_1mod(u8 byte, u32 reg)
34803 -{
34804 - if (is_ereg(reg))
34805 - byte |= 1;
34806 - return byte;
34807 -}
34808 -
34809 -static inline u8 add_2mod(u8 byte, u32 r1, u32 r2)
34810 -{
34811 - if (is_ereg(r1))
34812 - byte |= 1;
34813 - if (is_ereg(r2))
34814 - byte |= 4;
34815 - return byte;
34816 -}
34817 -
34818 -/* encode 'dst_reg' register into x64 opcode 'byte' */
34819 -static inline u8 add_1reg(u8 byte, u32 dst_reg)
34820 -{
34821 - return byte + reg2hex[dst_reg];
34822 -}
34823 -
34824 -/* encode 'dst_reg' and 'src_reg' registers into x64 opcode 'byte' */
34825 -static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34826 -{
34827 - return byte + reg2hex[dst_reg] + (reg2hex[src_reg] << 3);
34828 -}
34829 -
34830 -struct jit_context {
34831 - unsigned int cleanup_addr; /* epilogue code offset */
34832 - bool seen_ld_abs;
34833 -};
34834 -
34835 -static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
34836 - int oldproglen, struct jit_context *ctx)
34837 -{
34838 - struct sock_filter_int *insn = bpf_prog->insnsi;
34839 - int insn_cnt = bpf_prog->len;
34840 - u8 temp[64];
34841 - int i;
34842 - int proglen = 0;
34843 - u8 *prog = temp;
34844 - int stacksize = MAX_BPF_STACK +
34845 - 32 /* space for rbx, r13, r14, r15 */ +
34846 - 8 /* space for skb_copy_bits() buffer */;
34847 -
34848 - EMIT1(0x55); /* push rbp */
34849 - EMIT3(0x48, 0x89, 0xE5); /* mov rbp,rsp */
34850 -
34851 - /* sub rsp, stacksize */
34852 - EMIT3_off32(0x48, 0x81, 0xEC, stacksize);
34853 -
34854 - /* all classic BPF filters use R6(rbx) save it */
34855 -
34856 - /* mov qword ptr [rbp-X],rbx */
34857 - EMIT3_off32(0x48, 0x89, 0x9D, -stacksize);
34858 -
34859 - /* sk_convert_filter() maps classic BPF register X to R7 and uses R8
34860 - * as temporary, so all tcpdump filters need to spill/fill R7(r13) and
34861 - * R8(r14). R9(r15) spill could be made conditional, but there is only
34862 - * one 'bpf_error' return path out of helper functions inside bpf_jit.S
34863 - * The overhead of extra spill is negligible for any filter other
34864 - * than synthetic ones. Therefore not worth adding complexity.
34865 - */
34866 -
34867 - /* mov qword ptr [rbp-X],r13 */
34868 - EMIT3_off32(0x4C, 0x89, 0xAD, -stacksize + 8);
34869 - /* mov qword ptr [rbp-X],r14 */
34870 - EMIT3_off32(0x4C, 0x89, 0xB5, -stacksize + 16);
34871 - /* mov qword ptr [rbp-X],r15 */
34872 - EMIT3_off32(0x4C, 0x89, 0xBD, -stacksize + 24);
34873 -
34874 - /* clear A and X registers */
34875 - EMIT2(0x31, 0xc0); /* xor eax, eax */
34876 - EMIT3(0x4D, 0x31, 0xED); /* xor r13, r13 */
34877 -
34878 - if (ctx->seen_ld_abs) {
34879 - /* r9d : skb->len - skb->data_len (headlen)
34880 - * r10 : skb->data
34881 - */
34882 - if (is_imm8(offsetof(struct sk_buff, len)))
34883 - /* mov %r9d, off8(%rdi) */
34884 - EMIT4(0x44, 0x8b, 0x4f,
34885 - offsetof(struct sk_buff, len));
34886 - else
34887 - /* mov %r9d, off32(%rdi) */
34888 - EMIT3_off32(0x44, 0x8b, 0x8f,
34889 - offsetof(struct sk_buff, len));
34890 -
34891 - if (is_imm8(offsetof(struct sk_buff, data_len)))
34892 - /* sub %r9d, off8(%rdi) */
34893 - EMIT4(0x44, 0x2b, 0x4f,
34894 - offsetof(struct sk_buff, data_len));
34895 - else
34896 - EMIT3_off32(0x44, 0x2b, 0x8f,
34897 - offsetof(struct sk_buff, data_len));
34898 -
34899 - if (is_imm8(offsetof(struct sk_buff, data)))
34900 - /* mov %r10, off8(%rdi) */
34901 - EMIT4(0x4c, 0x8b, 0x57,
34902 - offsetof(struct sk_buff, data));
34903 - else
34904 - /* mov %r10, off32(%rdi) */
34905 - EMIT3_off32(0x4c, 0x8b, 0x97,
34906 - offsetof(struct sk_buff, data));
34907 - }
34908 -
34909 - for (i = 0; i < insn_cnt; i++, insn++) {
34910 - const s32 imm32 = insn->imm;
34911 - u32 dst_reg = insn->dst_reg;
34912 - u32 src_reg = insn->src_reg;
34913 - u8 b1 = 0, b2 = 0, b3 = 0;
34914 - s64 jmp_offset;
34915 - u8 jmp_cond;
34916 - int ilen;
34917 - u8 *func;
34918 -
34919 - switch (insn->code) {
34920 - /* ALU */
34921 - case BPF_ALU | BPF_ADD | BPF_X:
34922 - case BPF_ALU | BPF_SUB | BPF_X:
34923 - case BPF_ALU | BPF_AND | BPF_X:
34924 - case BPF_ALU | BPF_OR | BPF_X:
34925 - case BPF_ALU | BPF_XOR | BPF_X:
34926 - case BPF_ALU64 | BPF_ADD | BPF_X:
34927 - case BPF_ALU64 | BPF_SUB | BPF_X:
34928 - case BPF_ALU64 | BPF_AND | BPF_X:
34929 - case BPF_ALU64 | BPF_OR | BPF_X:
34930 - case BPF_ALU64 | BPF_XOR | BPF_X:
34931 - switch (BPF_OP(insn->code)) {
34932 - case BPF_ADD: b2 = 0x01; break;
34933 - case BPF_SUB: b2 = 0x29; break;
34934 - case BPF_AND: b2 = 0x21; break;
34935 - case BPF_OR: b2 = 0x09; break;
34936 - case BPF_XOR: b2 = 0x31; break;
34937 - }
34938 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34939 - EMIT1(add_2mod(0x48, dst_reg, src_reg));
34940 - else if (is_ereg(dst_reg) || is_ereg(src_reg))
34941 - EMIT1(add_2mod(0x40, dst_reg, src_reg));
34942 - EMIT2(b2, add_2reg(0xC0, dst_reg, src_reg));
34943 - break;
34944 -
34945 - /* mov dst, src */
34946 - case BPF_ALU64 | BPF_MOV | BPF_X:
34947 - EMIT_mov(dst_reg, src_reg);
34948 - break;
34949 -
34950 - /* mov32 dst, src */
34951 - case BPF_ALU | BPF_MOV | BPF_X:
34952 - if (is_ereg(dst_reg) || is_ereg(src_reg))
34953 - EMIT1(add_2mod(0x40, dst_reg, src_reg));
34954 - EMIT2(0x89, add_2reg(0xC0, dst_reg, src_reg));
34955 - break;
34956 -
34957 - /* neg dst */
34958 - case BPF_ALU | BPF_NEG:
34959 - case BPF_ALU64 | BPF_NEG:
34960 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34961 - EMIT1(add_1mod(0x48, dst_reg));
34962 - else if (is_ereg(dst_reg))
34963 - EMIT1(add_1mod(0x40, dst_reg));
34964 - EMIT2(0xF7, add_1reg(0xD8, dst_reg));
34965 - break;
34966 -
34967 - case BPF_ALU | BPF_ADD | BPF_K:
34968 - case BPF_ALU | BPF_SUB | BPF_K:
34969 - case BPF_ALU | BPF_AND | BPF_K:
34970 - case BPF_ALU | BPF_OR | BPF_K:
34971 - case BPF_ALU | BPF_XOR | BPF_K:
34972 - case BPF_ALU64 | BPF_ADD | BPF_K:
34973 - case BPF_ALU64 | BPF_SUB | BPF_K:
34974 - case BPF_ALU64 | BPF_AND | BPF_K:
34975 - case BPF_ALU64 | BPF_OR | BPF_K:
34976 - case BPF_ALU64 | BPF_XOR | BPF_K:
34977 - if (BPF_CLASS(insn->code) == BPF_ALU64)
34978 - EMIT1(add_1mod(0x48, dst_reg));
34979 - else if (is_ereg(dst_reg))
34980 - EMIT1(add_1mod(0x40, dst_reg));
34981 -
34982 - switch (BPF_OP(insn->code)) {
34983 - case BPF_ADD: b3 = 0xC0; break;
34984 - case BPF_SUB: b3 = 0xE8; break;
34985 - case BPF_AND: b3 = 0xE0; break;
34986 - case BPF_OR: b3 = 0xC8; break;
34987 - case BPF_XOR: b3 = 0xF0; break;
34988 - }
34989 -
34990 - if (is_imm8(imm32))
34991 - EMIT3(0x83, add_1reg(b3, dst_reg), imm32);
34992 - else
34993 - EMIT2_off32(0x81, add_1reg(b3, dst_reg), imm32);
34994 - break;
34995 -
34996 - case BPF_ALU64 | BPF_MOV | BPF_K:
34997 - /* optimization: if imm32 is positive,
34998 - * use 'mov eax, imm32' (which zero-extends imm32)
34999 - * to save 2 bytes
35000 - */
35001 - if (imm32 < 0) {
35002 - /* 'mov rax, imm32' sign extends imm32 */
35003 - b1 = add_1mod(0x48, dst_reg);
35004 - b2 = 0xC7;
35005 - b3 = 0xC0;
35006 - EMIT3_off32(b1, b2, add_1reg(b3, dst_reg), imm32);
35007 - break;
35008 - }
35009 -
35010 - case BPF_ALU | BPF_MOV | BPF_K:
35011 - /* mov %eax, imm32 */
35012 - if (is_ereg(dst_reg))
35013 - EMIT1(add_1mod(0x40, dst_reg));
35014 - EMIT1_off32(add_1reg(0xB8, dst_reg), imm32);
35015 - break;
35016 -
35017 - /* dst %= src, dst /= src, dst %= imm32, dst /= imm32 */
35018 - case BPF_ALU | BPF_MOD | BPF_X:
35019 - case BPF_ALU | BPF_DIV | BPF_X:
35020 - case BPF_ALU | BPF_MOD | BPF_K:
35021 - case BPF_ALU | BPF_DIV | BPF_K:
35022 - case BPF_ALU64 | BPF_MOD | BPF_X:
35023 - case BPF_ALU64 | BPF_DIV | BPF_X:
35024 - case BPF_ALU64 | BPF_MOD | BPF_K:
35025 - case BPF_ALU64 | BPF_DIV | BPF_K:
35026 - EMIT1(0x50); /* push rax */
35027 - EMIT1(0x52); /* push rdx */
35028 -
35029 - if (BPF_SRC(insn->code) == BPF_X)
35030 - /* mov r11, src_reg */
35031 - EMIT_mov(AUX_REG, src_reg);
35032 - else
35033 - /* mov r11, imm32 */
35034 - EMIT3_off32(0x49, 0xC7, 0xC3, imm32);
35035 -
35036 - /* mov rax, dst_reg */
35037 - EMIT_mov(BPF_REG_0, dst_reg);
35038 -
35039 - /* xor edx, edx
35040 - * equivalent to 'xor rdx, rdx', but one byte less
35041 - */
35042 - EMIT2(0x31, 0xd2);
35043 -
35044 - if (BPF_SRC(insn->code) == BPF_X) {
35045 - /* if (src_reg == 0) return 0 */
35046 -
35047 - /* cmp r11, 0 */
35048 - EMIT4(0x49, 0x83, 0xFB, 0x00);
35049 -
35050 - /* jne .+9 (skip over pop, pop, xor and jmp) */
35051 - EMIT2(X86_JNE, 1 + 1 + 2 + 5);
35052 - EMIT1(0x5A); /* pop rdx */
35053 - EMIT1(0x58); /* pop rax */
35054 - EMIT2(0x31, 0xc0); /* xor eax, eax */
35055 -
35056 - /* jmp cleanup_addr
35057 - * addrs[i] - 11, because there are 11 bytes
35058 - * after this insn: div, mov, pop, pop, mov
35059 - */
35060 - jmp_offset = ctx->cleanup_addr - (addrs[i] - 11);
35061 - EMIT1_off32(0xE9, jmp_offset);
35062 - }
35063 -
35064 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35065 - /* div r11 */
35066 - EMIT3(0x49, 0xF7, 0xF3);
35067 - else
35068 - /* div r11d */
35069 - EMIT3(0x41, 0xF7, 0xF3);
35070 -
35071 - if (BPF_OP(insn->code) == BPF_MOD)
35072 - /* mov r11, rdx */
35073 - EMIT3(0x49, 0x89, 0xD3);
35074 - else
35075 - /* mov r11, rax */
35076 - EMIT3(0x49, 0x89, 0xC3);
35077 -
35078 - EMIT1(0x5A); /* pop rdx */
35079 - EMIT1(0x58); /* pop rax */
35080 -
35081 - /* mov dst_reg, r11 */
35082 - EMIT_mov(dst_reg, AUX_REG);
35083 - break;
35084 -
35085 - case BPF_ALU | BPF_MUL | BPF_K:
35086 - case BPF_ALU | BPF_MUL | BPF_X:
35087 - case BPF_ALU64 | BPF_MUL | BPF_K:
35088 - case BPF_ALU64 | BPF_MUL | BPF_X:
35089 - EMIT1(0x50); /* push rax */
35090 - EMIT1(0x52); /* push rdx */
35091 -
35092 - /* mov r11, dst_reg */
35093 - EMIT_mov(AUX_REG, dst_reg);
35094 -
35095 - if (BPF_SRC(insn->code) == BPF_X)
35096 - /* mov rax, src_reg */
35097 - EMIT_mov(BPF_REG_0, src_reg);
35098 - else
35099 - /* mov rax, imm32 */
35100 - EMIT3_off32(0x48, 0xC7, 0xC0, imm32);
35101 -
35102 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35103 - EMIT1(add_1mod(0x48, AUX_REG));
35104 - else if (is_ereg(AUX_REG))
35105 - EMIT1(add_1mod(0x40, AUX_REG));
35106 - /* mul(q) r11 */
35107 - EMIT2(0xF7, add_1reg(0xE0, AUX_REG));
35108 -
35109 - /* mov r11, rax */
35110 - EMIT_mov(AUX_REG, BPF_REG_0);
35111 -
35112 - EMIT1(0x5A); /* pop rdx */
35113 - EMIT1(0x58); /* pop rax */
35114 -
35115 - /* mov dst_reg, r11 */
35116 - EMIT_mov(dst_reg, AUX_REG);
35117 - break;
35118 -
35119 - /* shifts */
35120 - case BPF_ALU | BPF_LSH | BPF_K:
35121 - case BPF_ALU | BPF_RSH | BPF_K:
35122 - case BPF_ALU | BPF_ARSH | BPF_K:
35123 - case BPF_ALU64 | BPF_LSH | BPF_K:
35124 - case BPF_ALU64 | BPF_RSH | BPF_K:
35125 - case BPF_ALU64 | BPF_ARSH | BPF_K:
35126 - if (BPF_CLASS(insn->code) == BPF_ALU64)
35127 - EMIT1(add_1mod(0x48, dst_reg));
35128 - else if (is_ereg(dst_reg))
35129 - EMIT1(add_1mod(0x40, dst_reg));
35130 -
35131 - switch (BPF_OP(insn->code)) {
35132 - case BPF_LSH: b3 = 0xE0; break;
35133 - case BPF_RSH: b3 = 0xE8; break;
35134 - case BPF_ARSH: b3 = 0xF8; break;
35135 - }
35136 - EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
35137 - break;
35138 -
35139 - case BPF_ALU | BPF_END | BPF_FROM_BE:
35140 - switch (imm32) {
35141 - case 16:
35142 - /* emit 'ror %ax, 8' to swap lower 2 bytes */
35143 - EMIT1(0x66);
35144 - if (is_ereg(dst_reg))
35145 - EMIT1(0x41);
35146 - EMIT3(0xC1, add_1reg(0xC8, dst_reg), 8);
35147 - break;
35148 - case 32:
35149 - /* emit 'bswap eax' to swap lower 4 bytes */
35150 - if (is_ereg(dst_reg))
35151 - EMIT2(0x41, 0x0F);
35152 - else
35153 - EMIT1(0x0F);
35154 - EMIT1(add_1reg(0xC8, dst_reg));
35155 - break;
35156 - case 64:
35157 - /* emit 'bswap rax' to swap 8 bytes */
35158 - EMIT3(add_1mod(0x48, dst_reg), 0x0F,
35159 - add_1reg(0xC8, dst_reg));
35160 - break;
35161 - }
35162 - break;
35163 -
35164 - case BPF_ALU | BPF_END | BPF_FROM_LE:
35165 - break;
35166 -
35167 - /* ST: *(u8*)(dst_reg + off) = imm */
35168 - case BPF_ST | BPF_MEM | BPF_B:
35169 - if (is_ereg(dst_reg))
35170 - EMIT2(0x41, 0xC6);
35171 - else
35172 - EMIT1(0xC6);
35173 - goto st;
35174 - case BPF_ST | BPF_MEM | BPF_H:
35175 - if (is_ereg(dst_reg))
35176 - EMIT3(0x66, 0x41, 0xC7);
35177 - else
35178 - EMIT2(0x66, 0xC7);
35179 - goto st;
35180 - case BPF_ST | BPF_MEM | BPF_W:
35181 - if (is_ereg(dst_reg))
35182 - EMIT2(0x41, 0xC7);
35183 - else
35184 - EMIT1(0xC7);
35185 - goto st;
35186 - case BPF_ST | BPF_MEM | BPF_DW:
35187 - EMIT2(add_1mod(0x48, dst_reg), 0xC7);
35188 -
35189 -st: if (is_imm8(insn->off))
35190 - EMIT2(add_1reg(0x40, dst_reg), insn->off);
35191 - else
35192 - EMIT1_off32(add_1reg(0x80, dst_reg), insn->off);
35193 -
35194 - EMIT(imm32, bpf_size_to_x86_bytes(BPF_SIZE(insn->code)));
35195 - break;
35196 -
35197 - /* STX: *(u8*)(dst_reg + off) = src_reg */
35198 - case BPF_STX | BPF_MEM | BPF_B:
35199 - /* emit 'mov byte ptr [rax + off], al' */
35200 - if (is_ereg(dst_reg) || is_ereg(src_reg) ||
35201 - /* have to add extra byte for x86 SIL, DIL regs */
35202 - src_reg == BPF_REG_1 || src_reg == BPF_REG_2)
35203 - EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x88);
35204 - else
35205 - EMIT1(0x88);
35206 - goto stx;
35207 - case BPF_STX | BPF_MEM | BPF_H:
35208 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35209 - EMIT3(0x66, add_2mod(0x40, dst_reg, src_reg), 0x89);
35210 - else
35211 - EMIT2(0x66, 0x89);
35212 - goto stx;
35213 - case BPF_STX | BPF_MEM | BPF_W:
35214 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35215 - EMIT2(add_2mod(0x40, dst_reg, src_reg), 0x89);
35216 - else
35217 - EMIT1(0x89);
35218 - goto stx;
35219 - case BPF_STX | BPF_MEM | BPF_DW:
35220 - EMIT2(add_2mod(0x48, dst_reg, src_reg), 0x89);
35221 -stx: if (is_imm8(insn->off))
35222 - EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35223 - else
35224 - EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35225 - insn->off);
35226 - break;
35227 -
35228 - /* LDX: dst_reg = *(u8*)(src_reg + off) */
35229 - case BPF_LDX | BPF_MEM | BPF_B:
35230 - /* emit 'movzx rax, byte ptr [rax + off]' */
35231 - EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB6);
35232 - goto ldx;
35233 - case BPF_LDX | BPF_MEM | BPF_H:
35234 - /* emit 'movzx rax, word ptr [rax + off]' */
35235 - EMIT3(add_2mod(0x48, src_reg, dst_reg), 0x0F, 0xB7);
35236 - goto ldx;
35237 - case BPF_LDX | BPF_MEM | BPF_W:
35238 - /* emit 'mov eax, dword ptr [rax+0x14]' */
35239 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35240 - EMIT2(add_2mod(0x40, src_reg, dst_reg), 0x8B);
35241 - else
35242 - EMIT1(0x8B);
35243 - goto ldx;
35244 - case BPF_LDX | BPF_MEM | BPF_DW:
35245 - /* emit 'mov rax, qword ptr [rax+0x14]' */
35246 - EMIT2(add_2mod(0x48, src_reg, dst_reg), 0x8B);
35247 -ldx: /* if insn->off == 0 we can save one extra byte, but
35248 - * special case of x86 r13 which always needs an offset
35249 - * is not worth the hassle
35250 - */
35251 - if (is_imm8(insn->off))
35252 - EMIT2(add_2reg(0x40, src_reg, dst_reg), insn->off);
35253 - else
35254 - EMIT1_off32(add_2reg(0x80, src_reg, dst_reg),
35255 - insn->off);
35256 - break;
35257 -
35258 - /* STX XADD: lock *(u32*)(dst_reg + off) += src_reg */
35259 - case BPF_STX | BPF_XADD | BPF_W:
35260 - /* emit 'lock add dword ptr [rax + off], eax' */
35261 - if (is_ereg(dst_reg) || is_ereg(src_reg))
35262 - EMIT3(0xF0, add_2mod(0x40, dst_reg, src_reg), 0x01);
35263 - else
35264 - EMIT2(0xF0, 0x01);
35265 - goto xadd;
35266 - case BPF_STX | BPF_XADD | BPF_DW:
35267 - EMIT3(0xF0, add_2mod(0x48, dst_reg, src_reg), 0x01);
35268 -xadd: if (is_imm8(insn->off))
35269 - EMIT2(add_2reg(0x40, dst_reg, src_reg), insn->off);
35270 - else
35271 - EMIT1_off32(add_2reg(0x80, dst_reg, src_reg),
35272 - insn->off);
35273 - break;
35274 -
35275 - /* call */
35276 - case BPF_JMP | BPF_CALL:
35277 - func = (u8 *) __bpf_call_base + imm32;
35278 - jmp_offset = func - (image + addrs[i]);
35279 - if (ctx->seen_ld_abs) {
35280 - EMIT2(0x41, 0x52); /* push %r10 */
35281 - EMIT2(0x41, 0x51); /* push %r9 */
35282 - /* need to adjust jmp offset, since
35283 - * pop %r9, pop %r10 take 4 bytes after call insn
35284 - */
35285 - jmp_offset += 4;
35286 - }
35287 - if (!imm32 || !is_simm32(jmp_offset)) {
35288 - pr_err("unsupported bpf func %d addr %p image %p\n",
35289 - imm32, func, image);
35290 - return -EINVAL;
35291 - }
35292 - EMIT1_off32(0xE8, jmp_offset);
35293 - if (ctx->seen_ld_abs) {
35294 - EMIT2(0x41, 0x59); /* pop %r9 */
35295 - EMIT2(0x41, 0x5A); /* pop %r10 */
35296 - }
35297 - break;
35298 -
35299 - /* cond jump */
35300 - case BPF_JMP | BPF_JEQ | BPF_X:
35301 - case BPF_JMP | BPF_JNE | BPF_X:
35302 - case BPF_JMP | BPF_JGT | BPF_X:
35303 - case BPF_JMP | BPF_JGE | BPF_X:
35304 - case BPF_JMP | BPF_JSGT | BPF_X:
35305 - case BPF_JMP | BPF_JSGE | BPF_X:
35306 - /* cmp dst_reg, src_reg */
35307 - EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x39,
35308 - add_2reg(0xC0, dst_reg, src_reg));
35309 - goto emit_cond_jmp;
35310 -
35311 - case BPF_JMP | BPF_JSET | BPF_X:
35312 - /* test dst_reg, src_reg */
35313 - EMIT3(add_2mod(0x48, dst_reg, src_reg), 0x85,
35314 - add_2reg(0xC0, dst_reg, src_reg));
35315 - goto emit_cond_jmp;
35316 -
35317 - case BPF_JMP | BPF_JSET | BPF_K:
35318 - /* test dst_reg, imm32 */
35319 - EMIT1(add_1mod(0x48, dst_reg));
35320 - EMIT2_off32(0xF7, add_1reg(0xC0, dst_reg), imm32);
35321 - goto emit_cond_jmp;
35322 -
35323 - case BPF_JMP | BPF_JEQ | BPF_K:
35324 - case BPF_JMP | BPF_JNE | BPF_K:
35325 - case BPF_JMP | BPF_JGT | BPF_K:
35326 - case BPF_JMP | BPF_JGE | BPF_K:
35327 - case BPF_JMP | BPF_JSGT | BPF_K:
35328 - case BPF_JMP | BPF_JSGE | BPF_K:
35329 - /* cmp dst_reg, imm8/32 */
35330 - EMIT1(add_1mod(0x48, dst_reg));
35331 -
35332 - if (is_imm8(imm32))
35333 - EMIT3(0x83, add_1reg(0xF8, dst_reg), imm32);
35334 - else
35335 - EMIT2_off32(0x81, add_1reg(0xF8, dst_reg), imm32);
35336 -
35337 -emit_cond_jmp: /* convert BPF opcode to x86 */
35338 - switch (BPF_OP(insn->code)) {
35339 - case BPF_JEQ:
35340 - jmp_cond = X86_JE;
35341 - break;
35342 - case BPF_JSET:
35343 - case BPF_JNE:
35344 - jmp_cond = X86_JNE;
35345 - break;
35346 - case BPF_JGT:
35347 - /* GT is unsigned '>', JA in x86 */
35348 - jmp_cond = X86_JA;
35349 - break;
35350 - case BPF_JGE:
35351 - /* GE is unsigned '>=', JAE in x86 */
35352 - jmp_cond = X86_JAE;
35353 - break;
35354 - case BPF_JSGT:
35355 - /* signed '>', GT in x86 */
35356 - jmp_cond = X86_JG;
35357 - break;
35358 - case BPF_JSGE:
35359 - /* signed '>=', GE in x86 */
35360 - jmp_cond = X86_JGE;
35361 - break;
35362 - default: /* to silence gcc warning */
35363 - return -EFAULT;
35364 - }
35365 - jmp_offset = addrs[i + insn->off] - addrs[i];
35366 - if (is_imm8(jmp_offset)) {
35367 - EMIT2(jmp_cond, jmp_offset);
35368 - } else if (is_simm32(jmp_offset)) {
35369 - EMIT2_off32(0x0F, jmp_cond + 0x10, jmp_offset);
35370 - } else {
35371 - pr_err("cond_jmp gen bug %llx\n", jmp_offset);
35372 - return -EFAULT;
35373 - }
35374 -
35375 - break;
35376 -
35377 - case BPF_JMP | BPF_JA:
35378 - jmp_offset = addrs[i + insn->off] - addrs[i];
35379 - if (!jmp_offset)
35380 - /* optimize out nop jumps */
35381 - break;
35382 -emit_jmp:
35383 - if (is_imm8(jmp_offset)) {
35384 - EMIT2(0xEB, jmp_offset);
35385 - } else if (is_simm32(jmp_offset)) {
35386 - EMIT1_off32(0xE9, jmp_offset);
35387 - } else {
35388 - pr_err("jmp gen bug %llx\n", jmp_offset);
35389 - return -EFAULT;
35390 - }
35391 - break;
35392 -
35393 - case BPF_LD | BPF_IND | BPF_W:
35394 - func = sk_load_word;
35395 - goto common_load;
35396 - case BPF_LD | BPF_ABS | BPF_W:
35397 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_word);
35398 -common_load: ctx->seen_ld_abs = true;
35399 - jmp_offset = func - (image + addrs[i]);
35400 - if (!func || !is_simm32(jmp_offset)) {
35401 - pr_err("unsupported bpf func %d addr %p image %p\n",
35402 - imm32, func, image);
35403 - return -EINVAL;
35404 - }
35405 - if (BPF_MODE(insn->code) == BPF_ABS) {
35406 - /* mov %esi, imm32 */
35407 - EMIT1_off32(0xBE, imm32);
35408 - } else {
35409 - /* mov %rsi, src_reg */
35410 - EMIT_mov(BPF_REG_2, src_reg);
35411 - if (imm32) {
35412 - if (is_imm8(imm32))
35413 - /* add %esi, imm8 */
35414 - EMIT3(0x83, 0xC6, imm32);
35415 - else
35416 - /* add %esi, imm32 */
35417 - EMIT2_off32(0x81, 0xC6, imm32);
35418 - }
35419 - }
35420 - /* skb pointer is in R6 (%rbx), it will be copied into
35421 - * %rdi if skb_copy_bits() call is necessary.
35422 - * sk_load_* helpers also use %r10 and %r9d.
35423 - * See bpf_jit.S
35424 - */
35425 - EMIT1_off32(0xE8, jmp_offset); /* call */
35426 - break;
35427 -
35428 - case BPF_LD | BPF_IND | BPF_H:
35429 - func = sk_load_half;
35430 - goto common_load;
35431 - case BPF_LD | BPF_ABS | BPF_H:
35432 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_half);
35433 - goto common_load;
35434 - case BPF_LD | BPF_IND | BPF_B:
35435 - func = sk_load_byte;
35436 - goto common_load;
35437 - case BPF_LD | BPF_ABS | BPF_B:
35438 - func = CHOOSE_LOAD_FUNC(imm32, sk_load_byte);
35439 - goto common_load;
35440 -
35441 - case BPF_JMP | BPF_EXIT:
35442 - if (i != insn_cnt - 1) {
35443 - jmp_offset = ctx->cleanup_addr - addrs[i];
35444 - goto emit_jmp;
35445 - }
35446 - /* update cleanup_addr */
35447 - ctx->cleanup_addr = proglen;
35448 - /* mov rbx, qword ptr [rbp-X] */
35449 - EMIT3_off32(0x48, 0x8B, 0x9D, -stacksize);
35450 - /* mov r13, qword ptr [rbp-X] */
35451 - EMIT3_off32(0x4C, 0x8B, 0xAD, -stacksize + 8);
35452 - /* mov r14, qword ptr [rbp-X] */
35453 - EMIT3_off32(0x4C, 0x8B, 0xB5, -stacksize + 16);
35454 - /* mov r15, qword ptr [rbp-X] */
35455 - EMIT3_off32(0x4C, 0x8B, 0xBD, -stacksize + 24);
35456 -
35457 - EMIT1(0xC9); /* leave */
35458 - EMIT1(0xC3); /* ret */
35459 - break;
35460 -
35461 - default:
35462 - /* By design x64 JIT should support all BPF instructions
35463 - * This error will be seen if new instruction was added
35464 - * to interpreter, but not to JIT
35465 - * or if there is junk in sk_filter
35466 - */
35467 - pr_err("bpf_jit: unknown opcode %02x\n", insn->code);
35468 - return -EINVAL;
35469 - }
35470 -
35471 - ilen = prog - temp;
35472 - if (image) {
35473 - if (unlikely(proglen + ilen > oldproglen)) {
35474 - pr_err("bpf_jit_compile fatal error\n");
35475 - return -EFAULT;
35476 - }
35477 - memcpy(image + proglen, temp, ilen);
35478 - }
35479 - proglen += ilen;
35480 - addrs[i] = proglen;
35481 - prog = temp;
35482 - }
35483 - return proglen;
35484 -}
35485 -
35486 -void bpf_jit_compile(struct sk_filter *prog)
35487 -{
35488 -}
35489 -
35490 -void bpf_int_jit_compile(struct sk_filter *prog)
35491 -{
35492 - struct bpf_binary_header *header = NULL;
35493 - int proglen, oldproglen = 0;
35494 - struct jit_context ctx = {};
35495 +void bpf_jit_compile(struct sk_filter *fp)
35496 +{
35497 + u8 temp[MAX_INSTR_CODE_SIZE];
35498 + u8 *prog;
35499 + unsigned int proglen, oldproglen = 0;
35500 + int ilen, i;
35501 + int t_offset, f_offset;
35502 + u8 t_op, f_op, seen = 0, pass;
35503 u8 *image = NULL;
35504 - int *addrs;
35505 - int pass;
35506 - int i;
35507 + u8 *header = NULL;
35508 + u8 *func;
35509 + int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
35510 + unsigned int cleanup_addr; /* epilogue code offset */
35511 + unsigned int *addrs;
35512 + const struct sock_filter *filter = fp->insns;
35513 + int flen = fp->len;
35514 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35515 + unsigned int randkey;
35516 +#endif
35517
35518 if (!bpf_jit_enable)
35519 return;
35520
35521 - if (!prog || !prog->len)
35522 - return;
35523 -
35524 - addrs = kmalloc(prog->len * sizeof(*addrs), GFP_KERNEL);
35525 - if (!addrs)
35526 + addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
35527 + if (addrs == NULL)
35528 return;
35529
35530 /* Before first pass, make a rough estimation of addrs[]
35531 - * each bpf instruction is translated to less than 64 bytes
35532 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
35533 */
35534 - for (proglen = 0, i = 0; i < prog->len; i++) {
35535 - proglen += 64;
35536 + for (proglen = 0, i = 0; i < flen; i++) {
35537 + proglen += MAX_INSTR_CODE_SIZE;
35538 addrs[i] = proglen;
35539 }
35540 - ctx.cleanup_addr = proglen;
35541 + cleanup_addr = proglen; /* epilogue address */
35542
35543 for (pass = 0; pass < 10; pass++) {
35544 - proglen = do_jit(prog, addrs, image, oldproglen, &ctx);
35545 - if (proglen <= 0) {
35546 - image = NULL;
35547 - if (header)
35548 - module_free(NULL, header);
35549 - goto out;
35550 + u8 seen_or_pass0 = (pass == 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;
35551 + /* no prologue/epilogue for trivial filters (RET something) */
35552 + proglen = 0;
35553 + prog = temp;
35554 +
35555 + if (seen_or_pass0) {
35556 + EMIT4(0x55, 0x48, 0x89, 0xe5); /* push %rbp; mov %rsp,%rbp */
35557 + EMIT4(0x48, 0x83, 0xec, 96); /* subq $96,%rsp */
35558 + /* note : must save %rbx in case bpf_error is hit */
35559 + if (seen_or_pass0 & (SEEN_XREG | SEEN_DATAREF))
35560 + EMIT4(0x48, 0x89, 0x5d, 0xf8); /* mov %rbx, -8(%rbp) */
35561 + if (seen_or_pass0 & SEEN_XREG)
35562 + CLEAR_X(); /* make sure we dont leek kernel memory */
35563 +
35564 + /*
35565 + * If this filter needs to access skb data,
35566 + * loads r9 and r8 with :
35567 + * r9 = skb->len - skb->data_len
35568 + * r8 = skb->data
35569 + */
35570 + if (seen_or_pass0 & SEEN_DATAREF) {
35571 + if (offsetof(struct sk_buff, len) <= 127)
35572 + /* mov off8(%rdi),%r9d */
35573 + EMIT4(0x44, 0x8b, 0x4f, offsetof(struct sk_buff, len));
35574 + else {
35575 + /* mov off32(%rdi),%r9d */
35576 + EMIT3(0x44, 0x8b, 0x8f);
35577 + EMIT(offsetof(struct sk_buff, len), 4);
35578 + }
35579 + if (is_imm8(offsetof(struct sk_buff, data_len)))
35580 + /* sub off8(%rdi),%r9d */
35581 + EMIT4(0x44, 0x2b, 0x4f, offsetof(struct sk_buff, data_len));
35582 + else {
35583 + EMIT3(0x44, 0x2b, 0x8f);
35584 + EMIT(offsetof(struct sk_buff, data_len), 4);
35585 + }
35586 +
35587 + if (is_imm8(offsetof(struct sk_buff, data)))
35588 + /* mov off8(%rdi),%r8 */
35589 + EMIT4(0x4c, 0x8b, 0x47, offsetof(struct sk_buff, data));
35590 + else {
35591 + /* mov off32(%rdi),%r8 */
35592 + EMIT3(0x4c, 0x8b, 0x87);
35593 + EMIT(offsetof(struct sk_buff, data), 4);
35594 + }
35595 + }
35596 }
35597 +
35598 + switch (filter[0].code) {
35599 + case BPF_S_RET_K:
35600 + case BPF_S_LD_W_LEN:
35601 + case BPF_S_ANC_PROTOCOL:
35602 + case BPF_S_ANC_IFINDEX:
35603 + case BPF_S_ANC_MARK:
35604 + case BPF_S_ANC_RXHASH:
35605 + case BPF_S_ANC_CPU:
35606 + case BPF_S_ANC_VLAN_TAG:
35607 + case BPF_S_ANC_VLAN_TAG_PRESENT:
35608 + case BPF_S_ANC_QUEUE:
35609 + case BPF_S_ANC_PKTTYPE:
35610 + case BPF_S_LD_W_ABS:
35611 + case BPF_S_LD_H_ABS:
35612 + case BPF_S_LD_B_ABS:
35613 + /* first instruction sets A register (or is RET 'constant') */
35614 + break;
35615 + default:
35616 + /* make sure we dont leak kernel information to user */
35617 + CLEAR_A(); /* A = 0 */
35618 + }
35619 +
35620 + for (i = 0; i < flen; i++) {
35621 + unsigned int K = filter[i].k;
35622 +
35623 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35624 + randkey = prandom_u32();
35625 +#endif
35626 +
35627 + switch (filter[i].code) {
35628 + case BPF_S_ALU_ADD_X: /* A += X; */
35629 + seen |= SEEN_XREG;
35630 + EMIT2(0x01, 0xd8); /* add %ebx,%eax */
35631 + break;
35632 + case BPF_S_ALU_ADD_K: /* A += K; */
35633 + if (!K)
35634 + break;
35635 + if (is_imm8(K))
35636 + EMIT3(0x83, 0xc0, K); /* add imm8,%eax */
35637 + else
35638 + EMIT1_off32(0x05, K); /* add imm32,%eax */
35639 + break;
35640 + case BPF_S_ALU_SUB_X: /* A -= X; */
35641 + seen |= SEEN_XREG;
35642 + EMIT2(0x29, 0xd8); /* sub %ebx,%eax */
35643 + break;
35644 + case BPF_S_ALU_SUB_K: /* A -= K */
35645 + if (!K)
35646 + break;
35647 + if (is_imm8(K))
35648 + EMIT3(0x83, 0xe8, K); /* sub imm8,%eax */
35649 + else
35650 + EMIT1_off32(0x2d, K); /* sub imm32,%eax */
35651 + break;
35652 + case BPF_S_ALU_MUL_X: /* A *= X; */
35653 + seen |= SEEN_XREG;
35654 + EMIT3(0x0f, 0xaf, 0xc3); /* imul %ebx,%eax */
35655 + break;
35656 + case BPF_S_ALU_MUL_K: /* A *= K */
35657 + if (is_imm8(K))
35658 + EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
35659 + else
35660 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
35661 + break;
35662 + case BPF_S_ALU_DIV_X: /* A /= X; */
35663 + seen |= SEEN_XREG;
35664 + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35665 + if (pc_ret0 > 0) {
35666 + /* addrs[pc_ret0 - 1] is start address of target
35667 + * (addrs[i] - 4) is the address following this jmp
35668 + * ("xor %edx,%edx; div %ebx" being 4 bytes long)
35669 + */
35670 + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35671 + (addrs[i] - 4));
35672 + } else {
35673 + EMIT_COND_JMP(X86_JNE, 2 + 5);
35674 + CLEAR_A();
35675 + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 4)); /* jmp .+off32 */
35676 + }
35677 + EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
35678 + break;
35679 + case BPF_S_ALU_MOD_X: /* A %= X; */
35680 + seen |= SEEN_XREG;
35681 + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */
35682 + if (pc_ret0 > 0) {
35683 + /* addrs[pc_ret0 - 1] is start address of target
35684 + * (addrs[i] - 6) is the address following this jmp
35685 + * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long)
35686 + */
35687 + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
35688 + (addrs[i] - 6));
35689 + } else {
35690 + EMIT_COND_JMP(X86_JNE, 2 + 5);
35691 + CLEAR_A();
35692 + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */
35693 + }
35694 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35695 + EMIT2(0xf7, 0xf3); /* div %ebx */
35696 + EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35697 + break;
35698 + case BPF_S_ALU_MOD_K: /* A %= K; */
35699 + if (K == 1) {
35700 + CLEAR_A();
35701 + break;
35702 + }
35703 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35704 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35705 + DILUTE_CONST_SEQUENCE(K, randkey);
35706 +#else
35707 + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35708 +#endif
35709 + EMIT2(0xf7, 0xf1); /* div %ecx */
35710 + EMIT2(0x89, 0xd0); /* mov %edx,%eax */
35711 + break;
35712 + case BPF_S_ALU_DIV_K: /* A /= K */
35713 + if (K == 1)
35714 + break;
35715 + EMIT2(0x31, 0xd2); /* xor %edx,%edx */
35716 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
35717 + DILUTE_CONST_SEQUENCE(K, randkey);
35718 +#else
35719 + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
35720 +#endif
35721 + EMIT2(0xf7, 0xf1); /* div %ecx */
35722 + break;
35723 + case BPF_S_ALU_AND_X:
35724 + seen |= SEEN_XREG;
35725 + EMIT2(0x21, 0xd8); /* and %ebx,%eax */
35726 + break;
35727 + case BPF_S_ALU_AND_K:
35728 + if (K >= 0xFFFFFF00) {
35729 + EMIT2(0x24, K & 0xFF); /* and imm8,%al */
35730 + } else if (K >= 0xFFFF0000) {
35731 + EMIT2(0x66, 0x25); /* and imm16,%ax */
35732 + EMIT(K, 2);
35733 + } else {
35734 + EMIT1_off32(0x25, K); /* and imm32,%eax */
35735 + }
35736 + break;
35737 + case BPF_S_ALU_OR_X:
35738 + seen |= SEEN_XREG;
35739 + EMIT2(0x09, 0xd8); /* or %ebx,%eax */
35740 + break;
35741 + case BPF_S_ALU_OR_K:
35742 + if (is_imm8(K))
35743 + EMIT3(0x83, 0xc8, K); /* or imm8,%eax */
35744 + else
35745 + EMIT1_off32(0x0d, K); /* or imm32,%eax */
35746 + break;
35747 + case BPF_S_ANC_ALU_XOR_X: /* A ^= X; */
35748 + case BPF_S_ALU_XOR_X:
35749 + seen |= SEEN_XREG;
35750 + EMIT2(0x31, 0xd8); /* xor %ebx,%eax */
35751 + break;
35752 + case BPF_S_ALU_XOR_K: /* A ^= K; */
35753 + if (K == 0)
35754 + break;
35755 + if (is_imm8(K))
35756 + EMIT3(0x83, 0xf0, K); /* xor imm8,%eax */
35757 + else
35758 + EMIT1_off32(0x35, K); /* xor imm32,%eax */
35759 + break;
35760 + case BPF_S_ALU_LSH_X: /* A <<= X; */
35761 + seen |= SEEN_XREG;
35762 + EMIT4(0x89, 0xd9, 0xd3, 0xe0); /* mov %ebx,%ecx; shl %cl,%eax */
35763 + break;
35764 + case BPF_S_ALU_LSH_K:
35765 + if (K == 0)
35766 + break;
35767 + else if (K == 1)
35768 + EMIT2(0xd1, 0xe0); /* shl %eax */
35769 + else
35770 + EMIT3(0xc1, 0xe0, K);
35771 + break;
35772 + case BPF_S_ALU_RSH_X: /* A >>= X; */
35773 + seen |= SEEN_XREG;
35774 + EMIT4(0x89, 0xd9, 0xd3, 0xe8); /* mov %ebx,%ecx; shr %cl,%eax */
35775 + break;
35776 + case BPF_S_ALU_RSH_K: /* A >>= K; */
35777 + if (K == 0)
35778 + break;
35779 + else if (K == 1)
35780 + EMIT2(0xd1, 0xe8); /* shr %eax */
35781 + else
35782 + EMIT3(0xc1, 0xe8, K);
35783 + break;
35784 + case BPF_S_ALU_NEG:
35785 + EMIT2(0xf7, 0xd8); /* neg %eax */
35786 + break;
35787 + case BPF_S_RET_K:
35788 + if (!K) {
35789 + if (pc_ret0 == -1)
35790 + pc_ret0 = i;
35791 + CLEAR_A();
35792 + } else {
35793 + EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35794 + }
35795 + /* fallinto */
35796 + case BPF_S_RET_A:
35797 + if (seen_or_pass0) {
35798 + if (i != flen - 1) {
35799 + EMIT_JMP(cleanup_addr - addrs[i]);
35800 + break;
35801 + }
35802 + if (seen_or_pass0 & SEEN_XREG)
35803 + EMIT4(0x48, 0x8b, 0x5d, 0xf8); /* mov -8(%rbp),%rbx */
35804 + EMIT1(0xc9); /* leaveq */
35805 + }
35806 + EMIT1(0xc3); /* ret */
35807 + break;
35808 + case BPF_S_MISC_TAX: /* X = A */
35809 + seen |= SEEN_XREG;
35810 + EMIT2(0x89, 0xc3); /* mov %eax,%ebx */
35811 + break;
35812 + case BPF_S_MISC_TXA: /* A = X */
35813 + seen |= SEEN_XREG;
35814 + EMIT2(0x89, 0xd8); /* mov %ebx,%eax */
35815 + break;
35816 + case BPF_S_LD_IMM: /* A = K */
35817 + if (!K)
35818 + CLEAR_A();
35819 + else
35820 + EMIT1_off32(0xb8, K); /* mov $imm32,%eax */
35821 + break;
35822 + case BPF_S_LDX_IMM: /* X = K */
35823 + seen |= SEEN_XREG;
35824 + if (!K)
35825 + CLEAR_X();
35826 + else
35827 + EMIT1_off32(0xbb, K); /* mov $imm32,%ebx */
35828 + break;
35829 + case BPF_S_LD_MEM: /* A = mem[K] : mov off8(%rbp),%eax */
35830 + seen |= SEEN_MEM;
35831 + EMIT3(0x8b, 0x45, 0xf0 - K*4);
35832 + break;
35833 + case BPF_S_LDX_MEM: /* X = mem[K] : mov off8(%rbp),%ebx */
35834 + seen |= SEEN_XREG | SEEN_MEM;
35835 + EMIT3(0x8b, 0x5d, 0xf0 - K*4);
35836 + break;
35837 + case BPF_S_ST: /* mem[K] = A : mov %eax,off8(%rbp) */
35838 + seen |= SEEN_MEM;
35839 + EMIT3(0x89, 0x45, 0xf0 - K*4);
35840 + break;
35841 + case BPF_S_STX: /* mem[K] = X : mov %ebx,off8(%rbp) */
35842 + seen |= SEEN_XREG | SEEN_MEM;
35843 + EMIT3(0x89, 0x5d, 0xf0 - K*4);
35844 + break;
35845 + case BPF_S_LD_W_LEN: /* A = skb->len; */
35846 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, len) != 4);
35847 + if (is_imm8(offsetof(struct sk_buff, len)))
35848 + /* mov off8(%rdi),%eax */
35849 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, len));
35850 + else {
35851 + EMIT2(0x8b, 0x87);
35852 + EMIT(offsetof(struct sk_buff, len), 4);
35853 + }
35854 + break;
35855 + case BPF_S_LDX_W_LEN: /* X = skb->len; */
35856 + seen |= SEEN_XREG;
35857 + if (is_imm8(offsetof(struct sk_buff, len)))
35858 + /* mov off8(%rdi),%ebx */
35859 + EMIT3(0x8b, 0x5f, offsetof(struct sk_buff, len));
35860 + else {
35861 + EMIT2(0x8b, 0x9f);
35862 + EMIT(offsetof(struct sk_buff, len), 4);
35863 + }
35864 + break;
35865 + case BPF_S_ANC_PROTOCOL: /* A = ntohs(skb->protocol); */
35866 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
35867 + if (is_imm8(offsetof(struct sk_buff, protocol))) {
35868 + /* movzwl off8(%rdi),%eax */
35869 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, protocol));
35870 + } else {
35871 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35872 + EMIT(offsetof(struct sk_buff, protocol), 4);
35873 + }
35874 + EMIT2(0x86, 0xc4); /* ntohs() : xchg %al,%ah */
35875 + break;
35876 + case BPF_S_ANC_IFINDEX:
35877 + if (is_imm8(offsetof(struct sk_buff, dev))) {
35878 + /* movq off8(%rdi),%rax */
35879 + EMIT4(0x48, 0x8b, 0x47, offsetof(struct sk_buff, dev));
35880 + } else {
35881 + EMIT3(0x48, 0x8b, 0x87); /* movq off32(%rdi),%rax */
35882 + EMIT(offsetof(struct sk_buff, dev), 4);
35883 + }
35884 + EMIT3(0x48, 0x85, 0xc0); /* test %rax,%rax */
35885 + EMIT_COND_JMP(X86_JE, cleanup_addr - (addrs[i] - 6));
35886 + BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
35887 + EMIT2(0x8b, 0x80); /* mov off32(%rax),%eax */
35888 + EMIT(offsetof(struct net_device, ifindex), 4);
35889 + break;
35890 + case BPF_S_ANC_MARK:
35891 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
35892 + if (is_imm8(offsetof(struct sk_buff, mark))) {
35893 + /* mov off8(%rdi),%eax */
35894 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, mark));
35895 + } else {
35896 + EMIT2(0x8b, 0x87);
35897 + EMIT(offsetof(struct sk_buff, mark), 4);
35898 + }
35899 + break;
35900 + case BPF_S_ANC_RXHASH:
35901 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
35902 + if (is_imm8(offsetof(struct sk_buff, hash))) {
35903 + /* mov off8(%rdi),%eax */
35904 + EMIT3(0x8b, 0x47, offsetof(struct sk_buff, hash));
35905 + } else {
35906 + EMIT2(0x8b, 0x87);
35907 + EMIT(offsetof(struct sk_buff, hash), 4);
35908 + }
35909 + break;
35910 + case BPF_S_ANC_QUEUE:
35911 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
35912 + if (is_imm8(offsetof(struct sk_buff, queue_mapping))) {
35913 + /* movzwl off8(%rdi),%eax */
35914 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, queue_mapping));
35915 + } else {
35916 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35917 + EMIT(offsetof(struct sk_buff, queue_mapping), 4);
35918 + }
35919 + break;
35920 + case BPF_S_ANC_CPU:
35921 +#ifdef CONFIG_SMP
35922 + EMIT4(0x65, 0x8b, 0x04, 0x25); /* mov %gs:off32,%eax */
35923 + EMIT((u32)(unsigned long)&cpu_number, 4); /* A = smp_processor_id(); */
35924 +#else
35925 + CLEAR_A();
35926 +#endif
35927 + break;
35928 + case BPF_S_ANC_VLAN_TAG:
35929 + case BPF_S_ANC_VLAN_TAG_PRESENT:
35930 + BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
35931 + if (is_imm8(offsetof(struct sk_buff, vlan_tci))) {
35932 + /* movzwl off8(%rdi),%eax */
35933 + EMIT4(0x0f, 0xb7, 0x47, offsetof(struct sk_buff, vlan_tci));
35934 + } else {
35935 + EMIT3(0x0f, 0xb7, 0x87); /* movzwl off32(%rdi),%eax */
35936 + EMIT(offsetof(struct sk_buff, vlan_tci), 4);
35937 + }
35938 + BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
35939 + if (filter[i].code == BPF_S_ANC_VLAN_TAG) {
35940 + EMIT3(0x80, 0xe4, 0xef); /* and $0xef,%ah */
35941 + } else {
35942 + EMIT3(0xc1, 0xe8, 0x0c); /* shr $0xc,%eax */
35943 + EMIT3(0x83, 0xe0, 0x01); /* and $0x1,%eax */
35944 + }
35945 + break;
35946 + case BPF_S_ANC_PKTTYPE:
35947 + {
35948 + int off = pkt_type_offset();
35949 +
35950 + if (off < 0)
35951 + goto out;
35952 + if (is_imm8(off)) {
35953 + /* movzbl off8(%rdi),%eax */
35954 + EMIT4(0x0f, 0xb6, 0x47, off);
35955 + } else {
35956 + /* movbl off32(%rdi),%eax */
35957 + EMIT3(0x0f, 0xb6, 0x87);
35958 + EMIT(off, 4);
35959 + }
35960 + EMIT3(0x83, 0xe0, PKT_TYPE_MAX); /* and $0x7,%eax */
35961 + break;
35962 + }
35963 + case BPF_S_LD_W_ABS:
35964 + func = CHOOSE_LOAD_FUNC(K, sk_load_word);
35965 +common_load: seen |= SEEN_DATAREF;
35966 + t_offset = func - (image + addrs[i]);
35967 + EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35968 + EMIT1_off32(0xe8, t_offset); /* call */
35969 + break;
35970 + case BPF_S_LD_H_ABS:
35971 + func = CHOOSE_LOAD_FUNC(K, sk_load_half);
35972 + goto common_load;
35973 + case BPF_S_LD_B_ABS:
35974 + func = CHOOSE_LOAD_FUNC(K, sk_load_byte);
35975 + goto common_load;
35976 + case BPF_S_LDX_B_MSH:
35977 + func = CHOOSE_LOAD_FUNC(K, sk_load_byte_msh);
35978 + seen |= SEEN_DATAREF | SEEN_XREG;
35979 + t_offset = func - (image + addrs[i]);
35980 + EMIT1_off32(0xbe, K); /* mov imm32,%esi */
35981 + EMIT1_off32(0xe8, t_offset); /* call sk_load_byte_msh */
35982 + break;
35983 + case BPF_S_LD_W_IND:
35984 + func = sk_load_word;
35985 +common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
35986 + t_offset = func - (image + addrs[i]);
35987 + if (K) {
35988 + if (is_imm8(K)) {
35989 + EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
35990 + } else {
35991 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
35992 + }
35993 + } else {
35994 + EMIT2(0x89,0xde); /* mov %ebx,%esi */
35995 + }
35996 + EMIT1_off32(0xe8, t_offset); /* call sk_load_xxx_ind */
35997 + break;
35998 + case BPF_S_LD_H_IND:
35999 + func = sk_load_half;
36000 + goto common_load_ind;
36001 + case BPF_S_LD_B_IND:
36002 + func = sk_load_byte;
36003 + goto common_load_ind;
36004 + case BPF_S_JMP_JA:
36005 + t_offset = addrs[i + K] - addrs[i];
36006 + EMIT_JMP(t_offset);
36007 + break;
36008 + COND_SEL(BPF_S_JMP_JGT_K, X86_JA, X86_JBE);
36009 + COND_SEL(BPF_S_JMP_JGE_K, X86_JAE, X86_JB);
36010 + COND_SEL(BPF_S_JMP_JEQ_K, X86_JE, X86_JNE);
36011 + COND_SEL(BPF_S_JMP_JSET_K,X86_JNE, X86_JE);
36012 + COND_SEL(BPF_S_JMP_JGT_X, X86_JA, X86_JBE);
36013 + COND_SEL(BPF_S_JMP_JGE_X, X86_JAE, X86_JB);
36014 + COND_SEL(BPF_S_JMP_JEQ_X, X86_JE, X86_JNE);
36015 + COND_SEL(BPF_S_JMP_JSET_X,X86_JNE, X86_JE);
36016 +
36017 +cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
36018 + t_offset = addrs[i + filter[i].jt] - addrs[i];
36019 +
36020 + /* same targets, can avoid doing the test :) */
36021 + if (filter[i].jt == filter[i].jf) {
36022 + EMIT_JMP(t_offset);
36023 + break;
36024 + }
36025 +
36026 + switch (filter[i].code) {
36027 + case BPF_S_JMP_JGT_X:
36028 + case BPF_S_JMP_JGE_X:
36029 + case BPF_S_JMP_JEQ_X:
36030 + seen |= SEEN_XREG;
36031 + EMIT2(0x39, 0xd8); /* cmp %ebx,%eax */
36032 + break;
36033 + case BPF_S_JMP_JSET_X:
36034 + seen |= SEEN_XREG;
36035 + EMIT2(0x85, 0xd8); /* test %ebx,%eax */
36036 + break;
36037 + case BPF_S_JMP_JEQ_K:
36038 + if (K == 0) {
36039 + EMIT2(0x85, 0xc0); /* test %eax,%eax */
36040 + break;
36041 + }
36042 + case BPF_S_JMP_JGT_K:
36043 + case BPF_S_JMP_JGE_K:
36044 + if (K <= 127)
36045 + EMIT3(0x83, 0xf8, K); /* cmp imm8,%eax */
36046 + else
36047 + EMIT1_off32(0x3d, K); /* cmp imm32,%eax */
36048 + break;
36049 + case BPF_S_JMP_JSET_K:
36050 + if (K <= 0xFF)
36051 + EMIT2(0xa8, K); /* test imm8,%al */
36052 + else if (!(K & 0xFFFF00FF))
36053 + EMIT3(0xf6, 0xc4, K >> 8); /* test imm8,%ah */
36054 + else if (K <= 0xFFFF) {
36055 + EMIT2(0x66, 0xa9); /* test imm16,%ax */
36056 + EMIT(K, 2);
36057 + } else {
36058 + EMIT1_off32(0xa9, K); /* test imm32,%eax */
36059 + }
36060 + break;
36061 + }
36062 + if (filter[i].jt != 0) {
36063 + if (filter[i].jf && f_offset)
36064 + t_offset += is_near(f_offset) ? 2 : 5;
36065 + EMIT_COND_JMP(t_op, t_offset);
36066 + if (filter[i].jf)
36067 + EMIT_JMP(f_offset);
36068 + break;
36069 + }
36070 + EMIT_COND_JMP(f_op, f_offset);
36071 + break;
36072 + default:
36073 + /* hmm, too complex filter, give up with jit compiler */
36074 + goto out;
36075 + }
36076 + ilen = prog - temp;
36077 + if (image) {
36078 + if (unlikely(proglen + ilen > oldproglen)) {
36079 + pr_err("bpb_jit_compile fatal error\n");
36080 + kfree(addrs);
36081 + module_free_exec(NULL, image);
36082 + return;
36083 + }
36084 + pax_open_kernel();
36085 + memcpy(image + proglen, temp, ilen);
36086 + pax_close_kernel();
36087 + }
36088 + proglen += ilen;
36089 + addrs[i] = proglen;
36090 + prog = temp;
36091 + }
36092 + /* last bpf instruction is always a RET :
36093 + * use it to give the cleanup instruction(s) addr
36094 + */
36095 + cleanup_addr = proglen - 1; /* ret */
36096 + if (seen_or_pass0)
36097 + cleanup_addr -= 1; /* leaveq */
36098 + if (seen_or_pass0 & SEEN_XREG)
36099 + cleanup_addr -= 4; /* mov -8(%rbp),%rbx */
36100 +
36101 if (image) {
36102 if (proglen != oldproglen)
36103 - pr_err("bpf_jit: proglen=%d != oldproglen=%d\n",
36104 - proglen, oldproglen);
36105 + pr_err("bpb_jit_compile proglen=%u != oldproglen=%u\n", proglen, oldproglen);
36106 break;
36107 }
36108 if (proglen == oldproglen) {
36109 @@ -918,32 +872,30 @@ void bpf_int_jit_compile(struct sk_filter *prog)
36110 }
36111
36112 if (bpf_jit_enable > 1)
36113 - bpf_jit_dump(prog->len, proglen, 0, image);
36114 + bpf_jit_dump(flen, proglen, pass, image);
36115
36116 if (image) {
36117 bpf_flush_icache(header, image + proglen);
36118 - set_memory_ro((unsigned long)header, header->pages);
36119 - prog->bpf_func = (void *)image;
36120 - prog->jited = 1;
36121 + fp->bpf_func = (void *)image;
36122 }
36123 out:
36124 kfree(addrs);
36125 + return;
36126 }
36127
36128 static void bpf_jit_free_deferred(struct work_struct *work)
36129 {
36130 struct sk_filter *fp = container_of(work, struct sk_filter, work);
36131 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
36132 - struct bpf_binary_header *header = (void *)addr;
36133
36134 - set_memory_rw(addr, header->pages);
36135 - module_free(NULL, header);
36136 + set_memory_rw(addr, 1);
36137 + module_free_exec(NULL, (void *)addr);
36138 kfree(fp);
36139 }
36140
36141 void bpf_jit_free(struct sk_filter *fp)
36142 {
36143 - if (fp->jited) {
36144 + if (fp->bpf_func != sk_run_filter) {
36145 INIT_WORK(&fp->work, bpf_jit_free_deferred);
36146 schedule_work(&fp->work);
36147 } else {
36148 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
36149 index 5d04be5..2beeaa2 100644
36150 --- a/arch/x86/oprofile/backtrace.c
36151 +++ b/arch/x86/oprofile/backtrace.c
36152 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
36153 struct stack_frame_ia32 *fp;
36154 unsigned long bytes;
36155
36156 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36157 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36158 if (bytes != 0)
36159 return NULL;
36160
36161 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
36162 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
36163
36164 oprofile_add_trace(bufhead[0].return_address);
36165
36166 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
36167 struct stack_frame bufhead[2];
36168 unsigned long bytes;
36169
36170 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
36171 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
36172 if (bytes != 0)
36173 return NULL;
36174
36175 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
36176 {
36177 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
36178
36179 - if (!user_mode_vm(regs)) {
36180 + if (!user_mode(regs)) {
36181 unsigned long stack = kernel_stack_pointer(regs);
36182 if (depth)
36183 dump_trace(NULL, regs, (unsigned long *)stack, 0,
36184 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
36185 index 379e8bd..6386e09 100644
36186 --- a/arch/x86/oprofile/nmi_int.c
36187 +++ b/arch/x86/oprofile/nmi_int.c
36188 @@ -23,6 +23,7 @@
36189 #include <asm/nmi.h>
36190 #include <asm/msr.h>
36191 #include <asm/apic.h>
36192 +#include <asm/pgtable.h>
36193
36194 #include "op_counter.h"
36195 #include "op_x86_model.h"
36196 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
36197 if (ret)
36198 return ret;
36199
36200 - if (!model->num_virt_counters)
36201 - model->num_virt_counters = model->num_counters;
36202 + if (!model->num_virt_counters) {
36203 + pax_open_kernel();
36204 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
36205 + pax_close_kernel();
36206 + }
36207
36208 mux_init(ops);
36209
36210 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
36211 index 50d86c0..7985318 100644
36212 --- a/arch/x86/oprofile/op_model_amd.c
36213 +++ b/arch/x86/oprofile/op_model_amd.c
36214 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
36215 num_counters = AMD64_NUM_COUNTERS;
36216 }
36217
36218 - op_amd_spec.num_counters = num_counters;
36219 - op_amd_spec.num_controls = num_counters;
36220 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36221 + pax_open_kernel();
36222 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
36223 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
36224 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
36225 + pax_close_kernel();
36226
36227 return 0;
36228 }
36229 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
36230 index d90528e..0127e2b 100644
36231 --- a/arch/x86/oprofile/op_model_ppro.c
36232 +++ b/arch/x86/oprofile/op_model_ppro.c
36233 @@ -19,6 +19,7 @@
36234 #include <asm/msr.h>
36235 #include <asm/apic.h>
36236 #include <asm/nmi.h>
36237 +#include <asm/pgtable.h>
36238
36239 #include "op_x86_model.h"
36240 #include "op_counter.h"
36241 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
36242
36243 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
36244
36245 - op_arch_perfmon_spec.num_counters = num_counters;
36246 - op_arch_perfmon_spec.num_controls = num_counters;
36247 + pax_open_kernel();
36248 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
36249 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
36250 + pax_close_kernel();
36251 }
36252
36253 static int arch_perfmon_init(struct oprofile_operations *ignore)
36254 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
36255 index 71e8a67..6a313bb 100644
36256 --- a/arch/x86/oprofile/op_x86_model.h
36257 +++ b/arch/x86/oprofile/op_x86_model.h
36258 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
36259 void (*switch_ctrl)(struct op_x86_model_spec const *model,
36260 struct op_msrs const * const msrs);
36261 #endif
36262 -};
36263 +} __do_const;
36264
36265 struct op_counter_config;
36266
36267 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
36268 index 84b9d67..260e5ff 100644
36269 --- a/arch/x86/pci/intel_mid_pci.c
36270 +++ b/arch/x86/pci/intel_mid_pci.c
36271 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
36272 pr_info("Intel MID platform detected, using MID PCI ops\n");
36273 pci_mmcfg_late_init();
36274 pcibios_enable_irq = intel_mid_pci_irq_enable;
36275 - pci_root_ops = intel_mid_pci_ops;
36276 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
36277 pci_soc_mode = 1;
36278 /* Continue with standard init */
36279 return 1;
36280 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
36281 index 84112f5..6334d60 100644
36282 --- a/arch/x86/pci/irq.c
36283 +++ b/arch/x86/pci/irq.c
36284 @@ -50,7 +50,7 @@ struct irq_router {
36285 struct irq_router_handler {
36286 u16 vendor;
36287 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
36288 -};
36289 +} __do_const;
36290
36291 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
36292 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
36293 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
36294 return 0;
36295 }
36296
36297 -static __initdata struct irq_router_handler pirq_routers[] = {
36298 +static __initconst const struct irq_router_handler pirq_routers[] = {
36299 { PCI_VENDOR_ID_INTEL, intel_router_probe },
36300 { PCI_VENDOR_ID_AL, ali_router_probe },
36301 { PCI_VENDOR_ID_ITE, ite_router_probe },
36302 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
36303 static void __init pirq_find_router(struct irq_router *r)
36304 {
36305 struct irq_routing_table *rt = pirq_table;
36306 - struct irq_router_handler *h;
36307 + const struct irq_router_handler *h;
36308
36309 #ifdef CONFIG_PCI_BIOS
36310 if (!rt->signature) {
36311 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
36312 return 0;
36313 }
36314
36315 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
36316 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
36317 {
36318 .callback = fix_broken_hp_bios_irq9,
36319 .ident = "HP Pavilion N5400 Series Laptop",
36320 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
36321 index c77b24a..c979855 100644
36322 --- a/arch/x86/pci/pcbios.c
36323 +++ b/arch/x86/pci/pcbios.c
36324 @@ -79,7 +79,7 @@ union bios32 {
36325 static struct {
36326 unsigned long address;
36327 unsigned short segment;
36328 -} bios32_indirect = { 0, __KERNEL_CS };
36329 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
36330
36331 /*
36332 * Returns the entry point for the given service, NULL on error
36333 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
36334 unsigned long length; /* %ecx */
36335 unsigned long entry; /* %edx */
36336 unsigned long flags;
36337 + struct desc_struct d, *gdt;
36338
36339 local_irq_save(flags);
36340 - __asm__("lcall *(%%edi); cld"
36341 +
36342 + gdt = get_cpu_gdt_table(smp_processor_id());
36343 +
36344 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
36345 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36346 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
36347 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36348 +
36349 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
36350 : "=a" (return_code),
36351 "=b" (address),
36352 "=c" (length),
36353 "=d" (entry)
36354 : "0" (service),
36355 "1" (0),
36356 - "D" (&bios32_indirect));
36357 + "D" (&bios32_indirect),
36358 + "r"(__PCIBIOS_DS)
36359 + : "memory");
36360 +
36361 + pax_open_kernel();
36362 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
36363 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
36364 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
36365 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
36366 + pax_close_kernel();
36367 +
36368 local_irq_restore(flags);
36369
36370 switch (return_code) {
36371 - case 0:
36372 - return address + entry;
36373 - case 0x80: /* Not present */
36374 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36375 - return 0;
36376 - default: /* Shouldn't happen */
36377 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36378 - service, return_code);
36379 + case 0: {
36380 + int cpu;
36381 + unsigned char flags;
36382 +
36383 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
36384 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
36385 + printk(KERN_WARNING "bios32_service: not valid\n");
36386 return 0;
36387 + }
36388 + address = address + PAGE_OFFSET;
36389 + length += 16UL; /* some BIOSs underreport this... */
36390 + flags = 4;
36391 + if (length >= 64*1024*1024) {
36392 + length >>= PAGE_SHIFT;
36393 + flags |= 8;
36394 + }
36395 +
36396 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
36397 + gdt = get_cpu_gdt_table(cpu);
36398 + pack_descriptor(&d, address, length, 0x9b, flags);
36399 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
36400 + pack_descriptor(&d, address, length, 0x93, flags);
36401 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
36402 + }
36403 + return entry;
36404 + }
36405 + case 0x80: /* Not present */
36406 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
36407 + return 0;
36408 + default: /* Shouldn't happen */
36409 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
36410 + service, return_code);
36411 + return 0;
36412 }
36413 }
36414
36415 static struct {
36416 unsigned long address;
36417 unsigned short segment;
36418 -} pci_indirect = { 0, __KERNEL_CS };
36419 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
36420
36421 -static int pci_bios_present;
36422 +static int pci_bios_present __read_only;
36423
36424 static int check_pcibios(void)
36425 {
36426 @@ -131,11 +174,13 @@ static int check_pcibios(void)
36427 unsigned long flags, pcibios_entry;
36428
36429 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
36430 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
36431 + pci_indirect.address = pcibios_entry;
36432
36433 local_irq_save(flags);
36434 - __asm__(
36435 - "lcall *(%%edi); cld\n\t"
36436 + __asm__("movw %w6, %%ds\n\t"
36437 + "lcall *%%ss:(%%edi); cld\n\t"
36438 + "push %%ss\n\t"
36439 + "pop %%ds\n\t"
36440 "jc 1f\n\t"
36441 "xor %%ah, %%ah\n"
36442 "1:"
36443 @@ -144,7 +189,8 @@ static int check_pcibios(void)
36444 "=b" (ebx),
36445 "=c" (ecx)
36446 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
36447 - "D" (&pci_indirect)
36448 + "D" (&pci_indirect),
36449 + "r" (__PCIBIOS_DS)
36450 : "memory");
36451 local_irq_restore(flags);
36452
36453 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36454
36455 switch (len) {
36456 case 1:
36457 - __asm__("lcall *(%%esi); cld\n\t"
36458 + __asm__("movw %w6, %%ds\n\t"
36459 + "lcall *%%ss:(%%esi); cld\n\t"
36460 + "push %%ss\n\t"
36461 + "pop %%ds\n\t"
36462 "jc 1f\n\t"
36463 "xor %%ah, %%ah\n"
36464 "1:"
36465 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36466 : "1" (PCIBIOS_READ_CONFIG_BYTE),
36467 "b" (bx),
36468 "D" ((long)reg),
36469 - "S" (&pci_indirect));
36470 + "S" (&pci_indirect),
36471 + "r" (__PCIBIOS_DS));
36472 /*
36473 * Zero-extend the result beyond 8 bits, do not trust the
36474 * BIOS having done it:
36475 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36476 *value &= 0xff;
36477 break;
36478 case 2:
36479 - __asm__("lcall *(%%esi); cld\n\t"
36480 + __asm__("movw %w6, %%ds\n\t"
36481 + "lcall *%%ss:(%%esi); cld\n\t"
36482 + "push %%ss\n\t"
36483 + "pop %%ds\n\t"
36484 "jc 1f\n\t"
36485 "xor %%ah, %%ah\n"
36486 "1:"
36487 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36488 : "1" (PCIBIOS_READ_CONFIG_WORD),
36489 "b" (bx),
36490 "D" ((long)reg),
36491 - "S" (&pci_indirect));
36492 + "S" (&pci_indirect),
36493 + "r" (__PCIBIOS_DS));
36494 /*
36495 * Zero-extend the result beyond 16 bits, do not trust the
36496 * BIOS having done it:
36497 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36498 *value &= 0xffff;
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 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
36510 : "1" (PCIBIOS_READ_CONFIG_DWORD),
36511 "b" (bx),
36512 "D" ((long)reg),
36513 - "S" (&pci_indirect));
36514 + "S" (&pci_indirect),
36515 + "r" (__PCIBIOS_DS));
36516 break;
36517 }
36518
36519 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36520
36521 switch (len) {
36522 case 1:
36523 - __asm__("lcall *(%%esi); cld\n\t"
36524 + __asm__("movw %w6, %%ds\n\t"
36525 + "lcall *%%ss:(%%esi); cld\n\t"
36526 + "push %%ss\n\t"
36527 + "pop %%ds\n\t"
36528 "jc 1f\n\t"
36529 "xor %%ah, %%ah\n"
36530 "1:"
36531 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36532 "c" (value),
36533 "b" (bx),
36534 "D" ((long)reg),
36535 - "S" (&pci_indirect));
36536 + "S" (&pci_indirect),
36537 + "r" (__PCIBIOS_DS));
36538 break;
36539 case 2:
36540 - __asm__("lcall *(%%esi); cld\n\t"
36541 + __asm__("movw %w6, %%ds\n\t"
36542 + "lcall *%%ss:(%%esi); cld\n\t"
36543 + "push %%ss\n\t"
36544 + "pop %%ds\n\t"
36545 "jc 1f\n\t"
36546 "xor %%ah, %%ah\n"
36547 "1:"
36548 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36549 "c" (value),
36550 "b" (bx),
36551 "D" ((long)reg),
36552 - "S" (&pci_indirect));
36553 + "S" (&pci_indirect),
36554 + "r" (__PCIBIOS_DS));
36555 break;
36556 case 4:
36557 - __asm__("lcall *(%%esi); cld\n\t"
36558 + __asm__("movw %w6, %%ds\n\t"
36559 + "lcall *%%ss:(%%esi); cld\n\t"
36560 + "push %%ss\n\t"
36561 + "pop %%ds\n\t"
36562 "jc 1f\n\t"
36563 "xor %%ah, %%ah\n"
36564 "1:"
36565 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
36566 "c" (value),
36567 "b" (bx),
36568 "D" ((long)reg),
36569 - "S" (&pci_indirect));
36570 + "S" (&pci_indirect),
36571 + "r" (__PCIBIOS_DS));
36572 break;
36573 }
36574
36575 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36576
36577 DBG("PCI: Fetching IRQ routing table... ");
36578 __asm__("push %%es\n\t"
36579 + "movw %w8, %%ds\n\t"
36580 "push %%ds\n\t"
36581 "pop %%es\n\t"
36582 - "lcall *(%%esi); cld\n\t"
36583 + "lcall *%%ss:(%%esi); cld\n\t"
36584 "pop %%es\n\t"
36585 + "push %%ss\n\t"
36586 + "pop %%ds\n"
36587 "jc 1f\n\t"
36588 "xor %%ah, %%ah\n"
36589 "1:"
36590 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
36591 "1" (0),
36592 "D" ((long) &opt),
36593 "S" (&pci_indirect),
36594 - "m" (opt)
36595 + "m" (opt),
36596 + "r" (__PCIBIOS_DS)
36597 : "memory");
36598 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
36599 if (ret & 0xff00)
36600 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36601 {
36602 int ret;
36603
36604 - __asm__("lcall *(%%esi); cld\n\t"
36605 + __asm__("movw %w5, %%ds\n\t"
36606 + "lcall *%%ss:(%%esi); cld\n\t"
36607 + "push %%ss\n\t"
36608 + "pop %%ds\n"
36609 "jc 1f\n\t"
36610 "xor %%ah, %%ah\n"
36611 "1:"
36612 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
36613 : "0" (PCIBIOS_SET_PCI_HW_INT),
36614 "b" ((dev->bus->number << 8) | dev->devfn),
36615 "c" ((irq << 8) | (pin + 10)),
36616 - "S" (&pci_indirect));
36617 + "S" (&pci_indirect),
36618 + "r" (__PCIBIOS_DS));
36619 return !(ret & 0xff00);
36620 }
36621 EXPORT_SYMBOL(pcibios_set_irq_routing);
36622 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
36623 index 9ee3491..872192f 100644
36624 --- a/arch/x86/platform/efi/efi_32.c
36625 +++ b/arch/x86/platform/efi/efi_32.c
36626 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
36627 {
36628 struct desc_ptr gdt_descr;
36629
36630 +#ifdef CONFIG_PAX_KERNEXEC
36631 + struct desc_struct d;
36632 +#endif
36633 +
36634 local_irq_save(efi_rt_eflags);
36635
36636 load_cr3(initial_page_table);
36637 __flush_tlb_all();
36638
36639 +#ifdef CONFIG_PAX_KERNEXEC
36640 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
36641 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36642 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
36643 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36644 +#endif
36645 +
36646 gdt_descr.address = __pa(get_cpu_gdt_table(0));
36647 gdt_descr.size = GDT_SIZE - 1;
36648 load_gdt(&gdt_descr);
36649 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
36650 {
36651 struct desc_ptr gdt_descr;
36652
36653 +#ifdef CONFIG_PAX_KERNEXEC
36654 + struct desc_struct d;
36655 +
36656 + memset(&d, 0, sizeof d);
36657 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
36658 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
36659 +#endif
36660 +
36661 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
36662 gdt_descr.size = GDT_SIZE - 1;
36663 load_gdt(&gdt_descr);
36664
36665 +#ifdef CONFIG_PAX_PER_CPU_PGD
36666 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36667 +#else
36668 load_cr3(swapper_pg_dir);
36669 +#endif
36670 +
36671 __flush_tlb_all();
36672
36673 local_irq_restore(efi_rt_eflags);
36674 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
36675 index 290d397..3906bcd 100644
36676 --- a/arch/x86/platform/efi/efi_64.c
36677 +++ b/arch/x86/platform/efi/efi_64.c
36678 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
36679 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
36680 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
36681 }
36682 +
36683 +#ifdef CONFIG_PAX_PER_CPU_PGD
36684 + load_cr3(swapper_pg_dir);
36685 +#endif
36686 +
36687 __flush_tlb_all();
36688 }
36689
36690 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
36691 for (pgd = 0; pgd < n_pgds; pgd++)
36692 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
36693 kfree(save_pgd);
36694 +
36695 +#ifdef CONFIG_PAX_PER_CPU_PGD
36696 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
36697 +#endif
36698 +
36699 __flush_tlb_all();
36700 local_irq_restore(efi_flags);
36701 early_code_mapping_set_exec(0);
36702 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
36703 index fbe66e6..eae5e38 100644
36704 --- a/arch/x86/platform/efi/efi_stub_32.S
36705 +++ b/arch/x86/platform/efi/efi_stub_32.S
36706 @@ -6,7 +6,9 @@
36707 */
36708
36709 #include <linux/linkage.h>
36710 +#include <linux/init.h>
36711 #include <asm/page_types.h>
36712 +#include <asm/segment.h>
36713
36714 /*
36715 * efi_call_phys(void *, ...) is a function with variable parameters.
36716 @@ -20,7 +22,7 @@
36717 * service functions will comply with gcc calling convention, too.
36718 */
36719
36720 -.text
36721 +__INIT
36722 ENTRY(efi_call_phys)
36723 /*
36724 * 0. The function can only be called in Linux kernel. So CS has been
36725 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
36726 * The mapping of lower virtual memory has been created in prelog and
36727 * epilog.
36728 */
36729 - movl $1f, %edx
36730 - subl $__PAGE_OFFSET, %edx
36731 - jmp *%edx
36732 +#ifdef CONFIG_PAX_KERNEXEC
36733 + movl $(__KERNEXEC_EFI_DS), %edx
36734 + mov %edx, %ds
36735 + mov %edx, %es
36736 + mov %edx, %ss
36737 + addl $2f,(1f)
36738 + ljmp *(1f)
36739 +
36740 +__INITDATA
36741 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
36742 +.previous
36743 +
36744 +2:
36745 + subl $2b,(1b)
36746 +#else
36747 + jmp 1f-__PAGE_OFFSET
36748 1:
36749 +#endif
36750
36751 /*
36752 * 2. Now on the top of stack is the return
36753 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
36754 * parameter 2, ..., param n. To make things easy, we save the return
36755 * address of efi_call_phys in a global variable.
36756 */
36757 - popl %edx
36758 - movl %edx, saved_return_addr
36759 - /* get the function pointer into ECX*/
36760 - popl %ecx
36761 - movl %ecx, efi_rt_function_ptr
36762 - movl $2f, %edx
36763 - subl $__PAGE_OFFSET, %edx
36764 - pushl %edx
36765 + popl (saved_return_addr)
36766 + popl (efi_rt_function_ptr)
36767
36768 /*
36769 * 3. Clear PG bit in %CR0.
36770 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
36771 /*
36772 * 5. Call the physical function.
36773 */
36774 - jmp *%ecx
36775 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
36776
36777 -2:
36778 /*
36779 * 6. After EFI runtime service returns, control will return to
36780 * following instruction. We'd better readjust stack pointer first.
36781 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
36782 movl %cr0, %edx
36783 orl $0x80000000, %edx
36784 movl %edx, %cr0
36785 - jmp 1f
36786 -1:
36787 +
36788 /*
36789 * 8. Now restore the virtual mode from flat mode by
36790 * adding EIP with PAGE_OFFSET.
36791 */
36792 - movl $1f, %edx
36793 - jmp *%edx
36794 +#ifdef CONFIG_PAX_KERNEXEC
36795 + movl $(__KERNEL_DS), %edx
36796 + mov %edx, %ds
36797 + mov %edx, %es
36798 + mov %edx, %ss
36799 + ljmp $(__KERNEL_CS),$1f
36800 +#else
36801 + jmp 1f+__PAGE_OFFSET
36802 +#endif
36803 1:
36804
36805 /*
36806 * 9. Balance the stack. And because EAX contain the return value,
36807 * we'd better not clobber it.
36808 */
36809 - leal efi_rt_function_ptr, %edx
36810 - movl (%edx), %ecx
36811 - pushl %ecx
36812 + pushl (efi_rt_function_ptr)
36813
36814 /*
36815 - * 10. Push the saved return address onto the stack and return.
36816 + * 10. Return to the saved return address.
36817 */
36818 - leal saved_return_addr, %edx
36819 - movl (%edx), %ecx
36820 - pushl %ecx
36821 - ret
36822 + jmpl *(saved_return_addr)
36823 ENDPROC(efi_call_phys)
36824 .previous
36825
36826 -.data
36827 +__INITDATA
36828 saved_return_addr:
36829 .long 0
36830 efi_rt_function_ptr:
36831 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
36832 index 5fcda72..cd4dc41 100644
36833 --- a/arch/x86/platform/efi/efi_stub_64.S
36834 +++ b/arch/x86/platform/efi/efi_stub_64.S
36835 @@ -11,6 +11,7 @@
36836 #include <asm/msr.h>
36837 #include <asm/processor-flags.h>
36838 #include <asm/page_types.h>
36839 +#include <asm/alternative-asm.h>
36840
36841 #define SAVE_XMM \
36842 mov %rsp, %rax; \
36843 @@ -88,6 +89,7 @@ ENTRY(efi_call)
36844 RESTORE_PGT
36845 addq $48, %rsp
36846 RESTORE_XMM
36847 + pax_force_retaddr 0, 1
36848 ret
36849 ENDPROC(efi_call)
36850
36851 @@ -245,8 +247,8 @@ efi_gdt64:
36852 .long 0 /* Filled out by user */
36853 .word 0
36854 .quad 0x0000000000000000 /* NULL descriptor */
36855 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
36856 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
36857 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
36858 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
36859 .quad 0x0080890000000000 /* TS descriptor */
36860 .quad 0x0000000000000000 /* TS continued */
36861 efi_gdt64_end:
36862 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
36863 index 1bbedc4..eb795b5 100644
36864 --- a/arch/x86/platform/intel-mid/intel-mid.c
36865 +++ b/arch/x86/platform/intel-mid/intel-mid.c
36866 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
36867 {
36868 };
36869
36870 -static void intel_mid_reboot(void)
36871 +static void __noreturn intel_mid_reboot(void)
36872 {
36873 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
36874 + BUG();
36875 }
36876
36877 static unsigned long __init intel_mid_calibrate_tsc(void)
36878 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
36879 index d6ee929..3637cb5 100644
36880 --- a/arch/x86/platform/olpc/olpc_dt.c
36881 +++ b/arch/x86/platform/olpc/olpc_dt.c
36882 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
36883 return res;
36884 }
36885
36886 -static struct of_pdt_ops prom_olpc_ops __initdata = {
36887 +static struct of_pdt_ops prom_olpc_ops __initconst = {
36888 .nextprop = olpc_dt_nextprop,
36889 .getproplen = olpc_dt_getproplen,
36890 .getproperty = olpc_dt_getproperty,
36891 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
36892 index 424f4c9..f2a2988 100644
36893 --- a/arch/x86/power/cpu.c
36894 +++ b/arch/x86/power/cpu.c
36895 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
36896 static void fix_processor_context(void)
36897 {
36898 int cpu = smp_processor_id();
36899 - struct tss_struct *t = &per_cpu(init_tss, cpu);
36900 -#ifdef CONFIG_X86_64
36901 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
36902 - tss_desc tss;
36903 -#endif
36904 + struct tss_struct *t = init_tss + cpu;
36905 +
36906 set_tss_desc(cpu, t); /*
36907 * This just modifies memory; should not be
36908 * necessary. But... This is necessary, because
36909 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
36910 */
36911
36912 #ifdef CONFIG_X86_64
36913 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
36914 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
36915 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
36916 -
36917 syscall_init(); /* This sets MSR_*STAR and related */
36918 #endif
36919 load_TR_desc(); /* This does ltr */
36920 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
36921 index bad628a..a102610 100644
36922 --- a/arch/x86/realmode/init.c
36923 +++ b/arch/x86/realmode/init.c
36924 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
36925 __va(real_mode_header->trampoline_header);
36926
36927 #ifdef CONFIG_X86_32
36928 - trampoline_header->start = __pa_symbol(startup_32_smp);
36929 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
36930 +
36931 +#ifdef CONFIG_PAX_KERNEXEC
36932 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
36933 +#endif
36934 +
36935 + trampoline_header->boot_cs = __BOOT_CS;
36936 trampoline_header->gdt_limit = __BOOT_DS + 7;
36937 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
36938 #else
36939 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
36940 *trampoline_cr4_features = read_cr4();
36941
36942 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
36943 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
36944 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
36945 trampoline_pgd[511] = init_level4_pgt[511].pgd;
36946 #endif
36947 }
36948 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
36949 index 7c0d7be..d24dc88 100644
36950 --- a/arch/x86/realmode/rm/Makefile
36951 +++ b/arch/x86/realmode/rm/Makefile
36952 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
36953
36954 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
36955 -I$(srctree)/arch/x86/boot
36956 +ifdef CONSTIFY_PLUGIN
36957 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
36958 +endif
36959 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
36960 GCOV_PROFILE := n
36961 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
36962 index a28221d..93c40f1 100644
36963 --- a/arch/x86/realmode/rm/header.S
36964 +++ b/arch/x86/realmode/rm/header.S
36965 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
36966 #endif
36967 /* APM/BIOS reboot */
36968 .long pa_machine_real_restart_asm
36969 -#ifdef CONFIG_X86_64
36970 +#ifdef CONFIG_X86_32
36971 + .long __KERNEL_CS
36972 +#else
36973 .long __KERNEL32_CS
36974 #endif
36975 END(real_mode_header)
36976 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
36977 index 48ddd76..c26749f 100644
36978 --- a/arch/x86/realmode/rm/trampoline_32.S
36979 +++ b/arch/x86/realmode/rm/trampoline_32.S
36980 @@ -24,6 +24,12 @@
36981 #include <asm/page_types.h>
36982 #include "realmode.h"
36983
36984 +#ifdef CONFIG_PAX_KERNEXEC
36985 +#define ta(X) (X)
36986 +#else
36987 +#define ta(X) (pa_ ## X)
36988 +#endif
36989 +
36990 .text
36991 .code16
36992
36993 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
36994
36995 cli # We should be safe anyway
36996
36997 - movl tr_start, %eax # where we need to go
36998 -
36999 movl $0xA5A5A5A5, trampoline_status
37000 # write marker for master knows we're running
37001
37002 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
37003 movw $1, %dx # protected mode (PE) bit
37004 lmsw %dx # into protected mode
37005
37006 - ljmpl $__BOOT_CS, $pa_startup_32
37007 + ljmpl *(trampoline_header)
37008
37009 .section ".text32","ax"
37010 .code32
37011 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
37012 .balign 8
37013 GLOBAL(trampoline_header)
37014 tr_start: .space 4
37015 - tr_gdt_pad: .space 2
37016 + tr_boot_cs: .space 2
37017 tr_gdt: .space 6
37018 END(trampoline_header)
37019
37020 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
37021 index dac7b20..72dbaca 100644
37022 --- a/arch/x86/realmode/rm/trampoline_64.S
37023 +++ b/arch/x86/realmode/rm/trampoline_64.S
37024 @@ -93,6 +93,7 @@ ENTRY(startup_32)
37025 movl %edx, %gs
37026
37027 movl pa_tr_cr4, %eax
37028 + andl $~X86_CR4_PCIDE, %eax
37029 movl %eax, %cr4 # Enable PAE mode
37030
37031 # Setup trampoline 4 level pagetables
37032 @@ -106,7 +107,7 @@ ENTRY(startup_32)
37033 wrmsr
37034
37035 # Enable paging and in turn activate Long Mode
37036 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
37037 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
37038 movl %eax, %cr0
37039
37040 /*
37041 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
37042 index 9e7e147..25a4158 100644
37043 --- a/arch/x86/realmode/rm/wakeup_asm.S
37044 +++ b/arch/x86/realmode/rm/wakeup_asm.S
37045 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
37046 lgdtl pmode_gdt
37047
37048 /* This really couldn't... */
37049 - movl pmode_entry, %eax
37050 movl pmode_cr0, %ecx
37051 movl %ecx, %cr0
37052 - ljmpl $__KERNEL_CS, $pa_startup_32
37053 - /* -> jmp *%eax in trampoline_32.S */
37054 +
37055 + ljmpl *pmode_entry
37056 #else
37057 jmp trampoline_start
37058 #endif
37059 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
37060 index 604a37e..e49702a 100644
37061 --- a/arch/x86/tools/Makefile
37062 +++ b/arch/x86/tools/Makefile
37063 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
37064
37065 $(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
37066
37067 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
37068 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
37069 hostprogs-y += relocs
37070 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
37071 PHONY += relocs
37072 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
37073 index bbb1d22..e505211 100644
37074 --- a/arch/x86/tools/relocs.c
37075 +++ b/arch/x86/tools/relocs.c
37076 @@ -1,5 +1,7 @@
37077 /* This is included from relocs_32/64.c */
37078
37079 +#include "../../../include/generated/autoconf.h"
37080 +
37081 #define ElfW(type) _ElfW(ELF_BITS, type)
37082 #define _ElfW(bits, type) __ElfW(bits, type)
37083 #define __ElfW(bits, type) Elf##bits##_##type
37084 @@ -11,6 +13,7 @@
37085 #define Elf_Sym ElfW(Sym)
37086
37087 static Elf_Ehdr ehdr;
37088 +static Elf_Phdr *phdr;
37089
37090 struct relocs {
37091 uint32_t *offset;
37092 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
37093 }
37094 }
37095
37096 +static void read_phdrs(FILE *fp)
37097 +{
37098 + unsigned int i;
37099 +
37100 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
37101 + if (!phdr) {
37102 + die("Unable to allocate %d program headers\n",
37103 + ehdr.e_phnum);
37104 + }
37105 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
37106 + die("Seek to %d failed: %s\n",
37107 + ehdr.e_phoff, strerror(errno));
37108 + }
37109 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
37110 + die("Cannot read ELF program headers: %s\n",
37111 + strerror(errno));
37112 + }
37113 + for(i = 0; i < ehdr.e_phnum; i++) {
37114 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
37115 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
37116 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
37117 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
37118 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
37119 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
37120 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
37121 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
37122 + }
37123 +
37124 +}
37125 +
37126 static void read_shdrs(FILE *fp)
37127 {
37128 - int i;
37129 + unsigned int i;
37130 Elf_Shdr shdr;
37131
37132 secs = calloc(ehdr.e_shnum, sizeof(struct section));
37133 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
37134
37135 static void read_strtabs(FILE *fp)
37136 {
37137 - int i;
37138 + unsigned int i;
37139 for (i = 0; i < ehdr.e_shnum; i++) {
37140 struct section *sec = &secs[i];
37141 if (sec->shdr.sh_type != SHT_STRTAB) {
37142 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
37143
37144 static void read_symtabs(FILE *fp)
37145 {
37146 - int i,j;
37147 + unsigned int i,j;
37148 for (i = 0; i < ehdr.e_shnum; i++) {
37149 struct section *sec = &secs[i];
37150 if (sec->shdr.sh_type != SHT_SYMTAB) {
37151 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
37152 }
37153
37154
37155 -static void read_relocs(FILE *fp)
37156 +static void read_relocs(FILE *fp, int use_real_mode)
37157 {
37158 - int i,j;
37159 + unsigned int i,j;
37160 + uint32_t base;
37161 +
37162 for (i = 0; i < ehdr.e_shnum; i++) {
37163 struct section *sec = &secs[i];
37164 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37165 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
37166 die("Cannot read symbol table: %s\n",
37167 strerror(errno));
37168 }
37169 + base = 0;
37170 +
37171 +#ifdef CONFIG_X86_32
37172 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
37173 + if (phdr[j].p_type != PT_LOAD )
37174 + continue;
37175 + 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)
37176 + continue;
37177 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
37178 + break;
37179 + }
37180 +#endif
37181 +
37182 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
37183 Elf_Rel *rel = &sec->reltab[j];
37184 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
37185 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
37186 rel->r_info = elf_xword_to_cpu(rel->r_info);
37187 #if (SHT_REL_TYPE == SHT_RELA)
37188 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
37189 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
37190
37191 static void print_absolute_symbols(void)
37192 {
37193 - int i;
37194 + unsigned int i;
37195 const char *format;
37196
37197 if (ELF_BITS == 64)
37198 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
37199 for (i = 0; i < ehdr.e_shnum; i++) {
37200 struct section *sec = &secs[i];
37201 char *sym_strtab;
37202 - int j;
37203 + unsigned int j;
37204
37205 if (sec->shdr.sh_type != SHT_SYMTAB) {
37206 continue;
37207 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
37208
37209 static void print_absolute_relocs(void)
37210 {
37211 - int i, printed = 0;
37212 + unsigned int i, printed = 0;
37213 const char *format;
37214
37215 if (ELF_BITS == 64)
37216 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
37217 struct section *sec_applies, *sec_symtab;
37218 char *sym_strtab;
37219 Elf_Sym *sh_symtab;
37220 - int j;
37221 + unsigned int j;
37222 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37223 continue;
37224 }
37225 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
37226 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
37227 Elf_Sym *sym, const char *symname))
37228 {
37229 - int i;
37230 + unsigned int i;
37231 /* Walk through the relocations */
37232 for (i = 0; i < ehdr.e_shnum; i++) {
37233 char *sym_strtab;
37234 Elf_Sym *sh_symtab;
37235 struct section *sec_applies, *sec_symtab;
37236 - int j;
37237 + unsigned int j;
37238 struct section *sec = &secs[i];
37239
37240 if (sec->shdr.sh_type != SHT_REL_TYPE) {
37241 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37242 {
37243 unsigned r_type = ELF32_R_TYPE(rel->r_info);
37244 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
37245 + char *sym_strtab = sec->link->link->strtab;
37246 +
37247 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
37248 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
37249 + return 0;
37250 +
37251 +#ifdef CONFIG_PAX_KERNEXEC
37252 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
37253 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
37254 + return 0;
37255 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
37256 + return 0;
37257 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
37258 + return 0;
37259 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
37260 + return 0;
37261 +#endif
37262
37263 switch (r_type) {
37264 case R_386_NONE:
37265 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
37266
37267 static void emit_relocs(int as_text, int use_real_mode)
37268 {
37269 - int i;
37270 + unsigned int i;
37271 int (*write_reloc)(uint32_t, FILE *) = write32;
37272 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
37273 const char *symname);
37274 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
37275 {
37276 regex_init(use_real_mode);
37277 read_ehdr(fp);
37278 + read_phdrs(fp);
37279 read_shdrs(fp);
37280 read_strtabs(fp);
37281 read_symtabs(fp);
37282 - read_relocs(fp);
37283 + read_relocs(fp, use_real_mode);
37284 if (ELF_BITS == 64)
37285 percpu_init();
37286 if (show_absolute_syms) {
37287 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
37288 index f40281e..92728c9 100644
37289 --- a/arch/x86/um/mem_32.c
37290 +++ b/arch/x86/um/mem_32.c
37291 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
37292 gate_vma.vm_start = FIXADDR_USER_START;
37293 gate_vma.vm_end = FIXADDR_USER_END;
37294 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
37295 - gate_vma.vm_page_prot = __P101;
37296 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
37297
37298 return 0;
37299 }
37300 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
37301 index 80ffa5b..a33bd15 100644
37302 --- a/arch/x86/um/tls_32.c
37303 +++ b/arch/x86/um/tls_32.c
37304 @@ -260,7 +260,7 @@ out:
37305 if (unlikely(task == current &&
37306 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
37307 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
37308 - "without flushed TLS.", current->pid);
37309 + "without flushed TLS.", task_pid_nr(current));
37310 }
37311
37312 return 0;
37313 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
37314 index 61b04fe..3134230 100644
37315 --- a/arch/x86/vdso/Makefile
37316 +++ b/arch/x86/vdso/Makefile
37317 @@ -170,7 +170,7 @@ quiet_cmd_vdso = VDSO $@
37318 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
37319 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
37320
37321 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37322 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
37323 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
37324 GCOV_PROFILE := n
37325
37326 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
37327 index e4f7781..ab5ab26 100644
37328 --- a/arch/x86/vdso/vdso32-setup.c
37329 +++ b/arch/x86/vdso/vdso32-setup.c
37330 @@ -14,6 +14,7 @@
37331 #include <asm/cpufeature.h>
37332 #include <asm/processor.h>
37333 #include <asm/vdso.h>
37334 +#include <asm/mman.h>
37335
37336 #ifdef CONFIG_COMPAT_VDSO
37337 #define VDSO_DEFAULT 0
37338 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
37339 index 5a5176d..e570acd 100644
37340 --- a/arch/x86/vdso/vma.c
37341 +++ b/arch/x86/vdso/vma.c
37342 @@ -16,10 +16,9 @@
37343 #include <asm/vdso.h>
37344 #include <asm/page.h>
37345 #include <asm/hpet.h>
37346 +#include <asm/mman.h>
37347
37348 #if defined(CONFIG_X86_64)
37349 -unsigned int __read_mostly vdso64_enabled = 1;
37350 -
37351 extern unsigned short vdso_sync_cpuid;
37352 #endif
37353
37354 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37355 .pages = no_pages,
37356 };
37357
37358 +#ifdef CONFIG_PAX_RANDMMAP
37359 + if (mm->pax_flags & MF_PAX_RANDMMAP)
37360 + calculate_addr = false;
37361 +#endif
37362 +
37363 if (calculate_addr) {
37364 addr = vdso_addr(current->mm->start_stack,
37365 image->sym_end_mapping);
37366 @@ -110,13 +114,13 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37367
37368 down_write(&mm->mmap_sem);
37369
37370 - addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, 0);
37371 + addr = get_unmapped_area(NULL, addr, image->sym_end_mapping, 0, MAP_EXECUTABLE);
37372 if (IS_ERR_VALUE(addr)) {
37373 ret = addr;
37374 goto up_fail;
37375 }
37376
37377 - current->mm->context.vdso = (void __user *)addr;
37378 + mm->context.vdso = addr;
37379
37380 /*
37381 * MAYWRITE to allow gdb to COW and set breakpoints
37382 @@ -161,15 +165,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
37383 hpet_address >> PAGE_SHIFT,
37384 PAGE_SIZE,
37385 pgprot_noncached(PAGE_READONLY));
37386 -
37387 - if (ret)
37388 - goto up_fail;
37389 }
37390 #endif
37391
37392 up_fail:
37393 if (ret)
37394 - current->mm->context.vdso = NULL;
37395 + current->mm->context.vdso = 0;
37396
37397 up_write(&mm->mmap_sem);
37398 return ret;
37399 @@ -189,8 +190,8 @@ static int load_vdso32(void)
37400
37401 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
37402 current_thread_info()->sysenter_return =
37403 - current->mm->context.vdso +
37404 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
37405 + (void __force_user *)(current->mm->context.vdso +
37406 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
37407
37408 return 0;
37409 }
37410 @@ -199,9 +200,6 @@ static int load_vdso32(void)
37411 #ifdef CONFIG_X86_64
37412 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37413 {
37414 - if (!vdso64_enabled)
37415 - return 0;
37416 -
37417 return map_vdso(&vdso_image_64, true);
37418 }
37419
37420 @@ -210,12 +208,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
37421 int uses_interp)
37422 {
37423 #ifdef CONFIG_X86_X32_ABI
37424 - if (test_thread_flag(TIF_X32)) {
37425 - if (!vdso64_enabled)
37426 - return 0;
37427 -
37428 + if (test_thread_flag(TIF_X32))
37429 return map_vdso(&vdso_image_x32, true);
37430 - }
37431 #endif
37432
37433 return load_vdso32();
37434 @@ -227,12 +221,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
37435 return load_vdso32();
37436 }
37437 #endif
37438 -
37439 -#ifdef CONFIG_X86_64
37440 -static __init int vdso_setup(char *s)
37441 -{
37442 - vdso64_enabled = simple_strtoul(s, NULL, 0);
37443 - return 0;
37444 -}
37445 -__setup("vdso=", vdso_setup);
37446 -#endif
37447 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
37448 index e88fda8..76ce7ce 100644
37449 --- a/arch/x86/xen/Kconfig
37450 +++ b/arch/x86/xen/Kconfig
37451 @@ -9,6 +9,7 @@ config XEN
37452 select XEN_HAVE_PVMMU
37453 depends on X86_64 || (X86_32 && X86_PAE)
37454 depends on X86_TSC
37455 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
37456 help
37457 This is the Linux Xen port. Enabling this will allow the
37458 kernel to boot in a paravirtualized environment under the
37459 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
37460 index ffb101e..98c0ecf 100644
37461 --- a/arch/x86/xen/enlighten.c
37462 +++ b/arch/x86/xen/enlighten.c
37463 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
37464
37465 struct shared_info xen_dummy_shared_info;
37466
37467 -void *xen_initial_gdt;
37468 -
37469 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
37470 __read_mostly int xen_have_vector_callback;
37471 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
37472 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
37473 {
37474 unsigned long va = dtr->address;
37475 unsigned int size = dtr->size + 1;
37476 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37477 - unsigned long frames[pages];
37478 + unsigned long frames[65536 / PAGE_SIZE];
37479 int f;
37480
37481 /*
37482 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37483 {
37484 unsigned long va = dtr->address;
37485 unsigned int size = dtr->size + 1;
37486 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
37487 - unsigned long frames[pages];
37488 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
37489 int f;
37490
37491 /*
37492 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
37493 * 8-byte entries, or 16 4k pages..
37494 */
37495
37496 - BUG_ON(size > 65536);
37497 + BUG_ON(size > GDT_SIZE);
37498 BUG_ON(va & ~PAGE_MASK);
37499
37500 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
37501 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
37502 return 0;
37503 }
37504
37505 -static void set_xen_basic_apic_ops(void)
37506 +static void __init set_xen_basic_apic_ops(void)
37507 {
37508 apic->read = xen_apic_read;
37509 apic->write = xen_apic_write;
37510 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
37511 #endif
37512 };
37513
37514 -static void xen_reboot(int reason)
37515 +static __noreturn void xen_reboot(int reason)
37516 {
37517 struct sched_shutdown r = { .reason = reason };
37518
37519 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
37520 - BUG();
37521 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
37522 + BUG();
37523 }
37524
37525 -static void xen_restart(char *msg)
37526 +static __noreturn void xen_restart(char *msg)
37527 {
37528 xen_reboot(SHUTDOWN_reboot);
37529 }
37530
37531 -static void xen_emergency_restart(void)
37532 +static __noreturn void xen_emergency_restart(void)
37533 {
37534 xen_reboot(SHUTDOWN_reboot);
37535 }
37536
37537 -static void xen_machine_halt(void)
37538 +static __noreturn void xen_machine_halt(void)
37539 {
37540 xen_reboot(SHUTDOWN_poweroff);
37541 }
37542
37543 -static void xen_machine_power_off(void)
37544 +static __noreturn void xen_machine_power_off(void)
37545 {
37546 if (pm_power_off)
37547 pm_power_off();
37548 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
37549 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
37550
37551 /* Work out if we support NX */
37552 - x86_configure_nx();
37553 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
37554 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
37555 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
37556 + unsigned l, h;
37557 +
37558 + __supported_pte_mask |= _PAGE_NX;
37559 + rdmsr(MSR_EFER, l, h);
37560 + l |= EFER_NX;
37561 + wrmsr(MSR_EFER, l, h);
37562 + }
37563 +#endif
37564
37565 /* Get mfn list */
37566 xen_build_dynamic_phys_to_machine();
37567 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
37568
37569 machine_ops = xen_machine_ops;
37570
37571 - /*
37572 - * The only reliable way to retain the initial address of the
37573 - * percpu gdt_page is to remember it here, so we can go and
37574 - * mark it RW later, when the initial percpu area is freed.
37575 - */
37576 - xen_initial_gdt = &per_cpu(gdt_page, 0);
37577 -
37578 xen_smp_init();
37579
37580 #ifdef CONFIG_ACPI_NUMA
37581 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
37582 index e8a1201..046c66c 100644
37583 --- a/arch/x86/xen/mmu.c
37584 +++ b/arch/x86/xen/mmu.c
37585 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
37586 return val;
37587 }
37588
37589 -static pteval_t pte_pfn_to_mfn(pteval_t val)
37590 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
37591 {
37592 if (val & _PAGE_PRESENT) {
37593 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
37594 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37595 /* L3_k[510] -> level2_kernel_pgt
37596 * L3_i[511] -> level2_fixmap_pgt */
37597 convert_pfn_mfn(level3_kernel_pgt);
37598 + convert_pfn_mfn(level3_vmalloc_start_pgt);
37599 + convert_pfn_mfn(level3_vmalloc_end_pgt);
37600 + convert_pfn_mfn(level3_vmemmap_pgt);
37601 }
37602 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
37603 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
37604 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
37605 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
37606 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
37607 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
37608 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
37609 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
37610 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
37611 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
37612 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
37613 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
37614 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
37615 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
37616
37617 @@ -2120,6 +2127,7 @@ static void __init xen_post_allocator_init(void)
37618 pv_mmu_ops.set_pud = xen_set_pud;
37619 #if PAGETABLE_LEVELS == 4
37620 pv_mmu_ops.set_pgd = xen_set_pgd;
37621 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
37622 #endif
37623
37624 /* This will work as long as patching hasn't happened yet
37625 @@ -2198,6 +2206,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
37626 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
37627 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
37628 .set_pgd = xen_set_pgd_hyper,
37629 + .set_pgd_batched = xen_set_pgd_hyper,
37630
37631 .alloc_pud = xen_alloc_pmd_init,
37632 .release_pud = xen_release_pmd_init,
37633 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
37634 index 7005974..54fb05f 100644
37635 --- a/arch/x86/xen/smp.c
37636 +++ b/arch/x86/xen/smp.c
37637 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
37638
37639 if (xen_pv_domain()) {
37640 if (!xen_feature(XENFEAT_writable_page_tables))
37641 - /* We've switched to the "real" per-cpu gdt, so make
37642 - * sure the old memory can be recycled. */
37643 - make_lowmem_page_readwrite(xen_initial_gdt);
37644 -
37645 #ifdef CONFIG_X86_32
37646 /*
37647 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
37648 * expects __USER_DS
37649 */
37650 - loadsegment(ds, __USER_DS);
37651 - loadsegment(es, __USER_DS);
37652 + loadsegment(ds, __KERNEL_DS);
37653 + loadsegment(es, __KERNEL_DS);
37654 #endif
37655
37656 xen_filter_cpu_maps();
37657 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37658 #ifdef CONFIG_X86_32
37659 /* Note: PVH is not yet supported on x86_32. */
37660 ctxt->user_regs.fs = __KERNEL_PERCPU;
37661 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
37662 + savesegment(gs, ctxt->user_regs.gs);
37663 #endif
37664 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
37665
37666 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
37667 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
37668 ctxt->flags = VGCF_IN_KERNEL;
37669 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
37670 - ctxt->user_regs.ds = __USER_DS;
37671 - ctxt->user_regs.es = __USER_DS;
37672 + ctxt->user_regs.ds = __KERNEL_DS;
37673 + ctxt->user_regs.es = __KERNEL_DS;
37674 ctxt->user_regs.ss = __KERNEL_DS;
37675
37676 xen_copy_trap_info(ctxt->trap_ctxt);
37677 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
37678 int rc;
37679
37680 per_cpu(current_task, cpu) = idle;
37681 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
37682 #ifdef CONFIG_X86_32
37683 irq_ctx_init(cpu);
37684 #else
37685 clear_tsk_thread_flag(idle, TIF_FORK);
37686 #endif
37687 - per_cpu(kernel_stack, cpu) =
37688 - (unsigned long)task_stack_page(idle) -
37689 - KERNEL_STACK_OFFSET + THREAD_SIZE;
37690 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
37691
37692 xen_setup_runstate_info(cpu);
37693 xen_setup_timer(cpu);
37694 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
37695
37696 void __init xen_smp_init(void)
37697 {
37698 - smp_ops = xen_smp_ops;
37699 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
37700 xen_fill_possible_map();
37701 }
37702
37703 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
37704 index fd92a64..1f72641 100644
37705 --- a/arch/x86/xen/xen-asm_32.S
37706 +++ b/arch/x86/xen/xen-asm_32.S
37707 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
37708 pushw %fs
37709 movl $(__KERNEL_PERCPU), %eax
37710 movl %eax, %fs
37711 - movl %fs:xen_vcpu, %eax
37712 + mov PER_CPU_VAR(xen_vcpu), %eax
37713 POP_FS
37714 #else
37715 movl %ss:xen_vcpu, %eax
37716 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
37717 index 485b695..fda3e7c 100644
37718 --- a/arch/x86/xen/xen-head.S
37719 +++ b/arch/x86/xen/xen-head.S
37720 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
37721 #ifdef CONFIG_X86_32
37722 mov %esi,xen_start_info
37723 mov $init_thread_union+THREAD_SIZE,%esp
37724 +#ifdef CONFIG_SMP
37725 + movl $cpu_gdt_table,%edi
37726 + movl $__per_cpu_load,%eax
37727 + movw %ax,__KERNEL_PERCPU + 2(%edi)
37728 + rorl $16,%eax
37729 + movb %al,__KERNEL_PERCPU + 4(%edi)
37730 + movb %ah,__KERNEL_PERCPU + 7(%edi)
37731 + movl $__per_cpu_end - 1,%eax
37732 + subl $__per_cpu_start,%eax
37733 + movw %ax,__KERNEL_PERCPU + 0(%edi)
37734 +#endif
37735 #else
37736 mov %rsi,xen_start_info
37737 mov $init_thread_union+THREAD_SIZE,%rsp
37738 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
37739 index 97d8765..c4526ec 100644
37740 --- a/arch/x86/xen/xen-ops.h
37741 +++ b/arch/x86/xen/xen-ops.h
37742 @@ -10,8 +10,6 @@
37743 extern const char xen_hypervisor_callback[];
37744 extern const char xen_failsafe_callback[];
37745
37746 -extern void *xen_initial_gdt;
37747 -
37748 struct trap_info;
37749 void xen_copy_trap_info(struct trap_info *traps);
37750
37751 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
37752 index 525bd3d..ef888b1 100644
37753 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
37754 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
37755 @@ -119,9 +119,9 @@
37756 ----------------------------------------------------------------------*/
37757
37758 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
37759 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
37760 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
37761 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
37762 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37763
37764 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
37765 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
37766 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
37767 index 2f33760..835e50a 100644
37768 --- a/arch/xtensa/variants/fsf/include/variant/core.h
37769 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
37770 @@ -11,6 +11,7 @@
37771 #ifndef _XTENSA_CORE_H
37772 #define _XTENSA_CORE_H
37773
37774 +#include <linux/const.h>
37775
37776 /****************************************************************************
37777 Parameters Useful for Any Code, USER or PRIVILEGED
37778 @@ -112,9 +113,9 @@
37779 ----------------------------------------------------------------------*/
37780
37781 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37782 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37783 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37784 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37785 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37786
37787 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
37788 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
37789 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
37790 index af00795..2bb8105 100644
37791 --- a/arch/xtensa/variants/s6000/include/variant/core.h
37792 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
37793 @@ -11,6 +11,7 @@
37794 #ifndef _XTENSA_CORE_CONFIGURATION_H
37795 #define _XTENSA_CORE_CONFIGURATION_H
37796
37797 +#include <linux/const.h>
37798
37799 /****************************************************************************
37800 Parameters Useful for Any Code, USER or PRIVILEGED
37801 @@ -118,9 +119,9 @@
37802 ----------------------------------------------------------------------*/
37803
37804 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
37805 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
37806 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
37807 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
37808 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
37809
37810 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
37811 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
37812 diff --git a/block/bio.c b/block/bio.c
37813 index 0ec61c9..93b94060 100644
37814 --- a/block/bio.c
37815 +++ b/block/bio.c
37816 @@ -1159,7 +1159,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
37817 /*
37818 * Overflow, abort
37819 */
37820 - if (end < start)
37821 + if (end < start || end - start > INT_MAX - nr_pages)
37822 return ERR_PTR(-EINVAL);
37823
37824 nr_pages += end - start;
37825 @@ -1293,7 +1293,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
37826 /*
37827 * Overflow, abort
37828 */
37829 - if (end < start)
37830 + if (end < start || end - start > INT_MAX - nr_pages)
37831 return ERR_PTR(-EINVAL);
37832
37833 nr_pages += end - start;
37834 @@ -1555,7 +1555,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
37835 const int read = bio_data_dir(bio) == READ;
37836 struct bio_map_data *bmd = bio->bi_private;
37837 int i;
37838 - char *p = bmd->sgvecs[0].iov_base;
37839 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
37840
37841 bio_for_each_segment_all(bvec, bio, i) {
37842 char *addr = page_address(bvec->bv_page);
37843 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
37844 index 28d227c..d4c0bad 100644
37845 --- a/block/blk-cgroup.c
37846 +++ b/block/blk-cgroup.c
37847 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
37848 static struct cgroup_subsys_state *
37849 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37850 {
37851 - static atomic64_t id_seq = ATOMIC64_INIT(0);
37852 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
37853 struct blkcg *blkcg;
37854
37855 if (!parent_css) {
37856 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
37857
37858 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
37859 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
37860 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
37861 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
37862 done:
37863 spin_lock_init(&blkcg->lock);
37864 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
37865 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
37866 index 0736729..2ec3b48 100644
37867 --- a/block/blk-iopoll.c
37868 +++ b/block/blk-iopoll.c
37869 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
37870 }
37871 EXPORT_SYMBOL(blk_iopoll_complete);
37872
37873 -static void blk_iopoll_softirq(struct softirq_action *h)
37874 +static __latent_entropy void blk_iopoll_softirq(void)
37875 {
37876 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
37877 int rearm = 0, budget = blk_iopoll_budget;
37878 diff --git a/block/blk-map.c b/block/blk-map.c
37879 index f890d43..97b0482 100644
37880 --- a/block/blk-map.c
37881 +++ b/block/blk-map.c
37882 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
37883 if (!len || !kbuf)
37884 return -EINVAL;
37885
37886 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
37887 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
37888 if (do_copy)
37889 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
37890 else
37891 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
37892 index 53b1737..08177d2e 100644
37893 --- a/block/blk-softirq.c
37894 +++ b/block/blk-softirq.c
37895 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
37896 * Softirq action handler - move entries to local list and loop over them
37897 * while passing them to the queue registered handler.
37898 */
37899 -static void blk_done_softirq(struct softirq_action *h)
37900 +static __latent_entropy void blk_done_softirq(void)
37901 {
37902 struct list_head *cpu_list, local_list;
37903
37904 diff --git a/block/bsg.c b/block/bsg.c
37905 index ff46add..c4ba8ee 100644
37906 --- a/block/bsg.c
37907 +++ b/block/bsg.c
37908 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
37909 struct sg_io_v4 *hdr, struct bsg_device *bd,
37910 fmode_t has_write_perm)
37911 {
37912 + unsigned char tmpcmd[sizeof(rq->__cmd)];
37913 + unsigned char *cmdptr;
37914 +
37915 if (hdr->request_len > BLK_MAX_CDB) {
37916 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
37917 if (!rq->cmd)
37918 return -ENOMEM;
37919 - }
37920 + cmdptr = rq->cmd;
37921 + } else
37922 + cmdptr = tmpcmd;
37923
37924 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
37925 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
37926 hdr->request_len))
37927 return -EFAULT;
37928
37929 + if (cmdptr != rq->cmd)
37930 + memcpy(rq->cmd, cmdptr, hdr->request_len);
37931 +
37932 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
37933 if (blk_verify_command(rq->cmd, has_write_perm))
37934 return -EPERM;
37935 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
37936 index a0926a6..b2b14b2 100644
37937 --- a/block/compat_ioctl.c
37938 +++ b/block/compat_ioctl.c
37939 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
37940 cgc = compat_alloc_user_space(sizeof(*cgc));
37941 cgc32 = compat_ptr(arg);
37942
37943 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
37944 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
37945 get_user(data, &cgc32->buffer) ||
37946 put_user(compat_ptr(data), &cgc->buffer) ||
37947 copy_in_user(&cgc->buflen, &cgc32->buflen,
37948 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
37949 err |= __get_user(f->spec1, &uf->spec1);
37950 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
37951 err |= __get_user(name, &uf->name);
37952 - f->name = compat_ptr(name);
37953 + f->name = (void __force_kernel *)compat_ptr(name);
37954 if (err) {
37955 err = -EFAULT;
37956 goto out;
37957 diff --git a/block/genhd.c b/block/genhd.c
37958 index 791f419..89f21c4 100644
37959 --- a/block/genhd.c
37960 +++ b/block/genhd.c
37961 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
37962
37963 /*
37964 * Register device numbers dev..(dev+range-1)
37965 - * range must be nonzero
37966 + * Noop if @range is zero.
37967 * The hash chain is sorted on range, so that subranges can override.
37968 */
37969 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
37970 struct kobject *(*probe)(dev_t, int *, void *),
37971 int (*lock)(dev_t, void *), void *data)
37972 {
37973 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
37974 + if (range)
37975 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
37976 }
37977
37978 EXPORT_SYMBOL(blk_register_region);
37979
37980 +/* undo blk_register_region(), noop if @range is zero */
37981 void blk_unregister_region(dev_t devt, unsigned long range)
37982 {
37983 - kobj_unmap(bdev_map, devt, range);
37984 + if (range)
37985 + kobj_unmap(bdev_map, devt, range);
37986 }
37987
37988 EXPORT_SYMBOL(blk_unregister_region);
37989 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
37990 index dc51f46..d5446a8 100644
37991 --- a/block/partitions/efi.c
37992 +++ b/block/partitions/efi.c
37993 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
37994 if (!gpt)
37995 return NULL;
37996
37997 + if (!le32_to_cpu(gpt->num_partition_entries))
37998 + return NULL;
37999 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
38000 + if (!pte)
38001 + return NULL;
38002 +
38003 count = le32_to_cpu(gpt->num_partition_entries) *
38004 le32_to_cpu(gpt->sizeof_partition_entry);
38005 - if (!count)
38006 - return NULL;
38007 - pte = kmalloc(count, GFP_KERNEL);
38008 - if (!pte)
38009 - return NULL;
38010 -
38011 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
38012 (u8 *) pte, count) < count) {
38013 kfree(pte);
38014 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
38015 index 14695c6..27a4636 100644
38016 --- a/block/scsi_ioctl.c
38017 +++ b/block/scsi_ioctl.c
38018 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
38019 return put_user(0, p);
38020 }
38021
38022 -static int sg_get_timeout(struct request_queue *q)
38023 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
38024 {
38025 return jiffies_to_clock_t(q->sg_timeout);
38026 }
38027 @@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
38028 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
38029 struct sg_io_hdr *hdr, fmode_t mode)
38030 {
38031 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
38032 + unsigned char tmpcmd[sizeof(rq->__cmd)];
38033 + unsigned char *cmdptr;
38034 +
38035 + if (rq->cmd != rq->__cmd)
38036 + cmdptr = rq->cmd;
38037 + else
38038 + cmdptr = tmpcmd;
38039 +
38040 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
38041 return -EFAULT;
38042 +
38043 + if (cmdptr != rq->cmd)
38044 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
38045 +
38046 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
38047 return -EPERM;
38048
38049 @@ -413,6 +425,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
38050 int err;
38051 unsigned int in_len, out_len, bytes, opcode, cmdlen;
38052 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
38053 + unsigned char tmpcmd[sizeof(rq->__cmd)];
38054 + unsigned char *cmdptr;
38055
38056 if (!sic)
38057 return -EINVAL;
38058 @@ -446,9 +460,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
38059 */
38060 err = -EFAULT;
38061 rq->cmd_len = cmdlen;
38062 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
38063 +
38064 + if (rq->cmd != rq->__cmd)
38065 + cmdptr = rq->cmd;
38066 + else
38067 + cmdptr = tmpcmd;
38068 +
38069 + if (copy_from_user(cmdptr, sic->data, cmdlen))
38070 goto error;
38071
38072 + if (rq->cmd != cmdptr)
38073 + memcpy(rq->cmd, cmdptr, cmdlen);
38074 +
38075 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
38076 goto error;
38077
38078 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
38079 index 7bdd61b..afec999 100644
38080 --- a/crypto/cryptd.c
38081 +++ b/crypto/cryptd.c
38082 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
38083
38084 struct cryptd_blkcipher_request_ctx {
38085 crypto_completion_t complete;
38086 -};
38087 +} __no_const;
38088
38089 struct cryptd_hash_ctx {
38090 struct crypto_shash *child;
38091 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
38092
38093 struct cryptd_aead_request_ctx {
38094 crypto_completion_t complete;
38095 -};
38096 +} __no_const;
38097
38098 static void cryptd_queue_worker(struct work_struct *work);
38099
38100 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
38101 index 309d345..1632720 100644
38102 --- a/crypto/pcrypt.c
38103 +++ b/crypto/pcrypt.c
38104 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
38105 int ret;
38106
38107 pinst->kobj.kset = pcrypt_kset;
38108 - ret = kobject_add(&pinst->kobj, NULL, name);
38109 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
38110 if (!ret)
38111 kobject_uevent(&pinst->kobj, KOBJ_ADD);
38112
38113 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
38114 index 6921c7f..78e1af7 100644
38115 --- a/drivers/acpi/acpica/hwxfsleep.c
38116 +++ b/drivers/acpi/acpica/hwxfsleep.c
38117 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
38118 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
38119
38120 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
38121 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38122 - acpi_hw_extended_sleep},
38123 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38124 - acpi_hw_extended_wake_prep},
38125 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
38126 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
38127 + .extended_function = acpi_hw_extended_sleep},
38128 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
38129 + .extended_function = acpi_hw_extended_wake_prep},
38130 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
38131 + .extended_function = acpi_hw_extended_wake}
38132 };
38133
38134 /*
38135 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
38136 index e5bcd91..74f050d 100644
38137 --- a/drivers/acpi/apei/apei-internal.h
38138 +++ b/drivers/acpi/apei/apei-internal.h
38139 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
38140 struct apei_exec_ins_type {
38141 u32 flags;
38142 apei_exec_ins_func_t run;
38143 -};
38144 +} __do_const;
38145
38146 struct apei_exec_context {
38147 u32 ip;
38148 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
38149 index dab7cb7..f0d2994 100644
38150 --- a/drivers/acpi/apei/ghes.c
38151 +++ b/drivers/acpi/apei/ghes.c
38152 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
38153 const struct acpi_hest_generic *generic,
38154 const struct acpi_generic_status *estatus)
38155 {
38156 - static atomic_t seqno;
38157 + static atomic_unchecked_t seqno;
38158 unsigned int curr_seqno;
38159 char pfx_seq[64];
38160
38161 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
38162 else
38163 pfx = KERN_ERR;
38164 }
38165 - curr_seqno = atomic_inc_return(&seqno);
38166 + curr_seqno = atomic_inc_return_unchecked(&seqno);
38167 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
38168 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
38169 pfx_seq, generic->header.source_id);
38170 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
38171 index a83e3c6..c3d617f 100644
38172 --- a/drivers/acpi/bgrt.c
38173 +++ b/drivers/acpi/bgrt.c
38174 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
38175 if (!bgrt_image)
38176 return -ENODEV;
38177
38178 - bin_attr_image.private = bgrt_image;
38179 - bin_attr_image.size = bgrt_image_size;
38180 + pax_open_kernel();
38181 + *(void **)&bin_attr_image.private = bgrt_image;
38182 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
38183 + pax_close_kernel();
38184
38185 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
38186 if (!bgrt_kobj)
38187 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
38188 index 3d8413d..95f638c 100644
38189 --- a/drivers/acpi/blacklist.c
38190 +++ b/drivers/acpi/blacklist.c
38191 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
38192 u32 is_critical_error;
38193 };
38194
38195 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
38196 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
38197
38198 /*
38199 * POLICY: If *anything* doesn't work, put it on the blacklist.
38200 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
38201 return 0;
38202 }
38203
38204 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
38205 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
38206 {
38207 .callback = dmi_disable_osi_vista,
38208 .ident = "Fujitsu Siemens",
38209 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
38210 index c68e724..e863008 100644
38211 --- a/drivers/acpi/custom_method.c
38212 +++ b/drivers/acpi/custom_method.c
38213 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
38214 struct acpi_table_header table;
38215 acpi_status status;
38216
38217 +#ifdef CONFIG_GRKERNSEC_KMEM
38218 + return -EPERM;
38219 +#endif
38220 +
38221 if (!(*ppos)) {
38222 /* parse the table header to get the table length */
38223 if (count <= sizeof(struct acpi_table_header))
38224 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
38225 index 3dca36d..abaf070 100644
38226 --- a/drivers/acpi/processor_idle.c
38227 +++ b/drivers/acpi/processor_idle.c
38228 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
38229 {
38230 int i, count = CPUIDLE_DRIVER_STATE_START;
38231 struct acpi_processor_cx *cx;
38232 - struct cpuidle_state *state;
38233 + cpuidle_state_no_const *state;
38234 struct cpuidle_driver *drv = &acpi_idle_driver;
38235
38236 if (!pr->flags.power_setup_done)
38237 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
38238 index 38cb978..352c761 100644
38239 --- a/drivers/acpi/sysfs.c
38240 +++ b/drivers/acpi/sysfs.c
38241 @@ -423,11 +423,11 @@ static u32 num_counters;
38242 static struct attribute **all_attrs;
38243 static u32 acpi_gpe_count;
38244
38245 -static struct attribute_group interrupt_stats_attr_group = {
38246 +static attribute_group_no_const interrupt_stats_attr_group = {
38247 .name = "interrupts",
38248 };
38249
38250 -static struct kobj_attribute *counter_attrs;
38251 +static kobj_attribute_no_const *counter_attrs;
38252
38253 static void delete_gpe_attr_array(void)
38254 {
38255 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
38256 index d72ce04..d6ab3c2 100644
38257 --- a/drivers/ata/libahci.c
38258 +++ b/drivers/ata/libahci.c
38259 @@ -1257,7 +1257,7 @@ int ahci_kick_engine(struct ata_port *ap)
38260 }
38261 EXPORT_SYMBOL_GPL(ahci_kick_engine);
38262
38263 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38264 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
38265 struct ata_taskfile *tf, int is_cmd, u16 flags,
38266 unsigned long timeout_msec)
38267 {
38268 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
38269 index 677c0c1..354b89b 100644
38270 --- a/drivers/ata/libata-core.c
38271 +++ b/drivers/ata/libata-core.c
38272 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
38273 static void ata_dev_xfermask(struct ata_device *dev);
38274 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
38275
38276 -atomic_t ata_print_id = ATOMIC_INIT(0);
38277 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
38278
38279 struct ata_force_param {
38280 const char *name;
38281 @@ -4863,7 +4863,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
38282 struct ata_port *ap;
38283 unsigned int tag;
38284
38285 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38286 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38287 ap = qc->ap;
38288
38289 qc->flags = 0;
38290 @@ -4879,7 +4879,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
38291 struct ata_port *ap;
38292 struct ata_link *link;
38293
38294 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38295 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
38296 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
38297 ap = qc->ap;
38298 link = qc->dev->link;
38299 @@ -5983,6 +5983,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38300 return;
38301
38302 spin_lock(&lock);
38303 + pax_open_kernel();
38304
38305 for (cur = ops->inherits; cur; cur = cur->inherits) {
38306 void **inherit = (void **)cur;
38307 @@ -5996,8 +5997,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
38308 if (IS_ERR(*pp))
38309 *pp = NULL;
38310
38311 - ops->inherits = NULL;
38312 + *(struct ata_port_operations **)&ops->inherits = NULL;
38313
38314 + pax_close_kernel();
38315 spin_unlock(&lock);
38316 }
38317
38318 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
38319
38320 /* give ports names and add SCSI hosts */
38321 for (i = 0; i < host->n_ports; i++) {
38322 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
38323 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
38324 host->ports[i]->local_port_no = i + 1;
38325 }
38326
38327 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
38328 index 72691fd..ad104c0 100644
38329 --- a/drivers/ata/libata-scsi.c
38330 +++ b/drivers/ata/libata-scsi.c
38331 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
38332
38333 if (rc)
38334 return rc;
38335 - ap->print_id = atomic_inc_return(&ata_print_id);
38336 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
38337 return 0;
38338 }
38339 EXPORT_SYMBOL_GPL(ata_sas_port_init);
38340 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
38341 index 45b5ab3..98446b8 100644
38342 --- a/drivers/ata/libata.h
38343 +++ b/drivers/ata/libata.h
38344 @@ -53,7 +53,7 @@ enum {
38345 ATA_DNXFER_QUIET = (1 << 31),
38346 };
38347
38348 -extern atomic_t ata_print_id;
38349 +extern atomic_unchecked_t ata_print_id;
38350 extern int atapi_passthru16;
38351 extern int libata_fua;
38352 extern int libata_noacpi;
38353 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
38354 index 4edb1a8..84e1658 100644
38355 --- a/drivers/ata/pata_arasan_cf.c
38356 +++ b/drivers/ata/pata_arasan_cf.c
38357 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
38358 /* Handle platform specific quirks */
38359 if (quirk) {
38360 if (quirk & CF_BROKEN_PIO) {
38361 - ap->ops->set_piomode = NULL;
38362 + pax_open_kernel();
38363 + *(void **)&ap->ops->set_piomode = NULL;
38364 + pax_close_kernel();
38365 ap->pio_mask = 0;
38366 }
38367 if (quirk & CF_BROKEN_MWDMA)
38368 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
38369 index f9b983a..887b9d8 100644
38370 --- a/drivers/atm/adummy.c
38371 +++ b/drivers/atm/adummy.c
38372 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
38373 vcc->pop(vcc, skb);
38374 else
38375 dev_kfree_skb_any(skb);
38376 - atomic_inc(&vcc->stats->tx);
38377 + atomic_inc_unchecked(&vcc->stats->tx);
38378
38379 return 0;
38380 }
38381 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
38382 index f1a9198..f466a4a 100644
38383 --- a/drivers/atm/ambassador.c
38384 +++ b/drivers/atm/ambassador.c
38385 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
38386 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
38387
38388 // VC layer stats
38389 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38390 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38391
38392 // free the descriptor
38393 kfree (tx_descr);
38394 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38395 dump_skb ("<<<", vc, skb);
38396
38397 // VC layer stats
38398 - atomic_inc(&atm_vcc->stats->rx);
38399 + atomic_inc_unchecked(&atm_vcc->stats->rx);
38400 __net_timestamp(skb);
38401 // end of our responsibility
38402 atm_vcc->push (atm_vcc, skb);
38403 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
38404 } else {
38405 PRINTK (KERN_INFO, "dropped over-size frame");
38406 // should we count this?
38407 - atomic_inc(&atm_vcc->stats->rx_drop);
38408 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38409 }
38410
38411 } else {
38412 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
38413 }
38414
38415 if (check_area (skb->data, skb->len)) {
38416 - atomic_inc(&atm_vcc->stats->tx_err);
38417 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
38418 return -ENOMEM; // ?
38419 }
38420
38421 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
38422 index 0e3f8f9..765a7a5 100644
38423 --- a/drivers/atm/atmtcp.c
38424 +++ b/drivers/atm/atmtcp.c
38425 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38426 if (vcc->pop) vcc->pop(vcc,skb);
38427 else dev_kfree_skb(skb);
38428 if (dev_data) return 0;
38429 - atomic_inc(&vcc->stats->tx_err);
38430 + atomic_inc_unchecked(&vcc->stats->tx_err);
38431 return -ENOLINK;
38432 }
38433 size = skb->len+sizeof(struct atmtcp_hdr);
38434 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38435 if (!new_skb) {
38436 if (vcc->pop) vcc->pop(vcc,skb);
38437 else dev_kfree_skb(skb);
38438 - atomic_inc(&vcc->stats->tx_err);
38439 + atomic_inc_unchecked(&vcc->stats->tx_err);
38440 return -ENOBUFS;
38441 }
38442 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
38443 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
38444 if (vcc->pop) vcc->pop(vcc,skb);
38445 else dev_kfree_skb(skb);
38446 out_vcc->push(out_vcc,new_skb);
38447 - atomic_inc(&vcc->stats->tx);
38448 - atomic_inc(&out_vcc->stats->rx);
38449 + atomic_inc_unchecked(&vcc->stats->tx);
38450 + atomic_inc_unchecked(&out_vcc->stats->rx);
38451 return 0;
38452 }
38453
38454 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38455 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
38456 read_unlock(&vcc_sklist_lock);
38457 if (!out_vcc) {
38458 - atomic_inc(&vcc->stats->tx_err);
38459 + atomic_inc_unchecked(&vcc->stats->tx_err);
38460 goto done;
38461 }
38462 skb_pull(skb,sizeof(struct atmtcp_hdr));
38463 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
38464 __net_timestamp(new_skb);
38465 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
38466 out_vcc->push(out_vcc,new_skb);
38467 - atomic_inc(&vcc->stats->tx);
38468 - atomic_inc(&out_vcc->stats->rx);
38469 + atomic_inc_unchecked(&vcc->stats->tx);
38470 + atomic_inc_unchecked(&out_vcc->stats->rx);
38471 done:
38472 if (vcc->pop) vcc->pop(vcc,skb);
38473 else dev_kfree_skb(skb);
38474 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
38475 index b1955ba..b179940 100644
38476 --- a/drivers/atm/eni.c
38477 +++ b/drivers/atm/eni.c
38478 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
38479 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
38480 vcc->dev->number);
38481 length = 0;
38482 - atomic_inc(&vcc->stats->rx_err);
38483 + atomic_inc_unchecked(&vcc->stats->rx_err);
38484 }
38485 else {
38486 length = ATM_CELL_SIZE-1; /* no HEC */
38487 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38488 size);
38489 }
38490 eff = length = 0;
38491 - atomic_inc(&vcc->stats->rx_err);
38492 + atomic_inc_unchecked(&vcc->stats->rx_err);
38493 }
38494 else {
38495 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
38496 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
38497 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
38498 vcc->dev->number,vcc->vci,length,size << 2,descr);
38499 length = eff = 0;
38500 - atomic_inc(&vcc->stats->rx_err);
38501 + atomic_inc_unchecked(&vcc->stats->rx_err);
38502 }
38503 }
38504 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
38505 @@ -767,7 +767,7 @@ rx_dequeued++;
38506 vcc->push(vcc,skb);
38507 pushed++;
38508 }
38509 - atomic_inc(&vcc->stats->rx);
38510 + atomic_inc_unchecked(&vcc->stats->rx);
38511 }
38512 wake_up(&eni_dev->rx_wait);
38513 }
38514 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
38515 PCI_DMA_TODEVICE);
38516 if (vcc->pop) vcc->pop(vcc,skb);
38517 else dev_kfree_skb_irq(skb);
38518 - atomic_inc(&vcc->stats->tx);
38519 + atomic_inc_unchecked(&vcc->stats->tx);
38520 wake_up(&eni_dev->tx_wait);
38521 dma_complete++;
38522 }
38523 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
38524 index 82f2ae0..f205c02 100644
38525 --- a/drivers/atm/firestream.c
38526 +++ b/drivers/atm/firestream.c
38527 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
38528 }
38529 }
38530
38531 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38532 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38533
38534 fs_dprintk (FS_DEBUG_TXMEM, "i");
38535 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
38536 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38537 #endif
38538 skb_put (skb, qe->p1 & 0xffff);
38539 ATM_SKB(skb)->vcc = atm_vcc;
38540 - atomic_inc(&atm_vcc->stats->rx);
38541 + atomic_inc_unchecked(&atm_vcc->stats->rx);
38542 __net_timestamp(skb);
38543 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
38544 atm_vcc->push (atm_vcc, skb);
38545 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
38546 kfree (pe);
38547 }
38548 if (atm_vcc)
38549 - atomic_inc(&atm_vcc->stats->rx_drop);
38550 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38551 break;
38552 case 0x1f: /* Reassembly abort: no buffers. */
38553 /* Silently increment error counter. */
38554 if (atm_vcc)
38555 - atomic_inc(&atm_vcc->stats->rx_drop);
38556 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
38557 break;
38558 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
38559 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
38560 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
38561 index d4725fc..2d4ea65 100644
38562 --- a/drivers/atm/fore200e.c
38563 +++ b/drivers/atm/fore200e.c
38564 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
38565 #endif
38566 /* check error condition */
38567 if (*entry->status & STATUS_ERROR)
38568 - atomic_inc(&vcc->stats->tx_err);
38569 + atomic_inc_unchecked(&vcc->stats->tx_err);
38570 else
38571 - atomic_inc(&vcc->stats->tx);
38572 + atomic_inc_unchecked(&vcc->stats->tx);
38573 }
38574 }
38575
38576 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38577 if (skb == NULL) {
38578 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
38579
38580 - atomic_inc(&vcc->stats->rx_drop);
38581 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38582 return -ENOMEM;
38583 }
38584
38585 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
38586
38587 dev_kfree_skb_any(skb);
38588
38589 - atomic_inc(&vcc->stats->rx_drop);
38590 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38591 return -ENOMEM;
38592 }
38593
38594 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38595
38596 vcc->push(vcc, skb);
38597 - atomic_inc(&vcc->stats->rx);
38598 + atomic_inc_unchecked(&vcc->stats->rx);
38599
38600 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
38601
38602 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
38603 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
38604 fore200e->atm_dev->number,
38605 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
38606 - atomic_inc(&vcc->stats->rx_err);
38607 + atomic_inc_unchecked(&vcc->stats->rx_err);
38608 }
38609 }
38610
38611 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
38612 goto retry_here;
38613 }
38614
38615 - atomic_inc(&vcc->stats->tx_err);
38616 + atomic_inc_unchecked(&vcc->stats->tx_err);
38617
38618 fore200e->tx_sat++;
38619 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
38620 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
38621 index aa6be26..f70a785 100644
38622 --- a/drivers/atm/he.c
38623 +++ b/drivers/atm/he.c
38624 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38625
38626 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
38627 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
38628 - atomic_inc(&vcc->stats->rx_drop);
38629 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38630 goto return_host_buffers;
38631 }
38632
38633 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38634 RBRQ_LEN_ERR(he_dev->rbrq_head)
38635 ? "LEN_ERR" : "",
38636 vcc->vpi, vcc->vci);
38637 - atomic_inc(&vcc->stats->rx_err);
38638 + atomic_inc_unchecked(&vcc->stats->rx_err);
38639 goto return_host_buffers;
38640 }
38641
38642 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
38643 vcc->push(vcc, skb);
38644 spin_lock(&he_dev->global_lock);
38645
38646 - atomic_inc(&vcc->stats->rx);
38647 + atomic_inc_unchecked(&vcc->stats->rx);
38648
38649 return_host_buffers:
38650 ++pdus_assembled;
38651 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
38652 tpd->vcc->pop(tpd->vcc, tpd->skb);
38653 else
38654 dev_kfree_skb_any(tpd->skb);
38655 - atomic_inc(&tpd->vcc->stats->tx_err);
38656 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
38657 }
38658 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
38659 return;
38660 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38661 vcc->pop(vcc, skb);
38662 else
38663 dev_kfree_skb_any(skb);
38664 - atomic_inc(&vcc->stats->tx_err);
38665 + atomic_inc_unchecked(&vcc->stats->tx_err);
38666 return -EINVAL;
38667 }
38668
38669 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38670 vcc->pop(vcc, skb);
38671 else
38672 dev_kfree_skb_any(skb);
38673 - atomic_inc(&vcc->stats->tx_err);
38674 + atomic_inc_unchecked(&vcc->stats->tx_err);
38675 return -EINVAL;
38676 }
38677 #endif
38678 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38679 vcc->pop(vcc, skb);
38680 else
38681 dev_kfree_skb_any(skb);
38682 - atomic_inc(&vcc->stats->tx_err);
38683 + atomic_inc_unchecked(&vcc->stats->tx_err);
38684 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38685 return -ENOMEM;
38686 }
38687 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38688 vcc->pop(vcc, skb);
38689 else
38690 dev_kfree_skb_any(skb);
38691 - atomic_inc(&vcc->stats->tx_err);
38692 + atomic_inc_unchecked(&vcc->stats->tx_err);
38693 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38694 return -ENOMEM;
38695 }
38696 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
38697 __enqueue_tpd(he_dev, tpd, cid);
38698 spin_unlock_irqrestore(&he_dev->global_lock, flags);
38699
38700 - atomic_inc(&vcc->stats->tx);
38701 + atomic_inc_unchecked(&vcc->stats->tx);
38702
38703 return 0;
38704 }
38705 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
38706 index 1dc0519..1aadaf7 100644
38707 --- a/drivers/atm/horizon.c
38708 +++ b/drivers/atm/horizon.c
38709 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
38710 {
38711 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
38712 // VC layer stats
38713 - atomic_inc(&vcc->stats->rx);
38714 + atomic_inc_unchecked(&vcc->stats->rx);
38715 __net_timestamp(skb);
38716 // end of our responsibility
38717 vcc->push (vcc, skb);
38718 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
38719 dev->tx_iovec = NULL;
38720
38721 // VC layer stats
38722 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
38723 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
38724
38725 // free the skb
38726 hrz_kfree_skb (skb);
38727 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
38728 index b621f56..1e3a799 100644
38729 --- a/drivers/atm/idt77252.c
38730 +++ b/drivers/atm/idt77252.c
38731 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
38732 else
38733 dev_kfree_skb(skb);
38734
38735 - atomic_inc(&vcc->stats->tx);
38736 + atomic_inc_unchecked(&vcc->stats->tx);
38737 }
38738
38739 atomic_dec(&scq->used);
38740 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38741 if ((sb = dev_alloc_skb(64)) == NULL) {
38742 printk("%s: Can't allocate buffers for aal0.\n",
38743 card->name);
38744 - atomic_add(i, &vcc->stats->rx_drop);
38745 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38746 break;
38747 }
38748 if (!atm_charge(vcc, sb->truesize)) {
38749 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
38750 card->name);
38751 - atomic_add(i - 1, &vcc->stats->rx_drop);
38752 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
38753 dev_kfree_skb(sb);
38754 break;
38755 }
38756 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38757 ATM_SKB(sb)->vcc = vcc;
38758 __net_timestamp(sb);
38759 vcc->push(vcc, sb);
38760 - atomic_inc(&vcc->stats->rx);
38761 + atomic_inc_unchecked(&vcc->stats->rx);
38762
38763 cell += ATM_CELL_PAYLOAD;
38764 }
38765 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38766 "(CDC: %08x)\n",
38767 card->name, len, rpp->len, readl(SAR_REG_CDC));
38768 recycle_rx_pool_skb(card, rpp);
38769 - atomic_inc(&vcc->stats->rx_err);
38770 + atomic_inc_unchecked(&vcc->stats->rx_err);
38771 return;
38772 }
38773 if (stat & SAR_RSQE_CRC) {
38774 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
38775 recycle_rx_pool_skb(card, rpp);
38776 - atomic_inc(&vcc->stats->rx_err);
38777 + atomic_inc_unchecked(&vcc->stats->rx_err);
38778 return;
38779 }
38780 if (skb_queue_len(&rpp->queue) > 1) {
38781 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38782 RXPRINTK("%s: Can't alloc RX skb.\n",
38783 card->name);
38784 recycle_rx_pool_skb(card, rpp);
38785 - atomic_inc(&vcc->stats->rx_err);
38786 + atomic_inc_unchecked(&vcc->stats->rx_err);
38787 return;
38788 }
38789 if (!atm_charge(vcc, skb->truesize)) {
38790 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38791 __net_timestamp(skb);
38792
38793 vcc->push(vcc, skb);
38794 - atomic_inc(&vcc->stats->rx);
38795 + atomic_inc_unchecked(&vcc->stats->rx);
38796
38797 return;
38798 }
38799 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
38800 __net_timestamp(skb);
38801
38802 vcc->push(vcc, skb);
38803 - atomic_inc(&vcc->stats->rx);
38804 + atomic_inc_unchecked(&vcc->stats->rx);
38805
38806 if (skb->truesize > SAR_FB_SIZE_3)
38807 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
38808 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
38809 if (vcc->qos.aal != ATM_AAL0) {
38810 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
38811 card->name, vpi, vci);
38812 - atomic_inc(&vcc->stats->rx_drop);
38813 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38814 goto drop;
38815 }
38816
38817 if ((sb = dev_alloc_skb(64)) == NULL) {
38818 printk("%s: Can't allocate buffers for AAL0.\n",
38819 card->name);
38820 - atomic_inc(&vcc->stats->rx_err);
38821 + atomic_inc_unchecked(&vcc->stats->rx_err);
38822 goto drop;
38823 }
38824
38825 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
38826 ATM_SKB(sb)->vcc = vcc;
38827 __net_timestamp(sb);
38828 vcc->push(vcc, sb);
38829 - atomic_inc(&vcc->stats->rx);
38830 + atomic_inc_unchecked(&vcc->stats->rx);
38831
38832 drop:
38833 skb_pull(queue, 64);
38834 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38835
38836 if (vc == NULL) {
38837 printk("%s: NULL connection in send().\n", card->name);
38838 - atomic_inc(&vcc->stats->tx_err);
38839 + atomic_inc_unchecked(&vcc->stats->tx_err);
38840 dev_kfree_skb(skb);
38841 return -EINVAL;
38842 }
38843 if (!test_bit(VCF_TX, &vc->flags)) {
38844 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
38845 - atomic_inc(&vcc->stats->tx_err);
38846 + atomic_inc_unchecked(&vcc->stats->tx_err);
38847 dev_kfree_skb(skb);
38848 return -EINVAL;
38849 }
38850 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38851 break;
38852 default:
38853 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
38854 - atomic_inc(&vcc->stats->tx_err);
38855 + atomic_inc_unchecked(&vcc->stats->tx_err);
38856 dev_kfree_skb(skb);
38857 return -EINVAL;
38858 }
38859
38860 if (skb_shinfo(skb)->nr_frags != 0) {
38861 printk("%s: No scatter-gather yet.\n", card->name);
38862 - atomic_inc(&vcc->stats->tx_err);
38863 + atomic_inc_unchecked(&vcc->stats->tx_err);
38864 dev_kfree_skb(skb);
38865 return -EINVAL;
38866 }
38867 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
38868
38869 err = queue_skb(card, vc, skb, oam);
38870 if (err) {
38871 - atomic_inc(&vcc->stats->tx_err);
38872 + atomic_inc_unchecked(&vcc->stats->tx_err);
38873 dev_kfree_skb(skb);
38874 return err;
38875 }
38876 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
38877 skb = dev_alloc_skb(64);
38878 if (!skb) {
38879 printk("%s: Out of memory in send_oam().\n", card->name);
38880 - atomic_inc(&vcc->stats->tx_err);
38881 + atomic_inc_unchecked(&vcc->stats->tx_err);
38882 return -ENOMEM;
38883 }
38884 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
38885 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
38886 index 4217f29..88f547a 100644
38887 --- a/drivers/atm/iphase.c
38888 +++ b/drivers/atm/iphase.c
38889 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
38890 status = (u_short) (buf_desc_ptr->desc_mode);
38891 if (status & (RX_CER | RX_PTE | RX_OFL))
38892 {
38893 - atomic_inc(&vcc->stats->rx_err);
38894 + atomic_inc_unchecked(&vcc->stats->rx_err);
38895 IF_ERR(printk("IA: bad packet, dropping it");)
38896 if (status & RX_CER) {
38897 IF_ERR(printk(" cause: packet CRC error\n");)
38898 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38899 len = dma_addr - buf_addr;
38900 if (len > iadev->rx_buf_sz) {
38901 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38902 - atomic_inc(&vcc->stats->rx_err);
38903 + atomic_inc_unchecked(&vcc->stats->rx_err);
38904 goto out_free_desc;
38905 }
38906
38907 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38908 ia_vcc = INPH_IA_VCC(vcc);
38909 if (ia_vcc == NULL)
38910 {
38911 - atomic_inc(&vcc->stats->rx_err);
38912 + atomic_inc_unchecked(&vcc->stats->rx_err);
38913 atm_return(vcc, skb->truesize);
38914 dev_kfree_skb_any(skb);
38915 goto INCR_DLE;
38916 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38917 if ((length > iadev->rx_buf_sz) || (length >
38918 (skb->len - sizeof(struct cpcs_trailer))))
38919 {
38920 - atomic_inc(&vcc->stats->rx_err);
38921 + atomic_inc_unchecked(&vcc->stats->rx_err);
38922 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38923 length, skb->len);)
38924 atm_return(vcc, skb->truesize);
38925 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38926
38927 IF_RX(printk("rx_dle_intr: skb push");)
38928 vcc->push(vcc,skb);
38929 - atomic_inc(&vcc->stats->rx);
38930 + atomic_inc_unchecked(&vcc->stats->rx);
38931 iadev->rx_pkt_cnt++;
38932 }
38933 INCR_DLE:
38934 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38935 {
38936 struct k_sonet_stats *stats;
38937 stats = &PRIV(_ia_dev[board])->sonet_stats;
38938 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38939 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38940 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38941 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38942 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38943 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38944 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38945 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38946 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38947 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38948 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38949 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38950 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38951 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38952 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38953 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38954 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38955 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38956 }
38957 ia_cmds.status = 0;
38958 break;
38959 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38960 if ((desc == 0) || (desc > iadev->num_tx_desc))
38961 {
38962 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38963 - atomic_inc(&vcc->stats->tx);
38964 + atomic_inc_unchecked(&vcc->stats->tx);
38965 if (vcc->pop)
38966 vcc->pop(vcc, skb);
38967 else
38968 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38969 ATM_DESC(skb) = vcc->vci;
38970 skb_queue_tail(&iadev->tx_dma_q, skb);
38971
38972 - atomic_inc(&vcc->stats->tx);
38973 + atomic_inc_unchecked(&vcc->stats->tx);
38974 iadev->tx_pkt_cnt++;
38975 /* Increment transaction counter */
38976 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38977
38978 #if 0
38979 /* add flow control logic */
38980 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38981 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38982 if (iavcc->vc_desc_cnt > 10) {
38983 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38984 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38985 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38986 index fa7d7019..1e404c7 100644
38987 --- a/drivers/atm/lanai.c
38988 +++ b/drivers/atm/lanai.c
38989 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38990 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38991 lanai_endtx(lanai, lvcc);
38992 lanai_free_skb(lvcc->tx.atmvcc, skb);
38993 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38994 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38995 }
38996
38997 /* Try to fill the buffer - don't call unless there is backlog */
38998 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38999 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
39000 __net_timestamp(skb);
39001 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
39002 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
39003 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
39004 out:
39005 lvcc->rx.buf.ptr = end;
39006 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
39007 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
39008 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
39009 "vcc %d\n", lanai->number, (unsigned int) s, vci);
39010 lanai->stats.service_rxnotaal5++;
39011 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
39012 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
39013 return 0;
39014 }
39015 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
39016 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
39017 int bytes;
39018 read_unlock(&vcc_sklist_lock);
39019 DPRINTK("got trashed rx pdu on vci %d\n", vci);
39020 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
39021 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
39022 lvcc->stats.x.aal5.service_trash++;
39023 bytes = (SERVICE_GET_END(s) * 16) -
39024 (((unsigned long) lvcc->rx.buf.ptr) -
39025 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
39026 }
39027 if (s & SERVICE_STREAM) {
39028 read_unlock(&vcc_sklist_lock);
39029 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
39030 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
39031 lvcc->stats.x.aal5.service_stream++;
39032 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
39033 "PDU on VCI %d!\n", lanai->number, vci);
39034 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
39035 return 0;
39036 }
39037 DPRINTK("got rx crc error on vci %d\n", vci);
39038 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
39039 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
39040 lvcc->stats.x.aal5.service_rxcrc++;
39041 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
39042 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
39043 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
39044 index 9988ac9..7c52585 100644
39045 --- a/drivers/atm/nicstar.c
39046 +++ b/drivers/atm/nicstar.c
39047 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39048 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
39049 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
39050 card->index);
39051 - atomic_inc(&vcc->stats->tx_err);
39052 + atomic_inc_unchecked(&vcc->stats->tx_err);
39053 dev_kfree_skb_any(skb);
39054 return -EINVAL;
39055 }
39056 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39057 if (!vc->tx) {
39058 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
39059 card->index);
39060 - atomic_inc(&vcc->stats->tx_err);
39061 + atomic_inc_unchecked(&vcc->stats->tx_err);
39062 dev_kfree_skb_any(skb);
39063 return -EINVAL;
39064 }
39065 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39066 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
39067 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
39068 card->index);
39069 - atomic_inc(&vcc->stats->tx_err);
39070 + atomic_inc_unchecked(&vcc->stats->tx_err);
39071 dev_kfree_skb_any(skb);
39072 return -EINVAL;
39073 }
39074
39075 if (skb_shinfo(skb)->nr_frags != 0) {
39076 printk("nicstar%d: No scatter-gather yet.\n", card->index);
39077 - atomic_inc(&vcc->stats->tx_err);
39078 + atomic_inc_unchecked(&vcc->stats->tx_err);
39079 dev_kfree_skb_any(skb);
39080 return -EINVAL;
39081 }
39082 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
39083 }
39084
39085 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
39086 - atomic_inc(&vcc->stats->tx_err);
39087 + atomic_inc_unchecked(&vcc->stats->tx_err);
39088 dev_kfree_skb_any(skb);
39089 return -EIO;
39090 }
39091 - atomic_inc(&vcc->stats->tx);
39092 + atomic_inc_unchecked(&vcc->stats->tx);
39093
39094 return 0;
39095 }
39096 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39097 printk
39098 ("nicstar%d: Can't allocate buffers for aal0.\n",
39099 card->index);
39100 - atomic_add(i, &vcc->stats->rx_drop);
39101 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
39102 break;
39103 }
39104 if (!atm_charge(vcc, sb->truesize)) {
39105 RXPRINTK
39106 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
39107 card->index);
39108 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39109 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
39110 dev_kfree_skb_any(sb);
39111 break;
39112 }
39113 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39114 ATM_SKB(sb)->vcc = vcc;
39115 __net_timestamp(sb);
39116 vcc->push(vcc, sb);
39117 - atomic_inc(&vcc->stats->rx);
39118 + atomic_inc_unchecked(&vcc->stats->rx);
39119 cell += ATM_CELL_PAYLOAD;
39120 }
39121
39122 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39123 if (iovb == NULL) {
39124 printk("nicstar%d: Out of iovec buffers.\n",
39125 card->index);
39126 - atomic_inc(&vcc->stats->rx_drop);
39127 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39128 recycle_rx_buf(card, skb);
39129 return;
39130 }
39131 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39132 small or large buffer itself. */
39133 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
39134 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
39135 - atomic_inc(&vcc->stats->rx_err);
39136 + atomic_inc_unchecked(&vcc->stats->rx_err);
39137 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39138 NS_MAX_IOVECS);
39139 NS_PRV_IOVCNT(iovb) = 0;
39140 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39141 ("nicstar%d: Expected a small buffer, and this is not one.\n",
39142 card->index);
39143 which_list(card, skb);
39144 - atomic_inc(&vcc->stats->rx_err);
39145 + atomic_inc_unchecked(&vcc->stats->rx_err);
39146 recycle_rx_buf(card, skb);
39147 vc->rx_iov = NULL;
39148 recycle_iov_buf(card, iovb);
39149 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39150 ("nicstar%d: Expected a large buffer, and this is not one.\n",
39151 card->index);
39152 which_list(card, skb);
39153 - atomic_inc(&vcc->stats->rx_err);
39154 + atomic_inc_unchecked(&vcc->stats->rx_err);
39155 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39156 NS_PRV_IOVCNT(iovb));
39157 vc->rx_iov = NULL;
39158 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39159 printk(" - PDU size mismatch.\n");
39160 else
39161 printk(".\n");
39162 - atomic_inc(&vcc->stats->rx_err);
39163 + atomic_inc_unchecked(&vcc->stats->rx_err);
39164 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
39165 NS_PRV_IOVCNT(iovb));
39166 vc->rx_iov = NULL;
39167 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39168 /* skb points to a small buffer */
39169 if (!atm_charge(vcc, skb->truesize)) {
39170 push_rxbufs(card, skb);
39171 - atomic_inc(&vcc->stats->rx_drop);
39172 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39173 } else {
39174 skb_put(skb, len);
39175 dequeue_sm_buf(card, skb);
39176 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39177 ATM_SKB(skb)->vcc = vcc;
39178 __net_timestamp(skb);
39179 vcc->push(vcc, skb);
39180 - atomic_inc(&vcc->stats->rx);
39181 + atomic_inc_unchecked(&vcc->stats->rx);
39182 }
39183 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
39184 struct sk_buff *sb;
39185 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39186 if (len <= NS_SMBUFSIZE) {
39187 if (!atm_charge(vcc, sb->truesize)) {
39188 push_rxbufs(card, sb);
39189 - atomic_inc(&vcc->stats->rx_drop);
39190 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39191 } else {
39192 skb_put(sb, len);
39193 dequeue_sm_buf(card, sb);
39194 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39195 ATM_SKB(sb)->vcc = vcc;
39196 __net_timestamp(sb);
39197 vcc->push(vcc, sb);
39198 - atomic_inc(&vcc->stats->rx);
39199 + atomic_inc_unchecked(&vcc->stats->rx);
39200 }
39201
39202 push_rxbufs(card, skb);
39203 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39204
39205 if (!atm_charge(vcc, skb->truesize)) {
39206 push_rxbufs(card, skb);
39207 - atomic_inc(&vcc->stats->rx_drop);
39208 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39209 } else {
39210 dequeue_lg_buf(card, skb);
39211 #ifdef NS_USE_DESTRUCTORS
39212 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39213 ATM_SKB(skb)->vcc = vcc;
39214 __net_timestamp(skb);
39215 vcc->push(vcc, skb);
39216 - atomic_inc(&vcc->stats->rx);
39217 + atomic_inc_unchecked(&vcc->stats->rx);
39218 }
39219
39220 push_rxbufs(card, sb);
39221 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39222 printk
39223 ("nicstar%d: Out of huge buffers.\n",
39224 card->index);
39225 - atomic_inc(&vcc->stats->rx_drop);
39226 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39227 recycle_iovec_rx_bufs(card,
39228 (struct iovec *)
39229 iovb->data,
39230 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39231 card->hbpool.count++;
39232 } else
39233 dev_kfree_skb_any(hb);
39234 - atomic_inc(&vcc->stats->rx_drop);
39235 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39236 } else {
39237 /* Copy the small buffer to the huge buffer */
39238 sb = (struct sk_buff *)iov->iov_base;
39239 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
39240 #endif /* NS_USE_DESTRUCTORS */
39241 __net_timestamp(hb);
39242 vcc->push(vcc, hb);
39243 - atomic_inc(&vcc->stats->rx);
39244 + atomic_inc_unchecked(&vcc->stats->rx);
39245 }
39246 }
39247
39248 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
39249 index 943cf0d..37d15d5 100644
39250 --- a/drivers/atm/solos-pci.c
39251 +++ b/drivers/atm/solos-pci.c
39252 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
39253 }
39254 atm_charge(vcc, skb->truesize);
39255 vcc->push(vcc, skb);
39256 - atomic_inc(&vcc->stats->rx);
39257 + atomic_inc_unchecked(&vcc->stats->rx);
39258 break;
39259
39260 case PKT_STATUS:
39261 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
39262 vcc = SKB_CB(oldskb)->vcc;
39263
39264 if (vcc) {
39265 - atomic_inc(&vcc->stats->tx);
39266 + atomic_inc_unchecked(&vcc->stats->tx);
39267 solos_pop(vcc, oldskb);
39268 } else {
39269 dev_kfree_skb_irq(oldskb);
39270 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
39271 index 0215934..ce9f5b1 100644
39272 --- a/drivers/atm/suni.c
39273 +++ b/drivers/atm/suni.c
39274 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
39275
39276
39277 #define ADD_LIMITED(s,v) \
39278 - atomic_add((v),&stats->s); \
39279 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
39280 + atomic_add_unchecked((v),&stats->s); \
39281 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
39282
39283
39284 static void suni_hz(unsigned long from_timer)
39285 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
39286 index 5120a96..e2572bd 100644
39287 --- a/drivers/atm/uPD98402.c
39288 +++ b/drivers/atm/uPD98402.c
39289 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
39290 struct sonet_stats tmp;
39291 int error = 0;
39292
39293 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39294 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
39295 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
39296 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
39297 if (zero && !error) {
39298 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
39299
39300
39301 #define ADD_LIMITED(s,v) \
39302 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
39303 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
39304 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39305 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
39306 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
39307 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
39308
39309
39310 static void stat_event(struct atm_dev *dev)
39311 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
39312 if (reason & uPD98402_INT_PFM) stat_event(dev);
39313 if (reason & uPD98402_INT_PCO) {
39314 (void) GET(PCOCR); /* clear interrupt cause */
39315 - atomic_add(GET(HECCT),
39316 + atomic_add_unchecked(GET(HECCT),
39317 &PRIV(dev)->sonet_stats.uncorr_hcs);
39318 }
39319 if ((reason & uPD98402_INT_RFO) &&
39320 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
39321 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
39322 uPD98402_INT_LOS),PIMR); /* enable them */
39323 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
39324 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39325 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
39326 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
39327 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
39328 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
39329 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
39330 return 0;
39331 }
39332
39333 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
39334 index 969c3c2..9b72956 100644
39335 --- a/drivers/atm/zatm.c
39336 +++ b/drivers/atm/zatm.c
39337 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39338 }
39339 if (!size) {
39340 dev_kfree_skb_irq(skb);
39341 - if (vcc) atomic_inc(&vcc->stats->rx_err);
39342 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
39343 continue;
39344 }
39345 if (!atm_charge(vcc,skb->truesize)) {
39346 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
39347 skb->len = size;
39348 ATM_SKB(skb)->vcc = vcc;
39349 vcc->push(vcc,skb);
39350 - atomic_inc(&vcc->stats->rx);
39351 + atomic_inc_unchecked(&vcc->stats->rx);
39352 }
39353 zout(pos & 0xffff,MTA(mbx));
39354 #if 0 /* probably a stupid idea */
39355 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
39356 skb_queue_head(&zatm_vcc->backlog,skb);
39357 break;
39358 }
39359 - atomic_inc(&vcc->stats->tx);
39360 + atomic_inc_unchecked(&vcc->stats->tx);
39361 wake_up(&zatm_vcc->tx_wait);
39362 }
39363
39364 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
39365 index 83e910a..b224a73 100644
39366 --- a/drivers/base/bus.c
39367 +++ b/drivers/base/bus.c
39368 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
39369 return -EINVAL;
39370
39371 mutex_lock(&subsys->p->mutex);
39372 - list_add_tail(&sif->node, &subsys->p->interfaces);
39373 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
39374 if (sif->add_dev) {
39375 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39376 while ((dev = subsys_dev_iter_next(&iter)))
39377 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
39378 subsys = sif->subsys;
39379
39380 mutex_lock(&subsys->p->mutex);
39381 - list_del_init(&sif->node);
39382 + pax_list_del_init((struct list_head *)&sif->node);
39383 if (sif->remove_dev) {
39384 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
39385 while ((dev = subsys_dev_iter_next(&iter)))
39386 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
39387 index 25798db..15f130e 100644
39388 --- a/drivers/base/devtmpfs.c
39389 +++ b/drivers/base/devtmpfs.c
39390 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
39391 if (!thread)
39392 return 0;
39393
39394 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
39395 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
39396 if (err)
39397 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
39398 else
39399 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
39400 *err = sys_unshare(CLONE_NEWNS);
39401 if (*err)
39402 goto out;
39403 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
39404 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
39405 if (*err)
39406 goto out;
39407 - sys_chdir("/.."); /* will traverse into overmounted root */
39408 - sys_chroot(".");
39409 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
39410 + sys_chroot((char __force_user *)".");
39411 complete(&setup_done);
39412 while (1) {
39413 spin_lock(&req_lock);
39414 diff --git a/drivers/base/node.c b/drivers/base/node.c
39415 index 8f7ed99..700dd0c 100644
39416 --- a/drivers/base/node.c
39417 +++ b/drivers/base/node.c
39418 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
39419 struct node_attr {
39420 struct device_attribute attr;
39421 enum node_states state;
39422 -};
39423 +} __do_const;
39424
39425 static ssize_t show_node_state(struct device *dev,
39426 struct device_attribute *attr, char *buf)
39427 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
39428 index eee55c1..b8c9393 100644
39429 --- a/drivers/base/power/domain.c
39430 +++ b/drivers/base/power/domain.c
39431 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
39432
39433 if (dev->power.subsys_data->domain_data) {
39434 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
39435 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
39436 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
39437 if (clear_td)
39438 - gpd_data->td = (struct gpd_timing_data){ 0 };
39439 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
39440
39441 if (--gpd_data->refcount == 0) {
39442 dev->power.subsys_data->domain_data = NULL;
39443 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
39444 {
39445 struct cpuidle_driver *cpuidle_drv;
39446 struct gpd_cpu_data *cpu_data;
39447 - struct cpuidle_state *idle_state;
39448 + cpuidle_state_no_const *idle_state;
39449 int ret = 0;
39450
39451 if (IS_ERR_OR_NULL(genpd) || state < 0)
39452 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
39453 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
39454 {
39455 struct gpd_cpu_data *cpu_data;
39456 - struct cpuidle_state *idle_state;
39457 + cpuidle_state_no_const *idle_state;
39458 int ret = 0;
39459
39460 if (IS_ERR_OR_NULL(genpd))
39461 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
39462 index 95b181d1..c4f0e19 100644
39463 --- a/drivers/base/power/sysfs.c
39464 +++ b/drivers/base/power/sysfs.c
39465 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
39466 return -EIO;
39467 }
39468 }
39469 - return sprintf(buf, p);
39470 + return sprintf(buf, "%s", p);
39471 }
39472
39473 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
39474 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
39475 index eb1bd2e..2667d3a 100644
39476 --- a/drivers/base/power/wakeup.c
39477 +++ b/drivers/base/power/wakeup.c
39478 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
39479 * They need to be modified together atomically, so it's better to use one
39480 * atomic variable to hold them both.
39481 */
39482 -static atomic_t combined_event_count = ATOMIC_INIT(0);
39483 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
39484
39485 #define IN_PROGRESS_BITS (sizeof(int) * 4)
39486 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
39487
39488 static void split_counters(unsigned int *cnt, unsigned int *inpr)
39489 {
39490 - unsigned int comb = atomic_read(&combined_event_count);
39491 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
39492
39493 *cnt = (comb >> IN_PROGRESS_BITS);
39494 *inpr = comb & MAX_IN_PROGRESS;
39495 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
39496 ws->start_prevent_time = ws->last_time;
39497
39498 /* Increment the counter of events in progress. */
39499 - cec = atomic_inc_return(&combined_event_count);
39500 + cec = atomic_inc_return_unchecked(&combined_event_count);
39501
39502 trace_wakeup_source_activate(ws->name, cec);
39503 }
39504 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
39505 * Increment the counter of registered wakeup events and decrement the
39506 * couter of wakeup events in progress simultaneously.
39507 */
39508 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
39509 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
39510 trace_wakeup_source_deactivate(ws->name, cec);
39511
39512 split_counters(&cnt, &inpr);
39513 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
39514 index dbb8350..4762f4c 100644
39515 --- a/drivers/base/syscore.c
39516 +++ b/drivers/base/syscore.c
39517 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
39518 void register_syscore_ops(struct syscore_ops *ops)
39519 {
39520 mutex_lock(&syscore_ops_lock);
39521 - list_add_tail(&ops->node, &syscore_ops_list);
39522 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
39523 mutex_unlock(&syscore_ops_lock);
39524 }
39525 EXPORT_SYMBOL_GPL(register_syscore_ops);
39526 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
39527 void unregister_syscore_ops(struct syscore_ops *ops)
39528 {
39529 mutex_lock(&syscore_ops_lock);
39530 - list_del(&ops->node);
39531 + pax_list_del((struct list_head *)&ops->node);
39532 mutex_unlock(&syscore_ops_lock);
39533 }
39534 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
39535 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
39536 index 4595c22..d4f6c54 100644
39537 --- a/drivers/block/cciss.c
39538 +++ b/drivers/block/cciss.c
39539 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
39540 while (!list_empty(&h->reqQ)) {
39541 c = list_entry(h->reqQ.next, CommandList_struct, list);
39542 /* can't do anything if fifo is full */
39543 - if ((h->access.fifo_full(h))) {
39544 + if ((h->access->fifo_full(h))) {
39545 dev_warn(&h->pdev->dev, "fifo full\n");
39546 break;
39547 }
39548 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
39549 h->Qdepth--;
39550
39551 /* Tell the controller execute command */
39552 - h->access.submit_command(h, c);
39553 + h->access->submit_command(h, c);
39554
39555 /* Put job onto the completed Q */
39556 addQ(&h->cmpQ, c);
39557 @@ -3447,17 +3447,17 @@ startio:
39558
39559 static inline unsigned long get_next_completion(ctlr_info_t *h)
39560 {
39561 - return h->access.command_completed(h);
39562 + return h->access->command_completed(h);
39563 }
39564
39565 static inline int interrupt_pending(ctlr_info_t *h)
39566 {
39567 - return h->access.intr_pending(h);
39568 + return h->access->intr_pending(h);
39569 }
39570
39571 static inline long interrupt_not_for_us(ctlr_info_t *h)
39572 {
39573 - return ((h->access.intr_pending(h) == 0) ||
39574 + return ((h->access->intr_pending(h) == 0) ||
39575 (h->interrupts_enabled == 0));
39576 }
39577
39578 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
39579 u32 a;
39580
39581 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
39582 - return h->access.command_completed(h);
39583 + return h->access->command_completed(h);
39584
39585 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
39586 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
39587 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
39588 trans_support & CFGTBL_Trans_use_short_tags);
39589
39590 /* Change the access methods to the performant access methods */
39591 - h->access = SA5_performant_access;
39592 + h->access = &SA5_performant_access;
39593 h->transMethod = CFGTBL_Trans_Performant;
39594
39595 return;
39596 @@ -4321,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
39597 if (prod_index < 0)
39598 return -ENODEV;
39599 h->product_name = products[prod_index].product_name;
39600 - h->access = *(products[prod_index].access);
39601 + h->access = products[prod_index].access;
39602
39603 if (cciss_board_disabled(h)) {
39604 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
39605 @@ -5053,7 +5053,7 @@ reinit_after_soft_reset:
39606 }
39607
39608 /* make sure the board interrupts are off */
39609 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39610 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39611 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
39612 if (rc)
39613 goto clean2;
39614 @@ -5103,7 +5103,7 @@ reinit_after_soft_reset:
39615 * fake ones to scoop up any residual completions.
39616 */
39617 spin_lock_irqsave(&h->lock, flags);
39618 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39619 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39620 spin_unlock_irqrestore(&h->lock, flags);
39621 free_irq(h->intr[h->intr_mode], h);
39622 rc = cciss_request_irq(h, cciss_msix_discard_completions,
39623 @@ -5123,9 +5123,9 @@ reinit_after_soft_reset:
39624 dev_info(&h->pdev->dev, "Board READY.\n");
39625 dev_info(&h->pdev->dev,
39626 "Waiting for stale completions to drain.\n");
39627 - h->access.set_intr_mask(h, CCISS_INTR_ON);
39628 + h->access->set_intr_mask(h, CCISS_INTR_ON);
39629 msleep(10000);
39630 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39631 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39632
39633 rc = controller_reset_failed(h->cfgtable);
39634 if (rc)
39635 @@ -5148,7 +5148,7 @@ reinit_after_soft_reset:
39636 cciss_scsi_setup(h);
39637
39638 /* Turn the interrupts on so we can service requests */
39639 - h->access.set_intr_mask(h, CCISS_INTR_ON);
39640 + h->access->set_intr_mask(h, CCISS_INTR_ON);
39641
39642 /* Get the firmware version */
39643 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
39644 @@ -5220,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
39645 kfree(flush_buf);
39646 if (return_code != IO_OK)
39647 dev_warn(&h->pdev->dev, "Error flushing cache\n");
39648 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
39649 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
39650 free_irq(h->intr[h->intr_mode], h);
39651 }
39652
39653 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
39654 index 7fda30e..2f27946 100644
39655 --- a/drivers/block/cciss.h
39656 +++ b/drivers/block/cciss.h
39657 @@ -101,7 +101,7 @@ struct ctlr_info
39658 /* information about each logical volume */
39659 drive_info_struct *drv[CISS_MAX_LUN];
39660
39661 - struct access_method access;
39662 + struct access_method *access;
39663
39664 /* queue and queue Info */
39665 struct list_head reqQ;
39666 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
39667 }
39668
39669 static struct access_method SA5_access = {
39670 - SA5_submit_command,
39671 - SA5_intr_mask,
39672 - SA5_fifo_full,
39673 - SA5_intr_pending,
39674 - SA5_completed,
39675 + .submit_command = SA5_submit_command,
39676 + .set_intr_mask = SA5_intr_mask,
39677 + .fifo_full = SA5_fifo_full,
39678 + .intr_pending = SA5_intr_pending,
39679 + .command_completed = SA5_completed,
39680 };
39681
39682 static struct access_method SA5B_access = {
39683 - SA5_submit_command,
39684 - SA5B_intr_mask,
39685 - SA5_fifo_full,
39686 - SA5B_intr_pending,
39687 - SA5_completed,
39688 + .submit_command = SA5_submit_command,
39689 + .set_intr_mask = SA5B_intr_mask,
39690 + .fifo_full = SA5_fifo_full,
39691 + .intr_pending = SA5B_intr_pending,
39692 + .command_completed = SA5_completed,
39693 };
39694
39695 static struct access_method SA5_performant_access = {
39696 - SA5_submit_command,
39697 - SA5_performant_intr_mask,
39698 - SA5_fifo_full,
39699 - SA5_performant_intr_pending,
39700 - SA5_performant_completed,
39701 + .submit_command = SA5_submit_command,
39702 + .set_intr_mask = SA5_performant_intr_mask,
39703 + .fifo_full = SA5_fifo_full,
39704 + .intr_pending = SA5_performant_intr_pending,
39705 + .command_completed = SA5_performant_completed,
39706 };
39707
39708 struct board_type {
39709 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
39710 index 2b94403..fd6ad1f 100644
39711 --- a/drivers/block/cpqarray.c
39712 +++ b/drivers/block/cpqarray.c
39713 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39714 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
39715 goto Enomem4;
39716 }
39717 - hba[i]->access.set_intr_mask(hba[i], 0);
39718 + hba[i]->access->set_intr_mask(hba[i], 0);
39719 if (request_irq(hba[i]->intr, do_ida_intr,
39720 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
39721 {
39722 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
39723 add_timer(&hba[i]->timer);
39724
39725 /* Enable IRQ now that spinlock and rate limit timer are set up */
39726 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39727 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
39728
39729 for(j=0; j<NWD; j++) {
39730 struct gendisk *disk = ida_gendisk[i][j];
39731 @@ -694,7 +694,7 @@ DBGINFO(
39732 for(i=0; i<NR_PRODUCTS; i++) {
39733 if (board_id == products[i].board_id) {
39734 c->product_name = products[i].product_name;
39735 - c->access = *(products[i].access);
39736 + c->access = products[i].access;
39737 break;
39738 }
39739 }
39740 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
39741 hba[ctlr]->intr = intr;
39742 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
39743 hba[ctlr]->product_name = products[j].product_name;
39744 - hba[ctlr]->access = *(products[j].access);
39745 + hba[ctlr]->access = products[j].access;
39746 hba[ctlr]->ctlr = ctlr;
39747 hba[ctlr]->board_id = board_id;
39748 hba[ctlr]->pci_dev = NULL; /* not PCI */
39749 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
39750
39751 while((c = h->reqQ) != NULL) {
39752 /* Can't do anything if we're busy */
39753 - if (h->access.fifo_full(h) == 0)
39754 + if (h->access->fifo_full(h) == 0)
39755 return;
39756
39757 /* Get the first entry from the request Q */
39758 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
39759 h->Qdepth--;
39760
39761 /* Tell the controller to do our bidding */
39762 - h->access.submit_command(h, c);
39763 + h->access->submit_command(h, c);
39764
39765 /* Get onto the completion Q */
39766 addQ(&h->cmpQ, c);
39767 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39768 unsigned long flags;
39769 __u32 a,a1;
39770
39771 - istat = h->access.intr_pending(h);
39772 + istat = h->access->intr_pending(h);
39773 /* Is this interrupt for us? */
39774 if (istat == 0)
39775 return IRQ_NONE;
39776 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
39777 */
39778 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
39779 if (istat & FIFO_NOT_EMPTY) {
39780 - while((a = h->access.command_completed(h))) {
39781 + while((a = h->access->command_completed(h))) {
39782 a1 = a; a &= ~3;
39783 if ((c = h->cmpQ) == NULL)
39784 {
39785 @@ -1448,11 +1448,11 @@ static int sendcmd(
39786 /*
39787 * Disable interrupt
39788 */
39789 - info_p->access.set_intr_mask(info_p, 0);
39790 + info_p->access->set_intr_mask(info_p, 0);
39791 /* Make sure there is room in the command FIFO */
39792 /* Actually it should be completely empty at this time. */
39793 for (i = 200000; i > 0; i--) {
39794 - temp = info_p->access.fifo_full(info_p);
39795 + temp = info_p->access->fifo_full(info_p);
39796 if (temp != 0) {
39797 break;
39798 }
39799 @@ -1465,7 +1465,7 @@ DBG(
39800 /*
39801 * Send the cmd
39802 */
39803 - info_p->access.submit_command(info_p, c);
39804 + info_p->access->submit_command(info_p, c);
39805 complete = pollcomplete(ctlr);
39806
39807 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
39808 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
39809 * we check the new geometry. Then turn interrupts back on when
39810 * we're done.
39811 */
39812 - host->access.set_intr_mask(host, 0);
39813 + host->access->set_intr_mask(host, 0);
39814 getgeometry(ctlr);
39815 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
39816 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
39817
39818 for(i=0; i<NWD; i++) {
39819 struct gendisk *disk = ida_gendisk[ctlr][i];
39820 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
39821 /* Wait (up to 2 seconds) for a command to complete */
39822
39823 for (i = 200000; i > 0; i--) {
39824 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
39825 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
39826 if (done == 0) {
39827 udelay(10); /* a short fixed delay */
39828 } else
39829 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
39830 index be73e9d..7fbf140 100644
39831 --- a/drivers/block/cpqarray.h
39832 +++ b/drivers/block/cpqarray.h
39833 @@ -99,7 +99,7 @@ struct ctlr_info {
39834 drv_info_t drv[NWD];
39835 struct proc_dir_entry *proc;
39836
39837 - struct access_method access;
39838 + struct access_method *access;
39839
39840 cmdlist_t *reqQ;
39841 cmdlist_t *cmpQ;
39842 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
39843 index a76ceb3..3c1a9fd 100644
39844 --- a/drivers/block/drbd/drbd_int.h
39845 +++ b/drivers/block/drbd/drbd_int.h
39846 @@ -331,7 +331,7 @@ struct drbd_epoch {
39847 struct drbd_connection *connection;
39848 struct list_head list;
39849 unsigned int barrier_nr;
39850 - atomic_t epoch_size; /* increased on every request added. */
39851 + atomic_unchecked_t epoch_size; /* increased on every request added. */
39852 atomic_t active; /* increased on every req. added, and dec on every finished. */
39853 unsigned long flags;
39854 };
39855 @@ -797,7 +797,7 @@ struct drbd_device {
39856 unsigned int al_tr_number;
39857 int al_tr_cycle;
39858 wait_queue_head_t seq_wait;
39859 - atomic_t packet_seq;
39860 + atomic_unchecked_t packet_seq;
39861 unsigned int peer_seq;
39862 spinlock_t peer_seq_lock;
39863 unsigned int minor;
39864 @@ -1407,7 +1407,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
39865 char __user *uoptval;
39866 int err;
39867
39868 - uoptval = (char __user __force *)optval;
39869 + uoptval = (char __force_user *)optval;
39870
39871 set_fs(KERNEL_DS);
39872 if (level == SOL_SOCKET)
39873 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
39874 index 89c497c..9c736ae 100644
39875 --- a/drivers/block/drbd/drbd_interval.c
39876 +++ b/drivers/block/drbd/drbd_interval.c
39877 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39878 }
39879
39880 static const struct rb_augment_callbacks augment_callbacks = {
39881 - augment_propagate,
39882 - augment_copy,
39883 - augment_rotate,
39884 + .propagate = augment_propagate,
39885 + .copy = augment_copy,
39886 + .rotate = augment_rotate,
39887 };
39888
39889 /**
39890 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39891 index 960645c..6c2724a 100644
39892 --- a/drivers/block/drbd/drbd_main.c
39893 +++ b/drivers/block/drbd/drbd_main.c
39894 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39895 p->sector = sector;
39896 p->block_id = block_id;
39897 p->blksize = blksize;
39898 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39899 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39900 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39901 }
39902
39903 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39904 return -EIO;
39905 p->sector = cpu_to_be64(req->i.sector);
39906 p->block_id = (unsigned long)req;
39907 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39908 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39909 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39910 if (device->state.conn >= C_SYNC_SOURCE &&
39911 device->state.conn <= C_PAUSED_SYNC_T)
39912 @@ -2670,8 +2670,8 @@ void drbd_destroy_connection(struct kref *kref)
39913 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39914 struct drbd_resource *resource = connection->resource;
39915
39916 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39917 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39918 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39919 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39920 kfree(connection->current_epoch);
39921
39922 idr_destroy(&connection->peer_devices);
39923 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39924 index 3f2e167..d3170e4 100644
39925 --- a/drivers/block/drbd/drbd_nl.c
39926 +++ b/drivers/block/drbd/drbd_nl.c
39927 @@ -3616,7 +3616,7 @@ finish:
39928
39929 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39930 {
39931 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39932 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39933 struct sk_buff *msg;
39934 struct drbd_genlmsghdr *d_out;
39935 unsigned seq;
39936 @@ -3629,7 +3629,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39937 return;
39938 }
39939
39940 - seq = atomic_inc_return(&drbd_genl_seq);
39941 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39942 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39943 if (!msg)
39944 goto failed;
39945 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39946 index 5b17ec8..6c21e6b 100644
39947 --- a/drivers/block/drbd/drbd_receiver.c
39948 +++ b/drivers/block/drbd/drbd_receiver.c
39949 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39950 struct drbd_device *device = peer_device->device;
39951 int err;
39952
39953 - atomic_set(&device->packet_seq, 0);
39954 + atomic_set_unchecked(&device->packet_seq, 0);
39955 device->peer_seq = 0;
39956
39957 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39958 @@ -1199,7 +1199,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39959 do {
39960 next_epoch = NULL;
39961
39962 - epoch_size = atomic_read(&epoch->epoch_size);
39963 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39964
39965 switch (ev & ~EV_CLEANUP) {
39966 case EV_PUT:
39967 @@ -1239,7 +1239,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39968 rv = FE_DESTROYED;
39969 } else {
39970 epoch->flags = 0;
39971 - atomic_set(&epoch->epoch_size, 0);
39972 + atomic_set_unchecked(&epoch->epoch_size, 0);
39973 /* atomic_set(&epoch->active, 0); is already zero */
39974 if (rv == FE_STILL_LIVE)
39975 rv = FE_RECYCLED;
39976 @@ -1490,7 +1490,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39977 conn_wait_active_ee_empty(connection);
39978 drbd_flush(connection);
39979
39980 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39981 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39982 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39983 if (epoch)
39984 break;
39985 @@ -1503,11 +1503,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39986 }
39987
39988 epoch->flags = 0;
39989 - atomic_set(&epoch->epoch_size, 0);
39990 + atomic_set_unchecked(&epoch->epoch_size, 0);
39991 atomic_set(&epoch->active, 0);
39992
39993 spin_lock(&connection->epoch_lock);
39994 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39995 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39996 list_add(&epoch->list, &connection->current_epoch->list);
39997 connection->current_epoch = epoch;
39998 connection->epochs++;
39999 @@ -2224,7 +2224,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
40000
40001 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
40002 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
40003 - atomic_inc(&connection->current_epoch->epoch_size);
40004 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
40005 err2 = drbd_drain_block(peer_device, pi->size);
40006 if (!err)
40007 err = err2;
40008 @@ -2266,7 +2266,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
40009
40010 spin_lock(&connection->epoch_lock);
40011 peer_req->epoch = connection->current_epoch;
40012 - atomic_inc(&peer_req->epoch->epoch_size);
40013 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
40014 atomic_inc(&peer_req->epoch->active);
40015 spin_unlock(&connection->epoch_lock);
40016
40017 @@ -4461,7 +4461,7 @@ struct data_cmd {
40018 int expect_payload;
40019 size_t pkt_size;
40020 int (*fn)(struct drbd_connection *, struct packet_info *);
40021 -};
40022 +} __do_const;
40023
40024 static struct data_cmd drbd_cmd_handler[] = {
40025 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
40026 @@ -4572,7 +4572,7 @@ static void conn_disconnect(struct drbd_connection *connection)
40027 if (!list_empty(&connection->current_epoch->list))
40028 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
40029 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
40030 - atomic_set(&connection->current_epoch->epoch_size, 0);
40031 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
40032 connection->send.seen_any_write_yet = false;
40033
40034 drbd_info(connection, "Connection closed\n");
40035 @@ -5364,7 +5364,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
40036 struct asender_cmd {
40037 size_t pkt_size;
40038 int (*fn)(struct drbd_connection *connection, struct packet_info *);
40039 -};
40040 +} __do_const;
40041
40042 static struct asender_cmd asender_tbl[] = {
40043 [P_PING] = { 0, got_Ping },
40044 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
40045 index 6cb1beb..bf490f7 100644
40046 --- a/drivers/block/loop.c
40047 +++ b/drivers/block/loop.c
40048 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
40049
40050 file_start_write(file);
40051 set_fs(get_ds());
40052 - bw = file->f_op->write(file, buf, len, &pos);
40053 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
40054 set_fs(old_fs);
40055 file_end_write(file);
40056 if (likely(bw == len))
40057 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
40058 index 02351e2..a9ea617 100644
40059 --- a/drivers/block/nvme-core.c
40060 +++ b/drivers/block/nvme-core.c
40061 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
40062 static struct task_struct *nvme_thread;
40063 static struct workqueue_struct *nvme_workq;
40064 static wait_queue_head_t nvme_kthread_wait;
40065 -static struct notifier_block nvme_nb;
40066
40067 static void nvme_reset_failed_dev(struct work_struct *ws);
40068
40069 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
40070 .err_handler = &nvme_err_handler,
40071 };
40072
40073 +static struct notifier_block nvme_nb = {
40074 + .notifier_call = &nvme_cpu_notify,
40075 +};
40076 +
40077 static int __init nvme_init(void)
40078 {
40079 int result;
40080 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
40081 else if (result > 0)
40082 nvme_major = result;
40083
40084 - nvme_nb.notifier_call = &nvme_cpu_notify;
40085 result = register_hotcpu_notifier(&nvme_nb);
40086 if (result)
40087 goto unregister_blkdev;
40088 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
40089 index 758ac44..58087fd 100644
40090 --- a/drivers/block/pktcdvd.c
40091 +++ b/drivers/block/pktcdvd.c
40092 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
40093
40094 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
40095 {
40096 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
40097 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
40098 }
40099
40100 /*
40101 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
40102 return -EROFS;
40103 }
40104 pd->settings.fp = ti.fp;
40105 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
40106 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
40107
40108 if (ti.nwa_v) {
40109 pd->nwa = be32_to_cpu(ti.next_writable);
40110 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
40111 index e5565fb..71be10b4 100644
40112 --- a/drivers/block/smart1,2.h
40113 +++ b/drivers/block/smart1,2.h
40114 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
40115 }
40116
40117 static struct access_method smart4_access = {
40118 - smart4_submit_command,
40119 - smart4_intr_mask,
40120 - smart4_fifo_full,
40121 - smart4_intr_pending,
40122 - smart4_completed,
40123 + .submit_command = smart4_submit_command,
40124 + .set_intr_mask = smart4_intr_mask,
40125 + .fifo_full = smart4_fifo_full,
40126 + .intr_pending = smart4_intr_pending,
40127 + .command_completed = smart4_completed,
40128 };
40129
40130 /*
40131 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
40132 }
40133
40134 static struct access_method smart2_access = {
40135 - smart2_submit_command,
40136 - smart2_intr_mask,
40137 - smart2_fifo_full,
40138 - smart2_intr_pending,
40139 - smart2_completed,
40140 + .submit_command = smart2_submit_command,
40141 + .set_intr_mask = smart2_intr_mask,
40142 + .fifo_full = smart2_fifo_full,
40143 + .intr_pending = smart2_intr_pending,
40144 + .command_completed = smart2_completed,
40145 };
40146
40147 /*
40148 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
40149 }
40150
40151 static struct access_method smart2e_access = {
40152 - smart2e_submit_command,
40153 - smart2e_intr_mask,
40154 - smart2e_fifo_full,
40155 - smart2e_intr_pending,
40156 - smart2e_completed,
40157 + .submit_command = smart2e_submit_command,
40158 + .set_intr_mask = smart2e_intr_mask,
40159 + .fifo_full = smart2e_fifo_full,
40160 + .intr_pending = smart2e_intr_pending,
40161 + .command_completed = smart2e_completed,
40162 };
40163
40164 /*
40165 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
40166 }
40167
40168 static struct access_method smart1_access = {
40169 - smart1_submit_command,
40170 - smart1_intr_mask,
40171 - smart1_fifo_full,
40172 - smart1_intr_pending,
40173 - smart1_completed,
40174 + .submit_command = smart1_submit_command,
40175 + .set_intr_mask = smart1_intr_mask,
40176 + .fifo_full = smart1_fifo_full,
40177 + .intr_pending = smart1_intr_pending,
40178 + .command_completed = smart1_completed,
40179 };
40180 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
40181 index f038dba..bb74c08 100644
40182 --- a/drivers/bluetooth/btwilink.c
40183 +++ b/drivers/bluetooth/btwilink.c
40184 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
40185
40186 static int bt_ti_probe(struct platform_device *pdev)
40187 {
40188 - static struct ti_st *hst;
40189 + struct ti_st *hst;
40190 struct hci_dev *hdev;
40191 int err;
40192
40193 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
40194 index 898b84b..86f74b9 100644
40195 --- a/drivers/cdrom/cdrom.c
40196 +++ b/drivers/cdrom/cdrom.c
40197 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
40198 ENSURE(reset, CDC_RESET);
40199 ENSURE(generic_packet, CDC_GENERIC_PACKET);
40200 cdi->mc_flags = 0;
40201 - cdo->n_minors = 0;
40202 cdi->options = CDO_USE_FFLAGS;
40203
40204 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
40205 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
40206 else
40207 cdi->cdda_method = CDDA_OLD;
40208
40209 - if (!cdo->generic_packet)
40210 - cdo->generic_packet = cdrom_dummy_generic_packet;
40211 + if (!cdo->generic_packet) {
40212 + pax_open_kernel();
40213 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
40214 + pax_close_kernel();
40215 + }
40216
40217 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
40218 mutex_lock(&cdrom_mutex);
40219 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
40220 if (cdi->exit)
40221 cdi->exit(cdi);
40222
40223 - cdi->ops->n_minors--;
40224 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
40225 }
40226
40227 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
40228 */
40229 nr = nframes;
40230 do {
40231 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40232 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
40233 if (cgc.buffer)
40234 break;
40235
40236 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
40237 struct cdrom_device_info *cdi;
40238 int ret;
40239
40240 - ret = scnprintf(info + *pos, max_size - *pos, header);
40241 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
40242 if (!ret)
40243 return 1;
40244
40245 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
40246 index 584bc31..e64a12c 100644
40247 --- a/drivers/cdrom/gdrom.c
40248 +++ b/drivers/cdrom/gdrom.c
40249 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
40250 .audio_ioctl = gdrom_audio_ioctl,
40251 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
40252 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
40253 - .n_minors = 1,
40254 };
40255
40256 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
40257 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
40258 index 6e9f74a..50c7cea 100644
40259 --- a/drivers/char/Kconfig
40260 +++ b/drivers/char/Kconfig
40261 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
40262
40263 config DEVKMEM
40264 bool "/dev/kmem virtual device support"
40265 - default y
40266 + default n
40267 + depends on !GRKERNSEC_KMEM
40268 help
40269 Say Y here if you want to support the /dev/kmem device. The
40270 /dev/kmem device is rarely used, but can be used for certain
40271 @@ -577,6 +578,7 @@ config DEVPORT
40272 bool
40273 depends on !M68K
40274 depends on ISA || PCI
40275 + depends on !GRKERNSEC_KMEM
40276 default y
40277
40278 source "drivers/s390/char/Kconfig"
40279 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
40280 index a48e05b..6bac831 100644
40281 --- a/drivers/char/agp/compat_ioctl.c
40282 +++ b/drivers/char/agp/compat_ioctl.c
40283 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
40284 return -ENOMEM;
40285 }
40286
40287 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
40288 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
40289 sizeof(*usegment) * ureserve.seg_count)) {
40290 kfree(usegment);
40291 kfree(ksegment);
40292 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
40293 index b297033..fa217ca 100644
40294 --- a/drivers/char/agp/frontend.c
40295 +++ b/drivers/char/agp/frontend.c
40296 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40297 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
40298 return -EFAULT;
40299
40300 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
40301 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
40302 return -EFAULT;
40303
40304 client = agp_find_client_by_pid(reserve.pid);
40305 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
40306 if (segment == NULL)
40307 return -ENOMEM;
40308
40309 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
40310 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
40311 sizeof(struct agp_segment) * reserve.seg_count)) {
40312 kfree(segment);
40313 return -EFAULT;
40314 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
40315 index 4f94375..413694e 100644
40316 --- a/drivers/char/genrtc.c
40317 +++ b/drivers/char/genrtc.c
40318 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
40319 switch (cmd) {
40320
40321 case RTC_PLL_GET:
40322 + memset(&pll, 0, sizeof(pll));
40323 if (get_rtc_pll(&pll))
40324 return -EINVAL;
40325 else
40326 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
40327 index d5d4cd8..22d561d 100644
40328 --- a/drivers/char/hpet.c
40329 +++ b/drivers/char/hpet.c
40330 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
40331 }
40332
40333 static int
40334 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
40335 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
40336 struct hpet_info *info)
40337 {
40338 struct hpet_timer __iomem *timer;
40339 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
40340 index 86fe45c..c0ea948 100644
40341 --- a/drivers/char/hw_random/intel-rng.c
40342 +++ b/drivers/char/hw_random/intel-rng.c
40343 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
40344
40345 if (no_fwh_detect)
40346 return -ENODEV;
40347 - printk(warning);
40348 + printk("%s", warning);
40349 return -EBUSY;
40350 }
40351
40352 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
40353 index e6db938..835e3a2 100644
40354 --- a/drivers/char/ipmi/ipmi_msghandler.c
40355 +++ b/drivers/char/ipmi/ipmi_msghandler.c
40356 @@ -438,7 +438,7 @@ struct ipmi_smi {
40357 struct proc_dir_entry *proc_dir;
40358 char proc_dir_name[10];
40359
40360 - atomic_t stats[IPMI_NUM_STATS];
40361 + atomic_unchecked_t stats[IPMI_NUM_STATS];
40362
40363 /*
40364 * run_to_completion duplicate of smb_info, smi_info
40365 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
40366 static DEFINE_MUTEX(smi_watchers_mutex);
40367
40368 #define ipmi_inc_stat(intf, stat) \
40369 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
40370 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
40371 #define ipmi_get_stat(intf, stat) \
40372 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
40373 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
40374
40375 static int is_lan_addr(struct ipmi_addr *addr)
40376 {
40377 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
40378 INIT_LIST_HEAD(&intf->cmd_rcvrs);
40379 init_waitqueue_head(&intf->waitq);
40380 for (i = 0; i < IPMI_NUM_STATS; i++)
40381 - atomic_set(&intf->stats[i], 0);
40382 + atomic_set_unchecked(&intf->stats[i], 0);
40383
40384 intf->proc_dir = NULL;
40385
40386 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
40387 index 5d66568..c9d93c3 100644
40388 --- a/drivers/char/ipmi/ipmi_si_intf.c
40389 +++ b/drivers/char/ipmi/ipmi_si_intf.c
40390 @@ -285,7 +285,7 @@ struct smi_info {
40391 unsigned char slave_addr;
40392
40393 /* Counters and things for the proc filesystem. */
40394 - atomic_t stats[SI_NUM_STATS];
40395 + atomic_unchecked_t stats[SI_NUM_STATS];
40396
40397 struct task_struct *thread;
40398
40399 @@ -294,9 +294,9 @@ struct smi_info {
40400 };
40401
40402 #define smi_inc_stat(smi, stat) \
40403 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
40404 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
40405 #define smi_get_stat(smi, stat) \
40406 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
40407 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
40408
40409 #define SI_MAX_PARMS 4
40410
40411 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
40412 atomic_set(&new_smi->req_events, 0);
40413 new_smi->run_to_completion = false;
40414 for (i = 0; i < SI_NUM_STATS; i++)
40415 - atomic_set(&new_smi->stats[i], 0);
40416 + atomic_set_unchecked(&new_smi->stats[i], 0);
40417
40418 new_smi->interrupt_disabled = true;
40419 atomic_set(&new_smi->stop_operation, 0);
40420 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
40421 index 917403f..dddd899 100644
40422 --- a/drivers/char/mem.c
40423 +++ b/drivers/char/mem.c
40424 @@ -18,6 +18,7 @@
40425 #include <linux/raw.h>
40426 #include <linux/tty.h>
40427 #include <linux/capability.h>
40428 +#include <linux/security.h>
40429 #include <linux/ptrace.h>
40430 #include <linux/device.h>
40431 #include <linux/highmem.h>
40432 @@ -36,6 +37,10 @@
40433
40434 #define DEVPORT_MINOR 4
40435
40436 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40437 +extern const struct file_operations grsec_fops;
40438 +#endif
40439 +
40440 static inline unsigned long size_inside_page(unsigned long start,
40441 unsigned long size)
40442 {
40443 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40444
40445 while (cursor < to) {
40446 if (!devmem_is_allowed(pfn)) {
40447 +#ifdef CONFIG_GRKERNSEC_KMEM
40448 + gr_handle_mem_readwrite(from, to);
40449 +#else
40450 printk(KERN_INFO
40451 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
40452 current->comm, from, to);
40453 +#endif
40454 return 0;
40455 }
40456 cursor += PAGE_SIZE;
40457 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40458 }
40459 return 1;
40460 }
40461 +#elif defined(CONFIG_GRKERNSEC_KMEM)
40462 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40463 +{
40464 + return 0;
40465 +}
40466 #else
40467 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
40468 {
40469 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40470
40471 while (count > 0) {
40472 unsigned long remaining;
40473 + char *temp;
40474
40475 sz = size_inside_page(p, count);
40476
40477 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
40478 if (!ptr)
40479 return -EFAULT;
40480
40481 - remaining = copy_to_user(buf, ptr, sz);
40482 +#ifdef CONFIG_PAX_USERCOPY
40483 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40484 + if (!temp) {
40485 + unxlate_dev_mem_ptr(p, ptr);
40486 + return -ENOMEM;
40487 + }
40488 + memcpy(temp, ptr, sz);
40489 +#else
40490 + temp = ptr;
40491 +#endif
40492 +
40493 + remaining = copy_to_user(buf, temp, sz);
40494 +
40495 +#ifdef CONFIG_PAX_USERCOPY
40496 + kfree(temp);
40497 +#endif
40498 +
40499 unxlate_dev_mem_ptr(p, ptr);
40500 if (remaining)
40501 return -EFAULT;
40502 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40503 size_t count, loff_t *ppos)
40504 {
40505 unsigned long p = *ppos;
40506 - ssize_t low_count, read, sz;
40507 + ssize_t low_count, read, sz, err = 0;
40508 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
40509 - int err = 0;
40510
40511 read = 0;
40512 if (p < (unsigned long) high_memory) {
40513 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40514 }
40515 #endif
40516 while (low_count > 0) {
40517 + char *temp;
40518 +
40519 sz = size_inside_page(p, low_count);
40520
40521 /*
40522 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
40523 */
40524 kbuf = xlate_dev_kmem_ptr((char *)p);
40525
40526 - if (copy_to_user(buf, kbuf, sz))
40527 +#ifdef CONFIG_PAX_USERCOPY
40528 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
40529 + if (!temp)
40530 + return -ENOMEM;
40531 + memcpy(temp, kbuf, sz);
40532 +#else
40533 + temp = kbuf;
40534 +#endif
40535 +
40536 + err = copy_to_user(buf, temp, sz);
40537 +
40538 +#ifdef CONFIG_PAX_USERCOPY
40539 + kfree(temp);
40540 +#endif
40541 +
40542 + if (err)
40543 return -EFAULT;
40544 buf += sz;
40545 p += sz;
40546 @@ -827,6 +874,9 @@ static const struct memdev {
40547 #ifdef CONFIG_PRINTK
40548 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
40549 #endif
40550 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
40551 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
40552 +#endif
40553 };
40554
40555 static int memory_open(struct inode *inode, struct file *filp)
40556 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
40557 continue;
40558
40559 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
40560 - NULL, devlist[minor].name);
40561 + NULL, "%s", devlist[minor].name);
40562 }
40563
40564 return tty_init();
40565 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
40566 index 9df78e2..01ba9ae 100644
40567 --- a/drivers/char/nvram.c
40568 +++ b/drivers/char/nvram.c
40569 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
40570
40571 spin_unlock_irq(&rtc_lock);
40572
40573 - if (copy_to_user(buf, contents, tmp - contents))
40574 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
40575 return -EFAULT;
40576
40577 *ppos = i;
40578 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
40579 index 8320abd..ec48108 100644
40580 --- a/drivers/char/pcmcia/synclink_cs.c
40581 +++ b/drivers/char/pcmcia/synclink_cs.c
40582 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40583
40584 if (debug_level >= DEBUG_LEVEL_INFO)
40585 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
40586 - __FILE__, __LINE__, info->device_name, port->count);
40587 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
40588
40589 - WARN_ON(!port->count);
40590 + WARN_ON(!atomic_read(&port->count));
40591
40592 if (tty_port_close_start(port, tty, filp) == 0)
40593 goto cleanup;
40594 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
40595 cleanup:
40596 if (debug_level >= DEBUG_LEVEL_INFO)
40597 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
40598 - tty->driver->name, port->count);
40599 + tty->driver->name, atomic_read(&port->count));
40600 }
40601
40602 /* Wait until the transmitter is empty.
40603 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40604
40605 if (debug_level >= DEBUG_LEVEL_INFO)
40606 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
40607 - __FILE__, __LINE__, tty->driver->name, port->count);
40608 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
40609
40610 /* If port is closing, signal caller to try again */
40611 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
40612 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
40613 goto cleanup;
40614 }
40615 spin_lock(&port->lock);
40616 - port->count++;
40617 + atomic_inc(&port->count);
40618 spin_unlock(&port->lock);
40619 spin_unlock_irqrestore(&info->netlock, flags);
40620
40621 - if (port->count == 1) {
40622 + if (atomic_read(&port->count) == 1) {
40623 /* 1st open on this device, init hardware */
40624 retval = startup(info, tty);
40625 if (retval < 0)
40626 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40627 unsigned short new_crctype;
40628
40629 /* return error if TTY interface open */
40630 - if (info->port.count)
40631 + if (atomic_read(&info->port.count))
40632 return -EBUSY;
40633
40634 switch (encoding)
40635 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
40636
40637 /* arbitrate between network and tty opens */
40638 spin_lock_irqsave(&info->netlock, flags);
40639 - if (info->port.count != 0 || info->netcount != 0) {
40640 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40641 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40642 spin_unlock_irqrestore(&info->netlock, flags);
40643 return -EBUSY;
40644 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40645 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
40646
40647 /* return error if TTY interface open */
40648 - if (info->port.count)
40649 + if (atomic_read(&info->port.count))
40650 return -EBUSY;
40651
40652 if (cmd != SIOCWANDEV)
40653 diff --git a/drivers/char/random.c b/drivers/char/random.c
40654 index 71529e1..822b036 100644
40655 --- a/drivers/char/random.c
40656 +++ b/drivers/char/random.c
40657 @@ -284,9 +284,6 @@
40658 /*
40659 * To allow fractional bits to be tracked, the entropy_count field is
40660 * denominated in units of 1/8th bits.
40661 - *
40662 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
40663 - * credit_entropy_bits() needs to be 64 bits wide.
40664 */
40665 #define ENTROPY_SHIFT 3
40666 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
40667 @@ -433,9 +430,9 @@ struct entropy_store {
40668 };
40669
40670 static void push_to_pool(struct work_struct *work);
40671 -static __u32 input_pool_data[INPUT_POOL_WORDS];
40672 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
40673 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
40674 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
40675 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40676 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
40677
40678 static struct entropy_store input_pool = {
40679 .poolinfo = &poolinfo_table[0],
40680 @@ -524,8 +521,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
40681 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
40682 }
40683
40684 - ACCESS_ONCE(r->input_rotate) = input_rotate;
40685 - ACCESS_ONCE(r->add_ptr) = i;
40686 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
40687 + ACCESS_ONCE_RW(r->add_ptr) = i;
40688 smp_wmb();
40689
40690 if (out)
40691 @@ -632,7 +629,7 @@ retry:
40692 /* The +2 corresponds to the /4 in the denominator */
40693
40694 do {
40695 - unsigned int anfrac = min(pnfrac, pool_size/2);
40696 + u64 anfrac = min(pnfrac, pool_size/2);
40697 unsigned int add =
40698 ((pool_size - entropy_count)*anfrac*3) >> s;
40699
40700 @@ -1177,7 +1174,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
40701
40702 extract_buf(r, tmp);
40703 i = min_t(int, nbytes, EXTRACT_SIZE);
40704 - if (copy_to_user(buf, tmp, i)) {
40705 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
40706 ret = -EFAULT;
40707 break;
40708 }
40709 @@ -1567,7 +1564,7 @@ static char sysctl_bootid[16];
40710 static int proc_do_uuid(struct ctl_table *table, int write,
40711 void __user *buffer, size_t *lenp, loff_t *ppos)
40712 {
40713 - struct ctl_table fake_table;
40714 + ctl_table_no_const fake_table;
40715 unsigned char buf[64], tmp_uuid[16], *uuid;
40716
40717 uuid = table->data;
40718 @@ -1597,7 +1594,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
40719 static int proc_do_entropy(struct ctl_table *table, int write,
40720 void __user *buffer, size_t *lenp, loff_t *ppos)
40721 {
40722 - struct ctl_table fake_table;
40723 + ctl_table_no_const fake_table;
40724 int entropy_count;
40725
40726 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
40727 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
40728 index 7cc1fe22..b602d6b 100644
40729 --- a/drivers/char/sonypi.c
40730 +++ b/drivers/char/sonypi.c
40731 @@ -54,6 +54,7 @@
40732
40733 #include <asm/uaccess.h>
40734 #include <asm/io.h>
40735 +#include <asm/local.h>
40736
40737 #include <linux/sonypi.h>
40738
40739 @@ -490,7 +491,7 @@ static struct sonypi_device {
40740 spinlock_t fifo_lock;
40741 wait_queue_head_t fifo_proc_list;
40742 struct fasync_struct *fifo_async;
40743 - int open_count;
40744 + local_t open_count;
40745 int model;
40746 struct input_dev *input_jog_dev;
40747 struct input_dev *input_key_dev;
40748 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
40749 static int sonypi_misc_release(struct inode *inode, struct file *file)
40750 {
40751 mutex_lock(&sonypi_device.lock);
40752 - sonypi_device.open_count--;
40753 + local_dec(&sonypi_device.open_count);
40754 mutex_unlock(&sonypi_device.lock);
40755 return 0;
40756 }
40757 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
40758 {
40759 mutex_lock(&sonypi_device.lock);
40760 /* Flush input queue on first open */
40761 - if (!sonypi_device.open_count)
40762 + if (!local_read(&sonypi_device.open_count))
40763 kfifo_reset(&sonypi_device.fifo);
40764 - sonypi_device.open_count++;
40765 + local_inc(&sonypi_device.open_count);
40766 mutex_unlock(&sonypi_device.lock);
40767
40768 return 0;
40769 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
40770 index 565a947..dcdc06e 100644
40771 --- a/drivers/char/tpm/tpm_acpi.c
40772 +++ b/drivers/char/tpm/tpm_acpi.c
40773 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
40774 virt = acpi_os_map_iomem(start, len);
40775 if (!virt) {
40776 kfree(log->bios_event_log);
40777 + log->bios_event_log = NULL;
40778 printk("%s: ERROR - Unable to map memory\n", __func__);
40779 return -EIO;
40780 }
40781
40782 - memcpy_fromio(log->bios_event_log, virt, len);
40783 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
40784
40785 acpi_os_unmap_iomem(virt, len);
40786 return 0;
40787 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
40788 index 59f7cb2..bac8b6d 100644
40789 --- a/drivers/char/tpm/tpm_eventlog.c
40790 +++ b/drivers/char/tpm/tpm_eventlog.c
40791 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
40792 event = addr;
40793
40794 if ((event->event_type == 0 && event->event_size == 0) ||
40795 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40796 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40797 return NULL;
40798
40799 return addr;
40800 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40801 return NULL;
40802
40803 if ((event->event_type == 0 && event->event_size == 0) ||
40804 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40805 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40806 return NULL;
40807
40808 (*pos)++;
40809 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40810 int i;
40811
40812 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40813 - seq_putc(m, data[i]);
40814 + if (!seq_putc(m, data[i]))
40815 + return -EFAULT;
40816
40817 return 0;
40818 }
40819 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40820 index 60aafb8..10c08e0 100644
40821 --- a/drivers/char/virtio_console.c
40822 +++ b/drivers/char/virtio_console.c
40823 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40824 if (to_user) {
40825 ssize_t ret;
40826
40827 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40828 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40829 if (ret)
40830 return -EFAULT;
40831 } else {
40832 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40833 if (!port_has_data(port) && !port->host_connected)
40834 return 0;
40835
40836 - return fill_readbuf(port, ubuf, count, true);
40837 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40838 }
40839
40840 static int wait_port_writable(struct port *port, bool nonblock)
40841 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40842 index 57a078e..c17cde8 100644
40843 --- a/drivers/clk/clk-composite.c
40844 +++ b/drivers/clk/clk-composite.c
40845 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40846 struct clk *clk;
40847 struct clk_init_data init;
40848 struct clk_composite *composite;
40849 - struct clk_ops *clk_composite_ops;
40850 + clk_ops_no_const *clk_composite_ops;
40851
40852 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40853 if (!composite) {
40854 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40855 index dd3a78c..386d49c 100644
40856 --- a/drivers/clk/socfpga/clk-gate.c
40857 +++ b/drivers/clk/socfpga/clk-gate.c
40858 @@ -22,6 +22,7 @@
40859 #include <linux/mfd/syscon.h>
40860 #include <linux/of.h>
40861 #include <linux/regmap.h>
40862 +#include <asm/pgtable.h>
40863
40864 #include "clk.h"
40865
40866 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40867 return 0;
40868 }
40869
40870 -static struct clk_ops gateclk_ops = {
40871 +static clk_ops_no_const gateclk_ops __read_only = {
40872 .prepare = socfpga_clk_prepare,
40873 .recalc_rate = socfpga_clk_recalc_rate,
40874 .get_parent = socfpga_clk_get_parent,
40875 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40876 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40877 socfpga_clk->hw.bit_idx = clk_gate[1];
40878
40879 - gateclk_ops.enable = clk_gate_ops.enable;
40880 - gateclk_ops.disable = clk_gate_ops.disable;
40881 + pax_open_kernel();
40882 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40883 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40884 + pax_close_kernel();
40885 }
40886
40887 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40888 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40889 index de6da95..c98278b 100644
40890 --- a/drivers/clk/socfpga/clk-pll.c
40891 +++ b/drivers/clk/socfpga/clk-pll.c
40892 @@ -21,6 +21,7 @@
40893 #include <linux/io.h>
40894 #include <linux/of.h>
40895 #include <linux/of_address.h>
40896 +#include <asm/pgtable.h>
40897
40898 #include "clk.h"
40899
40900 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40901 CLK_MGR_PLL_CLK_SRC_MASK;
40902 }
40903
40904 -static struct clk_ops clk_pll_ops = {
40905 +static clk_ops_no_const clk_pll_ops __read_only = {
40906 .recalc_rate = clk_pll_recalc_rate,
40907 .get_parent = clk_pll_get_parent,
40908 };
40909 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40910 pll_clk->hw.hw.init = &init;
40911
40912 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40913 - clk_pll_ops.enable = clk_gate_ops.enable;
40914 - clk_pll_ops.disable = clk_gate_ops.disable;
40915 + pax_open_kernel();
40916 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40917 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40918 + pax_close_kernel();
40919
40920 clk = clk_register(NULL, &pll_clk->hw.hw);
40921 if (WARN_ON(IS_ERR(clk))) {
40922 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40923 index b0c18ed..1713a80 100644
40924 --- a/drivers/cpufreq/acpi-cpufreq.c
40925 +++ b/drivers/cpufreq/acpi-cpufreq.c
40926 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40927 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40928 per_cpu(acfreq_data, cpu) = data;
40929
40930 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40931 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40932 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40933 + pax_open_kernel();
40934 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40935 + pax_close_kernel();
40936 + }
40937
40938 result = acpi_processor_register_performance(data->acpi_data, cpu);
40939 if (result)
40940 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40941 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40942 break;
40943 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40944 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40945 + pax_open_kernel();
40946 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40947 + pax_close_kernel();
40948 break;
40949 default:
40950 break;
40951 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40952 if (!msrs)
40953 return;
40954
40955 - acpi_cpufreq_driver.boost_supported = true;
40956 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40957 + pax_open_kernel();
40958 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40959 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40960 + pax_close_kernel();
40961
40962 cpu_notifier_register_begin();
40963
40964 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40965 index 6f02485..13684ae 100644
40966 --- a/drivers/cpufreq/cpufreq.c
40967 +++ b/drivers/cpufreq/cpufreq.c
40968 @@ -2100,7 +2100,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40969 }
40970
40971 mutex_lock(&cpufreq_governor_mutex);
40972 - list_del(&governor->governor_list);
40973 + pax_list_del(&governor->governor_list);
40974 mutex_unlock(&cpufreq_governor_mutex);
40975 return;
40976 }
40977 @@ -2316,7 +2316,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40978 return NOTIFY_OK;
40979 }
40980
40981 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40982 +static struct notifier_block cpufreq_cpu_notifier = {
40983 .notifier_call = cpufreq_cpu_callback,
40984 };
40985
40986 @@ -2356,13 +2356,17 @@ int cpufreq_boost_trigger_state(int state)
40987 return 0;
40988
40989 write_lock_irqsave(&cpufreq_driver_lock, flags);
40990 - cpufreq_driver->boost_enabled = state;
40991 + pax_open_kernel();
40992 + *(bool *)&cpufreq_driver->boost_enabled = state;
40993 + pax_close_kernel();
40994 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40995
40996 ret = cpufreq_driver->set_boost(state);
40997 if (ret) {
40998 write_lock_irqsave(&cpufreq_driver_lock, flags);
40999 - cpufreq_driver->boost_enabled = !state;
41000 + pax_open_kernel();
41001 + *(bool *)&cpufreq_driver->boost_enabled = !state;
41002 + pax_close_kernel();
41003 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
41004
41005 pr_err("%s: Cannot %s BOOST\n",
41006 @@ -2419,8 +2423,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
41007
41008 pr_debug("trying to register driver %s\n", driver_data->name);
41009
41010 - if (driver_data->setpolicy)
41011 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
41012 + if (driver_data->setpolicy) {
41013 + pax_open_kernel();
41014 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
41015 + pax_close_kernel();
41016 + }
41017
41018 write_lock_irqsave(&cpufreq_driver_lock, flags);
41019 if (cpufreq_driver) {
41020 @@ -2435,8 +2442,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
41021 * Check if driver provides function to enable boost -
41022 * if not, use cpufreq_boost_set_sw as default
41023 */
41024 - if (!cpufreq_driver->set_boost)
41025 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
41026 + if (!cpufreq_driver->set_boost) {
41027 + pax_open_kernel();
41028 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
41029 + pax_close_kernel();
41030 + }
41031
41032 ret = cpufreq_sysfs_create_file(&boost.attr);
41033 if (ret) {
41034 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
41035 index 1b44496..b80ff5e 100644
41036 --- a/drivers/cpufreq/cpufreq_governor.c
41037 +++ b/drivers/cpufreq/cpufreq_governor.c
41038 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
41039 struct dbs_data *dbs_data;
41040 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
41041 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
41042 - struct od_ops *od_ops = NULL;
41043 + const struct od_ops *od_ops = NULL;
41044 struct od_dbs_tuners *od_tuners = NULL;
41045 struct cs_dbs_tuners *cs_tuners = NULL;
41046 struct cpu_dbs_common_info *cpu_cdbs;
41047 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
41048
41049 if ((cdata->governor == GOV_CONSERVATIVE) &&
41050 (!policy->governor->initialized)) {
41051 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
41052 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
41053
41054 cpufreq_register_notifier(cs_ops->notifier_block,
41055 CPUFREQ_TRANSITION_NOTIFIER);
41056 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
41057
41058 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
41059 (policy->governor->initialized == 1)) {
41060 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
41061 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
41062
41063 cpufreq_unregister_notifier(cs_ops->notifier_block,
41064 CPUFREQ_TRANSITION_NOTIFIER);
41065 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
41066 index cc401d1..8197340 100644
41067 --- a/drivers/cpufreq/cpufreq_governor.h
41068 +++ b/drivers/cpufreq/cpufreq_governor.h
41069 @@ -212,7 +212,7 @@ struct common_dbs_data {
41070 void (*exit)(struct dbs_data *dbs_data);
41071
41072 /* Governor specific ops, see below */
41073 - void *gov_ops;
41074 + const void *gov_ops;
41075 };
41076
41077 /* Governor Per policy data */
41078 @@ -232,7 +232,7 @@ struct od_ops {
41079 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
41080 unsigned int freq_next, unsigned int relation);
41081 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
41082 -};
41083 +} __no_const;
41084
41085 struct cs_ops {
41086 struct notifier_block *notifier_block;
41087 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
41088 index 18d4091..434be15 100644
41089 --- a/drivers/cpufreq/cpufreq_ondemand.c
41090 +++ b/drivers/cpufreq/cpufreq_ondemand.c
41091 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
41092
41093 define_get_cpu_dbs_routines(od_cpu_dbs_info);
41094
41095 -static struct od_ops od_ops = {
41096 +static struct od_ops od_ops __read_only = {
41097 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
41098 .powersave_bias_target = generic_powersave_bias_target,
41099 .freq_increase = dbs_freq_increase,
41100 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
41101 (struct cpufreq_policy *, unsigned int, unsigned int),
41102 unsigned int powersave_bias)
41103 {
41104 - od_ops.powersave_bias_target = f;
41105 + pax_open_kernel();
41106 + *(void **)&od_ops.powersave_bias_target = f;
41107 + pax_close_kernel();
41108 od_set_powersave_bias(powersave_bias);
41109 }
41110 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
41111
41112 void od_unregister_powersave_bias_handler(void)
41113 {
41114 - od_ops.powersave_bias_target = generic_powersave_bias_target;
41115 + pax_open_kernel();
41116 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
41117 + pax_close_kernel();
41118 od_set_powersave_bias(0);
41119 }
41120 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
41121 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
41122 index 86631cb..c34ec78 100644
41123 --- a/drivers/cpufreq/intel_pstate.c
41124 +++ b/drivers/cpufreq/intel_pstate.c
41125 @@ -121,10 +121,10 @@ struct pstate_funcs {
41126 struct cpu_defaults {
41127 struct pstate_adjust_policy pid_policy;
41128 struct pstate_funcs funcs;
41129 -};
41130 +} __do_const;
41131
41132 static struct pstate_adjust_policy pid_params;
41133 -static struct pstate_funcs pstate_funcs;
41134 +static struct pstate_funcs *pstate_funcs;
41135
41136 struct perf_limits {
41137 int no_turbo;
41138 @@ -526,7 +526,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
41139
41140 cpu->pstate.current_pstate = pstate;
41141
41142 - pstate_funcs.set(cpu, pstate);
41143 + pstate_funcs->set(cpu, pstate);
41144 }
41145
41146 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
41147 @@ -546,12 +546,12 @@ static inline void intel_pstate_pstate_decrease(struct cpudata *cpu, int steps)
41148
41149 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
41150 {
41151 - cpu->pstate.min_pstate = pstate_funcs.get_min();
41152 - cpu->pstate.max_pstate = pstate_funcs.get_max();
41153 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
41154 + cpu->pstate.min_pstate = pstate_funcs->get_min();
41155 + cpu->pstate.max_pstate = pstate_funcs->get_max();
41156 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
41157
41158 - if (pstate_funcs.get_vid)
41159 - pstate_funcs.get_vid(cpu);
41160 + if (pstate_funcs->get_vid)
41161 + pstate_funcs->get_vid(cpu);
41162 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
41163 }
41164
41165 @@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
41166 rdmsrl(MSR_IA32_APERF, aperf);
41167 rdmsrl(MSR_IA32_MPERF, mperf);
41168
41169 - if (!pstate_funcs.get_max() ||
41170 - !pstate_funcs.get_min() ||
41171 - !pstate_funcs.get_turbo())
41172 + if (!pstate_funcs->get_max() ||
41173 + !pstate_funcs->get_min() ||
41174 + !pstate_funcs->get_turbo())
41175 return -ENODEV;
41176
41177 rdmsrl(MSR_IA32_APERF, tmp);
41178 @@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
41179 return 0;
41180 }
41181
41182 -static void copy_pid_params(struct pstate_adjust_policy *policy)
41183 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
41184 {
41185 pid_params.sample_rate_ms = policy->sample_rate_ms;
41186 pid_params.p_gain_pct = policy->p_gain_pct;
41187 @@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
41188
41189 static void copy_cpu_funcs(struct pstate_funcs *funcs)
41190 {
41191 - pstate_funcs.get_max = funcs->get_max;
41192 - pstate_funcs.get_min = funcs->get_min;
41193 - pstate_funcs.get_turbo = funcs->get_turbo;
41194 - pstate_funcs.set = funcs->set;
41195 - pstate_funcs.get_vid = funcs->get_vid;
41196 + pstate_funcs = funcs;
41197 }
41198
41199 #if IS_ENABLED(CONFIG_ACPI)
41200 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
41201 index 529cfd9..0e28fff 100644
41202 --- a/drivers/cpufreq/p4-clockmod.c
41203 +++ b/drivers/cpufreq/p4-clockmod.c
41204 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41205 case 0x0F: /* Core Duo */
41206 case 0x16: /* Celeron Core */
41207 case 0x1C: /* Atom */
41208 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41209 + pax_open_kernel();
41210 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41211 + pax_close_kernel();
41212 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
41213 case 0x0D: /* Pentium M (Dothan) */
41214 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41215 + pax_open_kernel();
41216 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41217 + pax_close_kernel();
41218 /* fall through */
41219 case 0x09: /* Pentium M (Banias) */
41220 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
41221 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
41222
41223 /* on P-4s, the TSC runs with constant frequency independent whether
41224 * throttling is active or not. */
41225 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41226 + pax_open_kernel();
41227 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
41228 + pax_close_kernel();
41229
41230 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
41231 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
41232 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
41233 index 9bb42ba..b01b4a2 100644
41234 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
41235 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
41236 @@ -18,14 +18,12 @@
41237 #include <asm/head.h>
41238 #include <asm/timer.h>
41239
41240 -static struct cpufreq_driver *cpufreq_us3_driver;
41241 -
41242 struct us3_freq_percpu_info {
41243 struct cpufreq_frequency_table table[4];
41244 };
41245
41246 /* Indexed by cpu number. */
41247 -static struct us3_freq_percpu_info *us3_freq_table;
41248 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
41249
41250 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
41251 * in the Safari config register.
41252 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
41253
41254 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
41255 {
41256 - if (cpufreq_us3_driver)
41257 - us3_freq_target(policy, 0);
41258 + us3_freq_target(policy, 0);
41259
41260 return 0;
41261 }
41262
41263 +static int __init us3_freq_init(void);
41264 +static void __exit us3_freq_exit(void);
41265 +
41266 +static struct cpufreq_driver cpufreq_us3_driver = {
41267 + .init = us3_freq_cpu_init,
41268 + .verify = cpufreq_generic_frequency_table_verify,
41269 + .target_index = us3_freq_target,
41270 + .get = us3_freq_get,
41271 + .exit = us3_freq_cpu_exit,
41272 + .name = "UltraSPARC-III",
41273 +
41274 +};
41275 +
41276 static int __init us3_freq_init(void)
41277 {
41278 unsigned long manuf, impl, ver;
41279 - int ret;
41280
41281 if (tlb_type != cheetah && tlb_type != cheetah_plus)
41282 return -ENODEV;
41283 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
41284 (impl == CHEETAH_IMPL ||
41285 impl == CHEETAH_PLUS_IMPL ||
41286 impl == JAGUAR_IMPL ||
41287 - impl == PANTHER_IMPL)) {
41288 - struct cpufreq_driver *driver;
41289 -
41290 - ret = -ENOMEM;
41291 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
41292 - if (!driver)
41293 - goto err_out;
41294 -
41295 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
41296 - GFP_KERNEL);
41297 - if (!us3_freq_table)
41298 - goto err_out;
41299 -
41300 - driver->init = us3_freq_cpu_init;
41301 - driver->verify = cpufreq_generic_frequency_table_verify;
41302 - driver->target_index = us3_freq_target;
41303 - driver->get = us3_freq_get;
41304 - driver->exit = us3_freq_cpu_exit;
41305 - strcpy(driver->name, "UltraSPARC-III");
41306 -
41307 - cpufreq_us3_driver = driver;
41308 - ret = cpufreq_register_driver(driver);
41309 - if (ret)
41310 - goto err_out;
41311 -
41312 - return 0;
41313 -
41314 -err_out:
41315 - if (driver) {
41316 - kfree(driver);
41317 - cpufreq_us3_driver = NULL;
41318 - }
41319 - kfree(us3_freq_table);
41320 - us3_freq_table = NULL;
41321 - return ret;
41322 - }
41323 + impl == PANTHER_IMPL))
41324 + return cpufreq_register_driver(&cpufreq_us3_driver);
41325
41326 return -ENODEV;
41327 }
41328
41329 static void __exit us3_freq_exit(void)
41330 {
41331 - if (cpufreq_us3_driver) {
41332 - cpufreq_unregister_driver(cpufreq_us3_driver);
41333 - kfree(cpufreq_us3_driver);
41334 - cpufreq_us3_driver = NULL;
41335 - kfree(us3_freq_table);
41336 - us3_freq_table = NULL;
41337 - }
41338 + cpufreq_unregister_driver(&cpufreq_us3_driver);
41339 }
41340
41341 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
41342 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
41343 index 7d4a315..21bb886 100644
41344 --- a/drivers/cpufreq/speedstep-centrino.c
41345 +++ b/drivers/cpufreq/speedstep-centrino.c
41346 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
41347 !cpu_has(cpu, X86_FEATURE_EST))
41348 return -ENODEV;
41349
41350 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
41351 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41352 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
41353 + pax_open_kernel();
41354 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
41355 + pax_close_kernel();
41356 + }
41357
41358 if (policy->cpu != 0)
41359 return -ENODEV;
41360 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
41361 index 9634f20..e1499c7 100644
41362 --- a/drivers/cpuidle/driver.c
41363 +++ b/drivers/cpuidle/driver.c
41364 @@ -205,7 +205,7 @@ static int poll_idle(struct cpuidle_device *dev,
41365
41366 static void poll_idle_init(struct cpuidle_driver *drv)
41367 {
41368 - struct cpuidle_state *state = &drv->states[0];
41369 + cpuidle_state_no_const *state = &drv->states[0];
41370
41371 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
41372 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
41373 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
41374 index ca89412..a7b9c49 100644
41375 --- a/drivers/cpuidle/governor.c
41376 +++ b/drivers/cpuidle/governor.c
41377 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
41378 mutex_lock(&cpuidle_lock);
41379 if (__cpuidle_find_governor(gov->name) == NULL) {
41380 ret = 0;
41381 - list_add_tail(&gov->governor_list, &cpuidle_governors);
41382 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
41383 if (!cpuidle_curr_governor ||
41384 cpuidle_curr_governor->rating < gov->rating)
41385 cpuidle_switch_governor(gov);
41386 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
41387 index efe2f17..b8124f9 100644
41388 --- a/drivers/cpuidle/sysfs.c
41389 +++ b/drivers/cpuidle/sysfs.c
41390 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
41391 NULL
41392 };
41393
41394 -static struct attribute_group cpuidle_attr_group = {
41395 +static attribute_group_no_const cpuidle_attr_group = {
41396 .attrs = cpuidle_default_attrs,
41397 .name = "cpuidle",
41398 };
41399 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
41400 index 12fea3e..1e28f47 100644
41401 --- a/drivers/crypto/hifn_795x.c
41402 +++ b/drivers/crypto/hifn_795x.c
41403 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
41404 MODULE_PARM_DESC(hifn_pll_ref,
41405 "PLL reference clock (pci[freq] or ext[freq], default ext)");
41406
41407 -static atomic_t hifn_dev_number;
41408 +static atomic_unchecked_t hifn_dev_number;
41409
41410 #define ACRYPTO_OP_DECRYPT 0
41411 #define ACRYPTO_OP_ENCRYPT 1
41412 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
41413 goto err_out_disable_pci_device;
41414
41415 snprintf(name, sizeof(name), "hifn%d",
41416 - atomic_inc_return(&hifn_dev_number)-1);
41417 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
41418
41419 err = pci_request_regions(pdev, name);
41420 if (err)
41421 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
41422 index 9f90369..bfcacdb 100644
41423 --- a/drivers/devfreq/devfreq.c
41424 +++ b/drivers/devfreq/devfreq.c
41425 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
41426 goto err_out;
41427 }
41428
41429 - list_add(&governor->node, &devfreq_governor_list);
41430 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
41431
41432 list_for_each_entry(devfreq, &devfreq_list, node) {
41433 int ret = 0;
41434 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
41435 }
41436 }
41437
41438 - list_del(&governor->node);
41439 + pax_list_del((struct list_head *)&governor->node);
41440 err_out:
41441 mutex_unlock(&devfreq_list_lock);
41442
41443 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
41444 index b35007e..55ad549 100644
41445 --- a/drivers/dma/sh/shdma-base.c
41446 +++ b/drivers/dma/sh/shdma-base.c
41447 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
41448 schan->slave_id = -EINVAL;
41449 }
41450
41451 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
41452 - sdev->desc_size, GFP_KERNEL);
41453 + schan->desc = kcalloc(sdev->desc_size,
41454 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
41455 if (!schan->desc) {
41456 ret = -ENOMEM;
41457 goto edescalloc;
41458 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
41459 index 146d5df..3c14970 100644
41460 --- a/drivers/dma/sh/shdmac.c
41461 +++ b/drivers/dma/sh/shdmac.c
41462 @@ -514,7 +514,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
41463 return ret;
41464 }
41465
41466 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
41467 +static struct notifier_block sh_dmae_nmi_notifier = {
41468 .notifier_call = sh_dmae_nmi_handler,
41469
41470 /* Run before NMI debug handler and KGDB */
41471 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
41472 index 592af5f..bb1d583 100644
41473 --- a/drivers/edac/edac_device.c
41474 +++ b/drivers/edac/edac_device.c
41475 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
41476 */
41477 int edac_device_alloc_index(void)
41478 {
41479 - static atomic_t device_indexes = ATOMIC_INIT(0);
41480 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
41481
41482 - return atomic_inc_return(&device_indexes) - 1;
41483 + return atomic_inc_return_unchecked(&device_indexes) - 1;
41484 }
41485 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
41486
41487 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
41488 index 01fae82..1dd8289 100644
41489 --- a/drivers/edac/edac_mc_sysfs.c
41490 +++ b/drivers/edac/edac_mc_sysfs.c
41491 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
41492 struct dev_ch_attribute {
41493 struct device_attribute attr;
41494 int channel;
41495 -};
41496 +} __do_const;
41497
41498 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
41499 struct dev_ch_attribute dev_attr_legacy_##_name = \
41500 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
41501 }
41502
41503 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
41504 + pax_open_kernel();
41505 if (mci->get_sdram_scrub_rate) {
41506 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41507 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41508 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
41509 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
41510 }
41511 if (mci->set_sdram_scrub_rate) {
41512 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41513 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41514 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
41515 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
41516 }
41517 + pax_close_kernel();
41518 err = device_create_file(&mci->dev,
41519 &dev_attr_sdram_scrub_rate);
41520 if (err) {
41521 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
41522 index 2cf44b4d..6dd2dc7 100644
41523 --- a/drivers/edac/edac_pci.c
41524 +++ b/drivers/edac/edac_pci.c
41525 @@ -29,7 +29,7 @@
41526
41527 static DEFINE_MUTEX(edac_pci_ctls_mutex);
41528 static LIST_HEAD(edac_pci_list);
41529 -static atomic_t pci_indexes = ATOMIC_INIT(0);
41530 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
41531
41532 /*
41533 * edac_pci_alloc_ctl_info
41534 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
41535 */
41536 int edac_pci_alloc_index(void)
41537 {
41538 - return atomic_inc_return(&pci_indexes) - 1;
41539 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
41540 }
41541 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
41542
41543 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
41544 index e8658e4..22746d6 100644
41545 --- a/drivers/edac/edac_pci_sysfs.c
41546 +++ b/drivers/edac/edac_pci_sysfs.c
41547 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
41548 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
41549 static int edac_pci_poll_msec = 1000; /* one second workq period */
41550
41551 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
41552 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
41553 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
41554 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
41555
41556 static struct kobject *edac_pci_top_main_kobj;
41557 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
41558 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
41559 void *value;
41560 ssize_t(*show) (void *, char *);
41561 ssize_t(*store) (void *, const char *, size_t);
41562 -};
41563 +} __do_const;
41564
41565 /* Set of show/store abstract level functions for PCI Parity object */
41566 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
41567 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41568 edac_printk(KERN_CRIT, EDAC_PCI,
41569 "Signaled System Error on %s\n",
41570 pci_name(dev));
41571 - atomic_inc(&pci_nonparity_count);
41572 + atomic_inc_unchecked(&pci_nonparity_count);
41573 }
41574
41575 if (status & (PCI_STATUS_PARITY)) {
41576 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41577 "Master Data Parity Error on %s\n",
41578 pci_name(dev));
41579
41580 - atomic_inc(&pci_parity_count);
41581 + atomic_inc_unchecked(&pci_parity_count);
41582 }
41583
41584 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41585 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41586 "Detected Parity Error on %s\n",
41587 pci_name(dev));
41588
41589 - atomic_inc(&pci_parity_count);
41590 + atomic_inc_unchecked(&pci_parity_count);
41591 }
41592 }
41593
41594 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41595 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
41596 "Signaled System Error on %s\n",
41597 pci_name(dev));
41598 - atomic_inc(&pci_nonparity_count);
41599 + atomic_inc_unchecked(&pci_nonparity_count);
41600 }
41601
41602 if (status & (PCI_STATUS_PARITY)) {
41603 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41604 "Master Data Parity Error on "
41605 "%s\n", pci_name(dev));
41606
41607 - atomic_inc(&pci_parity_count);
41608 + atomic_inc_unchecked(&pci_parity_count);
41609 }
41610
41611 if (status & (PCI_STATUS_DETECTED_PARITY)) {
41612 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
41613 "Detected Parity Error on %s\n",
41614 pci_name(dev));
41615
41616 - atomic_inc(&pci_parity_count);
41617 + atomic_inc_unchecked(&pci_parity_count);
41618 }
41619 }
41620 }
41621 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
41622 if (!check_pci_errors)
41623 return;
41624
41625 - before_count = atomic_read(&pci_parity_count);
41626 + before_count = atomic_read_unchecked(&pci_parity_count);
41627
41628 /* scan all PCI devices looking for a Parity Error on devices and
41629 * bridges.
41630 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
41631 /* Only if operator has selected panic on PCI Error */
41632 if (edac_pci_get_panic_on_pe()) {
41633 /* If the count is different 'after' from 'before' */
41634 - if (before_count != atomic_read(&pci_parity_count))
41635 + if (before_count != atomic_read_unchecked(&pci_parity_count))
41636 panic("EDAC: PCI Parity Error");
41637 }
41638 }
41639 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
41640 index 51b7e3a..aa8a3e8 100644
41641 --- a/drivers/edac/mce_amd.h
41642 +++ b/drivers/edac/mce_amd.h
41643 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
41644 bool (*mc0_mce)(u16, u8);
41645 bool (*mc1_mce)(u16, u8);
41646 bool (*mc2_mce)(u16, u8);
41647 -};
41648 +} __no_const;
41649
41650 void amd_report_gart_errors(bool);
41651 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
41652 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
41653 index 57ea7f4..af06b76 100644
41654 --- a/drivers/firewire/core-card.c
41655 +++ b/drivers/firewire/core-card.c
41656 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
41657 const struct fw_card_driver *driver,
41658 struct device *device)
41659 {
41660 - static atomic_t index = ATOMIC_INIT(-1);
41661 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
41662
41663 - card->index = atomic_inc_return(&index);
41664 + card->index = atomic_inc_return_unchecked(&index);
41665 card->driver = driver;
41666 card->device = device;
41667 card->current_tlabel = 0;
41668 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
41669
41670 void fw_core_remove_card(struct fw_card *card)
41671 {
41672 - struct fw_card_driver dummy_driver = dummy_driver_template;
41673 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
41674
41675 card->driver->update_phy_reg(card, 4,
41676 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
41677 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
41678 index 2c6d5e1..a2cca6b 100644
41679 --- a/drivers/firewire/core-device.c
41680 +++ b/drivers/firewire/core-device.c
41681 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
41682 struct config_rom_attribute {
41683 struct device_attribute attr;
41684 u32 key;
41685 -};
41686 +} __do_const;
41687
41688 static ssize_t show_immediate(struct device *dev,
41689 struct device_attribute *dattr, char *buf)
41690 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
41691 index eb6935c..3cc2bfa 100644
41692 --- a/drivers/firewire/core-transaction.c
41693 +++ b/drivers/firewire/core-transaction.c
41694 @@ -38,6 +38,7 @@
41695 #include <linux/timer.h>
41696 #include <linux/types.h>
41697 #include <linux/workqueue.h>
41698 +#include <linux/sched.h>
41699
41700 #include <asm/byteorder.h>
41701
41702 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
41703 index e1480ff6..1a429bd 100644
41704 --- a/drivers/firewire/core.h
41705 +++ b/drivers/firewire/core.h
41706 @@ -111,6 +111,7 @@ struct fw_card_driver {
41707
41708 int (*stop_iso)(struct fw_iso_context *ctx);
41709 };
41710 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
41711
41712 void fw_card_initialize(struct fw_card *card,
41713 const struct fw_card_driver *driver, struct device *device);
41714 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
41715 index a66a321..f6caf20 100644
41716 --- a/drivers/firewire/ohci.c
41717 +++ b/drivers/firewire/ohci.c
41718 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
41719 be32_to_cpu(ohci->next_header));
41720 }
41721
41722 +#ifndef CONFIG_GRKERNSEC
41723 if (param_remote_dma) {
41724 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
41725 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
41726 }
41727 +#endif
41728
41729 spin_unlock_irq(&ohci->lock);
41730
41731 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
41732 unsigned long flags;
41733 int n, ret = 0;
41734
41735 +#ifndef CONFIG_GRKERNSEC
41736 if (param_remote_dma)
41737 return 0;
41738 +#endif
41739
41740 /*
41741 * FIXME: Make sure this bitmask is cleared when we clear the busReset
41742 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
41743 index 94a58a0..f5eba42 100644
41744 --- a/drivers/firmware/dmi-id.c
41745 +++ b/drivers/firmware/dmi-id.c
41746 @@ -16,7 +16,7 @@
41747 struct dmi_device_attribute{
41748 struct device_attribute dev_attr;
41749 int field;
41750 -};
41751 +} __do_const;
41752 #define to_dmi_dev_attr(_dev_attr) \
41753 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
41754
41755 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
41756 index 17afc51..0ef90cd 100644
41757 --- a/drivers/firmware/dmi_scan.c
41758 +++ b/drivers/firmware/dmi_scan.c
41759 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
41760 if (buf == NULL)
41761 return -1;
41762
41763 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
41764 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
41765
41766 dmi_unmap(buf);
41767 return 0;
41768 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
41769 index 1491dd4..aa910db 100644
41770 --- a/drivers/firmware/efi/cper.c
41771 +++ b/drivers/firmware/efi/cper.c
41772 @@ -41,12 +41,12 @@
41773 */
41774 u64 cper_next_record_id(void)
41775 {
41776 - static atomic64_t seq;
41777 + static atomic64_unchecked_t seq;
41778
41779 - if (!atomic64_read(&seq))
41780 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
41781 + if (!atomic64_read_unchecked(&seq))
41782 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
41783
41784 - return atomic64_inc_return(&seq);
41785 + return atomic64_inc_return_unchecked(&seq);
41786 }
41787 EXPORT_SYMBOL_GPL(cper_next_record_id);
41788
41789 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
41790 index dc79346..b39bd69 100644
41791 --- a/drivers/firmware/efi/efi.c
41792 +++ b/drivers/firmware/efi/efi.c
41793 @@ -122,14 +122,16 @@ static struct attribute_group efi_subsys_attr_group = {
41794 };
41795
41796 static struct efivars generic_efivars;
41797 -static struct efivar_operations generic_ops;
41798 +static efivar_operations_no_const generic_ops __read_only;
41799
41800 static int generic_ops_register(void)
41801 {
41802 - generic_ops.get_variable = efi.get_variable;
41803 - generic_ops.set_variable = efi.set_variable;
41804 - generic_ops.get_next_variable = efi.get_next_variable;
41805 - generic_ops.query_variable_store = efi_query_variable_store;
41806 + pax_open_kernel();
41807 + *(void **)&generic_ops.get_variable = efi.get_variable;
41808 + *(void **)&generic_ops.set_variable = efi.set_variable;
41809 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41810 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41811 + pax_close_kernel();
41812
41813 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41814 }
41815 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41816 index 463c565..02a5640 100644
41817 --- a/drivers/firmware/efi/efivars.c
41818 +++ b/drivers/firmware/efi/efivars.c
41819 @@ -588,7 +588,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41820 static int
41821 create_efivars_bin_attributes(void)
41822 {
41823 - struct bin_attribute *attr;
41824 + bin_attribute_no_const *attr;
41825 int error;
41826
41827 /* new_var */
41828 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41829 index 2f569aa..c95f4fb 100644
41830 --- a/drivers/firmware/google/memconsole.c
41831 +++ b/drivers/firmware/google/memconsole.c
41832 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41833 if (!found_memconsole())
41834 return -ENODEV;
41835
41836 - memconsole_bin_attr.size = memconsole_length;
41837 + pax_open_kernel();
41838 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41839 + pax_close_kernel();
41840 +
41841 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41842 }
41843
41844 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41845 index cde3605..8b69df7 100644
41846 --- a/drivers/gpio/gpio-em.c
41847 +++ b/drivers/gpio/gpio-em.c
41848 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41849 struct em_gio_priv *p;
41850 struct resource *io[2], *irq[2];
41851 struct gpio_chip *gpio_chip;
41852 - struct irq_chip *irq_chip;
41853 + irq_chip_no_const *irq_chip;
41854 const char *name = dev_name(&pdev->dev);
41855 int ret;
41856
41857 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41858 index 7030422..42a3fe9 100644
41859 --- a/drivers/gpio/gpio-ich.c
41860 +++ b/drivers/gpio/gpio-ich.c
41861 @@ -94,7 +94,7 @@ struct ichx_desc {
41862 * this option allows driver caching written output values
41863 */
41864 bool use_outlvl_cache;
41865 -};
41866 +} __do_const;
41867
41868 static struct {
41869 spinlock_t lock;
41870 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41871 index b6ae89e..ac7349c 100644
41872 --- a/drivers/gpio/gpio-rcar.c
41873 +++ b/drivers/gpio/gpio-rcar.c
41874 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41875 struct gpio_rcar_priv *p;
41876 struct resource *io, *irq;
41877 struct gpio_chip *gpio_chip;
41878 - struct irq_chip *irq_chip;
41879 + irq_chip_no_const *irq_chip;
41880 struct device *dev = &pdev->dev;
41881 const char *name = dev_name(dev);
41882 int ret;
41883 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41884 index 66cbcc1..0c5e622 100644
41885 --- a/drivers/gpio/gpio-vr41xx.c
41886 +++ b/drivers/gpio/gpio-vr41xx.c
41887 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41888 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41889 maskl, pendl, maskh, pendh);
41890
41891 - atomic_inc(&irq_err_count);
41892 + atomic_inc_unchecked(&irq_err_count);
41893
41894 return -EINVAL;
41895 }
41896 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41897 index 2ebc907..01bdd6e 100644
41898 --- a/drivers/gpio/gpiolib.c
41899 +++ b/drivers/gpio/gpiolib.c
41900 @@ -1482,8 +1482,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41901 }
41902
41903 if (gpiochip->irqchip) {
41904 - gpiochip->irqchip->irq_request_resources = NULL;
41905 - gpiochip->irqchip->irq_release_resources = NULL;
41906 + pax_open_kernel();
41907 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41908 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41909 + pax_close_kernel();
41910 gpiochip->irqchip = NULL;
41911 }
41912 }
41913 @@ -1549,8 +1551,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41914 gpiochip->irqchip = NULL;
41915 return -EINVAL;
41916 }
41917 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41918 - irqchip->irq_release_resources = gpiochip_irq_relres;
41919 +
41920 + pax_open_kernel();
41921 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41922 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41923 + pax_close_kernel();
41924
41925 /*
41926 * Prepare the mapping since the irqchip shall be orthogonal to
41927 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41928 index fe94cc1..5e697b3 100644
41929 --- a/drivers/gpu/drm/drm_crtc.c
41930 +++ b/drivers/gpu/drm/drm_crtc.c
41931 @@ -3584,7 +3584,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41932 goto done;
41933 }
41934
41935 - if (copy_to_user(&enum_ptr[copied].name,
41936 + if (copy_to_user(enum_ptr[copied].name,
41937 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41938 ret = -EFAULT;
41939 goto done;
41940 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41941 index 8218078..9960928a 100644
41942 --- a/drivers/gpu/drm/drm_drv.c
41943 +++ b/drivers/gpu/drm/drm_drv.c
41944 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
41945 /**
41946 * Copy and IOCTL return string to user space
41947 */
41948 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
41949 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
41950 {
41951 int len;
41952
41953 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
41954 struct drm_file *file_priv = filp->private_data;
41955 struct drm_device *dev;
41956 const struct drm_ioctl_desc *ioctl = NULL;
41957 - drm_ioctl_t *func;
41958 + drm_ioctl_no_const_t func;
41959 unsigned int nr = DRM_IOCTL_NR(cmd);
41960 int retcode = -EINVAL;
41961 char stack_kdata[128];
41962 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41963 index 021fe5d..abc9ce6 100644
41964 --- a/drivers/gpu/drm/drm_fops.c
41965 +++ b/drivers/gpu/drm/drm_fops.c
41966 @@ -88,7 +88,7 @@ int drm_open(struct inode *inode, struct file *filp)
41967 return PTR_ERR(minor);
41968
41969 dev = minor->dev;
41970 - if (!dev->open_count++)
41971 + if (local_inc_return(&dev->open_count) == 1)
41972 need_setup = 1;
41973
41974 /* share address_space across all char-devs of a single device */
41975 @@ -105,7 +105,7 @@ int drm_open(struct inode *inode, struct file *filp)
41976 return 0;
41977
41978 err_undo:
41979 - dev->open_count--;
41980 + local_dec(&dev->open_count);
41981 drm_minor_release(minor);
41982 return retcode;
41983 }
41984 @@ -427,7 +427,7 @@ int drm_release(struct inode *inode, struct file *filp)
41985
41986 mutex_lock(&drm_global_mutex);
41987
41988 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41989 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41990
41991 if (dev->driver->preclose)
41992 dev->driver->preclose(dev, file_priv);
41993 @@ -436,10 +436,10 @@ int drm_release(struct inode *inode, struct file *filp)
41994 * Begin inline drm_release
41995 */
41996
41997 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41998 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41999 task_pid_nr(current),
42000 (long)old_encode_dev(file_priv->minor->kdev->devt),
42001 - dev->open_count);
42002 + local_read(&dev->open_count));
42003
42004 /* Release any auth tokens that might point to this file_priv,
42005 (do that under the drm_global_mutex) */
42006 @@ -540,7 +540,7 @@ int drm_release(struct inode *inode, struct file *filp)
42007 * End inline drm_release
42008 */
42009
42010 - if (!--dev->open_count) {
42011 + if (local_dec_and_test(&dev->open_count)) {
42012 retcode = drm_lastclose(dev);
42013 if (drm_device_is_unplugged(dev))
42014 drm_put_dev(dev);
42015 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
42016 index 3d2e91c..d31c4c9 100644
42017 --- a/drivers/gpu/drm/drm_global.c
42018 +++ b/drivers/gpu/drm/drm_global.c
42019 @@ -36,7 +36,7 @@
42020 struct drm_global_item {
42021 struct mutex mutex;
42022 void *object;
42023 - int refcount;
42024 + atomic_t refcount;
42025 };
42026
42027 static struct drm_global_item glob[DRM_GLOBAL_NUM];
42028 @@ -49,7 +49,7 @@ void drm_global_init(void)
42029 struct drm_global_item *item = &glob[i];
42030 mutex_init(&item->mutex);
42031 item->object = NULL;
42032 - item->refcount = 0;
42033 + atomic_set(&item->refcount, 0);
42034 }
42035 }
42036
42037 @@ -59,7 +59,7 @@ void drm_global_release(void)
42038 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
42039 struct drm_global_item *item = &glob[i];
42040 BUG_ON(item->object != NULL);
42041 - BUG_ON(item->refcount != 0);
42042 + BUG_ON(atomic_read(&item->refcount) != 0);
42043 }
42044 }
42045
42046 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
42047 struct drm_global_item *item = &glob[ref->global_type];
42048
42049 mutex_lock(&item->mutex);
42050 - if (item->refcount == 0) {
42051 + if (atomic_read(&item->refcount) == 0) {
42052 item->object = kzalloc(ref->size, GFP_KERNEL);
42053 if (unlikely(item->object == NULL)) {
42054 ret = -ENOMEM;
42055 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
42056 goto out_err;
42057
42058 }
42059 - ++item->refcount;
42060 + atomic_inc(&item->refcount);
42061 ref->object = item->object;
42062 mutex_unlock(&item->mutex);
42063 return 0;
42064 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
42065 struct drm_global_item *item = &glob[ref->global_type];
42066
42067 mutex_lock(&item->mutex);
42068 - BUG_ON(item->refcount == 0);
42069 + BUG_ON(atomic_read(&item->refcount) == 0);
42070 BUG_ON(ref->object != item->object);
42071 - if (--item->refcount == 0) {
42072 + if (atomic_dec_and_test(&item->refcount)) {
42073 ref->release(ref);
42074 item->object = NULL;
42075 }
42076 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
42077 index 86feedd..cba70f5 100644
42078 --- a/drivers/gpu/drm/drm_info.c
42079 +++ b/drivers/gpu/drm/drm_info.c
42080 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
42081 struct drm_local_map *map;
42082 struct drm_map_list *r_list;
42083
42084 - /* Hardcoded from _DRM_FRAME_BUFFER,
42085 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
42086 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
42087 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
42088 + static const char * const types[] = {
42089 + [_DRM_FRAME_BUFFER] = "FB",
42090 + [_DRM_REGISTERS] = "REG",
42091 + [_DRM_SHM] = "SHM",
42092 + [_DRM_AGP] = "AGP",
42093 + [_DRM_SCATTER_GATHER] = "SG",
42094 + [_DRM_CONSISTENT] = "PCI"};
42095 const char *type;
42096 int i;
42097
42098 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
42099 map = r_list->map;
42100 if (!map)
42101 continue;
42102 - if (map->type < 0 || map->type > 5)
42103 + if (map->type >= ARRAY_SIZE(types))
42104 type = "??";
42105 else
42106 type = types[map->type];
42107 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
42108 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
42109 vma->vm_flags & VM_LOCKED ? 'l' : '-',
42110 vma->vm_flags & VM_IO ? 'i' : '-',
42111 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42112 + 0);
42113 +#else
42114 vma->vm_pgoff);
42115 +#endif
42116
42117 #if defined(__i386__)
42118 pgprot = pgprot_val(vma->vm_page_prot);
42119 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
42120 index 2f4c4343..dd12cd2 100644
42121 --- a/drivers/gpu/drm/drm_ioc32.c
42122 +++ b/drivers/gpu/drm/drm_ioc32.c
42123 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
42124 request = compat_alloc_user_space(nbytes);
42125 if (!access_ok(VERIFY_WRITE, request, nbytes))
42126 return -EFAULT;
42127 - list = (struct drm_buf_desc *) (request + 1);
42128 + list = (struct drm_buf_desc __user *) (request + 1);
42129
42130 if (__put_user(count, &request->count)
42131 || __put_user(list, &request->list))
42132 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
42133 request = compat_alloc_user_space(nbytes);
42134 if (!access_ok(VERIFY_WRITE, request, nbytes))
42135 return -EFAULT;
42136 - list = (struct drm_buf_pub *) (request + 1);
42137 + list = (struct drm_buf_pub __user *) (request + 1);
42138
42139 if (__put_user(count, &request->count)
42140 || __put_user(list, &request->list))
42141 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
42142 return 0;
42143 }
42144
42145 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
42146 +drm_ioctl_compat_t drm_compat_ioctls[] = {
42147 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
42148 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
42149 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
42150 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
42151 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42152 {
42153 unsigned int nr = DRM_IOCTL_NR(cmd);
42154 - drm_ioctl_compat_t *fn;
42155 int ret;
42156
42157 /* Assume that ioctls without an explicit compat routine will just
42158 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42159 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
42160 return drm_ioctl(filp, cmd, arg);
42161
42162 - fn = drm_compat_ioctls[nr];
42163 -
42164 - if (fn != NULL)
42165 - ret = (*fn) (filp, cmd, arg);
42166 + if (drm_compat_ioctls[nr] != NULL)
42167 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
42168 else
42169 ret = drm_ioctl(filp, cmd, arg);
42170
42171 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
42172 index 14d1646..99f9d49 100644
42173 --- a/drivers/gpu/drm/drm_stub.c
42174 +++ b/drivers/gpu/drm/drm_stub.c
42175 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
42176
42177 drm_device_set_unplugged(dev);
42178
42179 - if (dev->open_count == 0) {
42180 + if (local_read(&dev->open_count) == 0) {
42181 drm_put_dev(dev);
42182 }
42183 mutex_unlock(&drm_global_mutex);
42184 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
42185 index 369b262..09ea3ab 100644
42186 --- a/drivers/gpu/drm/drm_sysfs.c
42187 +++ b/drivers/gpu/drm/drm_sysfs.c
42188 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
42189 */
42190 int drm_sysfs_device_add(struct drm_minor *minor)
42191 {
42192 - char *minor_str;
42193 + const char *minor_str;
42194 int r;
42195
42196 if (minor->type == DRM_MINOR_CONTROL)
42197 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
42198 index d4d16ed..8fb0b51 100644
42199 --- a/drivers/gpu/drm/i810/i810_drv.h
42200 +++ b/drivers/gpu/drm/i810/i810_drv.h
42201 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
42202 int page_flipping;
42203
42204 wait_queue_head_t irq_queue;
42205 - atomic_t irq_received;
42206 - atomic_t irq_emitted;
42207 + atomic_unchecked_t irq_received;
42208 + atomic_unchecked_t irq_emitted;
42209
42210 int front_offset;
42211 } drm_i810_private_t;
42212 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
42213 index d443441..ab091dd 100644
42214 --- a/drivers/gpu/drm/i915/i915_dma.c
42215 +++ b/drivers/gpu/drm/i915/i915_dma.c
42216 @@ -1290,7 +1290,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
42217 * locking inversion with the driver load path. And the access here is
42218 * completely racy anyway. So don't bother with locking for now.
42219 */
42220 - return dev->open_count == 0;
42221 + return local_read(&dev->open_count) == 0;
42222 }
42223
42224 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
42225 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42226 index 3a30133..ef4a743 100644
42227 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42228 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
42229 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
42230
42231 static int
42232 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
42233 - int count)
42234 + unsigned int count)
42235 {
42236 - int i;
42237 + unsigned int i;
42238 unsigned relocs_total = 0;
42239 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
42240
42241 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
42242 index 2e0613e..a8b94d9 100644
42243 --- a/drivers/gpu/drm/i915/i915_ioc32.c
42244 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
42245 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
42246 (unsigned long)request);
42247 }
42248
42249 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42250 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
42251 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
42252 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
42253 [DRM_I915_GETPARAM] = compat_i915_getparam,
42254 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
42255 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42256 {
42257 unsigned int nr = DRM_IOCTL_NR(cmd);
42258 - drm_ioctl_compat_t *fn = NULL;
42259 int ret;
42260
42261 if (nr < DRM_COMMAND_BASE)
42262 return drm_compat_ioctl(filp, cmd, arg);
42263
42264 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
42265 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42266 -
42267 - if (fn != NULL)
42268 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
42269 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
42270 ret = (*fn) (filp, cmd, arg);
42271 - else
42272 + } else
42273 ret = drm_ioctl(filp, cmd, arg);
42274
42275 return ret;
42276 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
42277 index f0be855..94e82d9 100644
42278 --- a/drivers/gpu/drm/i915/intel_display.c
42279 +++ b/drivers/gpu/drm/i915/intel_display.c
42280 @@ -11604,13 +11604,13 @@ struct intel_quirk {
42281 int subsystem_vendor;
42282 int subsystem_device;
42283 void (*hook)(struct drm_device *dev);
42284 -};
42285 +} __do_const;
42286
42287 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
42288 struct intel_dmi_quirk {
42289 void (*hook)(struct drm_device *dev);
42290 const struct dmi_system_id (*dmi_id_list)[];
42291 -};
42292 +} __do_const;
42293
42294 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42295 {
42296 @@ -11618,18 +11618,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
42297 return 1;
42298 }
42299
42300 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42301 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
42302 {
42303 - .dmi_id_list = &(const struct dmi_system_id[]) {
42304 - {
42305 - .callback = intel_dmi_reverse_brightness,
42306 - .ident = "NCR Corporation",
42307 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42308 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
42309 - },
42310 - },
42311 - { } /* terminating entry */
42312 + .callback = intel_dmi_reverse_brightness,
42313 + .ident = "NCR Corporation",
42314 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
42315 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
42316 },
42317 + },
42318 + { } /* terminating entry */
42319 +};
42320 +
42321 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
42322 + {
42323 + .dmi_id_list = &intel_dmi_quirks_table,
42324 .hook = quirk_invert_brightness,
42325 },
42326 };
42327 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
42328 index fe45321..836fdca 100644
42329 --- a/drivers/gpu/drm/mga/mga_drv.h
42330 +++ b/drivers/gpu/drm/mga/mga_drv.h
42331 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
42332 u32 clear_cmd;
42333 u32 maccess;
42334
42335 - atomic_t vbl_received; /**< Number of vblanks received. */
42336 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
42337 wait_queue_head_t fence_queue;
42338 - atomic_t last_fence_retired;
42339 + atomic_unchecked_t last_fence_retired;
42340 u32 next_fence_to_post;
42341
42342 unsigned int fb_cpp;
42343 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
42344 index 729bfd5..ead8823 100644
42345 --- a/drivers/gpu/drm/mga/mga_ioc32.c
42346 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
42347 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
42348 return 0;
42349 }
42350
42351 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
42352 +drm_ioctl_compat_t mga_compat_ioctls[] = {
42353 [DRM_MGA_INIT] = compat_mga_init,
42354 [DRM_MGA_GETPARAM] = compat_mga_getparam,
42355 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
42356 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
42357 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42358 {
42359 unsigned int nr = DRM_IOCTL_NR(cmd);
42360 - drm_ioctl_compat_t *fn = NULL;
42361 int ret;
42362
42363 if (nr < DRM_COMMAND_BASE)
42364 return drm_compat_ioctl(filp, cmd, arg);
42365
42366 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
42367 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42368 -
42369 - if (fn != NULL)
42370 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
42371 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
42372 ret = (*fn) (filp, cmd, arg);
42373 - else
42374 + } else
42375 ret = drm_ioctl(filp, cmd, arg);
42376
42377 return ret;
42378 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
42379 index 1b071b8..de8601a 100644
42380 --- a/drivers/gpu/drm/mga/mga_irq.c
42381 +++ b/drivers/gpu/drm/mga/mga_irq.c
42382 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
42383 if (crtc != 0)
42384 return 0;
42385
42386 - return atomic_read(&dev_priv->vbl_received);
42387 + return atomic_read_unchecked(&dev_priv->vbl_received);
42388 }
42389
42390
42391 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42392 /* VBLANK interrupt */
42393 if (status & MGA_VLINEPEN) {
42394 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
42395 - atomic_inc(&dev_priv->vbl_received);
42396 + atomic_inc_unchecked(&dev_priv->vbl_received);
42397 drm_handle_vblank(dev, 0);
42398 handled = 1;
42399 }
42400 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
42401 if ((prim_start & ~0x03) != (prim_end & ~0x03))
42402 MGA_WRITE(MGA_PRIMEND, prim_end);
42403
42404 - atomic_inc(&dev_priv->last_fence_retired);
42405 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
42406 wake_up(&dev_priv->fence_queue);
42407 handled = 1;
42408 }
42409 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
42410 * using fences.
42411 */
42412 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
42413 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
42414 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
42415 - *sequence) <= (1 << 23)));
42416
42417 *sequence = cur_fence;
42418 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
42419 index 8268a4c..5105708 100644
42420 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
42421 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
42422 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
42423 struct bit_table {
42424 const char id;
42425 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
42426 -};
42427 +} __no_const;
42428
42429 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
42430
42431 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
42432 index 7efbafa..19f8087 100644
42433 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
42434 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
42435 @@ -97,7 +97,6 @@ struct nouveau_drm {
42436 struct drm_global_reference mem_global_ref;
42437 struct ttm_bo_global_ref bo_global_ref;
42438 struct ttm_bo_device bdev;
42439 - atomic_t validate_sequence;
42440 int (*move)(struct nouveau_channel *,
42441 struct ttm_buffer_object *,
42442 struct ttm_mem_reg *, struct ttm_mem_reg *);
42443 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42444 index 462679a..88e32a7 100644
42445 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42446 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
42447 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
42448 unsigned long arg)
42449 {
42450 unsigned int nr = DRM_IOCTL_NR(cmd);
42451 - drm_ioctl_compat_t *fn = NULL;
42452 + drm_ioctl_compat_t fn = NULL;
42453 int ret;
42454
42455 if (nr < DRM_COMMAND_BASE)
42456 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42457 index ab0228f..20b756b 100644
42458 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
42459 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
42460 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42461 }
42462
42463 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
42464 - nouveau_vram_manager_init,
42465 - nouveau_vram_manager_fini,
42466 - nouveau_vram_manager_new,
42467 - nouveau_vram_manager_del,
42468 - nouveau_vram_manager_debug
42469 + .init = nouveau_vram_manager_init,
42470 + .takedown = nouveau_vram_manager_fini,
42471 + .get_node = nouveau_vram_manager_new,
42472 + .put_node = nouveau_vram_manager_del,
42473 + .debug = nouveau_vram_manager_debug
42474 };
42475
42476 static int
42477 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42478 }
42479
42480 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
42481 - nouveau_gart_manager_init,
42482 - nouveau_gart_manager_fini,
42483 - nouveau_gart_manager_new,
42484 - nouveau_gart_manager_del,
42485 - nouveau_gart_manager_debug
42486 + .init = nouveau_gart_manager_init,
42487 + .takedown = nouveau_gart_manager_fini,
42488 + .get_node = nouveau_gart_manager_new,
42489 + .put_node = nouveau_gart_manager_del,
42490 + .debug = nouveau_gart_manager_debug
42491 };
42492
42493 #include <core/subdev/vm/nv04.h>
42494 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
42495 }
42496
42497 const struct ttm_mem_type_manager_func nv04_gart_manager = {
42498 - nv04_gart_manager_init,
42499 - nv04_gart_manager_fini,
42500 - nv04_gart_manager_new,
42501 - nv04_gart_manager_del,
42502 - nv04_gart_manager_debug
42503 + .init = nv04_gart_manager_init,
42504 + .takedown = nv04_gart_manager_fini,
42505 + .get_node = nv04_gart_manager_new,
42506 + .put_node = nv04_gart_manager_del,
42507 + .debug = nv04_gart_manager_debug
42508 };
42509
42510 int
42511 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
42512 index 4f4c3fe..2cce716 100644
42513 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
42514 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
42515 @@ -70,7 +70,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
42516 * locking inversion with the driver load path. And the access here is
42517 * completely racy anyway. So don't bother with locking for now.
42518 */
42519 - return dev->open_count == 0;
42520 + return local_read(&dev->open_count) == 0;
42521 }
42522
42523 static const struct vga_switcheroo_client_ops
42524 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
42525 index eb89653..613cf71 100644
42526 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
42527 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
42528 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
42529 int ret;
42530
42531 mutex_lock(&qdev->async_io_mutex);
42532 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
42533 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42534 if (qdev->last_sent_io_cmd > irq_num) {
42535 if (intr)
42536 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42537 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42538 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42539 else
42540 ret = wait_event_timeout(qdev->io_cmd_event,
42541 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42542 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42543 /* 0 is timeout, just bail the "hw" has gone away */
42544 if (ret <= 0)
42545 goto out;
42546 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
42547 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
42548 }
42549 outb(val, addr);
42550 qdev->last_sent_io_cmd = irq_num + 1;
42551 if (intr)
42552 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
42553 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42554 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42555 else
42556 ret = wait_event_timeout(qdev->io_cmd_event,
42557 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42558 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
42559 out:
42560 if (ret > 0)
42561 ret = 0;
42562 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
42563 index c3c2bbd..bc3c0fb 100644
42564 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
42565 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
42566 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
42567 struct drm_info_node *node = (struct drm_info_node *) m->private;
42568 struct qxl_device *qdev = node->minor->dev->dev_private;
42569
42570 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
42571 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
42572 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
42573 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
42574 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
42575 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
42576 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
42577 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
42578 seq_printf(m, "%d\n", qdev->irq_received_error);
42579 return 0;
42580 }
42581 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
42582 index 36ed40b..0397633 100644
42583 --- a/drivers/gpu/drm/qxl/qxl_drv.h
42584 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
42585 @@ -290,10 +290,10 @@ struct qxl_device {
42586 unsigned int last_sent_io_cmd;
42587
42588 /* interrupt handling */
42589 - atomic_t irq_received;
42590 - atomic_t irq_received_display;
42591 - atomic_t irq_received_cursor;
42592 - atomic_t irq_received_io_cmd;
42593 + atomic_unchecked_t irq_received;
42594 + atomic_unchecked_t irq_received_display;
42595 + atomic_unchecked_t irq_received_cursor;
42596 + atomic_unchecked_t irq_received_io_cmd;
42597 unsigned irq_received_error;
42598 wait_queue_head_t display_event;
42599 wait_queue_head_t cursor_event;
42600 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
42601 index b110883..dd06418 100644
42602 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
42603 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
42604 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42605
42606 /* TODO copy slow path code from i915 */
42607 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
42608 - 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);
42609 + 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);
42610
42611 {
42612 struct qxl_drawable *draw = fb_cmd;
42613 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
42614 struct drm_qxl_reloc reloc;
42615
42616 if (copy_from_user(&reloc,
42617 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
42618 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
42619 sizeof(reloc))) {
42620 ret = -EFAULT;
42621 goto out_free_bos;
42622 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
42623
42624 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
42625
42626 - struct drm_qxl_command *commands =
42627 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
42628 + struct drm_qxl_command __user *commands =
42629 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
42630
42631 - if (copy_from_user(&user_cmd, &commands[cmd_num],
42632 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
42633 sizeof(user_cmd)))
42634 return -EFAULT;
42635
42636 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
42637 index 0bf1e20..42a7310 100644
42638 --- a/drivers/gpu/drm/qxl/qxl_irq.c
42639 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
42640 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
42641 if (!pending)
42642 return IRQ_NONE;
42643
42644 - atomic_inc(&qdev->irq_received);
42645 + atomic_inc_unchecked(&qdev->irq_received);
42646
42647 if (pending & QXL_INTERRUPT_DISPLAY) {
42648 - atomic_inc(&qdev->irq_received_display);
42649 + atomic_inc_unchecked(&qdev->irq_received_display);
42650 wake_up_all(&qdev->display_event);
42651 qxl_queue_garbage_collect(qdev, false);
42652 }
42653 if (pending & QXL_INTERRUPT_CURSOR) {
42654 - atomic_inc(&qdev->irq_received_cursor);
42655 + atomic_inc_unchecked(&qdev->irq_received_cursor);
42656 wake_up_all(&qdev->cursor_event);
42657 }
42658 if (pending & QXL_INTERRUPT_IO_CMD) {
42659 - atomic_inc(&qdev->irq_received_io_cmd);
42660 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
42661 wake_up_all(&qdev->io_cmd_event);
42662 }
42663 if (pending & QXL_INTERRUPT_ERROR) {
42664 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
42665 init_waitqueue_head(&qdev->io_cmd_event);
42666 INIT_WORK(&qdev->client_monitors_config_work,
42667 qxl_client_monitors_config_work_func);
42668 - atomic_set(&qdev->irq_received, 0);
42669 - atomic_set(&qdev->irq_received_display, 0);
42670 - atomic_set(&qdev->irq_received_cursor, 0);
42671 - atomic_set(&qdev->irq_received_io_cmd, 0);
42672 + atomic_set_unchecked(&qdev->irq_received, 0);
42673 + atomic_set_unchecked(&qdev->irq_received_display, 0);
42674 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
42675 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
42676 qdev->irq_received_error = 0;
42677 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
42678 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
42679 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
42680 index 71a1bae..cb1f103 100644
42681 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
42682 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
42683 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
42684 }
42685 }
42686
42687 -static struct vm_operations_struct qxl_ttm_vm_ops;
42688 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
42689 static const struct vm_operations_struct *ttm_vm_ops;
42690
42691 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42692 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
42693 return r;
42694 if (unlikely(ttm_vm_ops == NULL)) {
42695 ttm_vm_ops = vma->vm_ops;
42696 + pax_open_kernel();
42697 qxl_ttm_vm_ops = *ttm_vm_ops;
42698 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
42699 + pax_close_kernel();
42700 }
42701 vma->vm_ops = &qxl_ttm_vm_ops;
42702 return 0;
42703 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
42704 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
42705 {
42706 #if defined(CONFIG_DEBUG_FS)
42707 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
42708 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
42709 - unsigned i;
42710 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
42711 + {
42712 + .name = "qxl_mem_mm",
42713 + .show = &qxl_mm_dump_table,
42714 + },
42715 + {
42716 + .name = "qxl_surf_mm",
42717 + .show = &qxl_mm_dump_table,
42718 + }
42719 + };
42720
42721 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
42722 - if (i == 0)
42723 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
42724 - else
42725 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
42726 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
42727 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
42728 - qxl_mem_types_list[i].driver_features = 0;
42729 - if (i == 0)
42730 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42731 - else
42732 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42733 + pax_open_kernel();
42734 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
42735 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
42736 + pax_close_kernel();
42737
42738 - }
42739 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
42740 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
42741 #else
42742 return 0;
42743 #endif
42744 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
42745 index 59459fe..be26b31 100644
42746 --- a/drivers/gpu/drm/r128/r128_cce.c
42747 +++ b/drivers/gpu/drm/r128/r128_cce.c
42748 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
42749
42750 /* GH: Simple idle check.
42751 */
42752 - atomic_set(&dev_priv->idle_count, 0);
42753 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42754
42755 /* We don't support anything other than bus-mastering ring mode,
42756 * but the ring can be in either AGP or PCI space for the ring
42757 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
42758 index 5bf3f5f..7000661 100644
42759 --- a/drivers/gpu/drm/r128/r128_drv.h
42760 +++ b/drivers/gpu/drm/r128/r128_drv.h
42761 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
42762 int is_pci;
42763 unsigned long cce_buffers_offset;
42764
42765 - atomic_t idle_count;
42766 + atomic_unchecked_t idle_count;
42767
42768 int page_flipping;
42769 int current_page;
42770 u32 crtc_offset;
42771 u32 crtc_offset_cntl;
42772
42773 - atomic_t vbl_received;
42774 + atomic_unchecked_t vbl_received;
42775
42776 u32 color_fmt;
42777 unsigned int front_offset;
42778 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
42779 index 663f38c..c689495 100644
42780 --- a/drivers/gpu/drm/r128/r128_ioc32.c
42781 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
42782 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
42783 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
42784 }
42785
42786 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
42787 +drm_ioctl_compat_t r128_compat_ioctls[] = {
42788 [DRM_R128_INIT] = compat_r128_init,
42789 [DRM_R128_DEPTH] = compat_r128_depth,
42790 [DRM_R128_STIPPLE] = compat_r128_stipple,
42791 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
42792 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42793 {
42794 unsigned int nr = DRM_IOCTL_NR(cmd);
42795 - drm_ioctl_compat_t *fn = NULL;
42796 int ret;
42797
42798 if (nr < DRM_COMMAND_BASE)
42799 return drm_compat_ioctl(filp, cmd, arg);
42800
42801 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
42802 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42803 -
42804 - if (fn != NULL)
42805 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
42806 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
42807 ret = (*fn) (filp, cmd, arg);
42808 - else
42809 + } else
42810 ret = drm_ioctl(filp, cmd, arg);
42811
42812 return ret;
42813 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
42814 index c2ae496..30b5993 100644
42815 --- a/drivers/gpu/drm/r128/r128_irq.c
42816 +++ b/drivers/gpu/drm/r128/r128_irq.c
42817 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42818 if (crtc != 0)
42819 return 0;
42820
42821 - return atomic_read(&dev_priv->vbl_received);
42822 + return atomic_read_unchecked(&dev_priv->vbl_received);
42823 }
42824
42825 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42826 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42827 /* VBLANK interrupt */
42828 if (status & R128_CRTC_VBLANK_INT) {
42829 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42830 - atomic_inc(&dev_priv->vbl_received);
42831 + atomic_inc_unchecked(&dev_priv->vbl_received);
42832 drm_handle_vblank(dev, 0);
42833 return IRQ_HANDLED;
42834 }
42835 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42836 index 575e986..66e62ca 100644
42837 --- a/drivers/gpu/drm/r128/r128_state.c
42838 +++ b/drivers/gpu/drm/r128/r128_state.c
42839 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42840
42841 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42842 {
42843 - if (atomic_read(&dev_priv->idle_count) == 0)
42844 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42845 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42846 else
42847 - atomic_set(&dev_priv->idle_count, 0);
42848 + atomic_set_unchecked(&dev_priv->idle_count, 0);
42849 }
42850
42851 #endif
42852 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42853 index 4a85bb6..aaea819 100644
42854 --- a/drivers/gpu/drm/radeon/mkregtable.c
42855 +++ b/drivers/gpu/drm/radeon/mkregtable.c
42856 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42857 regex_t mask_rex;
42858 regmatch_t match[4];
42859 char buf[1024];
42860 - size_t end;
42861 + long end;
42862 int len;
42863 int done = 0;
42864 int r;
42865 unsigned o;
42866 struct offset *offset;
42867 char last_reg_s[10];
42868 - int last_reg;
42869 + unsigned long last_reg;
42870
42871 if (regcomp
42872 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42873 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42874 index 697add2..9860f5b 100644
42875 --- a/drivers/gpu/drm/radeon/radeon_device.c
42876 +++ b/drivers/gpu/drm/radeon/radeon_device.c
42877 @@ -1169,7 +1169,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42878 * locking inversion with the driver load path. And the access here is
42879 * completely racy anyway. So don't bother with locking for now.
42880 */
42881 - return dev->open_count == 0;
42882 + return local_read(&dev->open_count) == 0;
42883 }
42884
42885 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42886 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42887 index dafd812..1bf20c7 100644
42888 --- a/drivers/gpu/drm/radeon/radeon_drv.h
42889 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42890 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42891
42892 /* SW interrupt */
42893 wait_queue_head_t swi_queue;
42894 - atomic_t swi_emitted;
42895 + atomic_unchecked_t swi_emitted;
42896 int vblank_crtc;
42897 uint32_t irq_enable_reg;
42898 uint32_t r500_disp_irq_reg;
42899 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42900 index 0b98ea1..0881827 100644
42901 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42902 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42903 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42904 request = compat_alloc_user_space(sizeof(*request));
42905 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42906 || __put_user(req32.param, &request->param)
42907 - || __put_user((void __user *)(unsigned long)req32.value,
42908 + || __put_user((unsigned long)req32.value,
42909 &request->value))
42910 return -EFAULT;
42911
42912 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42913 #define compat_radeon_cp_setparam NULL
42914 #endif /* X86_64 || IA64 */
42915
42916 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42917 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42918 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42919 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42920 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42921 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42922 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42923 {
42924 unsigned int nr = DRM_IOCTL_NR(cmd);
42925 - drm_ioctl_compat_t *fn = NULL;
42926 int ret;
42927
42928 if (nr < DRM_COMMAND_BASE)
42929 return drm_compat_ioctl(filp, cmd, arg);
42930
42931 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42932 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42933 -
42934 - if (fn != NULL)
42935 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42936 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42937 ret = (*fn) (filp, cmd, arg);
42938 - else
42939 + } else
42940 ret = drm_ioctl(filp, cmd, arg);
42941
42942 return ret;
42943 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42944 index 244b19b..c19226d 100644
42945 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42946 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42947 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42948 unsigned int ret;
42949 RING_LOCALS;
42950
42951 - atomic_inc(&dev_priv->swi_emitted);
42952 - ret = atomic_read(&dev_priv->swi_emitted);
42953 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42954 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42955
42956 BEGIN_RING(4);
42957 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42958 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42959 drm_radeon_private_t *dev_priv =
42960 (drm_radeon_private_t *) dev->dev_private;
42961
42962 - atomic_set(&dev_priv->swi_emitted, 0);
42963 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42964 init_waitqueue_head(&dev_priv->swi_queue);
42965
42966 dev->max_vblank_count = 0x001fffff;
42967 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42968 index 23bb64f..69d7234 100644
42969 --- a/drivers/gpu/drm/radeon/radeon_state.c
42970 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42971 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42972 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42973 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42974
42975 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42976 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42977 sarea_priv->nbox * sizeof(depth_boxes[0])))
42978 return -EFAULT;
42979
42980 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42981 {
42982 drm_radeon_private_t *dev_priv = dev->dev_private;
42983 drm_radeon_getparam_t *param = data;
42984 - int value;
42985 + int value = 0;
42986
42987 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42988
42989 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42990 index c8a8a51..219dacc 100644
42991 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42992 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42993 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42994 man->size = size >> PAGE_SHIFT;
42995 }
42996
42997 -static struct vm_operations_struct radeon_ttm_vm_ops;
42998 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42999 static const struct vm_operations_struct *ttm_vm_ops = NULL;
43000
43001 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43002 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
43003 }
43004 if (unlikely(ttm_vm_ops == NULL)) {
43005 ttm_vm_ops = vma->vm_ops;
43006 + pax_open_kernel();
43007 radeon_ttm_vm_ops = *ttm_vm_ops;
43008 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
43009 + pax_close_kernel();
43010 }
43011 vma->vm_ops = &radeon_ttm_vm_ops;
43012 return 0;
43013 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
43014 index ef40381..347463e 100644
43015 --- a/drivers/gpu/drm/tegra/dc.c
43016 +++ b/drivers/gpu/drm/tegra/dc.c
43017 @@ -1173,7 +1173,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
43018 }
43019
43020 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
43021 - dc->debugfs_files[i].data = dc;
43022 + *(void **)&dc->debugfs_files[i].data = dc;
43023
43024 err = drm_debugfs_create_files(dc->debugfs_files,
43025 ARRAY_SIZE(debugfs_files),
43026 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
43027 index bd56f2a..255af4b 100644
43028 --- a/drivers/gpu/drm/tegra/dsi.c
43029 +++ b/drivers/gpu/drm/tegra/dsi.c
43030 @@ -41,7 +41,7 @@ struct tegra_dsi {
43031 struct clk *clk_lp;
43032 struct clk *clk;
43033
43034 - struct drm_info_list *debugfs_files;
43035 + drm_info_list_no_const *debugfs_files;
43036 struct drm_minor *minor;
43037 struct dentry *debugfs;
43038
43039 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
43040 index ba067bb..23afbbd 100644
43041 --- a/drivers/gpu/drm/tegra/hdmi.c
43042 +++ b/drivers/gpu/drm/tegra/hdmi.c
43043 @@ -60,7 +60,7 @@ struct tegra_hdmi {
43044 bool stereo;
43045 bool dvi;
43046
43047 - struct drm_info_list *debugfs_files;
43048 + drm_info_list_no_const *debugfs_files;
43049 struct drm_minor *minor;
43050 struct dentry *debugfs;
43051 };
43052 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
43053 index bd850c9..d9f3573 100644
43054 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
43055 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
43056 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
43057 }
43058
43059 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
43060 - ttm_bo_man_init,
43061 - ttm_bo_man_takedown,
43062 - ttm_bo_man_get_node,
43063 - ttm_bo_man_put_node,
43064 - ttm_bo_man_debug
43065 + .init = ttm_bo_man_init,
43066 + .takedown = ttm_bo_man_takedown,
43067 + .get_node = ttm_bo_man_get_node,
43068 + .put_node = ttm_bo_man_put_node,
43069 + .debug = ttm_bo_man_debug
43070 };
43071 EXPORT_SYMBOL(ttm_bo_manager_func);
43072 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
43073 index dbc2def..0a9f710 100644
43074 --- a/drivers/gpu/drm/ttm/ttm_memory.c
43075 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
43076 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
43077 zone->glob = glob;
43078 glob->zone_kernel = zone;
43079 ret = kobject_init_and_add(
43080 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43081 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43082 if (unlikely(ret != 0)) {
43083 kobject_put(&zone->kobj);
43084 return ret;
43085 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
43086 zone->glob = glob;
43087 glob->zone_dma32 = zone;
43088 ret = kobject_init_and_add(
43089 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
43090 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
43091 if (unlikely(ret != 0)) {
43092 kobject_put(&zone->kobj);
43093 return ret;
43094 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43095 index 863bef9..cba15cf 100644
43096 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
43097 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
43098 @@ -391,9 +391,9 @@ out:
43099 static unsigned long
43100 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
43101 {
43102 - static atomic_t start_pool = ATOMIC_INIT(0);
43103 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
43104 unsigned i;
43105 - unsigned pool_offset = atomic_add_return(1, &start_pool);
43106 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
43107 struct ttm_page_pool *pool;
43108 int shrink_pages = sc->nr_to_scan;
43109 unsigned long freed = 0;
43110 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
43111 index 3771763..883f206 100644
43112 --- a/drivers/gpu/drm/udl/udl_fb.c
43113 +++ b/drivers/gpu/drm/udl/udl_fb.c
43114 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
43115 fb_deferred_io_cleanup(info);
43116 kfree(info->fbdefio);
43117 info->fbdefio = NULL;
43118 - info->fbops->fb_mmap = udl_fb_mmap;
43119 }
43120
43121 pr_warn("released /dev/fb%d user=%d count=%d\n",
43122 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
43123 index ad02732..144f5ed 100644
43124 --- a/drivers/gpu/drm/via/via_drv.h
43125 +++ b/drivers/gpu/drm/via/via_drv.h
43126 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
43127 typedef uint32_t maskarray_t[5];
43128
43129 typedef struct drm_via_irq {
43130 - atomic_t irq_received;
43131 + atomic_unchecked_t irq_received;
43132 uint32_t pending_mask;
43133 uint32_t enable_mask;
43134 wait_queue_head_t irq_queue;
43135 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
43136 struct timeval last_vblank;
43137 int last_vblank_valid;
43138 unsigned usec_per_vblank;
43139 - atomic_t vbl_received;
43140 + atomic_unchecked_t vbl_received;
43141 drm_via_state_t hc_state;
43142 char pci_buf[VIA_PCI_BUF_SIZE];
43143 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
43144 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
43145 index 1319433..a993b0c 100644
43146 --- a/drivers/gpu/drm/via/via_irq.c
43147 +++ b/drivers/gpu/drm/via/via_irq.c
43148 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
43149 if (crtc != 0)
43150 return 0;
43151
43152 - return atomic_read(&dev_priv->vbl_received);
43153 + return atomic_read_unchecked(&dev_priv->vbl_received);
43154 }
43155
43156 irqreturn_t via_driver_irq_handler(int irq, void *arg)
43157 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43158
43159 status = VIA_READ(VIA_REG_INTERRUPT);
43160 if (status & VIA_IRQ_VBLANK_PENDING) {
43161 - atomic_inc(&dev_priv->vbl_received);
43162 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
43163 + atomic_inc_unchecked(&dev_priv->vbl_received);
43164 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
43165 do_gettimeofday(&cur_vblank);
43166 if (dev_priv->last_vblank_valid) {
43167 dev_priv->usec_per_vblank =
43168 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43169 dev_priv->last_vblank = cur_vblank;
43170 dev_priv->last_vblank_valid = 1;
43171 }
43172 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
43173 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
43174 DRM_DEBUG("US per vblank is: %u\n",
43175 dev_priv->usec_per_vblank);
43176 }
43177 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
43178
43179 for (i = 0; i < dev_priv->num_irqs; ++i) {
43180 if (status & cur_irq->pending_mask) {
43181 - atomic_inc(&cur_irq->irq_received);
43182 + atomic_inc_unchecked(&cur_irq->irq_received);
43183 wake_up(&cur_irq->irq_queue);
43184 handled = 1;
43185 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
43186 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
43187 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43188 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
43189 masks[irq][4]));
43190 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
43191 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
43192 } else {
43193 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
43194 (((cur_irq_sequence =
43195 - atomic_read(&cur_irq->irq_received)) -
43196 + atomic_read_unchecked(&cur_irq->irq_received)) -
43197 *sequence) <= (1 << 23)));
43198 }
43199 *sequence = cur_irq_sequence;
43200 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
43201 }
43202
43203 for (i = 0; i < dev_priv->num_irqs; ++i) {
43204 - atomic_set(&cur_irq->irq_received, 0);
43205 + atomic_set_unchecked(&cur_irq->irq_received, 0);
43206 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
43207 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
43208 init_waitqueue_head(&cur_irq->irq_queue);
43209 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
43210 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
43211 case VIA_IRQ_RELATIVE:
43212 irqwait->request.sequence +=
43213 - atomic_read(&cur_irq->irq_received);
43214 + atomic_read_unchecked(&cur_irq->irq_received);
43215 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
43216 case VIA_IRQ_ABSOLUTE:
43217 break;
43218 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43219 index 6b252a8..5975dfe 100644
43220 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43221 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
43222 @@ -437,7 +437,7 @@ struct vmw_private {
43223 * Fencing and IRQs.
43224 */
43225
43226 - atomic_t marker_seq;
43227 + atomic_unchecked_t marker_seq;
43228 wait_queue_head_t fence_queue;
43229 wait_queue_head_t fifo_queue;
43230 int fence_queue_waiters; /* Protected by hw_mutex */
43231 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43232 index 6ccd993..618d592 100644
43233 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43234 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
43235 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
43236 (unsigned int) min,
43237 (unsigned int) fifo->capabilities);
43238
43239 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43240 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
43241 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
43242 vmw_marker_queue_init(&fifo->marker_queue);
43243 return vmw_fifo_send_fence(dev_priv, &dummy);
43244 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
43245 if (reserveable)
43246 iowrite32(bytes, fifo_mem +
43247 SVGA_FIFO_RESERVED);
43248 - return fifo_mem + (next_cmd >> 2);
43249 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
43250 } else {
43251 need_bounce = true;
43252 }
43253 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43254
43255 fm = vmw_fifo_reserve(dev_priv, bytes);
43256 if (unlikely(fm == NULL)) {
43257 - *seqno = atomic_read(&dev_priv->marker_seq);
43258 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43259 ret = -ENOMEM;
43260 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
43261 false, 3*HZ);
43262 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
43263 }
43264
43265 do {
43266 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
43267 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
43268 } while (*seqno == 0);
43269
43270 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
43271 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43272 index b1273e8..9c274fd 100644
43273 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43274 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
43275 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
43276 }
43277
43278 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
43279 - vmw_gmrid_man_init,
43280 - vmw_gmrid_man_takedown,
43281 - vmw_gmrid_man_get_node,
43282 - vmw_gmrid_man_put_node,
43283 - vmw_gmrid_man_debug
43284 + .init = vmw_gmrid_man_init,
43285 + .takedown = vmw_gmrid_man_takedown,
43286 + .get_node = vmw_gmrid_man_get_node,
43287 + .put_node = vmw_gmrid_man_put_node,
43288 + .debug = vmw_gmrid_man_debug
43289 };
43290 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43291 index 37881ec..319065d 100644
43292 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43293 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
43294 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
43295 int ret;
43296
43297 num_clips = arg->num_clips;
43298 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43299 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43300
43301 if (unlikely(num_clips == 0))
43302 return 0;
43303 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
43304 int ret;
43305
43306 num_clips = arg->num_clips;
43307 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
43308 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
43309
43310 if (unlikely(num_clips == 0))
43311 return 0;
43312 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43313 index 0c42376..6febe77 100644
43314 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43315 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
43316 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
43317 * emitted. Then the fence is stale and signaled.
43318 */
43319
43320 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
43321 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
43322 > VMW_FENCE_WRAP);
43323
43324 return ret;
43325 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
43326
43327 if (fifo_idle)
43328 down_read(&fifo_state->rwsem);
43329 - signal_seq = atomic_read(&dev_priv->marker_seq);
43330 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
43331 ret = 0;
43332
43333 for (;;) {
43334 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43335 index 8a8725c2..afed796 100644
43336 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43337 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
43338 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
43339 while (!vmw_lag_lt(queue, us)) {
43340 spin_lock(&queue->lock);
43341 if (list_empty(&queue->head))
43342 - seqno = atomic_read(&dev_priv->marker_seq);
43343 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
43344 else {
43345 marker = list_first_entry(&queue->head,
43346 struct vmw_marker, head);
43347 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
43348 index 6866448..2ad2b34 100644
43349 --- a/drivers/gpu/vga/vga_switcheroo.c
43350 +++ b/drivers/gpu/vga/vga_switcheroo.c
43351 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
43352
43353 /* this version is for the case where the power switch is separate
43354 to the device being powered down. */
43355 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
43356 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
43357 {
43358 /* copy over all the bus versions */
43359 if (dev->bus && dev->bus->pm) {
43360 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
43361 return ret;
43362 }
43363
43364 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
43365 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
43366 {
43367 /* copy over all the bus versions */
43368 if (dev->bus && dev->bus->pm) {
43369 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
43370 index 8ed66fd..38ff772 100644
43371 --- a/drivers/hid/hid-core.c
43372 +++ b/drivers/hid/hid-core.c
43373 @@ -2488,7 +2488,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
43374
43375 int hid_add_device(struct hid_device *hdev)
43376 {
43377 - static atomic_t id = ATOMIC_INIT(0);
43378 + static atomic_unchecked_t id = ATOMIC_INIT(0);
43379 int ret;
43380
43381 if (WARN_ON(hdev->status & HID_STAT_ADDED))
43382 @@ -2530,7 +2530,7 @@ int hid_add_device(struct hid_device *hdev)
43383 /* XXX hack, any other cleaner solution after the driver core
43384 * is converted to allow more than 20 bytes as the device name? */
43385 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
43386 - hdev->vendor, hdev->product, atomic_inc_return(&id));
43387 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
43388
43389 hid_debug_register(hdev, dev_name(&hdev->dev));
43390 ret = device_add(&hdev->dev);
43391 diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
43392 index ecc2cbf..29a74c1 100644
43393 --- a/drivers/hid/hid-magicmouse.c
43394 +++ b/drivers/hid/hid-magicmouse.c
43395 @@ -290,6 +290,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43396 if (size < 4 || ((size - 4) % 9) != 0)
43397 return 0;
43398 npoints = (size - 4) / 9;
43399 + if (npoints > 15) {
43400 + hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
43401 + size);
43402 + return 0;
43403 + }
43404 msc->ntouches = 0;
43405 for (ii = 0; ii < npoints; ii++)
43406 magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
43407 @@ -307,6 +312,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
43408 if (size < 6 || ((size - 6) % 8) != 0)
43409 return 0;
43410 npoints = (size - 6) / 8;
43411 + if (npoints > 15) {
43412 + hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
43413 + size);
43414 + return 0;
43415 + }
43416 msc->ntouches = 0;
43417 for (ii = 0; ii < npoints; ii++)
43418 magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
43419 diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
43420 index acbb0210..020df3c 100644
43421 --- a/drivers/hid/hid-picolcd_core.c
43422 +++ b/drivers/hid/hid-picolcd_core.c
43423 @@ -350,6 +350,12 @@ static int picolcd_raw_event(struct hid_device *hdev,
43424 if (!data)
43425 return 1;
43426
43427 + if (size > 64) {
43428 + hid_warn(hdev, "invalid size value (%d) for picolcd raw event\n",
43429 + size);
43430 + return 0;
43431 + }
43432 +
43433 if (report->id == REPORT_KEY_STATE) {
43434 if (data->input_keys)
43435 ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
43436 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
43437 index c13fb5b..55a3802 100644
43438 --- a/drivers/hid/hid-wiimote-debug.c
43439 +++ b/drivers/hid/hid-wiimote-debug.c
43440 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
43441 else if (size == 0)
43442 return -EIO;
43443
43444 - if (copy_to_user(u, buf, size))
43445 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
43446 return -EFAULT;
43447
43448 *off += size;
43449 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
43450 index 0cb92e3..c7d453d 100644
43451 --- a/drivers/hid/uhid.c
43452 +++ b/drivers/hid/uhid.c
43453 @@ -47,7 +47,7 @@ struct uhid_device {
43454 struct mutex report_lock;
43455 wait_queue_head_t report_wait;
43456 atomic_t report_done;
43457 - atomic_t report_id;
43458 + atomic_unchecked_t report_id;
43459 struct uhid_event report_buf;
43460 };
43461
43462 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
43463
43464 spin_lock_irqsave(&uhid->qlock, flags);
43465 ev->type = UHID_FEATURE;
43466 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
43467 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
43468 ev->u.feature.rnum = rnum;
43469 ev->u.feature.rtype = report_type;
43470
43471 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
43472 spin_lock_irqsave(&uhid->qlock, flags);
43473
43474 /* id for old report; drop it silently */
43475 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
43476 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
43477 goto unlock;
43478 if (atomic_read(&uhid->report_done))
43479 goto unlock;
43480 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
43481 index 284cf66..084c627 100644
43482 --- a/drivers/hv/channel.c
43483 +++ b/drivers/hv/channel.c
43484 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
43485 int ret = 0;
43486 int t;
43487
43488 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
43489 - atomic_inc(&vmbus_connection.next_gpadl_handle);
43490 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
43491 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
43492
43493 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
43494 if (ret)
43495 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
43496 index edfc848..d83e195 100644
43497 --- a/drivers/hv/hv.c
43498 +++ b/drivers/hv/hv.c
43499 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
43500 u64 output_address = (output) ? virt_to_phys(output) : 0;
43501 u32 output_address_hi = output_address >> 32;
43502 u32 output_address_lo = output_address & 0xFFFFFFFF;
43503 - void *hypercall_page = hv_context.hypercall_page;
43504 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
43505
43506 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
43507 "=a"(hv_status_lo) : "d" (control_hi),
43508 @@ -154,7 +154,7 @@ int hv_init(void)
43509 /* See if the hypercall page is already set */
43510 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
43511
43512 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
43513 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
43514
43515 if (!virtaddr)
43516 goto cleanup;
43517 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
43518 index 5e90c5d..d8fcefb 100644
43519 --- a/drivers/hv/hv_balloon.c
43520 +++ b/drivers/hv/hv_balloon.c
43521 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
43522
43523 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
43524 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
43525 -static atomic_t trans_id = ATOMIC_INIT(0);
43526 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
43527
43528 static int dm_ring_size = (5 * PAGE_SIZE);
43529
43530 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
43531 pr_info("Memory hot add failed\n");
43532
43533 dm->state = DM_INITIALIZED;
43534 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43535 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43536 vmbus_sendpacket(dm->dev->channel, &resp,
43537 sizeof(struct dm_hot_add_response),
43538 (unsigned long)NULL,
43539 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
43540 memset(&status, 0, sizeof(struct dm_status));
43541 status.hdr.type = DM_STATUS_REPORT;
43542 status.hdr.size = sizeof(struct dm_status);
43543 - status.hdr.trans_id = atomic_inc_return(&trans_id);
43544 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43545
43546 /*
43547 * The host expects the guest to report free memory.
43548 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
43549 * send the status. This can happen if we were interrupted
43550 * after we picked our transaction ID.
43551 */
43552 - if (status.hdr.trans_id != atomic_read(&trans_id))
43553 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
43554 return;
43555
43556 /*
43557 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
43558 */
43559
43560 do {
43561 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
43562 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43563 ret = vmbus_sendpacket(dm_device.dev->channel,
43564 bl_resp,
43565 bl_resp->hdr.size,
43566 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
43567
43568 memset(&resp, 0, sizeof(struct dm_unballoon_response));
43569 resp.hdr.type = DM_UNBALLOON_RESPONSE;
43570 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
43571 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43572 resp.hdr.size = sizeof(struct dm_unballoon_response);
43573
43574 vmbus_sendpacket(dm_device.dev->channel, &resp,
43575 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
43576 memset(&version_req, 0, sizeof(struct dm_version_request));
43577 version_req.hdr.type = DM_VERSION_REQUEST;
43578 version_req.hdr.size = sizeof(struct dm_version_request);
43579 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43580 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43581 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
43582 version_req.is_last_attempt = 1;
43583
43584 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
43585 memset(&version_req, 0, sizeof(struct dm_version_request));
43586 version_req.hdr.type = DM_VERSION_REQUEST;
43587 version_req.hdr.size = sizeof(struct dm_version_request);
43588 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
43589 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43590 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
43591 version_req.is_last_attempt = 0;
43592
43593 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
43594 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
43595 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
43596 cap_msg.hdr.size = sizeof(struct dm_capabilities);
43597 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
43598 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
43599
43600 cap_msg.caps.cap_bits.balloon = 1;
43601 cap_msg.caps.cap_bits.hot_add = 1;
43602 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
43603 index 22b7507..fc2fc47 100644
43604 --- a/drivers/hv/hyperv_vmbus.h
43605 +++ b/drivers/hv/hyperv_vmbus.h
43606 @@ -607,7 +607,7 @@ enum vmbus_connect_state {
43607 struct vmbus_connection {
43608 enum vmbus_connect_state conn_state;
43609
43610 - atomic_t next_gpadl_handle;
43611 + atomic_unchecked_t next_gpadl_handle;
43612
43613 /*
43614 * Represents channel interrupts. Each bit position represents a
43615 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
43616 index 4d6b269..2e23b86 100644
43617 --- a/drivers/hv/vmbus_drv.c
43618 +++ b/drivers/hv/vmbus_drv.c
43619 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
43620 {
43621 int ret = 0;
43622
43623 - static atomic_t device_num = ATOMIC_INIT(0);
43624 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
43625
43626 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
43627 - atomic_inc_return(&device_num));
43628 + atomic_inc_return_unchecked(&device_num));
43629
43630 child_device_obj->device.bus = &hv_bus;
43631 child_device_obj->device.parent = &hv_acpi_dev->dev;
43632 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
43633 index 579bdf9..75118b5 100644
43634 --- a/drivers/hwmon/acpi_power_meter.c
43635 +++ b/drivers/hwmon/acpi_power_meter.c
43636 @@ -116,7 +116,7 @@ struct sensor_template {
43637 struct device_attribute *devattr,
43638 const char *buf, size_t count);
43639 int index;
43640 -};
43641 +} __do_const;
43642
43643 /* Averaging interval */
43644 static int update_avg_interval(struct acpi_power_meter_resource *resource)
43645 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
43646 struct sensor_template *attrs)
43647 {
43648 struct device *dev = &resource->acpi_dev->dev;
43649 - struct sensor_device_attribute *sensors =
43650 + sensor_device_attribute_no_const *sensors =
43651 &resource->sensors[resource->num_sensors];
43652 int res = 0;
43653
43654 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
43655 index 3288f13..71cfb4e 100644
43656 --- a/drivers/hwmon/applesmc.c
43657 +++ b/drivers/hwmon/applesmc.c
43658 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
43659 {
43660 struct applesmc_node_group *grp;
43661 struct applesmc_dev_attr *node;
43662 - struct attribute *attr;
43663 + attribute_no_const *attr;
43664 int ret, i;
43665
43666 for (grp = groups; grp->format; grp++) {
43667 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
43668 index ae208f6..48b6c5b 100644
43669 --- a/drivers/hwmon/asus_atk0110.c
43670 +++ b/drivers/hwmon/asus_atk0110.c
43671 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
43672 struct atk_sensor_data {
43673 struct list_head list;
43674 struct atk_data *data;
43675 - struct device_attribute label_attr;
43676 - struct device_attribute input_attr;
43677 - struct device_attribute limit1_attr;
43678 - struct device_attribute limit2_attr;
43679 + device_attribute_no_const label_attr;
43680 + device_attribute_no_const input_attr;
43681 + device_attribute_no_const limit1_attr;
43682 + device_attribute_no_const limit2_attr;
43683 char label_attr_name[ATTR_NAME_SIZE];
43684 char input_attr_name[ATTR_NAME_SIZE];
43685 char limit1_attr_name[ATTR_NAME_SIZE];
43686 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
43687 static struct device_attribute atk_name_attr =
43688 __ATTR(name, 0444, atk_name_show, NULL);
43689
43690 -static void atk_init_attribute(struct device_attribute *attr, char *name,
43691 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
43692 sysfs_show_func show)
43693 {
43694 sysfs_attr_init(&attr->attr);
43695 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
43696 index d76f0b7..55ae976 100644
43697 --- a/drivers/hwmon/coretemp.c
43698 +++ b/drivers/hwmon/coretemp.c
43699 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
43700 return NOTIFY_OK;
43701 }
43702
43703 -static struct notifier_block coretemp_cpu_notifier __refdata = {
43704 +static struct notifier_block coretemp_cpu_notifier = {
43705 .notifier_call = coretemp_cpu_callback,
43706 };
43707
43708 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43709 index 632f1dc..57e6a58 100644
43710 --- a/drivers/hwmon/ibmaem.c
43711 +++ b/drivers/hwmon/ibmaem.c
43712 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
43713 struct aem_rw_sensor_template *rw)
43714 {
43715 struct device *dev = &data->pdev->dev;
43716 - struct sensor_device_attribute *sensors = data->sensors;
43717 + sensor_device_attribute_no_const *sensors = data->sensors;
43718 int err;
43719
43720 /* Set up read-only sensors */
43721 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43722 index 14c82da..09b25d7 100644
43723 --- a/drivers/hwmon/iio_hwmon.c
43724 +++ b/drivers/hwmon/iio_hwmon.c
43725 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43726 {
43727 struct device *dev = &pdev->dev;
43728 struct iio_hwmon_state *st;
43729 - struct sensor_device_attribute *a;
43730 + sensor_device_attribute_no_const *a;
43731 int ret, i;
43732 int in_i = 1, temp_i = 1, curr_i = 1;
43733 enum iio_chan_type type;
43734 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43735 index 7710f46..427a28d 100644
43736 --- a/drivers/hwmon/nct6683.c
43737 +++ b/drivers/hwmon/nct6683.c
43738 @@ -397,11 +397,11 @@ static struct attribute_group *
43739 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43740 int repeat)
43741 {
43742 - struct sensor_device_attribute_2 *a2;
43743 - struct sensor_device_attribute *a;
43744 + sensor_device_attribute_2_no_const *a2;
43745 + sensor_device_attribute_no_const *a;
43746 struct sensor_device_template **t;
43747 struct sensor_device_attr_u *su;
43748 - struct attribute_group *group;
43749 + attribute_group_no_const *group;
43750 struct attribute **attrs;
43751 int i, j, count;
43752
43753 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43754 index 59d9a3f..2298fa4 100644
43755 --- a/drivers/hwmon/nct6775.c
43756 +++ b/drivers/hwmon/nct6775.c
43757 @@ -944,10 +944,10 @@ static struct attribute_group *
43758 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43759 int repeat)
43760 {
43761 - struct attribute_group *group;
43762 + attribute_group_no_const *group;
43763 struct sensor_device_attr_u *su;
43764 - struct sensor_device_attribute *a;
43765 - struct sensor_device_attribute_2 *a2;
43766 + sensor_device_attribute_no_const *a;
43767 + sensor_device_attribute_2_no_const *a2;
43768 struct attribute **attrs;
43769 struct sensor_device_template **t;
43770 int i, count;
43771 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43772 index 291d11f..3f0dbbd 100644
43773 --- a/drivers/hwmon/pmbus/pmbus_core.c
43774 +++ b/drivers/hwmon/pmbus/pmbus_core.c
43775 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43776 return 0;
43777 }
43778
43779 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43780 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43781 const char *name,
43782 umode_t mode,
43783 ssize_t (*show)(struct device *dev,
43784 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43785 dev_attr->store = store;
43786 }
43787
43788 -static void pmbus_attr_init(struct sensor_device_attribute *a,
43789 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43790 const char *name,
43791 umode_t mode,
43792 ssize_t (*show)(struct device *dev,
43793 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43794 u16 reg, u8 mask)
43795 {
43796 struct pmbus_boolean *boolean;
43797 - struct sensor_device_attribute *a;
43798 + sensor_device_attribute_no_const *a;
43799
43800 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43801 if (!boolean)
43802 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43803 bool update, bool readonly)
43804 {
43805 struct pmbus_sensor *sensor;
43806 - struct device_attribute *a;
43807 + device_attribute_no_const *a;
43808
43809 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43810 if (!sensor)
43811 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43812 const char *lstring, int index)
43813 {
43814 struct pmbus_label *label;
43815 - struct device_attribute *a;
43816 + device_attribute_no_const *a;
43817
43818 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43819 if (!label)
43820 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43821 index 97cd45a..ac54d8b 100644
43822 --- a/drivers/hwmon/sht15.c
43823 +++ b/drivers/hwmon/sht15.c
43824 @@ -169,7 +169,7 @@ struct sht15_data {
43825 int supply_uv;
43826 bool supply_uv_valid;
43827 struct work_struct update_supply_work;
43828 - atomic_t interrupt_handled;
43829 + atomic_unchecked_t interrupt_handled;
43830 };
43831
43832 /**
43833 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43834 ret = gpio_direction_input(data->pdata->gpio_data);
43835 if (ret)
43836 return ret;
43837 - atomic_set(&data->interrupt_handled, 0);
43838 + atomic_set_unchecked(&data->interrupt_handled, 0);
43839
43840 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43841 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43842 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43843 /* Only relevant if the interrupt hasn't occurred. */
43844 - if (!atomic_read(&data->interrupt_handled))
43845 + if (!atomic_read_unchecked(&data->interrupt_handled))
43846 schedule_work(&data->read_work);
43847 }
43848 ret = wait_event_timeout(data->wait_queue,
43849 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43850
43851 /* First disable the interrupt */
43852 disable_irq_nosync(irq);
43853 - atomic_inc(&data->interrupt_handled);
43854 + atomic_inc_unchecked(&data->interrupt_handled);
43855 /* Then schedule a reading work struct */
43856 if (data->state != SHT15_READING_NOTHING)
43857 schedule_work(&data->read_work);
43858 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43859 * If not, then start the interrupt again - care here as could
43860 * have gone low in meantime so verify it hasn't!
43861 */
43862 - atomic_set(&data->interrupt_handled, 0);
43863 + atomic_set_unchecked(&data->interrupt_handled, 0);
43864 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43865 /* If still not occurred or another handler was scheduled */
43866 if (gpio_get_value(data->pdata->gpio_data)
43867 - || atomic_read(&data->interrupt_handled))
43868 + || atomic_read_unchecked(&data->interrupt_handled))
43869 return;
43870 }
43871
43872 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43873 index 8df43c5..b07b91d 100644
43874 --- a/drivers/hwmon/via-cputemp.c
43875 +++ b/drivers/hwmon/via-cputemp.c
43876 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43877 return NOTIFY_OK;
43878 }
43879
43880 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43881 +static struct notifier_block via_cputemp_cpu_notifier = {
43882 .notifier_call = via_cputemp_cpu_callback,
43883 };
43884
43885 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43886 index 41fc683..a39cfea 100644
43887 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
43888 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43889 @@ -43,7 +43,7 @@
43890 extern struct i2c_adapter amd756_smbus;
43891
43892 static struct i2c_adapter *s4882_adapter;
43893 -static struct i2c_algorithm *s4882_algo;
43894 +static i2c_algorithm_no_const *s4882_algo;
43895
43896 /* Wrapper access functions for multiplexed SMBus */
43897 static DEFINE_MUTEX(amd756_lock);
43898 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43899 index b19a310..d6eece0 100644
43900 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
43901 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43902 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43903 /* usb layer */
43904
43905 /* Send command to device, and get response. */
43906 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43907 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43908 {
43909 int ret = 0;
43910 int actual;
43911 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43912 index b170bdf..3c76427 100644
43913 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43914 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43915 @@ -41,7 +41,7 @@
43916 extern struct i2c_adapter *nforce2_smbus;
43917
43918 static struct i2c_adapter *s4985_adapter;
43919 -static struct i2c_algorithm *s4985_algo;
43920 +static i2c_algorithm_no_const *s4985_algo;
43921
43922 /* Wrapper access functions for multiplexed SMBus */
43923 static DEFINE_MUTEX(nforce2_lock);
43924 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43925 index 80b47e8..1a6040d9 100644
43926 --- a/drivers/i2c/i2c-dev.c
43927 +++ b/drivers/i2c/i2c-dev.c
43928 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43929 break;
43930 }
43931
43932 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43933 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43934 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43935 if (IS_ERR(rdwr_pa[i].buf)) {
43936 res = PTR_ERR(rdwr_pa[i].buf);
43937 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43938 index 0b510ba..4fbb5085 100644
43939 --- a/drivers/ide/ide-cd.c
43940 +++ b/drivers/ide/ide-cd.c
43941 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43942 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43943 if ((unsigned long)buf & alignment
43944 || blk_rq_bytes(rq) & q->dma_pad_mask
43945 - || object_is_on_stack(buf))
43946 + || object_starts_on_stack(buf))
43947 drive->dma = 0;
43948 }
43949 }
43950 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43951 index 4b1f375..770b95f 100644
43952 --- a/drivers/iio/industrialio-core.c
43953 +++ b/drivers/iio/industrialio-core.c
43954 @@ -551,7 +551,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43955 }
43956
43957 static
43958 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43959 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43960 const char *postfix,
43961 struct iio_chan_spec const *chan,
43962 ssize_t (*readfunc)(struct device *dev,
43963 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43964 index c323917..6ddea8b 100644
43965 --- a/drivers/infiniband/core/cm.c
43966 +++ b/drivers/infiniband/core/cm.c
43967 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43968
43969 struct cm_counter_group {
43970 struct kobject obj;
43971 - atomic_long_t counter[CM_ATTR_COUNT];
43972 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43973 };
43974
43975 struct cm_counter_attribute {
43976 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43977 struct ib_mad_send_buf *msg = NULL;
43978 int ret;
43979
43980 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43981 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43982 counter[CM_REQ_COUNTER]);
43983
43984 /* Quick state check to discard duplicate REQs. */
43985 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43986 if (!cm_id_priv)
43987 return;
43988
43989 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43990 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43991 counter[CM_REP_COUNTER]);
43992 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43993 if (ret)
43994 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43995 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43996 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43997 spin_unlock_irq(&cm_id_priv->lock);
43998 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43999 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44000 counter[CM_RTU_COUNTER]);
44001 goto out;
44002 }
44003 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
44004 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
44005 dreq_msg->local_comm_id);
44006 if (!cm_id_priv) {
44007 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44008 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44009 counter[CM_DREQ_COUNTER]);
44010 cm_issue_drep(work->port, work->mad_recv_wc);
44011 return -EINVAL;
44012 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
44013 case IB_CM_MRA_REP_RCVD:
44014 break;
44015 case IB_CM_TIMEWAIT:
44016 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44017 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44018 counter[CM_DREQ_COUNTER]);
44019 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
44020 goto unlock;
44021 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
44022 cm_free_msg(msg);
44023 goto deref;
44024 case IB_CM_DREQ_RCVD:
44025 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44026 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44027 counter[CM_DREQ_COUNTER]);
44028 goto unlock;
44029 default:
44030 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
44031 ib_modify_mad(cm_id_priv->av.port->mad_agent,
44032 cm_id_priv->msg, timeout)) {
44033 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
44034 - atomic_long_inc(&work->port->
44035 + atomic_long_inc_unchecked(&work->port->
44036 counter_group[CM_RECV_DUPLICATES].
44037 counter[CM_MRA_COUNTER]);
44038 goto out;
44039 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
44040 break;
44041 case IB_CM_MRA_REQ_RCVD:
44042 case IB_CM_MRA_REP_RCVD:
44043 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44044 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44045 counter[CM_MRA_COUNTER]);
44046 /* fall through */
44047 default:
44048 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
44049 case IB_CM_LAP_IDLE:
44050 break;
44051 case IB_CM_MRA_LAP_SENT:
44052 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44053 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44054 counter[CM_LAP_COUNTER]);
44055 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
44056 goto unlock;
44057 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
44058 cm_free_msg(msg);
44059 goto deref;
44060 case IB_CM_LAP_RCVD:
44061 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44062 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44063 counter[CM_LAP_COUNTER]);
44064 goto unlock;
44065 default:
44066 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
44067 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
44068 if (cur_cm_id_priv) {
44069 spin_unlock_irq(&cm.lock);
44070 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
44071 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
44072 counter[CM_SIDR_REQ_COUNTER]);
44073 goto out; /* Duplicate message. */
44074 }
44075 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
44076 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
44077 msg->retries = 1;
44078
44079 - atomic_long_add(1 + msg->retries,
44080 + atomic_long_add_unchecked(1 + msg->retries,
44081 &port->counter_group[CM_XMIT].counter[attr_index]);
44082 if (msg->retries)
44083 - atomic_long_add(msg->retries,
44084 + atomic_long_add_unchecked(msg->retries,
44085 &port->counter_group[CM_XMIT_RETRIES].
44086 counter[attr_index]);
44087
44088 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
44089 }
44090
44091 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
44092 - atomic_long_inc(&port->counter_group[CM_RECV].
44093 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
44094 counter[attr_id - CM_ATTR_ID_OFFSET]);
44095
44096 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
44097 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
44098 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
44099
44100 return sprintf(buf, "%ld\n",
44101 - atomic_long_read(&group->counter[cm_attr->index]));
44102 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
44103 }
44104
44105 static const struct sysfs_ops cm_counter_ops = {
44106 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
44107 index 9f5ad7c..588cd84 100644
44108 --- a/drivers/infiniband/core/fmr_pool.c
44109 +++ b/drivers/infiniband/core/fmr_pool.c
44110 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
44111
44112 struct task_struct *thread;
44113
44114 - atomic_t req_ser;
44115 - atomic_t flush_ser;
44116 + atomic_unchecked_t req_ser;
44117 + atomic_unchecked_t flush_ser;
44118
44119 wait_queue_head_t force_wait;
44120 };
44121 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44122 struct ib_fmr_pool *pool = pool_ptr;
44123
44124 do {
44125 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
44126 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
44127 ib_fmr_batch_release(pool);
44128
44129 - atomic_inc(&pool->flush_ser);
44130 + atomic_inc_unchecked(&pool->flush_ser);
44131 wake_up_interruptible(&pool->force_wait);
44132
44133 if (pool->flush_function)
44134 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
44135 }
44136
44137 set_current_state(TASK_INTERRUPTIBLE);
44138 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
44139 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
44140 !kthread_should_stop())
44141 schedule();
44142 __set_current_state(TASK_RUNNING);
44143 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
44144 pool->dirty_watermark = params->dirty_watermark;
44145 pool->dirty_len = 0;
44146 spin_lock_init(&pool->pool_lock);
44147 - atomic_set(&pool->req_ser, 0);
44148 - atomic_set(&pool->flush_ser, 0);
44149 + atomic_set_unchecked(&pool->req_ser, 0);
44150 + atomic_set_unchecked(&pool->flush_ser, 0);
44151 init_waitqueue_head(&pool->force_wait);
44152
44153 pool->thread = kthread_run(ib_fmr_cleanup_thread,
44154 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
44155 }
44156 spin_unlock_irq(&pool->pool_lock);
44157
44158 - serial = atomic_inc_return(&pool->req_ser);
44159 + serial = atomic_inc_return_unchecked(&pool->req_ser);
44160 wake_up_process(pool->thread);
44161
44162 if (wait_event_interruptible(pool->force_wait,
44163 - atomic_read(&pool->flush_ser) - serial >= 0))
44164 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
44165 return -EINTR;
44166
44167 return 0;
44168 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
44169 } else {
44170 list_add_tail(&fmr->list, &pool->dirty_list);
44171 if (++pool->dirty_len >= pool->dirty_watermark) {
44172 - atomic_inc(&pool->req_ser);
44173 + atomic_inc_unchecked(&pool->req_ser);
44174 wake_up_process(pool->thread);
44175 }
44176 }
44177 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
44178 index ec7a298..8742e59 100644
44179 --- a/drivers/infiniband/hw/cxgb4/mem.c
44180 +++ b/drivers/infiniband/hw/cxgb4/mem.c
44181 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44182 int err;
44183 struct fw_ri_tpte tpt;
44184 u32 stag_idx;
44185 - static atomic_t key;
44186 + static atomic_unchecked_t key;
44187
44188 if (c4iw_fatal_error(rdev))
44189 return -EIO;
44190 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
44191 if (rdev->stats.stag.cur > rdev->stats.stag.max)
44192 rdev->stats.stag.max = rdev->stats.stag.cur;
44193 mutex_unlock(&rdev->stats.lock);
44194 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
44195 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
44196 }
44197 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
44198 __func__, stag_state, type, pdid, stag_idx);
44199 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
44200 index 79b3dbc..96e5fcc 100644
44201 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
44202 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
44203 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44204 struct ib_atomic_eth *ateth;
44205 struct ipath_ack_entry *e;
44206 u64 vaddr;
44207 - atomic64_t *maddr;
44208 + atomic64_unchecked_t *maddr;
44209 u64 sdata;
44210 u32 rkey;
44211 u8 next;
44212 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
44213 IB_ACCESS_REMOTE_ATOMIC)))
44214 goto nack_acc_unlck;
44215 /* Perform atomic OP and save result. */
44216 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44217 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44218 sdata = be64_to_cpu(ateth->swap_data);
44219 e = &qp->s_ack_queue[qp->r_head_ack_queue];
44220 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
44221 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44222 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44223 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44224 be64_to_cpu(ateth->compare_data),
44225 sdata);
44226 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
44227 index 1f95bba..9530f87 100644
44228 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
44229 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
44230 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
44231 unsigned long flags;
44232 struct ib_wc wc;
44233 u64 sdata;
44234 - atomic64_t *maddr;
44235 + atomic64_unchecked_t *maddr;
44236 enum ib_wc_status send_status;
44237
44238 /*
44239 @@ -382,11 +382,11 @@ again:
44240 IB_ACCESS_REMOTE_ATOMIC)))
44241 goto acc_err;
44242 /* Perform atomic OP and save result. */
44243 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
44244 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
44245 sdata = wqe->wr.wr.atomic.compare_add;
44246 *(u64 *) sqp->s_sge.sge.vaddr =
44247 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
44248 - (u64) atomic64_add_return(sdata, maddr) - sdata :
44249 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
44250 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
44251 sdata, wqe->wr.wr.atomic.swap);
44252 goto send_comp;
44253 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
44254 index 287ad05..5ae7b44d 100644
44255 --- a/drivers/infiniband/hw/mlx4/mad.c
44256 +++ b/drivers/infiniband/hw/mlx4/mad.c
44257 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
44258
44259 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
44260 {
44261 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
44262 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
44263 cpu_to_be64(0xff00000000000000LL);
44264 }
44265
44266 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
44267 index ed327e6..ca1739e0 100644
44268 --- a/drivers/infiniband/hw/mlx4/mcg.c
44269 +++ b/drivers/infiniband/hw/mlx4/mcg.c
44270 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
44271 {
44272 char name[20];
44273
44274 - atomic_set(&ctx->tid, 0);
44275 + atomic_set_unchecked(&ctx->tid, 0);
44276 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
44277 ctx->mcg_wq = create_singlethread_workqueue(name);
44278 if (!ctx->mcg_wq)
44279 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44280 index 369da3c..223e6e9 100644
44281 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
44282 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
44283 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
44284 struct list_head mcg_mgid0_list;
44285 struct workqueue_struct *mcg_wq;
44286 struct mlx4_ib_demux_pv_ctx **tun;
44287 - atomic_t tid;
44288 + atomic_unchecked_t tid;
44289 int flushing; /* flushing the work queue */
44290 };
44291
44292 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
44293 index 9d3e5c1..6f166df 100644
44294 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
44295 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
44296 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
44297 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
44298 }
44299
44300 -int mthca_QUERY_FW(struct mthca_dev *dev)
44301 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
44302 {
44303 struct mthca_mailbox *mailbox;
44304 u32 *outbox;
44305 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44306 CMD_TIME_CLASS_B);
44307 }
44308
44309 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44310 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44311 int num_mtt)
44312 {
44313 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
44314 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
44315 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
44316 }
44317
44318 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44319 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
44320 int eq_num)
44321 {
44322 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
44323 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
44324 CMD_TIME_CLASS_B);
44325 }
44326
44327 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44328 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
44329 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
44330 void *in_mad, void *response_mad)
44331 {
44332 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
44333 index ded76c1..0cf0a08 100644
44334 --- a/drivers/infiniband/hw/mthca/mthca_main.c
44335 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
44336 @@ -692,7 +692,7 @@ err_close:
44337 return err;
44338 }
44339
44340 -static int mthca_setup_hca(struct mthca_dev *dev)
44341 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
44342 {
44343 int err;
44344
44345 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
44346 index ed9a989..6aa5dc2 100644
44347 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
44348 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
44349 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
44350 * through the bitmaps)
44351 */
44352
44353 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44354 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
44355 {
44356 int o;
44357 int m;
44358 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
44359 return key;
44360 }
44361
44362 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44363 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
44364 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
44365 {
44366 struct mthca_mailbox *mailbox;
44367 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
44368 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
44369 }
44370
44371 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44372 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
44373 u64 *buffer_list, int buffer_size_shift,
44374 int list_len, u64 iova, u64 total_size,
44375 u32 access, struct mthca_mr *mr)
44376 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
44377 index 415f8e1..e34214e 100644
44378 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
44379 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
44380 @@ -764,7 +764,7 @@ unlock:
44381 return 0;
44382 }
44383
44384 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44385 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
44386 {
44387 struct mthca_dev *dev = to_mdev(ibcq->device);
44388 struct mthca_cq *cq = to_mcq(ibcq);
44389 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
44390 index 3b2a6dc..bce26ff 100644
44391 --- a/drivers/infiniband/hw/nes/nes.c
44392 +++ b/drivers/infiniband/hw/nes/nes.c
44393 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
44394 LIST_HEAD(nes_adapter_list);
44395 static LIST_HEAD(nes_dev_list);
44396
44397 -atomic_t qps_destroyed;
44398 +atomic_unchecked_t qps_destroyed;
44399
44400 static unsigned int ee_flsh_adapter;
44401 static unsigned int sysfs_nonidx_addr;
44402 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
44403 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
44404 struct nes_adapter *nesadapter = nesdev->nesadapter;
44405
44406 - atomic_inc(&qps_destroyed);
44407 + atomic_inc_unchecked(&qps_destroyed);
44408
44409 /* Free the control structures */
44410
44411 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
44412 index bd9d132..70d84f4 100644
44413 --- a/drivers/infiniband/hw/nes/nes.h
44414 +++ b/drivers/infiniband/hw/nes/nes.h
44415 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
44416 extern unsigned int wqm_quanta;
44417 extern struct list_head nes_adapter_list;
44418
44419 -extern atomic_t cm_connects;
44420 -extern atomic_t cm_accepts;
44421 -extern atomic_t cm_disconnects;
44422 -extern atomic_t cm_closes;
44423 -extern atomic_t cm_connecteds;
44424 -extern atomic_t cm_connect_reqs;
44425 -extern atomic_t cm_rejects;
44426 -extern atomic_t mod_qp_timouts;
44427 -extern atomic_t qps_created;
44428 -extern atomic_t qps_destroyed;
44429 -extern atomic_t sw_qps_destroyed;
44430 +extern atomic_unchecked_t cm_connects;
44431 +extern atomic_unchecked_t cm_accepts;
44432 +extern atomic_unchecked_t cm_disconnects;
44433 +extern atomic_unchecked_t cm_closes;
44434 +extern atomic_unchecked_t cm_connecteds;
44435 +extern atomic_unchecked_t cm_connect_reqs;
44436 +extern atomic_unchecked_t cm_rejects;
44437 +extern atomic_unchecked_t mod_qp_timouts;
44438 +extern atomic_unchecked_t qps_created;
44439 +extern atomic_unchecked_t qps_destroyed;
44440 +extern atomic_unchecked_t sw_qps_destroyed;
44441 extern u32 mh_detected;
44442 extern u32 mh_pauses_sent;
44443 extern u32 cm_packets_sent;
44444 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
44445 extern u32 cm_packets_received;
44446 extern u32 cm_packets_dropped;
44447 extern u32 cm_packets_retrans;
44448 -extern atomic_t cm_listens_created;
44449 -extern atomic_t cm_listens_destroyed;
44450 +extern atomic_unchecked_t cm_listens_created;
44451 +extern atomic_unchecked_t cm_listens_destroyed;
44452 extern u32 cm_backlog_drops;
44453 -extern atomic_t cm_loopbacks;
44454 -extern atomic_t cm_nodes_created;
44455 -extern atomic_t cm_nodes_destroyed;
44456 -extern atomic_t cm_accel_dropped_pkts;
44457 -extern atomic_t cm_resets_recvd;
44458 -extern atomic_t pau_qps_created;
44459 -extern atomic_t pau_qps_destroyed;
44460 +extern atomic_unchecked_t cm_loopbacks;
44461 +extern atomic_unchecked_t cm_nodes_created;
44462 +extern atomic_unchecked_t cm_nodes_destroyed;
44463 +extern atomic_unchecked_t cm_accel_dropped_pkts;
44464 +extern atomic_unchecked_t cm_resets_recvd;
44465 +extern atomic_unchecked_t pau_qps_created;
44466 +extern atomic_unchecked_t pau_qps_destroyed;
44467
44468 extern u32 int_mod_timer_init;
44469 extern u32 int_mod_cq_depth_256;
44470 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
44471 index 6f09a72..cf4399d 100644
44472 --- a/drivers/infiniband/hw/nes/nes_cm.c
44473 +++ b/drivers/infiniband/hw/nes/nes_cm.c
44474 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
44475 u32 cm_packets_retrans;
44476 u32 cm_packets_created;
44477 u32 cm_packets_received;
44478 -atomic_t cm_listens_created;
44479 -atomic_t cm_listens_destroyed;
44480 +atomic_unchecked_t cm_listens_created;
44481 +atomic_unchecked_t cm_listens_destroyed;
44482 u32 cm_backlog_drops;
44483 -atomic_t cm_loopbacks;
44484 -atomic_t cm_nodes_created;
44485 -atomic_t cm_nodes_destroyed;
44486 -atomic_t cm_accel_dropped_pkts;
44487 -atomic_t cm_resets_recvd;
44488 +atomic_unchecked_t cm_loopbacks;
44489 +atomic_unchecked_t cm_nodes_created;
44490 +atomic_unchecked_t cm_nodes_destroyed;
44491 +atomic_unchecked_t cm_accel_dropped_pkts;
44492 +atomic_unchecked_t cm_resets_recvd;
44493
44494 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
44495 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
44496 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
44497 /* instance of function pointers for client API */
44498 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
44499 static struct nes_cm_ops nes_cm_api = {
44500 - mini_cm_accelerated,
44501 - mini_cm_listen,
44502 - mini_cm_del_listen,
44503 - mini_cm_connect,
44504 - mini_cm_close,
44505 - mini_cm_accept,
44506 - mini_cm_reject,
44507 - mini_cm_recv_pkt,
44508 - mini_cm_dealloc_core,
44509 - mini_cm_get,
44510 - mini_cm_set
44511 + .accelerated = mini_cm_accelerated,
44512 + .listen = mini_cm_listen,
44513 + .stop_listener = mini_cm_del_listen,
44514 + .connect = mini_cm_connect,
44515 + .close = mini_cm_close,
44516 + .accept = mini_cm_accept,
44517 + .reject = mini_cm_reject,
44518 + .recv_pkt = mini_cm_recv_pkt,
44519 + .destroy_cm_core = mini_cm_dealloc_core,
44520 + .get = mini_cm_get,
44521 + .set = mini_cm_set
44522 };
44523
44524 static struct nes_cm_core *g_cm_core;
44525
44526 -atomic_t cm_connects;
44527 -atomic_t cm_accepts;
44528 -atomic_t cm_disconnects;
44529 -atomic_t cm_closes;
44530 -atomic_t cm_connecteds;
44531 -atomic_t cm_connect_reqs;
44532 -atomic_t cm_rejects;
44533 +atomic_unchecked_t cm_connects;
44534 +atomic_unchecked_t cm_accepts;
44535 +atomic_unchecked_t cm_disconnects;
44536 +atomic_unchecked_t cm_closes;
44537 +atomic_unchecked_t cm_connecteds;
44538 +atomic_unchecked_t cm_connect_reqs;
44539 +atomic_unchecked_t cm_rejects;
44540
44541 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
44542 {
44543 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
44544 kfree(listener);
44545 listener = NULL;
44546 ret = 0;
44547 - atomic_inc(&cm_listens_destroyed);
44548 + atomic_inc_unchecked(&cm_listens_destroyed);
44549 } else {
44550 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
44551 }
44552 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
44553 cm_node->rem_mac);
44554
44555 add_hte_node(cm_core, cm_node);
44556 - atomic_inc(&cm_nodes_created);
44557 + atomic_inc_unchecked(&cm_nodes_created);
44558
44559 return cm_node;
44560 }
44561 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
44562 }
44563
44564 atomic_dec(&cm_core->node_cnt);
44565 - atomic_inc(&cm_nodes_destroyed);
44566 + atomic_inc_unchecked(&cm_nodes_destroyed);
44567 nesqp = cm_node->nesqp;
44568 if (nesqp) {
44569 nesqp->cm_node = NULL;
44570 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
44571
44572 static void drop_packet(struct sk_buff *skb)
44573 {
44574 - atomic_inc(&cm_accel_dropped_pkts);
44575 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44576 dev_kfree_skb_any(skb);
44577 }
44578
44579 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
44580 {
44581
44582 int reset = 0; /* whether to send reset in case of err.. */
44583 - atomic_inc(&cm_resets_recvd);
44584 + atomic_inc_unchecked(&cm_resets_recvd);
44585 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
44586 " refcnt=%d\n", cm_node, cm_node->state,
44587 atomic_read(&cm_node->ref_count));
44588 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
44589 rem_ref_cm_node(cm_node->cm_core, cm_node);
44590 return NULL;
44591 }
44592 - atomic_inc(&cm_loopbacks);
44593 + atomic_inc_unchecked(&cm_loopbacks);
44594 loopbackremotenode->loopbackpartner = cm_node;
44595 loopbackremotenode->tcp_cntxt.rcv_wscale =
44596 NES_CM_DEFAULT_RCV_WND_SCALE;
44597 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
44598 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
44599 else {
44600 rem_ref_cm_node(cm_core, cm_node);
44601 - atomic_inc(&cm_accel_dropped_pkts);
44602 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
44603 dev_kfree_skb_any(skb);
44604 }
44605 break;
44606 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44607
44608 if ((cm_id) && (cm_id->event_handler)) {
44609 if (issue_disconn) {
44610 - atomic_inc(&cm_disconnects);
44611 + atomic_inc_unchecked(&cm_disconnects);
44612 cm_event.event = IW_CM_EVENT_DISCONNECT;
44613 cm_event.status = disconn_status;
44614 cm_event.local_addr = cm_id->local_addr;
44615 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
44616 }
44617
44618 if (issue_close) {
44619 - atomic_inc(&cm_closes);
44620 + atomic_inc_unchecked(&cm_closes);
44621 nes_disconnect(nesqp, 1);
44622
44623 cm_id->provider_data = nesqp;
44624 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44625
44626 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
44627 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
44628 - atomic_inc(&cm_accepts);
44629 + atomic_inc_unchecked(&cm_accepts);
44630
44631 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
44632 netdev_refcnt_read(nesvnic->netdev));
44633 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
44634 struct nes_cm_core *cm_core;
44635 u8 *start_buff;
44636
44637 - atomic_inc(&cm_rejects);
44638 + atomic_inc_unchecked(&cm_rejects);
44639 cm_node = (struct nes_cm_node *)cm_id->provider_data;
44640 loopback = cm_node->loopbackpartner;
44641 cm_core = cm_node->cm_core;
44642 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
44643 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
44644 ntohs(laddr->sin_port));
44645
44646 - atomic_inc(&cm_connects);
44647 + atomic_inc_unchecked(&cm_connects);
44648 nesqp->active_conn = 1;
44649
44650 /* cache the cm_id in the qp */
44651 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
44652 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
44653 return err;
44654 }
44655 - atomic_inc(&cm_listens_created);
44656 + atomic_inc_unchecked(&cm_listens_created);
44657 }
44658
44659 cm_id->add_ref(cm_id);
44660 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
44661
44662 if (nesqp->destroyed)
44663 return;
44664 - atomic_inc(&cm_connecteds);
44665 + atomic_inc_unchecked(&cm_connecteds);
44666 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
44667 " local port 0x%04X. jiffies = %lu.\n",
44668 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
44669 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
44670
44671 cm_id->add_ref(cm_id);
44672 ret = cm_id->event_handler(cm_id, &cm_event);
44673 - atomic_inc(&cm_closes);
44674 + atomic_inc_unchecked(&cm_closes);
44675 cm_event.event = IW_CM_EVENT_CLOSE;
44676 cm_event.status = 0;
44677 cm_event.provider_data = cm_id->provider_data;
44678 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
44679 return;
44680 cm_id = cm_node->cm_id;
44681
44682 - atomic_inc(&cm_connect_reqs);
44683 + atomic_inc_unchecked(&cm_connect_reqs);
44684 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44685 cm_node, cm_id, jiffies);
44686
44687 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
44688 return;
44689 cm_id = cm_node->cm_id;
44690
44691 - atomic_inc(&cm_connect_reqs);
44692 + atomic_inc_unchecked(&cm_connect_reqs);
44693 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
44694 cm_node, cm_id, jiffies);
44695
44696 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
44697 index 4166452..fc952c3 100644
44698 --- a/drivers/infiniband/hw/nes/nes_mgt.c
44699 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
44700 @@ -40,8 +40,8 @@
44701 #include "nes.h"
44702 #include "nes_mgt.h"
44703
44704 -atomic_t pau_qps_created;
44705 -atomic_t pau_qps_destroyed;
44706 +atomic_unchecked_t pau_qps_created;
44707 +atomic_unchecked_t pau_qps_destroyed;
44708
44709 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44710 {
44711 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44712 {
44713 struct sk_buff *skb;
44714 unsigned long flags;
44715 - atomic_inc(&pau_qps_destroyed);
44716 + atomic_inc_unchecked(&pau_qps_destroyed);
44717
44718 /* Free packets that have not yet been forwarded */
44719 /* Lock is acquired by skb_dequeue when removing the skb */
44720 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44721 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44722 skb_queue_head_init(&nesqp->pau_list);
44723 spin_lock_init(&nesqp->pau_lock);
44724 - atomic_inc(&pau_qps_created);
44725 + atomic_inc_unchecked(&pau_qps_created);
44726 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44727 }
44728
44729 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44730 index 49eb511..a774366 100644
44731 --- a/drivers/infiniband/hw/nes/nes_nic.c
44732 +++ b/drivers/infiniband/hw/nes/nes_nic.c
44733 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44734 target_stat_values[++index] = mh_detected;
44735 target_stat_values[++index] = mh_pauses_sent;
44736 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44737 - target_stat_values[++index] = atomic_read(&cm_connects);
44738 - target_stat_values[++index] = atomic_read(&cm_accepts);
44739 - target_stat_values[++index] = atomic_read(&cm_disconnects);
44740 - target_stat_values[++index] = atomic_read(&cm_connecteds);
44741 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44742 - target_stat_values[++index] = atomic_read(&cm_rejects);
44743 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44744 - target_stat_values[++index] = atomic_read(&qps_created);
44745 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44746 - target_stat_values[++index] = atomic_read(&qps_destroyed);
44747 - target_stat_values[++index] = atomic_read(&cm_closes);
44748 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44749 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44750 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44751 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44752 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44753 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44754 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44755 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44756 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44757 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44758 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44759 target_stat_values[++index] = cm_packets_sent;
44760 target_stat_values[++index] = cm_packets_bounced;
44761 target_stat_values[++index] = cm_packets_created;
44762 target_stat_values[++index] = cm_packets_received;
44763 target_stat_values[++index] = cm_packets_dropped;
44764 target_stat_values[++index] = cm_packets_retrans;
44765 - target_stat_values[++index] = atomic_read(&cm_listens_created);
44766 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44767 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44768 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44769 target_stat_values[++index] = cm_backlog_drops;
44770 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
44771 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
44772 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44773 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44774 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44775 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44776 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44777 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44778 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44779 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44780 target_stat_values[++index] = nesadapter->free_4kpbl;
44781 target_stat_values[++index] = nesadapter->free_256pbl;
44782 target_stat_values[++index] = int_mod_timer_init;
44783 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44784 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44785 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44786 - target_stat_values[++index] = atomic_read(&pau_qps_created);
44787 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44788 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44789 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44790 }
44791
44792 /**
44793 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44794 index 218dd35..97ce31d 100644
44795 --- a/drivers/infiniband/hw/nes/nes_verbs.c
44796 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
44797 @@ -46,9 +46,9 @@
44798
44799 #include <rdma/ib_umem.h>
44800
44801 -atomic_t mod_qp_timouts;
44802 -atomic_t qps_created;
44803 -atomic_t sw_qps_destroyed;
44804 +atomic_unchecked_t mod_qp_timouts;
44805 +atomic_unchecked_t qps_created;
44806 +atomic_unchecked_t sw_qps_destroyed;
44807
44808 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44809
44810 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44811 if (init_attr->create_flags)
44812 return ERR_PTR(-EINVAL);
44813
44814 - atomic_inc(&qps_created);
44815 + atomic_inc_unchecked(&qps_created);
44816 switch (init_attr->qp_type) {
44817 case IB_QPT_RC:
44818 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44819 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44820 struct iw_cm_event cm_event;
44821 int ret = 0;
44822
44823 - atomic_inc(&sw_qps_destroyed);
44824 + atomic_inc_unchecked(&sw_qps_destroyed);
44825 nesqp->destroyed = 1;
44826
44827 /* Blow away the connection if it exists. */
44828 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44829 index c00ae09..04e91be 100644
44830 --- a/drivers/infiniband/hw/qib/qib.h
44831 +++ b/drivers/infiniband/hw/qib/qib.h
44832 @@ -52,6 +52,7 @@
44833 #include <linux/kref.h>
44834 #include <linux/sched.h>
44835 #include <linux/kthread.h>
44836 +#include <linux/slab.h>
44837
44838 #include "qib_common.h"
44839 #include "qib_verbs.h"
44840 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44841 index 24c41ba..102d71f 100644
44842 --- a/drivers/input/gameport/gameport.c
44843 +++ b/drivers/input/gameport/gameport.c
44844 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44845 */
44846 static void gameport_init_port(struct gameport *gameport)
44847 {
44848 - static atomic_t gameport_no = ATOMIC_INIT(0);
44849 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44850
44851 __module_get(THIS_MODULE);
44852
44853 mutex_init(&gameport->drv_mutex);
44854 device_initialize(&gameport->dev);
44855 dev_set_name(&gameport->dev, "gameport%lu",
44856 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
44857 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44858 gameport->dev.bus = &gameport_bus;
44859 gameport->dev.release = gameport_release_port;
44860 if (gameport->parent)
44861 diff --git a/drivers/input/input.c b/drivers/input/input.c
44862 index 29ca0bb..f4bc2e3 100644
44863 --- a/drivers/input/input.c
44864 +++ b/drivers/input/input.c
44865 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44866 */
44867 struct input_dev *input_allocate_device(void)
44868 {
44869 - static atomic_t input_no = ATOMIC_INIT(0);
44870 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44871 struct input_dev *dev;
44872
44873 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44874 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44875 INIT_LIST_HEAD(&dev->node);
44876
44877 dev_set_name(&dev->dev, "input%ld",
44878 - (unsigned long) atomic_inc_return(&input_no) - 1);
44879 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44880
44881 __module_get(THIS_MODULE);
44882 }
44883 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44884 index 4a95b22..874c182 100644
44885 --- a/drivers/input/joystick/sidewinder.c
44886 +++ b/drivers/input/joystick/sidewinder.c
44887 @@ -30,6 +30,7 @@
44888 #include <linux/kernel.h>
44889 #include <linux/module.h>
44890 #include <linux/slab.h>
44891 +#include <linux/sched.h>
44892 #include <linux/input.h>
44893 #include <linux/gameport.h>
44894 #include <linux/jiffies.h>
44895 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44896 index 603fe0d..f63decc 100644
44897 --- a/drivers/input/joystick/xpad.c
44898 +++ b/drivers/input/joystick/xpad.c
44899 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44900
44901 static int xpad_led_probe(struct usb_xpad *xpad)
44902 {
44903 - static atomic_t led_seq = ATOMIC_INIT(0);
44904 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44905 long led_no;
44906 struct xpad_led *led;
44907 struct led_classdev *led_cdev;
44908 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44909 if (!led)
44910 return -ENOMEM;
44911
44912 - led_no = (long)atomic_inc_return(&led_seq) - 1;
44913 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44914
44915 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44916 led->xpad = xpad;
44917 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44918 index 719410f..1896169 100644
44919 --- a/drivers/input/misc/ims-pcu.c
44920 +++ b/drivers/input/misc/ims-pcu.c
44921 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44922
44923 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44924 {
44925 - static atomic_t device_no = ATOMIC_INIT(0);
44926 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44927
44928 const struct ims_pcu_device_info *info;
44929 int error;
44930 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44931 }
44932
44933 /* Device appears to be operable, complete initialization */
44934 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44935 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44936
44937 /*
44938 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44939 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44940 index 2f0b39d..7370f13 100644
44941 --- a/drivers/input/mouse/psmouse.h
44942 +++ b/drivers/input/mouse/psmouse.h
44943 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44944 ssize_t (*set)(struct psmouse *psmouse, void *data,
44945 const char *buf, size_t count);
44946 bool protect;
44947 -};
44948 +} __do_const;
44949 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44950
44951 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44952 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44953 index b604564..3f14ae4 100644
44954 --- a/drivers/input/mousedev.c
44955 +++ b/drivers/input/mousedev.c
44956 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44957
44958 spin_unlock_irq(&client->packet_lock);
44959
44960 - if (copy_to_user(buffer, data, count))
44961 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44962 return -EFAULT;
44963
44964 return count;
44965 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44966 index b29134d..394deb0 100644
44967 --- a/drivers/input/serio/serio.c
44968 +++ b/drivers/input/serio/serio.c
44969 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44970 */
44971 static void serio_init_port(struct serio *serio)
44972 {
44973 - static atomic_t serio_no = ATOMIC_INIT(0);
44974 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44975
44976 __module_get(THIS_MODULE);
44977
44978 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44979 mutex_init(&serio->drv_mutex);
44980 device_initialize(&serio->dev);
44981 dev_set_name(&serio->dev, "serio%ld",
44982 - (long)atomic_inc_return(&serio_no) - 1);
44983 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44984 serio->dev.bus = &serio_bus;
44985 serio->dev.release = serio_release_port;
44986 serio->dev.groups = serio_device_attr_groups;
44987 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44988 index c9a02fe..0debc75 100644
44989 --- a/drivers/input/serio/serio_raw.c
44990 +++ b/drivers/input/serio/serio_raw.c
44991 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44992
44993 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44994 {
44995 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44996 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44997 struct serio_raw *serio_raw;
44998 int err;
44999
45000 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
45001 }
45002
45003 snprintf(serio_raw->name, sizeof(serio_raw->name),
45004 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
45005 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
45006 kref_init(&serio_raw->kref);
45007 INIT_LIST_HEAD(&serio_raw->client_list);
45008 init_waitqueue_head(&serio_raw->wait);
45009 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
45010 index e5555fc..937986d 100644
45011 --- a/drivers/iommu/iommu.c
45012 +++ b/drivers/iommu/iommu.c
45013 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
45014 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
45015 {
45016 bus_register_notifier(bus, &iommu_bus_nb);
45017 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
45018 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
45019 }
45020
45021 /**
45022 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
45023 index 33c4395..e06447e 100644
45024 --- a/drivers/iommu/irq_remapping.c
45025 +++ b/drivers/iommu/irq_remapping.c
45026 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
45027 void panic_if_irq_remap(const char *msg)
45028 {
45029 if (irq_remapping_enabled)
45030 - panic(msg);
45031 + panic("%s", msg);
45032 }
45033
45034 static void ir_ack_apic_edge(struct irq_data *data)
45035 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
45036
45037 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
45038 {
45039 - chip->irq_print_chip = ir_print_prefix;
45040 - chip->irq_ack = ir_ack_apic_edge;
45041 - chip->irq_eoi = ir_ack_apic_level;
45042 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
45043 + pax_open_kernel();
45044 + *(void **)&chip->irq_print_chip = ir_print_prefix;
45045 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
45046 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
45047 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
45048 + pax_close_kernel();
45049 }
45050
45051 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
45052 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
45053 index 7c131cf..035129b 100644
45054 --- a/drivers/irqchip/irq-gic.c
45055 +++ b/drivers/irqchip/irq-gic.c
45056 @@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
45057 * Supported arch specific GIC irq extension.
45058 * Default make them NULL.
45059 */
45060 -struct irq_chip gic_arch_extn = {
45061 +irq_chip_no_const gic_arch_extn = {
45062 .irq_eoi = NULL,
45063 .irq_mask = NULL,
45064 .irq_unmask = NULL,
45065 @@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
45066 chained_irq_exit(chip, desc);
45067 }
45068
45069 -static struct irq_chip gic_chip = {
45070 +static irq_chip_no_const gic_chip __read_only = {
45071 .name = "GIC",
45072 .irq_mask = gic_mask_irq,
45073 .irq_unmask = gic_unmask_irq,
45074 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
45075 index 8777065..a4a9967 100644
45076 --- a/drivers/irqchip/irq-renesas-irqc.c
45077 +++ b/drivers/irqchip/irq-renesas-irqc.c
45078 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
45079 struct irqc_priv *p;
45080 struct resource *io;
45081 struct resource *irq;
45082 - struct irq_chip *irq_chip;
45083 + irq_chip_no_const *irq_chip;
45084 const char *name = dev_name(&pdev->dev);
45085 int ret;
45086 int k;
45087 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
45088 index f9a87ed..3fdd854 100644
45089 --- a/drivers/isdn/capi/capi.c
45090 +++ b/drivers/isdn/capi/capi.c
45091 @@ -81,8 +81,8 @@ struct capiminor {
45092
45093 struct capi20_appl *ap;
45094 u32 ncci;
45095 - atomic_t datahandle;
45096 - atomic_t msgid;
45097 + atomic_unchecked_t datahandle;
45098 + atomic_unchecked_t msgid;
45099
45100 struct tty_port port;
45101 int ttyinstop;
45102 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
45103 capimsg_setu16(s, 2, mp->ap->applid);
45104 capimsg_setu8 (s, 4, CAPI_DATA_B3);
45105 capimsg_setu8 (s, 5, CAPI_RESP);
45106 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
45107 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
45108 capimsg_setu32(s, 8, mp->ncci);
45109 capimsg_setu16(s, 12, datahandle);
45110 }
45111 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
45112 mp->outbytes -= len;
45113 spin_unlock_bh(&mp->outlock);
45114
45115 - datahandle = atomic_inc_return(&mp->datahandle);
45116 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
45117 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
45118 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45119 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
45120 capimsg_setu16(skb->data, 2, mp->ap->applid);
45121 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
45122 capimsg_setu8 (skb->data, 5, CAPI_REQ);
45123 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
45124 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
45125 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
45126 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
45127 capimsg_setu16(skb->data, 16, len); /* Data length */
45128 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
45129 index b7ae0a0..04590fa 100644
45130 --- a/drivers/isdn/gigaset/bas-gigaset.c
45131 +++ b/drivers/isdn/gigaset/bas-gigaset.c
45132 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
45133
45134
45135 static const struct gigaset_ops gigops = {
45136 - gigaset_write_cmd,
45137 - gigaset_write_room,
45138 - gigaset_chars_in_buffer,
45139 - gigaset_brkchars,
45140 - gigaset_init_bchannel,
45141 - gigaset_close_bchannel,
45142 - gigaset_initbcshw,
45143 - gigaset_freebcshw,
45144 - gigaset_reinitbcshw,
45145 - gigaset_initcshw,
45146 - gigaset_freecshw,
45147 - gigaset_set_modem_ctrl,
45148 - gigaset_baud_rate,
45149 - gigaset_set_line_ctrl,
45150 - gigaset_isoc_send_skb,
45151 - gigaset_isoc_input,
45152 + .write_cmd = gigaset_write_cmd,
45153 + .write_room = gigaset_write_room,
45154 + .chars_in_buffer = gigaset_chars_in_buffer,
45155 + .brkchars = gigaset_brkchars,
45156 + .init_bchannel = gigaset_init_bchannel,
45157 + .close_bchannel = gigaset_close_bchannel,
45158 + .initbcshw = gigaset_initbcshw,
45159 + .freebcshw = gigaset_freebcshw,
45160 + .reinitbcshw = gigaset_reinitbcshw,
45161 + .initcshw = gigaset_initcshw,
45162 + .freecshw = gigaset_freecshw,
45163 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45164 + .baud_rate = gigaset_baud_rate,
45165 + .set_line_ctrl = gigaset_set_line_ctrl,
45166 + .send_skb = gigaset_isoc_send_skb,
45167 + .handle_input = gigaset_isoc_input,
45168 };
45169
45170 /* bas_gigaset_init
45171 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
45172 index 600c79b..3752bab 100644
45173 --- a/drivers/isdn/gigaset/interface.c
45174 +++ b/drivers/isdn/gigaset/interface.c
45175 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
45176 }
45177 tty->driver_data = cs;
45178
45179 - ++cs->port.count;
45180 + atomic_inc(&cs->port.count);
45181
45182 - if (cs->port.count == 1) {
45183 + if (atomic_read(&cs->port.count) == 1) {
45184 tty_port_tty_set(&cs->port, tty);
45185 cs->port.low_latency = 1;
45186 }
45187 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
45188
45189 if (!cs->connected)
45190 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
45191 - else if (!cs->port.count)
45192 + else if (!atomic_read(&cs->port.count))
45193 dev_warn(cs->dev, "%s: device not opened\n", __func__);
45194 - else if (!--cs->port.count)
45195 + else if (!atomic_dec_return(&cs->port.count))
45196 tty_port_tty_set(&cs->port, NULL);
45197
45198 mutex_unlock(&cs->mutex);
45199 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
45200 index 8c91fd5..14f13ce 100644
45201 --- a/drivers/isdn/gigaset/ser-gigaset.c
45202 +++ b/drivers/isdn/gigaset/ser-gigaset.c
45203 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
45204 }
45205
45206 static const struct gigaset_ops ops = {
45207 - gigaset_write_cmd,
45208 - gigaset_write_room,
45209 - gigaset_chars_in_buffer,
45210 - gigaset_brkchars,
45211 - gigaset_init_bchannel,
45212 - gigaset_close_bchannel,
45213 - gigaset_initbcshw,
45214 - gigaset_freebcshw,
45215 - gigaset_reinitbcshw,
45216 - gigaset_initcshw,
45217 - gigaset_freecshw,
45218 - gigaset_set_modem_ctrl,
45219 - gigaset_baud_rate,
45220 - gigaset_set_line_ctrl,
45221 - gigaset_m10x_send_skb, /* asyncdata.c */
45222 - gigaset_m10x_input, /* asyncdata.c */
45223 + .write_cmd = gigaset_write_cmd,
45224 + .write_room = gigaset_write_room,
45225 + .chars_in_buffer = gigaset_chars_in_buffer,
45226 + .brkchars = gigaset_brkchars,
45227 + .init_bchannel = gigaset_init_bchannel,
45228 + .close_bchannel = gigaset_close_bchannel,
45229 + .initbcshw = gigaset_initbcshw,
45230 + .freebcshw = gigaset_freebcshw,
45231 + .reinitbcshw = gigaset_reinitbcshw,
45232 + .initcshw = gigaset_initcshw,
45233 + .freecshw = gigaset_freecshw,
45234 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45235 + .baud_rate = gigaset_baud_rate,
45236 + .set_line_ctrl = gigaset_set_line_ctrl,
45237 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
45238 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
45239 };
45240
45241
45242 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
45243 index d0a41cb..b953e50 100644
45244 --- a/drivers/isdn/gigaset/usb-gigaset.c
45245 +++ b/drivers/isdn/gigaset/usb-gigaset.c
45246 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
45247 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
45248 memcpy(cs->hw.usb->bchars, buf, 6);
45249 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
45250 - 0, 0, &buf, 6, 2000);
45251 + 0, 0, buf, 6, 2000);
45252 }
45253
45254 static void gigaset_freebcshw(struct bc_state *bcs)
45255 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
45256 }
45257
45258 static const struct gigaset_ops ops = {
45259 - gigaset_write_cmd,
45260 - gigaset_write_room,
45261 - gigaset_chars_in_buffer,
45262 - gigaset_brkchars,
45263 - gigaset_init_bchannel,
45264 - gigaset_close_bchannel,
45265 - gigaset_initbcshw,
45266 - gigaset_freebcshw,
45267 - gigaset_reinitbcshw,
45268 - gigaset_initcshw,
45269 - gigaset_freecshw,
45270 - gigaset_set_modem_ctrl,
45271 - gigaset_baud_rate,
45272 - gigaset_set_line_ctrl,
45273 - gigaset_m10x_send_skb,
45274 - gigaset_m10x_input,
45275 + .write_cmd = gigaset_write_cmd,
45276 + .write_room = gigaset_write_room,
45277 + .chars_in_buffer = gigaset_chars_in_buffer,
45278 + .brkchars = gigaset_brkchars,
45279 + .init_bchannel = gigaset_init_bchannel,
45280 + .close_bchannel = gigaset_close_bchannel,
45281 + .initbcshw = gigaset_initbcshw,
45282 + .freebcshw = gigaset_freebcshw,
45283 + .reinitbcshw = gigaset_reinitbcshw,
45284 + .initcshw = gigaset_initcshw,
45285 + .freecshw = gigaset_freecshw,
45286 + .set_modem_ctrl = gigaset_set_modem_ctrl,
45287 + .baud_rate = gigaset_baud_rate,
45288 + .set_line_ctrl = gigaset_set_line_ctrl,
45289 + .send_skb = gigaset_m10x_send_skb,
45290 + .handle_input = gigaset_m10x_input,
45291 };
45292
45293 /*
45294 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
45295 index 4d9b195..455075c 100644
45296 --- a/drivers/isdn/hardware/avm/b1.c
45297 +++ b/drivers/isdn/hardware/avm/b1.c
45298 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
45299 }
45300 if (left) {
45301 if (t4file->user) {
45302 - if (copy_from_user(buf, dp, left))
45303 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45304 return -EFAULT;
45305 } else {
45306 memcpy(buf, dp, left);
45307 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
45308 }
45309 if (left) {
45310 if (config->user) {
45311 - if (copy_from_user(buf, dp, left))
45312 + if (left > sizeof buf || copy_from_user(buf, dp, left))
45313 return -EFAULT;
45314 } else {
45315 memcpy(buf, dp, left);
45316 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
45317 index 9b856e1..fa03c92 100644
45318 --- a/drivers/isdn/i4l/isdn_common.c
45319 +++ b/drivers/isdn/i4l/isdn_common.c
45320 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
45321 } else
45322 return -EINVAL;
45323 case IIOCDBGVAR:
45324 + if (!capable(CAP_SYS_RAWIO))
45325 + return -EPERM;
45326 if (arg) {
45327 if (copy_to_user(argp, &dev, sizeof(ulong)))
45328 return -EFAULT;
45329 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
45330 index 91d5730..336523e 100644
45331 --- a/drivers/isdn/i4l/isdn_concap.c
45332 +++ b/drivers/isdn/i4l/isdn_concap.c
45333 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
45334 }
45335
45336 struct concap_device_ops isdn_concap_reliable_dl_dops = {
45337 - &isdn_concap_dl_data_req,
45338 - &isdn_concap_dl_connect_req,
45339 - &isdn_concap_dl_disconn_req
45340 + .data_req = &isdn_concap_dl_data_req,
45341 + .connect_req = &isdn_concap_dl_connect_req,
45342 + .disconn_req = &isdn_concap_dl_disconn_req
45343 };
45344
45345 /* The following should better go into a dedicated source file such that
45346 diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
45347 index 62f0688..38ceac5 100644
45348 --- a/drivers/isdn/i4l/isdn_ppp.c
45349 +++ b/drivers/isdn/i4l/isdn_ppp.c
45350 @@ -378,15 +378,10 @@ isdn_ppp_release(int min, struct file *file)
45351 is->slcomp = NULL;
45352 #endif
45353 #ifdef CONFIG_IPPP_FILTER
45354 - if (is->pass_filter) {
45355 - sk_unattached_filter_destroy(is->pass_filter);
45356 - is->pass_filter = NULL;
45357 - }
45358 -
45359 - if (is->active_filter) {
45360 - sk_unattached_filter_destroy(is->active_filter);
45361 - is->active_filter = NULL;
45362 - }
45363 + kfree(is->pass_filter);
45364 + is->pass_filter = NULL;
45365 + kfree(is->active_filter);
45366 + is->active_filter = NULL;
45367 #endif
45368
45369 /* TODO: if this was the previous master: link the stuff to the new master */
45370 @@ -442,7 +437,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45371 {
45372 struct sock_fprog uprog;
45373 struct sock_filter *code = NULL;
45374 - int len;
45375 + int len, err;
45376
45377 if (copy_from_user(&uprog, arg, sizeof(uprog)))
45378 return -EFAULT;
45379 @@ -458,6 +453,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
45380 if (IS_ERR(code))
45381 return PTR_ERR(code);
45382
45383 + err = sk_chk_filter(code, uprog.len);
45384 + if (err) {
45385 + kfree(code);
45386 + return err;
45387 + }
45388 +
45389 *p = code;
45390 return uprog.len;
45391 }
45392 @@ -628,53 +629,25 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
45393 #ifdef CONFIG_IPPP_FILTER
45394 case PPPIOCSPASS:
45395 {
45396 - struct sock_fprog_kern fprog;
45397 struct sock_filter *code;
45398 - int err, len = get_filter(argp, &code);
45399 -
45400 + int len = get_filter(argp, &code);
45401 if (len < 0)
45402 return len;
45403 -
45404 - fprog.len = len;
45405 - fprog.filter = code;
45406 -
45407 - if (is->pass_filter) {
45408 - sk_unattached_filter_destroy(is->pass_filter);
45409 - is->pass_filter = NULL;
45410 - }
45411 - if (fprog.filter != NULL)
45412 - err = sk_unattached_filter_create(&is->pass_filter,
45413 - &fprog);
45414 - else
45415 - err = 0;
45416 - kfree(code);
45417 -
45418 - return err;
45419 + kfree(is->pass_filter);
45420 + is->pass_filter = code;
45421 + is->pass_len = len;
45422 + break;
45423 }
45424 case PPPIOCSACTIVE:
45425 {
45426 - struct sock_fprog_kern fprog;
45427 struct sock_filter *code;
45428 - int err, len = get_filter(argp, &code);
45429 -
45430 + int len = get_filter(argp, &code);
45431 if (len < 0)
45432 return len;
45433 -
45434 - fprog.len = len;
45435 - fprog.filter = code;
45436 -
45437 - if (is->active_filter) {
45438 - sk_unattached_filter_destroy(is->active_filter);
45439 - is->active_filter = NULL;
45440 - }
45441 - if (fprog.filter != NULL)
45442 - err = sk_unattached_filter_create(&is->active_filter,
45443 - &fprog);
45444 - else
45445 - err = 0;
45446 - kfree(code);
45447 -
45448 - return err;
45449 + kfree(is->active_filter);
45450 + is->active_filter = code;
45451 + is->active_len = len;
45452 + break;
45453 }
45454 #endif /* CONFIG_IPPP_FILTER */
45455 default:
45456 @@ -1174,14 +1147,14 @@ isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *
45457 }
45458
45459 if (is->pass_filter
45460 - && SK_RUN_FILTER(is->pass_filter, skb) == 0) {
45461 + && sk_run_filter(skb, is->pass_filter) == 0) {
45462 if (is->debug & 0x2)
45463 printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
45464 kfree_skb(skb);
45465 return;
45466 }
45467 if (!(is->active_filter
45468 - && SK_RUN_FILTER(is->active_filter, skb) == 0)) {
45469 + && sk_run_filter(skb, is->active_filter) == 0)) {
45470 if (is->debug & 0x2)
45471 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45472 lp->huptimer = 0;
45473 @@ -1320,14 +1293,14 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
45474 }
45475
45476 if (ipt->pass_filter
45477 - && SK_RUN_FILTER(ipt->pass_filter, skb) == 0) {
45478 + && sk_run_filter(skb, ipt->pass_filter) == 0) {
45479 if (ipt->debug & 0x4)
45480 printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
45481 kfree_skb(skb);
45482 goto unlock;
45483 }
45484 if (!(ipt->active_filter
45485 - && SK_RUN_FILTER(ipt->active_filter, skb) == 0)) {
45486 + && sk_run_filter(skb, ipt->active_filter) == 0)) {
45487 if (ipt->debug & 0x4)
45488 printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
45489 lp->huptimer = 0;
45490 @@ -1517,9 +1490,9 @@ int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
45491 }
45492
45493 drop |= is->pass_filter
45494 - && SK_RUN_FILTER(is->pass_filter, skb) == 0;
45495 + && sk_run_filter(skb, is->pass_filter) == 0;
45496 drop |= is->active_filter
45497 - && SK_RUN_FILTER(is->active_filter, skb) == 0;
45498 + && sk_run_filter(skb, is->active_filter) == 0;
45499
45500 skb_push(skb, IPPP_MAX_HEADER - 4);
45501 return drop;
45502 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
45503 index 3c5f249..5fac4d0 100644
45504 --- a/drivers/isdn/i4l/isdn_tty.c
45505 +++ b/drivers/isdn/i4l/isdn_tty.c
45506 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
45507
45508 #ifdef ISDN_DEBUG_MODEM_OPEN
45509 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
45510 - port->count);
45511 + atomic_read(&port->count));
45512 #endif
45513 - port->count++;
45514 + atomic_inc(&port->count);
45515 port->tty = tty;
45516 /*
45517 * Start up serial port
45518 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45519 #endif
45520 return;
45521 }
45522 - if ((tty->count == 1) && (port->count != 1)) {
45523 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
45524 /*
45525 * Uh, oh. tty->count is 1, which means that the tty
45526 * structure will be freed. Info->count should always
45527 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
45528 * serial port won't be shutdown.
45529 */
45530 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
45531 - "info->count is %d\n", port->count);
45532 - port->count = 1;
45533 + "info->count is %d\n", atomic_read(&port->count));
45534 + atomic_set(&port->count, 1);
45535 }
45536 - if (--port->count < 0) {
45537 + if (atomic_dec_return(&port->count) < 0) {
45538 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
45539 - info->line, port->count);
45540 - port->count = 0;
45541 + info->line, atomic_read(&port->count));
45542 + atomic_set(&port->count, 0);
45543 }
45544 - if (port->count) {
45545 + if (atomic_read(&port->count)) {
45546 #ifdef ISDN_DEBUG_MODEM_OPEN
45547 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
45548 #endif
45549 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
45550 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
45551 return;
45552 isdn_tty_shutdown(info);
45553 - port->count = 0;
45554 + atomic_set(&port->count, 0);
45555 port->flags &= ~ASYNC_NORMAL_ACTIVE;
45556 port->tty = NULL;
45557 wake_up_interruptible(&port->open_wait);
45558 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
45559 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
45560 modem_info *info = &dev->mdm.info[i];
45561
45562 - if (info->port.count == 0)
45563 + if (atomic_read(&info->port.count) == 0)
45564 continue;
45565 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
45566 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
45567 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
45568 index e2d4e58..40cd045 100644
45569 --- a/drivers/isdn/i4l/isdn_x25iface.c
45570 +++ b/drivers/isdn/i4l/isdn_x25iface.c
45571 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
45572
45573
45574 static struct concap_proto_ops ix25_pops = {
45575 - &isdn_x25iface_proto_new,
45576 - &isdn_x25iface_proto_del,
45577 - &isdn_x25iface_proto_restart,
45578 - &isdn_x25iface_proto_close,
45579 - &isdn_x25iface_xmit,
45580 - &isdn_x25iface_receive,
45581 - &isdn_x25iface_connect_ind,
45582 - &isdn_x25iface_disconn_ind
45583 + .proto_new = &isdn_x25iface_proto_new,
45584 + .proto_del = &isdn_x25iface_proto_del,
45585 + .restart = &isdn_x25iface_proto_restart,
45586 + .close = &isdn_x25iface_proto_close,
45587 + .encap_and_xmit = &isdn_x25iface_xmit,
45588 + .data_ind = &isdn_x25iface_receive,
45589 + .connect_ind = &isdn_x25iface_connect_ind,
45590 + .disconn_ind = &isdn_x25iface_disconn_ind
45591 };
45592
45593 /* error message helper function */
45594 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
45595 index 6a7447c..cae33fe 100644
45596 --- a/drivers/isdn/icn/icn.c
45597 +++ b/drivers/isdn/icn/icn.c
45598 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
45599 if (count > len)
45600 count = len;
45601 if (user) {
45602 - if (copy_from_user(msg, buf, count))
45603 + if (count > sizeof msg || copy_from_user(msg, buf, count))
45604 return -EFAULT;
45605 } else
45606 memcpy(msg, buf, count);
45607 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
45608 index a4f05c5..1433bc5 100644
45609 --- a/drivers/isdn/mISDN/dsp_cmx.c
45610 +++ b/drivers/isdn/mISDN/dsp_cmx.c
45611 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
45612 static u16 dsp_count; /* last sample count */
45613 static int dsp_count_valid; /* if we have last sample count */
45614
45615 -void
45616 +void __intentional_overflow(-1)
45617 dsp_cmx_send(void *arg)
45618 {
45619 struct dsp_conf *conf;
45620 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
45621 index f58a354..fbae176 100644
45622 --- a/drivers/leds/leds-clevo-mail.c
45623 +++ b/drivers/leds/leds-clevo-mail.c
45624 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
45625 * detected as working, but in reality it is not) as low as
45626 * possible.
45627 */
45628 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
45629 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
45630 {
45631 .callback = clevo_mail_led_dmi_callback,
45632 .ident = "Clevo D410J",
45633 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
45634 index 2eb3ef6..295891f 100644
45635 --- a/drivers/leds/leds-ss4200.c
45636 +++ b/drivers/leds/leds-ss4200.c
45637 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
45638 * detected as working, but in reality it is not) as low as
45639 * possible.
45640 */
45641 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
45642 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
45643 {
45644 .callback = ss4200_led_dmi_callback,
45645 .ident = "Intel SS4200-E",
45646 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
45647 index 0bf1e4e..b4bf44e 100644
45648 --- a/drivers/lguest/core.c
45649 +++ b/drivers/lguest/core.c
45650 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
45651 * The end address needs +1 because __get_vm_area allocates an
45652 * extra guard page, so we need space for that.
45653 */
45654 +
45655 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
45656 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45657 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
45658 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45659 +#else
45660 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
45661 VM_ALLOC, switcher_addr, switcher_addr
45662 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
45663 +#endif
45664 +
45665 if (!switcher_vma) {
45666 err = -ENOMEM;
45667 printk("lguest: could not map switcher pages high\n");
45668 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
45669 * Now the Switcher is mapped at the right address, we can't fail!
45670 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
45671 */
45672 - memcpy(switcher_vma->addr, start_switcher_text,
45673 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
45674 end_switcher_text - start_switcher_text);
45675
45676 printk(KERN_INFO "lguest: mapped switcher at %p\n",
45677 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
45678 index e8b55c3..3514c37 100644
45679 --- a/drivers/lguest/page_tables.c
45680 +++ b/drivers/lguest/page_tables.c
45681 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
45682 /*:*/
45683
45684 #ifdef CONFIG_X86_PAE
45685 -static void release_pmd(pmd_t *spmd)
45686 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
45687 {
45688 /* If the entry's not present, there's nothing to release. */
45689 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
45690 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
45691 index 922a1ac..9dd0c2a 100644
45692 --- a/drivers/lguest/x86/core.c
45693 +++ b/drivers/lguest/x86/core.c
45694 @@ -59,7 +59,7 @@ static struct {
45695 /* Offset from where switcher.S was compiled to where we've copied it */
45696 static unsigned long switcher_offset(void)
45697 {
45698 - return switcher_addr - (unsigned long)start_switcher_text;
45699 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
45700 }
45701
45702 /* This cpu's struct lguest_pages (after the Switcher text page) */
45703 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
45704 * These copies are pretty cheap, so we do them unconditionally: */
45705 /* Save the current Host top-level page directory.
45706 */
45707 +
45708 +#ifdef CONFIG_PAX_PER_CPU_PGD
45709 + pages->state.host_cr3 = read_cr3();
45710 +#else
45711 pages->state.host_cr3 = __pa(current->mm->pgd);
45712 +#endif
45713 +
45714 /*
45715 * Set up the Guest's page tables to see this CPU's pages (and no
45716 * other CPU's pages).
45717 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
45718 * compiled-in switcher code and the high-mapped copy we just made.
45719 */
45720 for (i = 0; i < IDT_ENTRIES; i++)
45721 - default_idt_entries[i] += switcher_offset();
45722 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
45723
45724 /*
45725 * Set up the Switcher's per-cpu areas.
45726 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
45727 * it will be undisturbed when we switch. To change %cs and jump we
45728 * need this structure to feed to Intel's "lcall" instruction.
45729 */
45730 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
45731 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
45732 lguest_entry.segment = LGUEST_CS;
45733
45734 /*
45735 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
45736 index 40634b0..4f5855e 100644
45737 --- a/drivers/lguest/x86/switcher_32.S
45738 +++ b/drivers/lguest/x86/switcher_32.S
45739 @@ -87,6 +87,7 @@
45740 #include <asm/page.h>
45741 #include <asm/segment.h>
45742 #include <asm/lguest.h>
45743 +#include <asm/processor-flags.h>
45744
45745 // We mark the start of the code to copy
45746 // It's placed in .text tho it's never run here
45747 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
45748 // Changes type when we load it: damn Intel!
45749 // For after we switch over our page tables
45750 // That entry will be read-only: we'd crash.
45751 +
45752 +#ifdef CONFIG_PAX_KERNEXEC
45753 + mov %cr0, %edx
45754 + xor $X86_CR0_WP, %edx
45755 + mov %edx, %cr0
45756 +#endif
45757 +
45758 movl $(GDT_ENTRY_TSS*8), %edx
45759 ltr %dx
45760
45761 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
45762 // Let's clear it again for our return.
45763 // The GDT descriptor of the Host
45764 // Points to the table after two "size" bytes
45765 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
45766 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
45767 // Clear "used" from type field (byte 5, bit 2)
45768 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
45769 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
45770 +
45771 +#ifdef CONFIG_PAX_KERNEXEC
45772 + mov %cr0, %eax
45773 + xor $X86_CR0_WP, %eax
45774 + mov %eax, %cr0
45775 +#endif
45776
45777 // Once our page table's switched, the Guest is live!
45778 // The Host fades as we run this final step.
45779 @@ -295,13 +309,12 @@ deliver_to_host:
45780 // I consulted gcc, and it gave
45781 // These instructions, which I gladly credit:
45782 leal (%edx,%ebx,8), %eax
45783 - movzwl (%eax),%edx
45784 - movl 4(%eax), %eax
45785 - xorw %ax, %ax
45786 - orl %eax, %edx
45787 + movl 4(%eax), %edx
45788 + movw (%eax), %dx
45789 // Now the address of the handler's in %edx
45790 // We call it now: its "iret" drops us home.
45791 - jmp *%edx
45792 + ljmp $__KERNEL_CS, $1f
45793 +1: jmp *%edx
45794
45795 // Every interrupt can come to us here
45796 // But we must truly tell each apart.
45797 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
45798 index a08e3ee..df8ade2 100644
45799 --- a/drivers/md/bcache/closure.h
45800 +++ b/drivers/md/bcache/closure.h
45801 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
45802 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
45803 struct workqueue_struct *wq)
45804 {
45805 - BUG_ON(object_is_on_stack(cl));
45806 + BUG_ON(object_starts_on_stack(cl));
45807 closure_set_ip(cl);
45808 cl->fn = fn;
45809 cl->wq = wq;
45810 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45811 index 67f8b31..9418f2b 100644
45812 --- a/drivers/md/bitmap.c
45813 +++ b/drivers/md/bitmap.c
45814 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45815 chunk_kb ? "KB" : "B");
45816 if (bitmap->storage.file) {
45817 seq_printf(seq, ", file: ");
45818 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45819 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45820 }
45821
45822 seq_printf(seq, "\n");
45823 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45824 index 5152142..623d141 100644
45825 --- a/drivers/md/dm-ioctl.c
45826 +++ b/drivers/md/dm-ioctl.c
45827 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45828 cmd == DM_LIST_VERSIONS_CMD)
45829 return 0;
45830
45831 - if ((cmd == DM_DEV_CREATE_CMD)) {
45832 + if (cmd == DM_DEV_CREATE_CMD) {
45833 if (!*param->name) {
45834 DMWARN("name not supplied when creating device");
45835 return -EINVAL;
45836 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45837 index 7dfdb5c..4caada6 100644
45838 --- a/drivers/md/dm-raid1.c
45839 +++ b/drivers/md/dm-raid1.c
45840 @@ -40,7 +40,7 @@ enum dm_raid1_error {
45841
45842 struct mirror {
45843 struct mirror_set *ms;
45844 - atomic_t error_count;
45845 + atomic_unchecked_t error_count;
45846 unsigned long error_type;
45847 struct dm_dev *dev;
45848 sector_t offset;
45849 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45850 struct mirror *m;
45851
45852 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45853 - if (!atomic_read(&m->error_count))
45854 + if (!atomic_read_unchecked(&m->error_count))
45855 return m;
45856
45857 return NULL;
45858 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45859 * simple way to tell if a device has encountered
45860 * errors.
45861 */
45862 - atomic_inc(&m->error_count);
45863 + atomic_inc_unchecked(&m->error_count);
45864
45865 if (test_and_set_bit(error_type, &m->error_type))
45866 return;
45867 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45868 struct mirror *m = get_default_mirror(ms);
45869
45870 do {
45871 - if (likely(!atomic_read(&m->error_count)))
45872 + if (likely(!atomic_read_unchecked(&m->error_count)))
45873 return m;
45874
45875 if (m-- == ms->mirror)
45876 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45877 {
45878 struct mirror *default_mirror = get_default_mirror(m->ms);
45879
45880 - return !atomic_read(&default_mirror->error_count);
45881 + return !atomic_read_unchecked(&default_mirror->error_count);
45882 }
45883
45884 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45885 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45886 */
45887 if (likely(region_in_sync(ms, region, 1)))
45888 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45889 - else if (m && atomic_read(&m->error_count))
45890 + else if (m && atomic_read_unchecked(&m->error_count))
45891 m = NULL;
45892
45893 if (likely(m))
45894 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45895 }
45896
45897 ms->mirror[mirror].ms = ms;
45898 - atomic_set(&(ms->mirror[mirror].error_count), 0);
45899 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45900 ms->mirror[mirror].error_type = 0;
45901 ms->mirror[mirror].offset = offset;
45902
45903 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45904 */
45905 static char device_status_char(struct mirror *m)
45906 {
45907 - if (!atomic_read(&(m->error_count)))
45908 + if (!atomic_read_unchecked(&(m->error_count)))
45909 return 'A';
45910
45911 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45912 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45913 index 28a9012..9c0f6a5 100644
45914 --- a/drivers/md/dm-stats.c
45915 +++ b/drivers/md/dm-stats.c
45916 @@ -382,7 +382,7 @@ do_sync_free:
45917 synchronize_rcu_expedited();
45918 dm_stat_free(&s->rcu_head);
45919 } else {
45920 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45921 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45922 call_rcu(&s->rcu_head, dm_stat_free);
45923 }
45924 return 0;
45925 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45926 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45927 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45928 ));
45929 - ACCESS_ONCE(last->last_sector) = end_sector;
45930 - ACCESS_ONCE(last->last_rw) = bi_rw;
45931 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
45932 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45933 }
45934
45935 rcu_read_lock();
45936 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45937 index d1600d2..4c3af3a 100644
45938 --- a/drivers/md/dm-stripe.c
45939 +++ b/drivers/md/dm-stripe.c
45940 @@ -21,7 +21,7 @@ struct stripe {
45941 struct dm_dev *dev;
45942 sector_t physical_start;
45943
45944 - atomic_t error_count;
45945 + atomic_unchecked_t error_count;
45946 };
45947
45948 struct stripe_c {
45949 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
45950 kfree(sc);
45951 return r;
45952 }
45953 - atomic_set(&(sc->stripe[i].error_count), 0);
45954 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
45955 }
45956
45957 ti->private = sc;
45958 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
45959 DMEMIT("%d ", sc->stripes);
45960 for (i = 0; i < sc->stripes; i++) {
45961 DMEMIT("%s ", sc->stripe[i].dev->name);
45962 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
45963 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
45964 'D' : 'A';
45965 }
45966 buffer[i] = '\0';
45967 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
45968 */
45969 for (i = 0; i < sc->stripes; i++)
45970 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
45971 - atomic_inc(&(sc->stripe[i].error_count));
45972 - if (atomic_read(&(sc->stripe[i].error_count)) <
45973 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
45974 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
45975 DM_IO_ERROR_THRESHOLD)
45976 schedule_work(&sc->trigger_event);
45977 }
45978 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
45979 index 5f59f1e..01bd02e 100644
45980 --- a/drivers/md/dm-table.c
45981 +++ b/drivers/md/dm-table.c
45982 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
45983 static int open_dev(struct dm_dev_internal *d, dev_t dev,
45984 struct mapped_device *md)
45985 {
45986 - static char *_claim_ptr = "I belong to device-mapper";
45987 + static char _claim_ptr[] = "I belong to device-mapper";
45988 struct block_device *bdev;
45989
45990 int r;
45991 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
45992 if (!dev_size)
45993 return 0;
45994
45995 - if ((start >= dev_size) || (start + len > dev_size)) {
45996 + if ((start >= dev_size) || (len > dev_size - start)) {
45997 DMWARN("%s: %s too small for target: "
45998 "start=%llu, len=%llu, dev_size=%llu",
45999 dm_device_name(ti->table->md), bdevname(bdev, b),
46000 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
46001 index e9d33ad..dae9880d 100644
46002 --- a/drivers/md/dm-thin-metadata.c
46003 +++ b/drivers/md/dm-thin-metadata.c
46004 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
46005 {
46006 pmd->info.tm = pmd->tm;
46007 pmd->info.levels = 2;
46008 - pmd->info.value_type.context = pmd->data_sm;
46009 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
46010 pmd->info.value_type.size = sizeof(__le64);
46011 pmd->info.value_type.inc = data_block_inc;
46012 pmd->info.value_type.dec = data_block_dec;
46013 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
46014
46015 pmd->bl_info.tm = pmd->tm;
46016 pmd->bl_info.levels = 1;
46017 - pmd->bl_info.value_type.context = pmd->data_sm;
46018 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
46019 pmd->bl_info.value_type.size = sizeof(__le64);
46020 pmd->bl_info.value_type.inc = data_block_inc;
46021 pmd->bl_info.value_type.dec = data_block_dec;
46022 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
46023 index 32b958d..34011e8 100644
46024 --- a/drivers/md/dm.c
46025 +++ b/drivers/md/dm.c
46026 @@ -180,9 +180,9 @@ struct mapped_device {
46027 /*
46028 * Event handling.
46029 */
46030 - atomic_t event_nr;
46031 + atomic_unchecked_t event_nr;
46032 wait_queue_head_t eventq;
46033 - atomic_t uevent_seq;
46034 + atomic_unchecked_t uevent_seq;
46035 struct list_head uevent_list;
46036 spinlock_t uevent_lock; /* Protect access to uevent_list */
46037
46038 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
46039 spin_lock_init(&md->deferred_lock);
46040 atomic_set(&md->holders, 1);
46041 atomic_set(&md->open_count, 0);
46042 - atomic_set(&md->event_nr, 0);
46043 - atomic_set(&md->uevent_seq, 0);
46044 + atomic_set_unchecked(&md->event_nr, 0);
46045 + atomic_set_unchecked(&md->uevent_seq, 0);
46046 INIT_LIST_HEAD(&md->uevent_list);
46047 spin_lock_init(&md->uevent_lock);
46048
46049 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
46050
46051 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
46052
46053 - atomic_inc(&md->event_nr);
46054 + atomic_inc_unchecked(&md->event_nr);
46055 wake_up(&md->eventq);
46056 }
46057
46058 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
46059
46060 uint32_t dm_next_uevent_seq(struct mapped_device *md)
46061 {
46062 - return atomic_add_return(1, &md->uevent_seq);
46063 + return atomic_add_return_unchecked(1, &md->uevent_seq);
46064 }
46065
46066 uint32_t dm_get_event_nr(struct mapped_device *md)
46067 {
46068 - return atomic_read(&md->event_nr);
46069 + return atomic_read_unchecked(&md->event_nr);
46070 }
46071
46072 int dm_wait_event(struct mapped_device *md, int event_nr)
46073 {
46074 return wait_event_interruptible(md->eventq,
46075 - (event_nr != atomic_read(&md->event_nr)));
46076 + (event_nr != atomic_read_unchecked(&md->event_nr)));
46077 }
46078
46079 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
46080 diff --git a/drivers/md/md.c b/drivers/md/md.c
46081 index 32fc19c..cb6eba3 100644
46082 --- a/drivers/md/md.c
46083 +++ b/drivers/md/md.c
46084 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
46085 * start build, activate spare
46086 */
46087 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
46088 -static atomic_t md_event_count;
46089 +static atomic_unchecked_t md_event_count;
46090 void md_new_event(struct mddev *mddev)
46091 {
46092 - atomic_inc(&md_event_count);
46093 + atomic_inc_unchecked(&md_event_count);
46094 wake_up(&md_event_waiters);
46095 }
46096 EXPORT_SYMBOL_GPL(md_new_event);
46097 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
46098 */
46099 static void md_new_event_inintr(struct mddev *mddev)
46100 {
46101 - atomic_inc(&md_event_count);
46102 + atomic_inc_unchecked(&md_event_count);
46103 wake_up(&md_event_waiters);
46104 }
46105
46106 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
46107 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
46108 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
46109 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
46110 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46111 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
46112
46113 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
46114 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
46115 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
46116 else
46117 sb->resync_offset = cpu_to_le64(0);
46118
46119 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
46120 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
46121
46122 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
46123 sb->size = cpu_to_le64(mddev->dev_sectors);
46124 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
46125 static ssize_t
46126 errors_show(struct md_rdev *rdev, char *page)
46127 {
46128 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
46129 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
46130 }
46131
46132 static ssize_t
46133 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
46134 char *e;
46135 unsigned long n = simple_strtoul(buf, &e, 10);
46136 if (*buf && (*e == 0 || *e == '\n')) {
46137 - atomic_set(&rdev->corrected_errors, n);
46138 + atomic_set_unchecked(&rdev->corrected_errors, n);
46139 return len;
46140 }
46141 return -EINVAL;
46142 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
46143 rdev->sb_loaded = 0;
46144 rdev->bb_page = NULL;
46145 atomic_set(&rdev->nr_pending, 0);
46146 - atomic_set(&rdev->read_errors, 0);
46147 - atomic_set(&rdev->corrected_errors, 0);
46148 + atomic_set_unchecked(&rdev->read_errors, 0);
46149 + atomic_set_unchecked(&rdev->corrected_errors, 0);
46150
46151 INIT_LIST_HEAD(&rdev->same_set);
46152 init_waitqueue_head(&rdev->blocked_wait);
46153 @@ -7068,7 +7068,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
46154
46155 spin_unlock(&pers_lock);
46156 seq_printf(seq, "\n");
46157 - seq->poll_event = atomic_read(&md_event_count);
46158 + seq->poll_event = atomic_read_unchecked(&md_event_count);
46159 return 0;
46160 }
46161 if (v == (void*)2) {
46162 @@ -7171,7 +7171,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
46163 return error;
46164
46165 seq = file->private_data;
46166 - seq->poll_event = atomic_read(&md_event_count);
46167 + seq->poll_event = atomic_read_unchecked(&md_event_count);
46168 return error;
46169 }
46170
46171 @@ -7188,7 +7188,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
46172 /* always allow read */
46173 mask = POLLIN | POLLRDNORM;
46174
46175 - if (seq->poll_event != atomic_read(&md_event_count))
46176 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
46177 mask |= POLLERR | POLLPRI;
46178 return mask;
46179 }
46180 @@ -7232,7 +7232,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
46181 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
46182 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
46183 (int)part_stat_read(&disk->part0, sectors[1]) -
46184 - atomic_read(&disk->sync_io);
46185 + atomic_read_unchecked(&disk->sync_io);
46186 /* sync IO will cause sync_io to increase before the disk_stats
46187 * as sync_io is counted when a request starts, and
46188 * disk_stats is counted when it completes.
46189 diff --git a/drivers/md/md.h b/drivers/md/md.h
46190 index a49d991..3582bb7 100644
46191 --- a/drivers/md/md.h
46192 +++ b/drivers/md/md.h
46193 @@ -94,13 +94,13 @@ struct md_rdev {
46194 * only maintained for arrays that
46195 * support hot removal
46196 */
46197 - atomic_t read_errors; /* number of consecutive read errors that
46198 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
46199 * we have tried to ignore.
46200 */
46201 struct timespec last_read_error; /* monotonic time since our
46202 * last read error
46203 */
46204 - atomic_t corrected_errors; /* number of corrected read errors,
46205 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
46206 * for reporting to userspace and storing
46207 * in superblock.
46208 */
46209 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
46210
46211 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
46212 {
46213 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46214 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
46215 }
46216
46217 struct md_personality
46218 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
46219 index 786b689..ea8c956 100644
46220 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
46221 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
46222 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
46223 * Flick into a mode where all blocks get allocated in the new area.
46224 */
46225 smm->begin = old_len;
46226 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
46227 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
46228
46229 /*
46230 * Extend.
46231 @@ -710,7 +710,7 @@ out:
46232 /*
46233 * Switch back to normal behaviour.
46234 */
46235 - memcpy(sm, &ops, sizeof(*sm));
46236 + memcpy((void *)sm, &ops, sizeof(*sm));
46237 return r;
46238 }
46239
46240 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
46241 index 3e6d115..ffecdeb 100644
46242 --- a/drivers/md/persistent-data/dm-space-map.h
46243 +++ b/drivers/md/persistent-data/dm-space-map.h
46244 @@ -71,6 +71,7 @@ struct dm_space_map {
46245 dm_sm_threshold_fn fn,
46246 void *context);
46247 };
46248 +typedef struct dm_space_map __no_const dm_space_map_no_const;
46249
46250 /*----------------------------------------------------------------*/
46251
46252 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
46253 index 56e24c0..e1c8e1f 100644
46254 --- a/drivers/md/raid1.c
46255 +++ b/drivers/md/raid1.c
46256 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
46257 if (r1_sync_page_io(rdev, sect, s,
46258 bio->bi_io_vec[idx].bv_page,
46259 READ) != 0)
46260 - atomic_add(s, &rdev->corrected_errors);
46261 + atomic_add_unchecked(s, &rdev->corrected_errors);
46262 }
46263 sectors -= s;
46264 sect += s;
46265 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
46266 test_bit(In_sync, &rdev->flags)) {
46267 if (r1_sync_page_io(rdev, sect, s,
46268 conf->tmppage, READ)) {
46269 - atomic_add(s, &rdev->corrected_errors);
46270 + atomic_add_unchecked(s, &rdev->corrected_errors);
46271 printk(KERN_INFO
46272 "md/raid1:%s: read error corrected "
46273 "(%d sectors at %llu on %s)\n",
46274 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
46275 index cb882aa..cb8aeca 100644
46276 --- a/drivers/md/raid10.c
46277 +++ b/drivers/md/raid10.c
46278 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
46279 /* The write handler will notice the lack of
46280 * R10BIO_Uptodate and record any errors etc
46281 */
46282 - atomic_add(r10_bio->sectors,
46283 + atomic_add_unchecked(r10_bio->sectors,
46284 &conf->mirrors[d].rdev->corrected_errors);
46285
46286 /* for reconstruct, we always reschedule after a read.
46287 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46288 {
46289 struct timespec cur_time_mon;
46290 unsigned long hours_since_last;
46291 - unsigned int read_errors = atomic_read(&rdev->read_errors);
46292 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
46293
46294 ktime_get_ts(&cur_time_mon);
46295
46296 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
46297 * overflowing the shift of read_errors by hours_since_last.
46298 */
46299 if (hours_since_last >= 8 * sizeof(read_errors))
46300 - atomic_set(&rdev->read_errors, 0);
46301 + atomic_set_unchecked(&rdev->read_errors, 0);
46302 else
46303 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
46304 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
46305 }
46306
46307 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
46308 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46309 return;
46310
46311 check_decay_read_errors(mddev, rdev);
46312 - atomic_inc(&rdev->read_errors);
46313 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
46314 + atomic_inc_unchecked(&rdev->read_errors);
46315 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
46316 char b[BDEVNAME_SIZE];
46317 bdevname(rdev->bdev, b);
46318
46319 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46320 "md/raid10:%s: %s: Raid device exceeded "
46321 "read_error threshold [cur %d:max %d]\n",
46322 mdname(mddev), b,
46323 - atomic_read(&rdev->read_errors), max_read_errors);
46324 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
46325 printk(KERN_NOTICE
46326 "md/raid10:%s: %s: Failing raid device\n",
46327 mdname(mddev), b);
46328 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
46329 sect +
46330 choose_data_offset(r10_bio, rdev)),
46331 bdevname(rdev->bdev, b));
46332 - atomic_add(s, &rdev->corrected_errors);
46333 + atomic_add_unchecked(s, &rdev->corrected_errors);
46334 }
46335
46336 rdev_dec_pending(rdev, mddev);
46337 @@ -2954,6 +2954,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr,
46338 */
46339 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) {
46340 end_reshape(conf);
46341 + close_sync(conf);
46342 return 0;
46343 }
46344
46345 @@ -4411,7 +4412,7 @@ read_more:
46346 read_bio->bi_private = r10_bio;
46347 read_bio->bi_end_io = end_sync_read;
46348 read_bio->bi_rw = READ;
46349 - read_bio->bi_flags &= ~(BIO_POOL_MASK - 1);
46350 + read_bio->bi_flags &= (~0UL << BIO_RESET_BITS);
46351 read_bio->bi_flags |= 1 << BIO_UPTODATE;
46352 read_bio->bi_vcnt = 0;
46353 read_bio->bi_iter.bi_size = 0;
46354 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
46355 index 6234b2e..4990801 100644
46356 --- a/drivers/md/raid5.c
46357 +++ b/drivers/md/raid5.c
46358 @@ -1731,6 +1731,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
46359 return 1;
46360 }
46361
46362 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46363 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
46364 +#endif
46365 +
46366 static int grow_stripes(struct r5conf *conf, int num)
46367 {
46368 struct kmem_cache *sc;
46369 @@ -1742,7 +1746,11 @@ static int grow_stripes(struct r5conf *conf, int num)
46370 "raid%d-%s", conf->level, mdname(conf->mddev));
46371 else
46372 sprintf(conf->cache_name[0],
46373 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46374 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
46375 +#else
46376 "raid%d-%p", conf->level, conf->mddev);
46377 +#endif
46378 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
46379
46380 conf->active_name = 0;
46381 @@ -2018,21 +2026,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
46382 mdname(conf->mddev), STRIPE_SECTORS,
46383 (unsigned long long)s,
46384 bdevname(rdev->bdev, b));
46385 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
46386 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
46387 clear_bit(R5_ReadError, &sh->dev[i].flags);
46388 clear_bit(R5_ReWrite, &sh->dev[i].flags);
46389 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
46390 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
46391
46392 - if (atomic_read(&rdev->read_errors))
46393 - atomic_set(&rdev->read_errors, 0);
46394 + if (atomic_read_unchecked(&rdev->read_errors))
46395 + atomic_set_unchecked(&rdev->read_errors, 0);
46396 } else {
46397 const char *bdn = bdevname(rdev->bdev, b);
46398 int retry = 0;
46399 int set_bad = 0;
46400
46401 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
46402 - atomic_inc(&rdev->read_errors);
46403 + atomic_inc_unchecked(&rdev->read_errors);
46404 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
46405 printk_ratelimited(
46406 KERN_WARNING
46407 @@ -2060,7 +2068,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
46408 mdname(conf->mddev),
46409 (unsigned long long)s,
46410 bdn);
46411 - } else if (atomic_read(&rdev->read_errors)
46412 + } else if (atomic_read_unchecked(&rdev->read_errors)
46413 > conf->max_nr_stripes)
46414 printk(KERN_WARNING
46415 "md/raid:%s: Too many read errors, failing device %s.\n",
46416 @@ -3817,6 +3825,8 @@ static void handle_stripe(struct stripe_head *sh)
46417 set_bit(R5_Wantwrite, &dev->flags);
46418 if (prexor)
46419 continue;
46420 + if (s.failed > 1)
46421 + continue;
46422 if (!test_bit(R5_Insync, &dev->flags) ||
46423 ((i == sh->pd_idx || i == sh->qd_idx) &&
46424 s.failed == 0))
46425 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
46426 index 983db75..ef9248c 100644
46427 --- a/drivers/media/dvb-core/dvbdev.c
46428 +++ b/drivers/media/dvb-core/dvbdev.c
46429 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
46430 const struct dvb_device *template, void *priv, int type)
46431 {
46432 struct dvb_device *dvbdev;
46433 - struct file_operations *dvbdevfops;
46434 + file_operations_no_const *dvbdevfops;
46435 struct device *clsdev;
46436 int minor;
46437 int id;
46438 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
46439 index 539f4db..cdd403b 100644
46440 --- a/drivers/media/dvb-frontends/af9033.h
46441 +++ b/drivers/media/dvb-frontends/af9033.h
46442 @@ -82,7 +82,7 @@ struct af9033_ops {
46443 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
46444 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
46445 int onoff);
46446 -};
46447 +} __no_const;
46448
46449
46450 #if IS_ENABLED(CONFIG_DVB_AF9033)
46451 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
46452 index 9b6c3bb..baeb5c7 100644
46453 --- a/drivers/media/dvb-frontends/dib3000.h
46454 +++ b/drivers/media/dvb-frontends/dib3000.h
46455 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
46456 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
46457 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
46458 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
46459 -};
46460 +} __no_const;
46461
46462 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
46463 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
46464 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
46465 index ed8cb90..5ef7f79 100644
46466 --- a/drivers/media/pci/cx88/cx88-video.c
46467 +++ b/drivers/media/pci/cx88/cx88-video.c
46468 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
46469
46470 /* ------------------------------------------------------------------ */
46471
46472 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46473 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46474 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46475 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46476 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46477 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
46478
46479 module_param_array(video_nr, int, NULL, 0444);
46480 module_param_array(vbi_nr, int, NULL, 0444);
46481 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
46482 index 802642d..5534900 100644
46483 --- a/drivers/media/pci/ivtv/ivtv-driver.c
46484 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
46485 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
46486 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
46487
46488 /* ivtv instance counter */
46489 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
46490 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
46491
46492 /* Parameter declarations */
46493 static int cardtype[IVTV_MAX_CARDS];
46494 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
46495 index 9a726ea..f5e9b52 100644
46496 --- a/drivers/media/platform/omap/omap_vout.c
46497 +++ b/drivers/media/platform/omap/omap_vout.c
46498 @@ -63,7 +63,6 @@ enum omap_vout_channels {
46499 OMAP_VIDEO2,
46500 };
46501
46502 -static struct videobuf_queue_ops video_vbq_ops;
46503 /* Variables configurable through module params*/
46504 static u32 video1_numbuffers = 3;
46505 static u32 video2_numbuffers = 3;
46506 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
46507 {
46508 struct videobuf_queue *q;
46509 struct omap_vout_device *vout = NULL;
46510 + static struct videobuf_queue_ops video_vbq_ops = {
46511 + .buf_setup = omap_vout_buffer_setup,
46512 + .buf_prepare = omap_vout_buffer_prepare,
46513 + .buf_release = omap_vout_buffer_release,
46514 + .buf_queue = omap_vout_buffer_queue,
46515 + };
46516
46517 vout = video_drvdata(file);
46518 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
46519 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
46520 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
46521
46522 q = &vout->vbq;
46523 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
46524 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
46525 - video_vbq_ops.buf_release = omap_vout_buffer_release;
46526 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
46527 spin_lock_init(&vout->vbq_lock);
46528
46529 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
46530 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
46531 index fb2acc5..a2fcbdc4 100644
46532 --- a/drivers/media/platform/s5p-tv/mixer.h
46533 +++ b/drivers/media/platform/s5p-tv/mixer.h
46534 @@ -156,7 +156,7 @@ struct mxr_layer {
46535 /** layer index (unique identifier) */
46536 int idx;
46537 /** callbacks for layer methods */
46538 - struct mxr_layer_ops ops;
46539 + struct mxr_layer_ops *ops;
46540 /** format array */
46541 const struct mxr_format **fmt_array;
46542 /** size of format array */
46543 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46544 index 74344c7..a39e70e 100644
46545 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46546 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
46547 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
46548 {
46549 struct mxr_layer *layer;
46550 int ret;
46551 - struct mxr_layer_ops ops = {
46552 + static struct mxr_layer_ops ops = {
46553 .release = mxr_graph_layer_release,
46554 .buffer_set = mxr_graph_buffer_set,
46555 .stream_set = mxr_graph_stream_set,
46556 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
46557 index b713403..53cb5ad 100644
46558 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
46559 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
46560 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
46561 layer->update_buf = next;
46562 }
46563
46564 - layer->ops.buffer_set(layer, layer->update_buf);
46565 + layer->ops->buffer_set(layer, layer->update_buf);
46566
46567 if (done && done != layer->shadow_buf)
46568 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
46569 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
46570 index 8a8dbc8..b74c62d 100644
46571 --- a/drivers/media/platform/s5p-tv/mixer_video.c
46572 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
46573 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
46574 layer->geo.src.height = layer->geo.src.full_height;
46575
46576 mxr_geometry_dump(mdev, &layer->geo);
46577 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46578 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46579 mxr_geometry_dump(mdev, &layer->geo);
46580 }
46581
46582 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
46583 layer->geo.dst.full_width = mbus_fmt.width;
46584 layer->geo.dst.full_height = mbus_fmt.height;
46585 layer->geo.dst.field = mbus_fmt.field;
46586 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46587 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
46588
46589 mxr_geometry_dump(mdev, &layer->geo);
46590 }
46591 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
46592 /* set source size to highest accepted value */
46593 geo->src.full_width = max(geo->dst.full_width, pix->width);
46594 geo->src.full_height = max(geo->dst.full_height, pix->height);
46595 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46596 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46597 mxr_geometry_dump(mdev, &layer->geo);
46598 /* set cropping to total visible screen */
46599 geo->src.width = pix->width;
46600 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
46601 geo->src.x_offset = 0;
46602 geo->src.y_offset = 0;
46603 /* assure consistency of geometry */
46604 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46605 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
46606 mxr_geometry_dump(mdev, &layer->geo);
46607 /* set full size to lowest possible value */
46608 geo->src.full_width = 0;
46609 geo->src.full_height = 0;
46610 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46611 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
46612 mxr_geometry_dump(mdev, &layer->geo);
46613
46614 /* returning results */
46615 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
46616 target->width = s->r.width;
46617 target->height = s->r.height;
46618
46619 - layer->ops.fix_geometry(layer, stage, s->flags);
46620 + layer->ops->fix_geometry(layer, stage, s->flags);
46621
46622 /* retrieve update selection rectangle */
46623 res.left = target->x_offset;
46624 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
46625 mxr_output_get(mdev);
46626
46627 mxr_layer_update_output(layer);
46628 - layer->ops.format_set(layer);
46629 + layer->ops->format_set(layer);
46630 /* enabling layer in hardware */
46631 spin_lock_irqsave(&layer->enq_slock, flags);
46632 layer->state = MXR_LAYER_STREAMING;
46633 spin_unlock_irqrestore(&layer->enq_slock, flags);
46634
46635 - layer->ops.stream_set(layer, MXR_ENABLE);
46636 + layer->ops->stream_set(layer, MXR_ENABLE);
46637 mxr_streamer_get(mdev);
46638
46639 return 0;
46640 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
46641 spin_unlock_irqrestore(&layer->enq_slock, flags);
46642
46643 /* disabling layer in hardware */
46644 - layer->ops.stream_set(layer, MXR_DISABLE);
46645 + layer->ops->stream_set(layer, MXR_DISABLE);
46646 /* remove one streamer */
46647 mxr_streamer_put(mdev);
46648 /* allow changes in output configuration */
46649 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
46650
46651 void mxr_layer_release(struct mxr_layer *layer)
46652 {
46653 - if (layer->ops.release)
46654 - layer->ops.release(layer);
46655 + if (layer->ops->release)
46656 + layer->ops->release(layer);
46657 }
46658
46659 void mxr_base_layer_release(struct mxr_layer *layer)
46660 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
46661
46662 layer->mdev = mdev;
46663 layer->idx = idx;
46664 - layer->ops = *ops;
46665 + layer->ops = ops;
46666
46667 spin_lock_init(&layer->enq_slock);
46668 INIT_LIST_HEAD(&layer->enq_list);
46669 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46670 index c9388c4..ce71ece 100644
46671 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46672 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
46673 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
46674 {
46675 struct mxr_layer *layer;
46676 int ret;
46677 - struct mxr_layer_ops ops = {
46678 + static struct mxr_layer_ops ops = {
46679 .release = mxr_vp_layer_release,
46680 .buffer_set = mxr_vp_buffer_set,
46681 .stream_set = mxr_vp_stream_set,
46682 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
46683 index d00bf3d..1301a0c 100644
46684 --- a/drivers/media/platform/vivi.c
46685 +++ b/drivers/media/platform/vivi.c
46686 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
46687 MODULE_LICENSE("Dual BSD/GPL");
46688 MODULE_VERSION(VIVI_VERSION);
46689
46690 -static unsigned video_nr = -1;
46691 -module_param(video_nr, uint, 0644);
46692 +static int video_nr = -1;
46693 +module_param(video_nr, int, 0644);
46694 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
46695
46696 static unsigned n_devs = 1;
46697 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
46698 index d719e59..63f3470 100644
46699 --- a/drivers/media/radio/radio-cadet.c
46700 +++ b/drivers/media/radio/radio-cadet.c
46701 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46702 unsigned char readbuf[RDS_BUFFER];
46703 int i = 0;
46704
46705 + if (count > RDS_BUFFER)
46706 + return -EFAULT;
46707 mutex_lock(&dev->lock);
46708 if (dev->rdsstat == 0)
46709 cadet_start_rds(dev);
46710 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
46711 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
46712 mutex_unlock(&dev->lock);
46713
46714 - if (i && copy_to_user(data, readbuf, i))
46715 - return -EFAULT;
46716 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
46717 + i = -EFAULT;
46718 +
46719 return i;
46720 }
46721
46722 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
46723 index 5236035..c622c74 100644
46724 --- a/drivers/media/radio/radio-maxiradio.c
46725 +++ b/drivers/media/radio/radio-maxiradio.c
46726 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
46727 /* TEA5757 pin mappings */
46728 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
46729
46730 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
46731 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
46732
46733 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
46734 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
46735 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
46736 index 050b3bb..79f62b9 100644
46737 --- a/drivers/media/radio/radio-shark.c
46738 +++ b/drivers/media/radio/radio-shark.c
46739 @@ -79,7 +79,7 @@ struct shark_device {
46740 u32 last_val;
46741 };
46742
46743 -static atomic_t shark_instance = ATOMIC_INIT(0);
46744 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46745
46746 static void shark_write_val(struct snd_tea575x *tea, u32 val)
46747 {
46748 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
46749 index 8654e0d..0608a64 100644
46750 --- a/drivers/media/radio/radio-shark2.c
46751 +++ b/drivers/media/radio/radio-shark2.c
46752 @@ -74,7 +74,7 @@ struct shark_device {
46753 u8 *transfer_buffer;
46754 };
46755
46756 -static atomic_t shark_instance = ATOMIC_INIT(0);
46757 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46758
46759 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46760 {
46761 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46762 index 2fd9009..278cc1e 100644
46763 --- a/drivers/media/radio/radio-si476x.c
46764 +++ b/drivers/media/radio/radio-si476x.c
46765 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46766 struct si476x_radio *radio;
46767 struct v4l2_ctrl *ctrl;
46768
46769 - static atomic_t instance = ATOMIC_INIT(0);
46770 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
46771
46772 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46773 if (!radio)
46774 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46775 index 9fd1527..8927230 100644
46776 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
46777 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46778 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
46779
46780 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
46781 {
46782 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
46783 - char result[64];
46784 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
46785 - sizeof(result), 0);
46786 + char *buf;
46787 + char *result;
46788 + int retval;
46789 +
46790 + buf = kmalloc(2, GFP_KERNEL);
46791 + if (buf == NULL)
46792 + return -ENOMEM;
46793 + result = kmalloc(64, GFP_KERNEL);
46794 + if (result == NULL) {
46795 + kfree(buf);
46796 + return -ENOMEM;
46797 + }
46798 +
46799 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
46800 + buf[1] = enable ? 1 : 0;
46801 +
46802 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
46803 +
46804 + kfree(buf);
46805 + kfree(result);
46806 + return retval;
46807 }
46808
46809 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
46810 {
46811 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
46812 - char state[3];
46813 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
46814 + char *buf;
46815 + char *state;
46816 + int retval;
46817 +
46818 + buf = kmalloc(2, GFP_KERNEL);
46819 + if (buf == NULL)
46820 + return -ENOMEM;
46821 + state = kmalloc(3, GFP_KERNEL);
46822 + if (state == NULL) {
46823 + kfree(buf);
46824 + return -ENOMEM;
46825 + }
46826 +
46827 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
46828 + buf[1] = enable ? 1 : 0;
46829 +
46830 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
46831 +
46832 + kfree(buf);
46833 + kfree(state);
46834 + return retval;
46835 }
46836
46837 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46838 {
46839 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
46840 - char state[3];
46841 + char *query;
46842 + char *state;
46843 int ret;
46844 + query = kmalloc(1, GFP_KERNEL);
46845 + if (query == NULL)
46846 + return -ENOMEM;
46847 + state = kmalloc(3, GFP_KERNEL);
46848 + if (state == NULL) {
46849 + kfree(query);
46850 + return -ENOMEM;
46851 + }
46852 +
46853 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
46854
46855 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
46856
46857 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
46858 - sizeof(state), 0);
46859 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
46860 if (ret < 0) {
46861 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
46862 "state info\n");
46863 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46864
46865 /* Copy this pointer as we are gonna need it in the release phase */
46866 cinergyt2_usb_device = adap->dev;
46867 -
46868 + kfree(query);
46869 + kfree(state);
46870 return 0;
46871 }
46872
46873 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
46874 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46875 {
46876 struct cinergyt2_state *st = d->priv;
46877 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
46878 + u8 *key, *cmd;
46879 int i;
46880
46881 + cmd = kmalloc(1, GFP_KERNEL);
46882 + if (cmd == NULL)
46883 + return -EINVAL;
46884 + key = kzalloc(5, GFP_KERNEL);
46885 + if (key == NULL) {
46886 + kfree(cmd);
46887 + return -EINVAL;
46888 + }
46889 +
46890 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
46891 +
46892 *state = REMOTE_NO_KEY_PRESSED;
46893
46894 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
46895 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
46896 if (key[4] == 0xff) {
46897 /* key repeat */
46898 st->rc_counter++;
46899 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46900 *event = d->last_event;
46901 deb_rc("repeat key, event %x\n",
46902 *event);
46903 - return 0;
46904 + goto out;
46905 }
46906 }
46907 deb_rc("repeated key (non repeatable)\n");
46908 }
46909 - return 0;
46910 + goto out;
46911 }
46912
46913 /* hack to pass checksum on the custom field */
46914 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46915
46916 deb_rc("key: %*ph\n", 5, key);
46917 }
46918 +out:
46919 + kfree(cmd);
46920 + kfree(key);
46921 return 0;
46922 }
46923
46924 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46925 index c890fe4..f9b2ae6 100644
46926 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46927 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46928 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
46929 fe_status_t *status)
46930 {
46931 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46932 - struct dvbt_get_status_msg result;
46933 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46934 + struct dvbt_get_status_msg *result;
46935 + u8 *cmd;
46936 int ret;
46937
46938 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
46939 - sizeof(result), 0);
46940 + cmd = kmalloc(1, GFP_KERNEL);
46941 + if (cmd == NULL)
46942 + return -ENOMEM;
46943 + result = kmalloc(sizeof(*result), GFP_KERNEL);
46944 + if (result == NULL) {
46945 + kfree(cmd);
46946 + return -ENOMEM;
46947 + }
46948 +
46949 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46950 +
46951 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
46952 + sizeof(*result), 0);
46953 if (ret < 0)
46954 - return ret;
46955 + goto out;
46956
46957 *status = 0;
46958
46959 - if (0xffff - le16_to_cpu(result.gain) > 30)
46960 + if (0xffff - le16_to_cpu(result->gain) > 30)
46961 *status |= FE_HAS_SIGNAL;
46962 - if (result.lock_bits & (1 << 6))
46963 + if (result->lock_bits & (1 << 6))
46964 *status |= FE_HAS_LOCK;
46965 - if (result.lock_bits & (1 << 5))
46966 + if (result->lock_bits & (1 << 5))
46967 *status |= FE_HAS_SYNC;
46968 - if (result.lock_bits & (1 << 4))
46969 + if (result->lock_bits & (1 << 4))
46970 *status |= FE_HAS_CARRIER;
46971 - if (result.lock_bits & (1 << 1))
46972 + if (result->lock_bits & (1 << 1))
46973 *status |= FE_HAS_VITERBI;
46974
46975 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
46976 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
46977 *status &= ~FE_HAS_LOCK;
46978
46979 - return 0;
46980 +out:
46981 + kfree(cmd);
46982 + kfree(result);
46983 + return ret;
46984 }
46985
46986 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
46987 {
46988 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46989 - struct dvbt_get_status_msg status;
46990 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46991 + struct dvbt_get_status_msg *status;
46992 + char *cmd;
46993 int ret;
46994
46995 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46996 - sizeof(status), 0);
46997 + cmd = kmalloc(1, GFP_KERNEL);
46998 + if (cmd == NULL)
46999 + return -ENOMEM;
47000 + status = kmalloc(sizeof(*status), GFP_KERNEL);
47001 + if (status == NULL) {
47002 + kfree(cmd);
47003 + return -ENOMEM;
47004 + }
47005 +
47006 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
47007 +
47008 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
47009 + sizeof(*status), 0);
47010 if (ret < 0)
47011 - return ret;
47012 + goto out;
47013
47014 - *ber = le32_to_cpu(status.viterbi_error_rate);
47015 + *ber = le32_to_cpu(status->viterbi_error_rate);
47016 +out:
47017 + kfree(cmd);
47018 + kfree(status);
47019 return 0;
47020 }
47021
47022 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
47023 {
47024 struct cinergyt2_fe_state *state = fe->demodulator_priv;
47025 - struct dvbt_get_status_msg status;
47026 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
47027 + struct dvbt_get_status_msg *status;
47028 + u8 *cmd;
47029 int ret;
47030
47031 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
47032 - sizeof(status), 0);
47033 + cmd = kmalloc(1, GFP_KERNEL);
47034 + if (cmd == NULL)
47035 + return -ENOMEM;
47036 + status = kmalloc(sizeof(*status), GFP_KERNEL);
47037 + if (status == NULL) {
47038 + kfree(cmd);
47039 + return -ENOMEM;
47040 + }
47041 +
47042 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
47043 +
47044 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
47045 + sizeof(*status), 0);
47046 if (ret < 0) {
47047 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
47048 ret);
47049 - return ret;
47050 + goto out;
47051 }
47052 - *unc = le32_to_cpu(status.uncorrected_block_count);
47053 - return 0;
47054 + *unc = le32_to_cpu(status->uncorrected_block_count);
47055 +
47056 +out:
47057 + kfree(cmd);
47058 + kfree(status);
47059 + return ret;
47060 }
47061
47062 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
47063 u16 *strength)
47064 {
47065 struct cinergyt2_fe_state *state = fe->demodulator_priv;
47066 - struct dvbt_get_status_msg status;
47067 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
47068 + struct dvbt_get_status_msg *status;
47069 + char *cmd;
47070 int ret;
47071
47072 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
47073 - sizeof(status), 0);
47074 + cmd = kmalloc(1, GFP_KERNEL);
47075 + if (cmd == NULL)
47076 + return -ENOMEM;
47077 + status = kmalloc(sizeof(*status), GFP_KERNEL);
47078 + if (status == NULL) {
47079 + kfree(cmd);
47080 + return -ENOMEM;
47081 + }
47082 +
47083 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
47084 +
47085 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
47086 + sizeof(*status), 0);
47087 if (ret < 0) {
47088 err("cinergyt2_fe_read_signal_strength() Failed!"
47089 " (Error=%d)\n", ret);
47090 - return ret;
47091 + goto out;
47092 }
47093 - *strength = (0xffff - le16_to_cpu(status.gain));
47094 + *strength = (0xffff - le16_to_cpu(status->gain));
47095 +
47096 +out:
47097 + kfree(cmd);
47098 + kfree(status);
47099 return 0;
47100 }
47101
47102 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
47103 {
47104 struct cinergyt2_fe_state *state = fe->demodulator_priv;
47105 - struct dvbt_get_status_msg status;
47106 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
47107 + struct dvbt_get_status_msg *status;
47108 + char *cmd;
47109 int ret;
47110
47111 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
47112 - sizeof(status), 0);
47113 + cmd = kmalloc(1, GFP_KERNEL);
47114 + if (cmd == NULL)
47115 + return -ENOMEM;
47116 + status = kmalloc(sizeof(*status), GFP_KERNEL);
47117 + if (status == NULL) {
47118 + kfree(cmd);
47119 + return -ENOMEM;
47120 + }
47121 +
47122 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
47123 +
47124 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
47125 + sizeof(*status), 0);
47126 if (ret < 0) {
47127 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
47128 - return ret;
47129 + goto out;
47130 }
47131 - *snr = (status.snr << 8) | status.snr;
47132 - return 0;
47133 + *snr = (status->snr << 8) | status->snr;
47134 +
47135 +out:
47136 + kfree(cmd);
47137 + kfree(status);
47138 + return ret;
47139 }
47140
47141 static int cinergyt2_fe_init(struct dvb_frontend *fe)
47142 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
47143 {
47144 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
47145 struct cinergyt2_fe_state *state = fe->demodulator_priv;
47146 - struct dvbt_set_parameters_msg param;
47147 - char result[2];
47148 + struct dvbt_set_parameters_msg *param;
47149 + char *result;
47150 int err;
47151
47152 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
47153 - param.tps = cpu_to_le16(compute_tps(fep));
47154 - param.freq = cpu_to_le32(fep->frequency / 1000);
47155 - param.flags = 0;
47156 + result = kmalloc(2, GFP_KERNEL);
47157 + if (result == NULL)
47158 + return -ENOMEM;
47159 + param = kmalloc(sizeof(*param), GFP_KERNEL);
47160 + if (param == NULL) {
47161 + kfree(result);
47162 + return -ENOMEM;
47163 + }
47164 +
47165 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
47166 + param->tps = cpu_to_le16(compute_tps(fep));
47167 + param->freq = cpu_to_le32(fep->frequency / 1000);
47168 + param->flags = 0;
47169
47170 switch (fep->bandwidth_hz) {
47171 default:
47172 case 8000000:
47173 - param.bandwidth = 8;
47174 + param->bandwidth = 8;
47175 break;
47176 case 7000000:
47177 - param.bandwidth = 7;
47178 + param->bandwidth = 7;
47179 break;
47180 case 6000000:
47181 - param.bandwidth = 6;
47182 + param->bandwidth = 6;
47183 break;
47184 }
47185
47186 err = dvb_usb_generic_rw(state->d,
47187 - (char *)&param, sizeof(param),
47188 - result, sizeof(result), 0);
47189 + (char *)param, sizeof(*param),
47190 + result, 2, 0);
47191 if (err < 0)
47192 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
47193
47194 - return (err < 0) ? err : 0;
47195 + kfree(result);
47196 + kfree(param);
47197 + return err;
47198 }
47199
47200 static void cinergyt2_fe_release(struct dvb_frontend *fe)
47201 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
47202 index a1c641e..3007da9 100644
47203 --- a/drivers/media/usb/dvb-usb/cxusb.c
47204 +++ b/drivers/media/usb/dvb-usb/cxusb.c
47205 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
47206
47207 struct dib0700_adapter_state {
47208 int (*set_param_save) (struct dvb_frontend *);
47209 -};
47210 +} __no_const;
47211
47212 static int dib7070_set_param_override(struct dvb_frontend *fe)
47213 {
47214 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
47215 index 733a7ff..f8b52e3 100644
47216 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
47217 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
47218 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
47219
47220 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
47221 {
47222 - struct hexline hx;
47223 - u8 reset;
47224 + struct hexline *hx;
47225 + u8 *reset;
47226 int ret,pos=0;
47227
47228 + reset = kmalloc(1, GFP_KERNEL);
47229 + if (reset == NULL)
47230 + return -ENOMEM;
47231 +
47232 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
47233 + if (hx == NULL) {
47234 + kfree(reset);
47235 + return -ENOMEM;
47236 + }
47237 +
47238 /* stop the CPU */
47239 - reset = 1;
47240 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
47241 + reset[0] = 1;
47242 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
47243 err("could not stop the USB controller CPU.");
47244
47245 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
47246 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
47247 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
47248 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
47249 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
47250 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
47251
47252 - if (ret != hx.len) {
47253 + if (ret != hx->len) {
47254 err("error while transferring firmware "
47255 "(transferred size: %d, block size: %d)",
47256 - ret,hx.len);
47257 + ret,hx->len);
47258 ret = -EINVAL;
47259 break;
47260 }
47261 }
47262 if (ret < 0) {
47263 err("firmware download failed at %d with %d",pos,ret);
47264 + kfree(reset);
47265 + kfree(hx);
47266 return ret;
47267 }
47268
47269 if (ret == 0) {
47270 /* restart the CPU */
47271 - reset = 0;
47272 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
47273 + reset[0] = 0;
47274 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
47275 err("could not restart the USB controller CPU.");
47276 ret = -EINVAL;
47277 }
47278 } else
47279 ret = -EIO;
47280
47281 + kfree(reset);
47282 + kfree(hx);
47283 +
47284 return ret;
47285 }
47286 EXPORT_SYMBOL(usb_cypress_load_firmware);
47287 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
47288 index ae0f56a..ec71784 100644
47289 --- a/drivers/media/usb/dvb-usb/dw2102.c
47290 +++ b/drivers/media/usb/dvb-usb/dw2102.c
47291 @@ -118,7 +118,7 @@ struct su3000_state {
47292
47293 struct s6x0_state {
47294 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
47295 -};
47296 +} __no_const;
47297
47298 /* debug */
47299 static int dvb_usb_dw2102_debug;
47300 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
47301 index d947e03..87fef42 100644
47302 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
47303 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
47304 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
47305 static int technisat_usb2_i2c_access(struct usb_device *udev,
47306 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
47307 {
47308 - u8 b[64];
47309 - int ret, actual_length;
47310 + u8 *b = kmalloc(64, GFP_KERNEL);
47311 + int ret, actual_length, error = 0;
47312 +
47313 + if (b == NULL)
47314 + return -ENOMEM;
47315
47316 deb_i2c("i2c-access: %02x, tx: ", device_addr);
47317 debug_dump(tx, txlen, deb_i2c);
47318 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47319
47320 if (ret < 0) {
47321 err("i2c-error: out failed %02x = %d", device_addr, ret);
47322 - return -ENODEV;
47323 + error = -ENODEV;
47324 + goto out;
47325 }
47326
47327 ret = usb_bulk_msg(udev,
47328 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47329 b, 64, &actual_length, 1000);
47330 if (ret < 0) {
47331 err("i2c-error: in failed %02x = %d", device_addr, ret);
47332 - return -ENODEV;
47333 + error = -ENODEV;
47334 + goto out;
47335 }
47336
47337 if (b[0] != I2C_STATUS_OK) {
47338 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47339 /* handle tuner-i2c-nak */
47340 if (!(b[0] == I2C_STATUS_NAK &&
47341 device_addr == 0x60
47342 - /* && device_is_technisat_usb2 */))
47343 - return -ENODEV;
47344 + /* && device_is_technisat_usb2 */)) {
47345 + error = -ENODEV;
47346 + goto out;
47347 + }
47348 }
47349
47350 deb_i2c("status: %d, ", b[0]);
47351 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
47352
47353 deb_i2c("\n");
47354
47355 - return 0;
47356 +out:
47357 + kfree(b);
47358 + return error;
47359 }
47360
47361 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
47362 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
47363 {
47364 int ret;
47365
47366 - u8 led[8] = {
47367 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47368 - 0
47369 - };
47370 + u8 *led = kzalloc(8, GFP_KERNEL);
47371 +
47372 + if (led == NULL)
47373 + return -ENOMEM;
47374
47375 if (disable_led_control && state != TECH_LED_OFF)
47376 return 0;
47377
47378 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
47379 +
47380 switch (state) {
47381 case TECH_LED_ON:
47382 led[1] = 0x82;
47383 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
47384 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
47385 USB_TYPE_VENDOR | USB_DIR_OUT,
47386 0, 0,
47387 - led, sizeof(led), 500);
47388 + led, 8, 500);
47389
47390 mutex_unlock(&d->i2c_mutex);
47391 +
47392 + kfree(led);
47393 +
47394 return ret;
47395 }
47396
47397 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
47398 {
47399 int ret;
47400 - u8 b = 0;
47401 + u8 *b = kzalloc(1, GFP_KERNEL);
47402 +
47403 + if (b == NULL)
47404 + return -ENOMEM;
47405
47406 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
47407 return -EAGAIN;
47408 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
47409 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
47410 USB_TYPE_VENDOR | USB_DIR_OUT,
47411 (red << 8) | green, 0,
47412 - &b, 1, 500);
47413 + b, 1, 500);
47414
47415 mutex_unlock(&d->i2c_mutex);
47416
47417 + kfree(b);
47418 +
47419 return ret;
47420 }
47421
47422 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47423 struct dvb_usb_device_description **desc, int *cold)
47424 {
47425 int ret;
47426 - u8 version[3];
47427 + u8 *version = kmalloc(3, GFP_KERNEL);
47428
47429 /* first select the interface */
47430 if (usb_set_interface(udev, 0, 1) != 0)
47431 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47432
47433 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
47434
47435 + if (version == NULL)
47436 + return 0;
47437 +
47438 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
47439 GET_VERSION_INFO_VENDOR_REQUEST,
47440 USB_TYPE_VENDOR | USB_DIR_IN,
47441 0, 0,
47442 - version, sizeof(version), 500);
47443 + version, 3, 500);
47444
47445 if (ret < 0)
47446 *cold = 1;
47447 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
47448 *cold = 0;
47449 }
47450
47451 + kfree(version);
47452 +
47453 return 0;
47454 }
47455
47456 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
47457
47458 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47459 {
47460 - u8 buf[62], *b;
47461 + u8 *buf, *b;
47462 int ret;
47463 struct ir_raw_event ev;
47464
47465 + buf = kmalloc(62, GFP_KERNEL);
47466 +
47467 + if (buf == NULL)
47468 + return -ENOMEM;
47469 +
47470 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
47471 buf[1] = 0x08;
47472 buf[2] = 0x8f;
47473 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
47474 GET_IR_DATA_VENDOR_REQUEST,
47475 USB_TYPE_VENDOR | USB_DIR_IN,
47476 0x8080, 0,
47477 - buf, sizeof(buf), 500);
47478 + buf, 62, 500);
47479
47480 unlock:
47481 mutex_unlock(&d->i2c_mutex);
47482
47483 - if (ret < 0)
47484 + if (ret < 0) {
47485 + kfree(buf);
47486 return ret;
47487 + }
47488
47489 - if (ret == 1)
47490 + if (ret == 1) {
47491 + kfree(buf);
47492 return 0; /* no key pressed */
47493 + }
47494
47495 /* decoding */
47496 b = buf+1;
47497 @@ -653,6 +686,8 @@ unlock:
47498
47499 ir_raw_event_handle(d->rc_dev);
47500
47501 + kfree(buf);
47502 +
47503 return 1;
47504 }
47505
47506 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47507 index 7e2411c..cef73ca 100644
47508 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47509 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
47510 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
47511 __u32 reserved;
47512 };
47513
47514 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47515 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47516 enum v4l2_memory memory)
47517 {
47518 void __user *up_pln;
47519 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47520 return 0;
47521 }
47522
47523 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
47524 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
47525 enum v4l2_memory memory)
47526 {
47527 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
47528 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47529 * by passing a very big num_planes value */
47530 uplane = compat_alloc_user_space(num_planes *
47531 sizeof(struct v4l2_plane));
47532 - kp->m.planes = uplane;
47533 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
47534
47535 while (--num_planes >= 0) {
47536 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
47537 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
47538 if (num_planes == 0)
47539 return 0;
47540
47541 - uplane = kp->m.planes;
47542 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
47543 if (get_user(p, &up->m.planes))
47544 return -EFAULT;
47545 uplane32 = compat_ptr(p);
47546 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
47547 get_user(kp->capability, &up->capability) ||
47548 get_user(kp->flags, &up->flags))
47549 return -EFAULT;
47550 - kp->base = compat_ptr(tmp);
47551 + kp->base = (void __force_kernel *)compat_ptr(tmp);
47552 get_v4l2_pix_format(&kp->fmt, &up->fmt);
47553 return 0;
47554 }
47555 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47556 n * sizeof(struct v4l2_ext_control32)))
47557 return -EFAULT;
47558 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
47559 - kp->controls = kcontrols;
47560 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
47561 while (--n >= 0) {
47562 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
47563 return -EFAULT;
47564 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
47565 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
47566 {
47567 struct v4l2_ext_control32 __user *ucontrols;
47568 - struct v4l2_ext_control __user *kcontrols = kp->controls;
47569 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
47570 int n = kp->count;
47571 compat_caddr_t p;
47572
47573 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
47574 put_user(kp->start_block, &up->start_block) ||
47575 put_user(kp->blocks, &up->blocks) ||
47576 put_user(tmp, &up->edid) ||
47577 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
47578 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
47579 return -EFAULT;
47580 return 0;
47581 }
47582 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
47583 index 55c6832..a91c7a6 100644
47584 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
47585 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
47586 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
47587 return 0;
47588
47589 case V4L2_CTRL_TYPE_STRING:
47590 - len = strlen(c->string);
47591 - if (len < ctrl->minimum)
47592 + len = strlen_user(c->string);
47593 + if (!len || len < ctrl->minimum)
47594 return -ERANGE;
47595 if ((len - ctrl->minimum) % ctrl->step)
47596 return -ERANGE;
47597 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
47598 index 015f92a..59e311e 100644
47599 --- a/drivers/media/v4l2-core/v4l2-device.c
47600 +++ b/drivers/media/v4l2-core/v4l2-device.c
47601 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
47602 EXPORT_SYMBOL_GPL(v4l2_device_put);
47603
47604 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
47605 - atomic_t *instance)
47606 + atomic_unchecked_t *instance)
47607 {
47608 - int num = atomic_inc_return(instance) - 1;
47609 + int num = atomic_inc_return_unchecked(instance) - 1;
47610 int len = strlen(basename);
47611
47612 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
47613 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
47614 index 16bffd8..3ab516a 100644
47615 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
47616 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
47617 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
47618 struct file *file, void *fh, void *p);
47619 } u;
47620 void (*debug)(const void *arg, bool write_only);
47621 -};
47622 +} __do_const;
47623 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
47624
47625 /* This control needs a priority check */
47626 #define INFO_FL_PRIO (1 << 0)
47627 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
47628 struct video_device *vfd = video_devdata(file);
47629 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
47630 bool write_only = false;
47631 - struct v4l2_ioctl_info default_info;
47632 + v4l2_ioctl_info_no_const default_info;
47633 const struct v4l2_ioctl_info *info;
47634 void *fh = file->private_data;
47635 struct v4l2_fh *vfh = NULL;
47636 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47637 ret = -EINVAL;
47638 break;
47639 }
47640 - *user_ptr = (void __user *)buf->m.planes;
47641 + *user_ptr = (void __force_user *)buf->m.planes;
47642 *kernel_ptr = (void **)&buf->m.planes;
47643 *array_size = sizeof(struct v4l2_plane) * buf->length;
47644 ret = 1;
47645 @@ -2293,7 +2294,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47646 ret = -EINVAL;
47647 break;
47648 }
47649 - *user_ptr = (void __user *)edid->edid;
47650 + *user_ptr = (void __force_user *)edid->edid;
47651 *kernel_ptr = (void **)&edid->edid;
47652 *array_size = edid->blocks * 128;
47653 ret = 1;
47654 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
47655 ret = -EINVAL;
47656 break;
47657 }
47658 - *user_ptr = (void __user *)ctrls->controls;
47659 + *user_ptr = (void __force_user *)ctrls->controls;
47660 *kernel_ptr = (void **)&ctrls->controls;
47661 *array_size = sizeof(struct v4l2_ext_control)
47662 * ctrls->count;
47663 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
47664 }
47665
47666 if (has_array_args) {
47667 - *kernel_ptr = (void __force *)user_ptr;
47668 + *kernel_ptr = (void __force_kernel *)user_ptr;
47669 if (copy_to_user(user_ptr, mbuf, array_size))
47670 err = -EFAULT;
47671 goto out_array_args;
47672 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
47673 index ebc0af7..baed058 100644
47674 --- a/drivers/message/fusion/mptbase.c
47675 +++ b/drivers/message/fusion/mptbase.c
47676 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47677 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
47678 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
47679
47680 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47681 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
47682 +#else
47683 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
47684 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
47685 +#endif
47686 +
47687 /*
47688 * Rounding UP to nearest 4-kB boundary here...
47689 */
47690 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
47691 ioc->facts.GlobalCredits);
47692
47693 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
47694 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47695 + NULL, NULL);
47696 +#else
47697 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
47698 +#endif
47699 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
47700 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
47701 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
47702 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
47703 index 711fcb5..5da1fb0 100644
47704 --- a/drivers/message/fusion/mptsas.c
47705 +++ b/drivers/message/fusion/mptsas.c
47706 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
47707 return 0;
47708 }
47709
47710 +static inline void
47711 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47712 +{
47713 + if (phy_info->port_details) {
47714 + phy_info->port_details->rphy = rphy;
47715 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47716 + ioc->name, rphy));
47717 + }
47718 +
47719 + if (rphy) {
47720 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47721 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47722 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47723 + ioc->name, rphy, rphy->dev.release));
47724 + }
47725 +}
47726 +
47727 /* no mutex */
47728 static void
47729 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
47730 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
47731 return NULL;
47732 }
47733
47734 -static inline void
47735 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
47736 -{
47737 - if (phy_info->port_details) {
47738 - phy_info->port_details->rphy = rphy;
47739 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
47740 - ioc->name, rphy));
47741 - }
47742 -
47743 - if (rphy) {
47744 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
47745 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
47746 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
47747 - ioc->name, rphy, rphy->dev.release));
47748 - }
47749 -}
47750 -
47751 static inline struct sas_port *
47752 mptsas_get_port(struct mptsas_phyinfo *phy_info)
47753 {
47754 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
47755 index 2a1c6f2..a04c6a2 100644
47756 --- a/drivers/message/fusion/mptscsih.c
47757 +++ b/drivers/message/fusion/mptscsih.c
47758 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
47759
47760 h = shost_priv(SChost);
47761
47762 - if (h) {
47763 - if (h->info_kbuf == NULL)
47764 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47765 - return h->info_kbuf;
47766 - h->info_kbuf[0] = '\0';
47767 + if (!h)
47768 + return NULL;
47769
47770 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47771 - h->info_kbuf[size-1] = '\0';
47772 - }
47773 + if (h->info_kbuf == NULL)
47774 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
47775 + return h->info_kbuf;
47776 + h->info_kbuf[0] = '\0';
47777 +
47778 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
47779 + h->info_kbuf[size-1] = '\0';
47780
47781 return h->info_kbuf;
47782 }
47783 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
47784 index b7d87cd..3fb36da 100644
47785 --- a/drivers/message/i2o/i2o_proc.c
47786 +++ b/drivers/message/i2o/i2o_proc.c
47787 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
47788 "Array Controller Device"
47789 };
47790
47791 -static char *chtostr(char *tmp, u8 *chars, int n)
47792 -{
47793 - tmp[0] = 0;
47794 - return strncat(tmp, (char *)chars, n);
47795 -}
47796 -
47797 static int i2o_report_query_status(struct seq_file *seq, int block_status,
47798 char *group)
47799 {
47800 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
47801 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
47802 {
47803 struct i2o_controller *c = (struct i2o_controller *)seq->private;
47804 - static u32 work32[5];
47805 - static u8 *work8 = (u8 *) work32;
47806 - static u16 *work16 = (u16 *) work32;
47807 + u32 work32[5];
47808 + u8 *work8 = (u8 *) work32;
47809 + u16 *work16 = (u16 *) work32;
47810 int token;
47811 u32 hwcap;
47812
47813 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47814 } *result;
47815
47816 i2o_exec_execute_ddm_table ddm_table;
47817 - char tmp[28 + 1];
47818
47819 result = kmalloc(sizeof(*result), GFP_KERNEL);
47820 if (!result)
47821 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47822
47823 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47824 seq_printf(seq, "%-#8x", ddm_table.module_id);
47825 - seq_printf(seq, "%-29s",
47826 - chtostr(tmp, ddm_table.module_name_version, 28));
47827 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47828 seq_printf(seq, "%9d ", ddm_table.data_size);
47829 seq_printf(seq, "%8d", ddm_table.code_size);
47830
47831 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47832
47833 i2o_driver_result_table *result;
47834 i2o_driver_store_table *dst;
47835 - char tmp[28 + 1];
47836
47837 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47838 if (result == NULL)
47839 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47840
47841 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47842 seq_printf(seq, "%-#8x", dst->module_id);
47843 - seq_printf(seq, "%-29s",
47844 - chtostr(tmp, dst->module_name_version, 28));
47845 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47846 + seq_printf(seq, "%-.28s", dst->module_name_version);
47847 + seq_printf(seq, "%-.8s", dst->date);
47848 seq_printf(seq, "%8d ", dst->module_size);
47849 seq_printf(seq, "%8d ", dst->mpb_size);
47850 seq_printf(seq, "0x%04x", dst->module_flags);
47851 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47852 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47853 {
47854 struct i2o_device *d = (struct i2o_device *)seq->private;
47855 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47856 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47857 // == (allow) 512d bytes (max)
47858 - static u16 *work16 = (u16 *) work32;
47859 + u16 *work16 = (u16 *) work32;
47860 int token;
47861 - char tmp[16 + 1];
47862
47863 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47864
47865 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47866 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47867 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47868 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47869 - seq_printf(seq, "Vendor info : %s\n",
47870 - chtostr(tmp, (u8 *) (work32 + 2), 16));
47871 - seq_printf(seq, "Product info : %s\n",
47872 - chtostr(tmp, (u8 *) (work32 + 6), 16));
47873 - seq_printf(seq, "Description : %s\n",
47874 - chtostr(tmp, (u8 *) (work32 + 10), 16));
47875 - seq_printf(seq, "Product rev. : %s\n",
47876 - chtostr(tmp, (u8 *) (work32 + 14), 8));
47877 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47878 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47879 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47880 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47881
47882 seq_printf(seq, "Serial number : ");
47883 print_serial_number(seq, (u8 *) (work32 + 16),
47884 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47885 u8 pad[256]; // allow up to 256 byte (max) serial number
47886 } result;
47887
47888 - char tmp[24 + 1];
47889 -
47890 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47891
47892 if (token < 0) {
47893 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47894 }
47895
47896 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47897 - seq_printf(seq, "Module name : %s\n",
47898 - chtostr(tmp, result.module_name, 24));
47899 - seq_printf(seq, "Module revision : %s\n",
47900 - chtostr(tmp, result.module_rev, 8));
47901 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
47902 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47903
47904 seq_printf(seq, "Serial number : ");
47905 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47906 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47907 u8 instance_number[4];
47908 } result;
47909
47910 - char tmp[64 + 1];
47911 -
47912 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47913
47914 if (token < 0) {
47915 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47916 return 0;
47917 }
47918
47919 - seq_printf(seq, "Device name : %s\n",
47920 - chtostr(tmp, result.device_name, 64));
47921 - seq_printf(seq, "Service name : %s\n",
47922 - chtostr(tmp, result.service_name, 64));
47923 - seq_printf(seq, "Physical name : %s\n",
47924 - chtostr(tmp, result.physical_location, 64));
47925 - seq_printf(seq, "Instance number : %s\n",
47926 - chtostr(tmp, result.instance_number, 4));
47927 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
47928 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
47929 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47930 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47931
47932 return 0;
47933 }
47934 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47935 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47936 {
47937 struct i2o_device *d = (struct i2o_device *)seq->private;
47938 - static u32 work32[12];
47939 - static u16 *work16 = (u16 *) work32;
47940 - static u8 *work8 = (u8 *) work32;
47941 + u32 work32[12];
47942 + u16 *work16 = (u16 *) work32;
47943 + u8 *work8 = (u8 *) work32;
47944 int token;
47945
47946 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47947 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47948 index 92752fb..a7494f6 100644
47949 --- a/drivers/message/i2o/iop.c
47950 +++ b/drivers/message/i2o/iop.c
47951 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47952
47953 spin_lock_irqsave(&c->context_list_lock, flags);
47954
47955 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47956 - atomic_inc(&c->context_list_counter);
47957 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47958 + atomic_inc_unchecked(&c->context_list_counter);
47959
47960 - entry->context = atomic_read(&c->context_list_counter);
47961 + entry->context = atomic_read_unchecked(&c->context_list_counter);
47962
47963 list_add(&entry->list, &c->context_list);
47964
47965 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47966
47967 #if BITS_PER_LONG == 64
47968 spin_lock_init(&c->context_list_lock);
47969 - atomic_set(&c->context_list_counter, 0);
47970 + atomic_set_unchecked(&c->context_list_counter, 0);
47971 INIT_LIST_HEAD(&c->context_list);
47972 #endif
47973
47974 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47975 index d1a22aa..d0f7bf7 100644
47976 --- a/drivers/mfd/ab8500-debugfs.c
47977 +++ b/drivers/mfd/ab8500-debugfs.c
47978 @@ -100,7 +100,7 @@ static int irq_last;
47979 static u32 *irq_count;
47980 static int num_irqs;
47981
47982 -static struct device_attribute **dev_attr;
47983 +static device_attribute_no_const **dev_attr;
47984 static char **event_name;
47985
47986 static u8 avg_sample = SAMPLE_16;
47987 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47988 index a83eed5..62a58a9 100644
47989 --- a/drivers/mfd/max8925-i2c.c
47990 +++ b/drivers/mfd/max8925-i2c.c
47991 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47992 const struct i2c_device_id *id)
47993 {
47994 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47995 - static struct max8925_chip *chip;
47996 + struct max8925_chip *chip;
47997 struct device_node *node = client->dev.of_node;
47998
47999 if (node && !pdata) {
48000 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
48001 index f9e42ea..614d240 100644
48002 --- a/drivers/mfd/tps65910.c
48003 +++ b/drivers/mfd/tps65910.c
48004 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
48005 struct tps65910_platform_data *pdata)
48006 {
48007 int ret = 0;
48008 - static struct regmap_irq_chip *tps6591x_irqs_chip;
48009 + struct regmap_irq_chip *tps6591x_irqs_chip;
48010
48011 if (!irq) {
48012 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
48013 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
48014 index 596b1f6..5b6ab74 100644
48015 --- a/drivers/mfd/twl4030-irq.c
48016 +++ b/drivers/mfd/twl4030-irq.c
48017 @@ -34,6 +34,7 @@
48018 #include <linux/of.h>
48019 #include <linux/irqdomain.h>
48020 #include <linux/i2c/twl.h>
48021 +#include <asm/pgtable.h>
48022
48023 #include "twl-core.h"
48024
48025 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
48026 * Install an irq handler for each of the SIH modules;
48027 * clone dummy irq_chip since PIH can't *do* anything
48028 */
48029 - twl4030_irq_chip = dummy_irq_chip;
48030 - twl4030_irq_chip.name = "twl4030";
48031 + pax_open_kernel();
48032 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
48033 + *(const char **)&twl4030_irq_chip.name = "twl4030";
48034
48035 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
48036 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
48037 + pax_close_kernel();
48038
48039 for (i = irq_base; i < irq_end; i++) {
48040 irq_set_chip_and_handler(i, &twl4030_irq_chip,
48041 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
48042 index 464419b..64bae8d 100644
48043 --- a/drivers/misc/c2port/core.c
48044 +++ b/drivers/misc/c2port/core.c
48045 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
48046 goto error_idr_alloc;
48047 c2dev->id = ret;
48048
48049 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
48050 + pax_open_kernel();
48051 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
48052 + pax_close_kernel();
48053
48054 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
48055 "c2port%d", c2dev->id);
48056 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
48057 index 3f2b625..945e179 100644
48058 --- a/drivers/misc/eeprom/sunxi_sid.c
48059 +++ b/drivers/misc/eeprom/sunxi_sid.c
48060 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
48061
48062 platform_set_drvdata(pdev, sid_data);
48063
48064 - sid_bin_attr.size = sid_data->keysize;
48065 + pax_open_kernel();
48066 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
48067 + pax_close_kernel();
48068 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
48069 return -ENODEV;
48070
48071 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
48072 index 36f5d52..32311c3 100644
48073 --- a/drivers/misc/kgdbts.c
48074 +++ b/drivers/misc/kgdbts.c
48075 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
48076 char before[BREAK_INSTR_SIZE];
48077 char after[BREAK_INSTR_SIZE];
48078
48079 - probe_kernel_read(before, (char *)kgdbts_break_test,
48080 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
48081 BREAK_INSTR_SIZE);
48082 init_simple_test();
48083 ts.tst = plant_and_detach_test;
48084 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
48085 /* Activate test with initial breakpoint */
48086 if (!is_early)
48087 kgdb_breakpoint();
48088 - probe_kernel_read(after, (char *)kgdbts_break_test,
48089 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
48090 BREAK_INSTR_SIZE);
48091 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
48092 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
48093 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
48094 index 3ef4627..8d00486 100644
48095 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
48096 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
48097 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
48098 * the lid is closed. This leads to interrupts as soon as a little move
48099 * is done.
48100 */
48101 - atomic_inc(&lis3->count);
48102 + atomic_inc_unchecked(&lis3->count);
48103
48104 wake_up_interruptible(&lis3->misc_wait);
48105 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
48106 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
48107 if (lis3->pm_dev)
48108 pm_runtime_get_sync(lis3->pm_dev);
48109
48110 - atomic_set(&lis3->count, 0);
48111 + atomic_set_unchecked(&lis3->count, 0);
48112 return 0;
48113 }
48114
48115 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
48116 add_wait_queue(&lis3->misc_wait, &wait);
48117 while (true) {
48118 set_current_state(TASK_INTERRUPTIBLE);
48119 - data = atomic_xchg(&lis3->count, 0);
48120 + data = atomic_xchg_unchecked(&lis3->count, 0);
48121 if (data)
48122 break;
48123
48124 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
48125 struct lis3lv02d, miscdev);
48126
48127 poll_wait(file, &lis3->misc_wait, wait);
48128 - if (atomic_read(&lis3->count))
48129 + if (atomic_read_unchecked(&lis3->count))
48130 return POLLIN | POLLRDNORM;
48131 return 0;
48132 }
48133 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
48134 index c439c82..1f20f57 100644
48135 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
48136 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
48137 @@ -297,7 +297,7 @@ struct lis3lv02d {
48138 struct input_polled_dev *idev; /* input device */
48139 struct platform_device *pdev; /* platform device */
48140 struct regulator_bulk_data regulators[2];
48141 - atomic_t count; /* interrupt count after last read */
48142 + atomic_unchecked_t count; /* interrupt count after last read */
48143 union axis_conversion ac; /* hw -> logical axis */
48144 int mapped_btns[3];
48145
48146 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
48147 index 2f30bad..c4c13d0 100644
48148 --- a/drivers/misc/sgi-gru/gruhandles.c
48149 +++ b/drivers/misc/sgi-gru/gruhandles.c
48150 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
48151 unsigned long nsec;
48152
48153 nsec = CLKS2NSEC(clks);
48154 - atomic_long_inc(&mcs_op_statistics[op].count);
48155 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
48156 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
48157 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
48158 if (mcs_op_statistics[op].max < nsec)
48159 mcs_op_statistics[op].max = nsec;
48160 }
48161 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
48162 index 4f76359..cdfcb2e 100644
48163 --- a/drivers/misc/sgi-gru/gruprocfs.c
48164 +++ b/drivers/misc/sgi-gru/gruprocfs.c
48165 @@ -32,9 +32,9 @@
48166
48167 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
48168
48169 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
48170 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
48171 {
48172 - unsigned long val = atomic_long_read(v);
48173 + unsigned long val = atomic_long_read_unchecked(v);
48174
48175 seq_printf(s, "%16lu %s\n", val, id);
48176 }
48177 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
48178
48179 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
48180 for (op = 0; op < mcsop_last; op++) {
48181 - count = atomic_long_read(&mcs_op_statistics[op].count);
48182 - total = atomic_long_read(&mcs_op_statistics[op].total);
48183 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
48184 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
48185 max = mcs_op_statistics[op].max;
48186 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
48187 count ? total / count : 0, max);
48188 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
48189 index 5c3ce24..4915ccb 100644
48190 --- a/drivers/misc/sgi-gru/grutables.h
48191 +++ b/drivers/misc/sgi-gru/grutables.h
48192 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
48193 * GRU statistics.
48194 */
48195 struct gru_stats_s {
48196 - atomic_long_t vdata_alloc;
48197 - atomic_long_t vdata_free;
48198 - atomic_long_t gts_alloc;
48199 - atomic_long_t gts_free;
48200 - atomic_long_t gms_alloc;
48201 - atomic_long_t gms_free;
48202 - atomic_long_t gts_double_allocate;
48203 - atomic_long_t assign_context;
48204 - atomic_long_t assign_context_failed;
48205 - atomic_long_t free_context;
48206 - atomic_long_t load_user_context;
48207 - atomic_long_t load_kernel_context;
48208 - atomic_long_t lock_kernel_context;
48209 - atomic_long_t unlock_kernel_context;
48210 - atomic_long_t steal_user_context;
48211 - atomic_long_t steal_kernel_context;
48212 - atomic_long_t steal_context_failed;
48213 - atomic_long_t nopfn;
48214 - atomic_long_t asid_new;
48215 - atomic_long_t asid_next;
48216 - atomic_long_t asid_wrap;
48217 - atomic_long_t asid_reuse;
48218 - atomic_long_t intr;
48219 - atomic_long_t intr_cbr;
48220 - atomic_long_t intr_tfh;
48221 - atomic_long_t intr_spurious;
48222 - atomic_long_t intr_mm_lock_failed;
48223 - atomic_long_t call_os;
48224 - atomic_long_t call_os_wait_queue;
48225 - atomic_long_t user_flush_tlb;
48226 - atomic_long_t user_unload_context;
48227 - atomic_long_t user_exception;
48228 - atomic_long_t set_context_option;
48229 - atomic_long_t check_context_retarget_intr;
48230 - atomic_long_t check_context_unload;
48231 - atomic_long_t tlb_dropin;
48232 - atomic_long_t tlb_preload_page;
48233 - atomic_long_t tlb_dropin_fail_no_asid;
48234 - atomic_long_t tlb_dropin_fail_upm;
48235 - atomic_long_t tlb_dropin_fail_invalid;
48236 - atomic_long_t tlb_dropin_fail_range_active;
48237 - atomic_long_t tlb_dropin_fail_idle;
48238 - atomic_long_t tlb_dropin_fail_fmm;
48239 - atomic_long_t tlb_dropin_fail_no_exception;
48240 - atomic_long_t tfh_stale_on_fault;
48241 - atomic_long_t mmu_invalidate_range;
48242 - atomic_long_t mmu_invalidate_page;
48243 - atomic_long_t flush_tlb;
48244 - atomic_long_t flush_tlb_gru;
48245 - atomic_long_t flush_tlb_gru_tgh;
48246 - atomic_long_t flush_tlb_gru_zero_asid;
48247 + atomic_long_unchecked_t vdata_alloc;
48248 + atomic_long_unchecked_t vdata_free;
48249 + atomic_long_unchecked_t gts_alloc;
48250 + atomic_long_unchecked_t gts_free;
48251 + atomic_long_unchecked_t gms_alloc;
48252 + atomic_long_unchecked_t gms_free;
48253 + atomic_long_unchecked_t gts_double_allocate;
48254 + atomic_long_unchecked_t assign_context;
48255 + atomic_long_unchecked_t assign_context_failed;
48256 + atomic_long_unchecked_t free_context;
48257 + atomic_long_unchecked_t load_user_context;
48258 + atomic_long_unchecked_t load_kernel_context;
48259 + atomic_long_unchecked_t lock_kernel_context;
48260 + atomic_long_unchecked_t unlock_kernel_context;
48261 + atomic_long_unchecked_t steal_user_context;
48262 + atomic_long_unchecked_t steal_kernel_context;
48263 + atomic_long_unchecked_t steal_context_failed;
48264 + atomic_long_unchecked_t nopfn;
48265 + atomic_long_unchecked_t asid_new;
48266 + atomic_long_unchecked_t asid_next;
48267 + atomic_long_unchecked_t asid_wrap;
48268 + atomic_long_unchecked_t asid_reuse;
48269 + atomic_long_unchecked_t intr;
48270 + atomic_long_unchecked_t intr_cbr;
48271 + atomic_long_unchecked_t intr_tfh;
48272 + atomic_long_unchecked_t intr_spurious;
48273 + atomic_long_unchecked_t intr_mm_lock_failed;
48274 + atomic_long_unchecked_t call_os;
48275 + atomic_long_unchecked_t call_os_wait_queue;
48276 + atomic_long_unchecked_t user_flush_tlb;
48277 + atomic_long_unchecked_t user_unload_context;
48278 + atomic_long_unchecked_t user_exception;
48279 + atomic_long_unchecked_t set_context_option;
48280 + atomic_long_unchecked_t check_context_retarget_intr;
48281 + atomic_long_unchecked_t check_context_unload;
48282 + atomic_long_unchecked_t tlb_dropin;
48283 + atomic_long_unchecked_t tlb_preload_page;
48284 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
48285 + atomic_long_unchecked_t tlb_dropin_fail_upm;
48286 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
48287 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
48288 + atomic_long_unchecked_t tlb_dropin_fail_idle;
48289 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
48290 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
48291 + atomic_long_unchecked_t tfh_stale_on_fault;
48292 + atomic_long_unchecked_t mmu_invalidate_range;
48293 + atomic_long_unchecked_t mmu_invalidate_page;
48294 + atomic_long_unchecked_t flush_tlb;
48295 + atomic_long_unchecked_t flush_tlb_gru;
48296 + atomic_long_unchecked_t flush_tlb_gru_tgh;
48297 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
48298
48299 - atomic_long_t copy_gpa;
48300 - atomic_long_t read_gpa;
48301 + atomic_long_unchecked_t copy_gpa;
48302 + atomic_long_unchecked_t read_gpa;
48303
48304 - atomic_long_t mesq_receive;
48305 - atomic_long_t mesq_receive_none;
48306 - atomic_long_t mesq_send;
48307 - atomic_long_t mesq_send_failed;
48308 - atomic_long_t mesq_noop;
48309 - atomic_long_t mesq_send_unexpected_error;
48310 - atomic_long_t mesq_send_lb_overflow;
48311 - atomic_long_t mesq_send_qlimit_reached;
48312 - atomic_long_t mesq_send_amo_nacked;
48313 - atomic_long_t mesq_send_put_nacked;
48314 - atomic_long_t mesq_page_overflow;
48315 - atomic_long_t mesq_qf_locked;
48316 - atomic_long_t mesq_qf_noop_not_full;
48317 - atomic_long_t mesq_qf_switch_head_failed;
48318 - atomic_long_t mesq_qf_unexpected_error;
48319 - atomic_long_t mesq_noop_unexpected_error;
48320 - atomic_long_t mesq_noop_lb_overflow;
48321 - atomic_long_t mesq_noop_qlimit_reached;
48322 - atomic_long_t mesq_noop_amo_nacked;
48323 - atomic_long_t mesq_noop_put_nacked;
48324 - atomic_long_t mesq_noop_page_overflow;
48325 + atomic_long_unchecked_t mesq_receive;
48326 + atomic_long_unchecked_t mesq_receive_none;
48327 + atomic_long_unchecked_t mesq_send;
48328 + atomic_long_unchecked_t mesq_send_failed;
48329 + atomic_long_unchecked_t mesq_noop;
48330 + atomic_long_unchecked_t mesq_send_unexpected_error;
48331 + atomic_long_unchecked_t mesq_send_lb_overflow;
48332 + atomic_long_unchecked_t mesq_send_qlimit_reached;
48333 + atomic_long_unchecked_t mesq_send_amo_nacked;
48334 + atomic_long_unchecked_t mesq_send_put_nacked;
48335 + atomic_long_unchecked_t mesq_page_overflow;
48336 + atomic_long_unchecked_t mesq_qf_locked;
48337 + atomic_long_unchecked_t mesq_qf_noop_not_full;
48338 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
48339 + atomic_long_unchecked_t mesq_qf_unexpected_error;
48340 + atomic_long_unchecked_t mesq_noop_unexpected_error;
48341 + atomic_long_unchecked_t mesq_noop_lb_overflow;
48342 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
48343 + atomic_long_unchecked_t mesq_noop_amo_nacked;
48344 + atomic_long_unchecked_t mesq_noop_put_nacked;
48345 + atomic_long_unchecked_t mesq_noop_page_overflow;
48346
48347 };
48348
48349 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
48350 tghop_invalidate, mcsop_last};
48351
48352 struct mcs_op_statistic {
48353 - atomic_long_t count;
48354 - atomic_long_t total;
48355 + atomic_long_unchecked_t count;
48356 + atomic_long_unchecked_t total;
48357 unsigned long max;
48358 };
48359
48360 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
48361
48362 #define STAT(id) do { \
48363 if (gru_options & OPT_STATS) \
48364 - atomic_long_inc(&gru_stats.id); \
48365 + atomic_long_inc_unchecked(&gru_stats.id); \
48366 } while (0)
48367
48368 #ifdef CONFIG_SGI_GRU_DEBUG
48369 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
48370 index c862cd4..0d176fe 100644
48371 --- a/drivers/misc/sgi-xp/xp.h
48372 +++ b/drivers/misc/sgi-xp/xp.h
48373 @@ -288,7 +288,7 @@ struct xpc_interface {
48374 xpc_notify_func, void *);
48375 void (*received) (short, int, void *);
48376 enum xp_retval (*partid_to_nasids) (short, void *);
48377 -};
48378 +} __no_const;
48379
48380 extern struct xpc_interface xpc_interface;
48381
48382 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
48383 index 01be66d..e3a0c7e 100644
48384 --- a/drivers/misc/sgi-xp/xp_main.c
48385 +++ b/drivers/misc/sgi-xp/xp_main.c
48386 @@ -78,13 +78,13 @@ xpc_notloaded(void)
48387 }
48388
48389 struct xpc_interface xpc_interface = {
48390 - (void (*)(int))xpc_notloaded,
48391 - (void (*)(int))xpc_notloaded,
48392 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48393 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48394 + .connect = (void (*)(int))xpc_notloaded,
48395 + .disconnect = (void (*)(int))xpc_notloaded,
48396 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
48397 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
48398 void *))xpc_notloaded,
48399 - (void (*)(short, int, void *))xpc_notloaded,
48400 - (enum xp_retval(*)(short, void *))xpc_notloaded
48401 + .received = (void (*)(short, int, void *))xpc_notloaded,
48402 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
48403 };
48404 EXPORT_SYMBOL_GPL(xpc_interface);
48405
48406 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
48407 index b94d5f7..7f494c5 100644
48408 --- a/drivers/misc/sgi-xp/xpc.h
48409 +++ b/drivers/misc/sgi-xp/xpc.h
48410 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
48411 void (*received_payload) (struct xpc_channel *, void *);
48412 void (*notify_senders_of_disconnect) (struct xpc_channel *);
48413 };
48414 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
48415
48416 /* struct xpc_partition act_state values (for XPC HB) */
48417
48418 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
48419 /* found in xpc_main.c */
48420 extern struct device *xpc_part;
48421 extern struct device *xpc_chan;
48422 -extern struct xpc_arch_operations xpc_arch_ops;
48423 +extern xpc_arch_operations_no_const xpc_arch_ops;
48424 extern int xpc_disengage_timelimit;
48425 extern int xpc_disengage_timedout;
48426 extern int xpc_activate_IRQ_rcvd;
48427 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
48428 index 82dc574..8539ab2 100644
48429 --- a/drivers/misc/sgi-xp/xpc_main.c
48430 +++ b/drivers/misc/sgi-xp/xpc_main.c
48431 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
48432 .notifier_call = xpc_system_die,
48433 };
48434
48435 -struct xpc_arch_operations xpc_arch_ops;
48436 +xpc_arch_operations_no_const xpc_arch_ops;
48437
48438 /*
48439 * Timer function to enforce the timelimit on the partition disengage.
48440 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
48441
48442 if (((die_args->trapnr == X86_TRAP_MF) ||
48443 (die_args->trapnr == X86_TRAP_XF)) &&
48444 - !user_mode_vm(die_args->regs))
48445 + !user_mode(die_args->regs))
48446 xpc_die_deactivate();
48447
48448 break;
48449 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
48450 index 452782b..0c10e40 100644
48451 --- a/drivers/mmc/card/block.c
48452 +++ b/drivers/mmc/card/block.c
48453 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
48454 if (idata->ic.postsleep_min_us)
48455 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
48456
48457 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
48458 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
48459 err = -EFAULT;
48460 goto cmd_rel_host;
48461 }
48462 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
48463 index f51b5ba..86614a7 100644
48464 --- a/drivers/mmc/core/mmc_ops.c
48465 +++ b/drivers/mmc/core/mmc_ops.c
48466 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
48467 void *data_buf;
48468 int is_on_stack;
48469
48470 - is_on_stack = object_is_on_stack(buf);
48471 + is_on_stack = object_starts_on_stack(buf);
48472 if (is_on_stack) {
48473 /*
48474 * dma onto stack is unsafe/nonportable, but callers to this
48475 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
48476 index 738fa24..1568451 100644
48477 --- a/drivers/mmc/host/dw_mmc.h
48478 +++ b/drivers/mmc/host/dw_mmc.h
48479 @@ -257,5 +257,5 @@ struct dw_mci_drv_data {
48480 int (*parse_dt)(struct dw_mci *host);
48481 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
48482 struct dw_mci_tuning_data *tuning_data);
48483 -};
48484 +} __do_const;
48485 #endif /* _DW_MMC_H_ */
48486 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
48487 index 249ab80..9314ce1 100644
48488 --- a/drivers/mmc/host/mmci.c
48489 +++ b/drivers/mmc/host/mmci.c
48490 @@ -1507,7 +1507,9 @@ static int mmci_probe(struct amba_device *dev,
48491 mmc->caps |= MMC_CAP_CMD23;
48492
48493 if (variant->busy_detect) {
48494 - mmci_ops.card_busy = mmci_card_busy;
48495 + pax_open_kernel();
48496 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
48497 + pax_close_kernel();
48498 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
48499 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
48500 mmc->max_busy_timeout = 0;
48501 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
48502 index ccec0e3..199f9ce 100644
48503 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
48504 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
48505 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
48506 host->mmc->caps |= MMC_CAP_1_8V_DDR;
48507 }
48508
48509 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
48510 - sdhci_esdhc_ops.platform_execute_tuning =
48511 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
48512 + pax_open_kernel();
48513 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
48514 esdhc_executing_tuning;
48515 + pax_close_kernel();
48516 + }
48517
48518 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
48519 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
48520 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
48521 index fa5954a..56840e5 100644
48522 --- a/drivers/mmc/host/sdhci-s3c.c
48523 +++ b/drivers/mmc/host/sdhci-s3c.c
48524 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
48525 * we can use overriding functions instead of default.
48526 */
48527 if (sc->no_divider) {
48528 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48529 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48530 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48531 + pax_open_kernel();
48532 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
48533 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
48534 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
48535 + pax_close_kernel();
48536 }
48537
48538 /* It supports additional host capabilities if needed */
48539 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
48540 index 423666b..81ff5eb 100644
48541 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
48542 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
48543 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
48544 size_t totlen = 0, thislen;
48545 int ret = 0;
48546 size_t buflen = 0;
48547 - static char *buffer;
48548 + char *buffer;
48549
48550 if (!ECCBUF_SIZE) {
48551 /* We should fall back to a general writev implementation.
48552 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
48553 index 9f2012a..a81c720 100644
48554 --- a/drivers/mtd/nand/denali.c
48555 +++ b/drivers/mtd/nand/denali.c
48556 @@ -24,6 +24,7 @@
48557 #include <linux/slab.h>
48558 #include <linux/mtd/mtd.h>
48559 #include <linux/module.h>
48560 +#include <linux/slab.h>
48561
48562 #include "denali.h"
48563
48564 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48565 index f638cd8..2cbf586 100644
48566 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48567 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
48568 @@ -387,7 +387,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
48569
48570 /* first try to map the upper buffer directly */
48571 if (virt_addr_valid(this->upper_buf) &&
48572 - !object_is_on_stack(this->upper_buf)) {
48573 + !object_starts_on_stack(this->upper_buf)) {
48574 sg_init_one(sgl, this->upper_buf, this->upper_len);
48575 ret = dma_map_sg(this->dev, sgl, 1, dr);
48576 if (ret == 0)
48577 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
48578 index 51b9d6a..52af9a7 100644
48579 --- a/drivers/mtd/nftlmount.c
48580 +++ b/drivers/mtd/nftlmount.c
48581 @@ -24,6 +24,7 @@
48582 #include <asm/errno.h>
48583 #include <linux/delay.h>
48584 #include <linux/slab.h>
48585 +#include <linux/sched.h>
48586 #include <linux/mtd/mtd.h>
48587 #include <linux/mtd/nand.h>
48588 #include <linux/mtd/nftl.h>
48589 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
48590 index cf49c22..971b133 100644
48591 --- a/drivers/mtd/sm_ftl.c
48592 +++ b/drivers/mtd/sm_ftl.c
48593 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
48594 #define SM_CIS_VENDOR_OFFSET 0x59
48595 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
48596 {
48597 - struct attribute_group *attr_group;
48598 + attribute_group_no_const *attr_group;
48599 struct attribute **attributes;
48600 struct sm_sysfs_attribute *vendor_attribute;
48601 char *vendor;
48602 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
48603 index 5ab3c18..5c3a836 100644
48604 --- a/drivers/net/bonding/bond_netlink.c
48605 +++ b/drivers/net/bonding/bond_netlink.c
48606 @@ -542,7 +542,7 @@ nla_put_failure:
48607 return -EMSGSIZE;
48608 }
48609
48610 -struct rtnl_link_ops bond_link_ops __read_mostly = {
48611 +struct rtnl_link_ops bond_link_ops = {
48612 .kind = "bond",
48613 .priv_size = sizeof(struct bonding),
48614 .setup = bond_setup,
48615 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
48616 index 4168822..f38eeddf 100644
48617 --- a/drivers/net/can/Kconfig
48618 +++ b/drivers/net/can/Kconfig
48619 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
48620
48621 config CAN_FLEXCAN
48622 tristate "Support for Freescale FLEXCAN based chips"
48623 - depends on ARM || PPC
48624 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
48625 ---help---
48626 Say Y here if you want to support for Freescale FlexCAN.
48627
48628 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
48629 index 1d162cc..b546a75 100644
48630 --- a/drivers/net/ethernet/8390/ax88796.c
48631 +++ b/drivers/net/ethernet/8390/ax88796.c
48632 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
48633 if (ax->plat->reg_offsets)
48634 ei_local->reg_offset = ax->plat->reg_offsets;
48635 else {
48636 + resource_size_t _mem_size = mem_size;
48637 + do_div(_mem_size, 0x18);
48638 ei_local->reg_offset = ax->reg_offsets;
48639 for (ret = 0; ret < 0x18; ret++)
48640 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
48641 + ax->reg_offsets[ret] = _mem_size * ret;
48642 }
48643
48644 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
48645 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
48646 index 7330681..7e9e463 100644
48647 --- a/drivers/net/ethernet/altera/altera_tse_main.c
48648 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
48649 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
48650 return 0;
48651 }
48652
48653 -static struct net_device_ops altera_tse_netdev_ops = {
48654 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
48655 .ndo_open = tse_open,
48656 .ndo_stop = tse_shutdown,
48657 .ndo_start_xmit = tse_start_xmit,
48658 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
48659 ndev->netdev_ops = &altera_tse_netdev_ops;
48660 altera_tse_set_ethtool_ops(ndev);
48661
48662 + pax_open_kernel();
48663 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
48664
48665 if (priv->hash_filter)
48666 altera_tse_netdev_ops.ndo_set_rx_mode =
48667 tse_set_rx_mode_hashfilter;
48668 + pax_close_kernel();
48669
48670 /* Scatter/gather IO is not supported,
48671 * so it is turned off
48672 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48673 index bf462ee8..18b8375 100644
48674 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48675 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
48676 @@ -986,14 +986,14 @@ do { \
48677 * operations, everything works on mask values.
48678 */
48679 #define XMDIO_READ(_pdata, _mmd, _reg) \
48680 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
48681 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
48682 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
48683
48684 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
48685 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
48686
48687 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
48688 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
48689 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
48690 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
48691
48692 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
48693 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48694 index 6bb76d5..ded47a8 100644
48695 --- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48696 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
48697 @@ -273,7 +273,7 @@ static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer,
48698 struct xgbe_prv_data *pdata = filp->private_data;
48699 unsigned int value;
48700
48701 - value = pdata->hw_if.read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48702 + value = pdata->hw_if->read_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48703 pdata->debugfs_xpcs_reg);
48704
48705 return xgbe_common_read(buffer, count, ppos, value);
48706 @@ -291,7 +291,7 @@ static ssize_t xpcs_reg_value_write(struct file *filp,
48707 if (len < 0)
48708 return len;
48709
48710 - pdata->hw_if.write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48711 + pdata->hw_if->write_mmd_regs(pdata, pdata->debugfs_xpcs_mmd,
48712 pdata->debugfs_xpcs_reg, value);
48713
48714 return len;
48715 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48716 index 6f1c859..e96ac1a 100644
48717 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48718 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
48719 @@ -236,7 +236,7 @@ err_ring:
48720
48721 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48722 {
48723 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48724 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48725 struct xgbe_channel *channel;
48726 struct xgbe_ring *ring;
48727 struct xgbe_ring_data *rdata;
48728 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
48729
48730 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
48731 {
48732 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48733 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48734 struct xgbe_channel *channel;
48735 struct xgbe_ring *ring;
48736 struct xgbe_ring_desc *rdesc;
48737 @@ -496,7 +496,7 @@ err_out:
48738 static void xgbe_realloc_skb(struct xgbe_channel *channel)
48739 {
48740 struct xgbe_prv_data *pdata = channel->pdata;
48741 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48742 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48743 struct xgbe_ring *ring = channel->rx_ring;
48744 struct xgbe_ring_data *rdata;
48745 struct sk_buff *skb = NULL;
48746 @@ -540,17 +540,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
48747 DBGPR("<--xgbe_realloc_skb\n");
48748 }
48749
48750 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
48751 -{
48752 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
48753 -
48754 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
48755 - desc_if->free_ring_resources = xgbe_free_ring_resources;
48756 - desc_if->map_tx_skb = xgbe_map_tx_skb;
48757 - desc_if->realloc_skb = xgbe_realloc_skb;
48758 - desc_if->unmap_skb = xgbe_unmap_skb;
48759 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
48760 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48761 -
48762 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
48763 -}
48764 +const struct xgbe_desc_if default_xgbe_desc_if = {
48765 + .alloc_ring_resources = xgbe_alloc_ring_resources,
48766 + .free_ring_resources = xgbe_free_ring_resources,
48767 + .map_tx_skb = xgbe_map_tx_skb,
48768 + .realloc_skb = xgbe_realloc_skb,
48769 + .unmap_skb = xgbe_unmap_skb,
48770 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48771 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48772 +};
48773 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48774 index 002293b..5ced1dd 100644
48775 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48776 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48777 @@ -2030,7 +2030,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48778
48779 static int xgbe_init(struct xgbe_prv_data *pdata)
48780 {
48781 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48782 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48783 int ret;
48784
48785 DBGPR("-->xgbe_init\n");
48786 @@ -2096,87 +2096,82 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48787 return 0;
48788 }
48789
48790 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48791 -{
48792 - DBGPR("-->xgbe_init_function_ptrs\n");
48793 -
48794 - hw_if->tx_complete = xgbe_tx_complete;
48795 -
48796 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48797 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48798 - hw_if->set_addn_mac_addrs = xgbe_set_addn_mac_addrs;
48799 - hw_if->set_mac_address = xgbe_set_mac_address;
48800 -
48801 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48802 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48803 -
48804 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48805 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48806 -
48807 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48808 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48809 -
48810 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48811 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48812 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48813 -
48814 - hw_if->enable_tx = xgbe_enable_tx;
48815 - hw_if->disable_tx = xgbe_disable_tx;
48816 - hw_if->enable_rx = xgbe_enable_rx;
48817 - hw_if->disable_rx = xgbe_disable_rx;
48818 -
48819 - hw_if->powerup_tx = xgbe_powerup_tx;
48820 - hw_if->powerdown_tx = xgbe_powerdown_tx;
48821 - hw_if->powerup_rx = xgbe_powerup_rx;
48822 - hw_if->powerdown_rx = xgbe_powerdown_rx;
48823 -
48824 - hw_if->pre_xmit = xgbe_pre_xmit;
48825 - hw_if->dev_read = xgbe_dev_read;
48826 - hw_if->enable_int = xgbe_enable_int;
48827 - hw_if->disable_int = xgbe_disable_int;
48828 - hw_if->init = xgbe_init;
48829 - hw_if->exit = xgbe_exit;
48830 +const struct xgbe_hw_if default_xgbe_hw_if = {
48831 + .tx_complete = xgbe_tx_complete,
48832 +
48833 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48834 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48835 + .set_addn_mac_addrs = xgbe_set_addn_mac_addrs,
48836 + .set_mac_address = xgbe_set_mac_address,
48837 +
48838 + .enable_rx_csum = xgbe_enable_rx_csum,
48839 + .disable_rx_csum = xgbe_disable_rx_csum,
48840 +
48841 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48842 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48843 +
48844 + .read_mmd_regs = xgbe_read_mmd_regs,
48845 + .write_mmd_regs = xgbe_write_mmd_regs,
48846 +
48847 + .set_gmii_speed = xgbe_set_gmii_speed,
48848 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48849 + .set_xgmii_speed = xgbe_set_xgmii_speed,
48850 +
48851 + .enable_tx = xgbe_enable_tx,
48852 + .disable_tx = xgbe_disable_tx,
48853 + .enable_rx = xgbe_enable_rx,
48854 + .disable_rx = xgbe_disable_rx,
48855 +
48856 + .powerup_tx = xgbe_powerup_tx,
48857 + .powerdown_tx = xgbe_powerdown_tx,
48858 + .powerup_rx = xgbe_powerup_rx,
48859 + .powerdown_rx = xgbe_powerdown_rx,
48860 +
48861 + .pre_xmit = xgbe_pre_xmit,
48862 + .dev_read = xgbe_dev_read,
48863 + .enable_int = xgbe_enable_int,
48864 + .disable_int = xgbe_disable_int,
48865 + .init = xgbe_init,
48866 + .exit = xgbe_exit,
48867
48868 /* Descriptor related Sequences have to be initialized here */
48869 - hw_if->tx_desc_init = xgbe_tx_desc_init;
48870 - hw_if->rx_desc_init = xgbe_rx_desc_init;
48871 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48872 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48873 - hw_if->is_last_desc = xgbe_is_last_desc;
48874 - hw_if->is_context_desc = xgbe_is_context_desc;
48875 + .tx_desc_init = xgbe_tx_desc_init,
48876 + .rx_desc_init = xgbe_rx_desc_init,
48877 + .tx_desc_reset = xgbe_tx_desc_reset,
48878 + .rx_desc_reset = xgbe_rx_desc_reset,
48879 + .is_last_desc = xgbe_is_last_desc,
48880 + .is_context_desc = xgbe_is_context_desc,
48881
48882 /* For FLOW ctrl */
48883 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48884 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48885 + .config_tx_flow_control = xgbe_config_tx_flow_control,
48886 + .config_rx_flow_control = xgbe_config_rx_flow_control,
48887
48888 /* For RX coalescing */
48889 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48890 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48891 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48892 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48893 + .config_rx_coalesce = xgbe_config_rx_coalesce,
48894 + .config_tx_coalesce = xgbe_config_tx_coalesce,
48895 + .usec_to_riwt = xgbe_usec_to_riwt,
48896 + .riwt_to_usec = xgbe_riwt_to_usec,
48897
48898 /* For RX and TX threshold config */
48899 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48900 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48901 + .config_rx_threshold = xgbe_config_rx_threshold,
48902 + .config_tx_threshold = xgbe_config_tx_threshold,
48903
48904 /* For RX and TX Store and Forward Mode config */
48905 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48906 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48907 + .config_rsf_mode = xgbe_config_rsf_mode,
48908 + .config_tsf_mode = xgbe_config_tsf_mode,
48909
48910 /* For TX DMA Operating on Second Frame config */
48911 - hw_if->config_osp_mode = xgbe_config_osp_mode;
48912 + .config_osp_mode = xgbe_config_osp_mode,
48913
48914 /* For RX and TX PBL config */
48915 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48916 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48917 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48918 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48919 - hw_if->config_pblx8 = xgbe_config_pblx8;
48920 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48921 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48922 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48923 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48924 + .config_pblx8 = xgbe_config_pblx8,
48925
48926 /* For MMC statistics support */
48927 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48928 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48929 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48930 -
48931 - DBGPR("<--xgbe_init_function_ptrs\n");
48932 -}
48933 + .tx_mmc_int = xgbe_tx_mmc_int,
48934 + .rx_mmc_int = xgbe_rx_mmc_int,
48935 + .read_mmc_stats = xgbe_read_mmc_stats,
48936 +};
48937 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48938 index cfe3d93..07a78ae 100644
48939 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48940 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48941 @@ -153,7 +153,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48942
48943 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48944 {
48945 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48946 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48947 struct xgbe_channel *channel;
48948 unsigned int i;
48949
48950 @@ -170,7 +170,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48951
48952 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48953 {
48954 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48955 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48956 struct xgbe_channel *channel;
48957 unsigned int i;
48958
48959 @@ -188,7 +188,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48960 static irqreturn_t xgbe_isr(int irq, void *data)
48961 {
48962 struct xgbe_prv_data *pdata = data;
48963 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48964 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48965 struct xgbe_channel *channel;
48966 unsigned int dma_isr, dma_ch_isr;
48967 unsigned int mac_isr;
48968 @@ -403,7 +403,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata)
48969
48970 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48971 {
48972 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48973 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48974
48975 DBGPR("-->xgbe_init_tx_coalesce\n");
48976
48977 @@ -417,7 +417,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48978
48979 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48980 {
48981 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48982 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48983
48984 DBGPR("-->xgbe_init_rx_coalesce\n");
48985
48986 @@ -431,7 +431,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48987
48988 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48989 {
48990 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48991 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48992 struct xgbe_channel *channel;
48993 struct xgbe_ring *ring;
48994 struct xgbe_ring_data *rdata;
48995 @@ -456,7 +456,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48996
48997 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48998 {
48999 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
49000 + struct xgbe_desc_if *desc_if = pdata->desc_if;
49001 struct xgbe_channel *channel;
49002 struct xgbe_ring *ring;
49003 struct xgbe_ring_data *rdata;
49004 @@ -482,7 +482,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
49005 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
49006 {
49007 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49008 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49009 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49010 unsigned long flags;
49011
49012 DBGPR("-->xgbe_powerdown\n");
49013 @@ -520,7 +520,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
49014 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
49015 {
49016 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49017 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49018 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49019 unsigned long flags;
49020
49021 DBGPR("-->xgbe_powerup\n");
49022 @@ -557,7 +557,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
49023
49024 static int xgbe_start(struct xgbe_prv_data *pdata)
49025 {
49026 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49027 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49028 struct net_device *netdev = pdata->netdev;
49029
49030 DBGPR("-->xgbe_start\n");
49031 @@ -583,7 +583,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
49032
49033 static void xgbe_stop(struct xgbe_prv_data *pdata)
49034 {
49035 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49036 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49037 struct net_device *netdev = pdata->netdev;
49038
49039 DBGPR("-->xgbe_stop\n");
49040 @@ -603,7 +603,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
49041
49042 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
49043 {
49044 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49045 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49046
49047 DBGPR("-->xgbe_restart_dev\n");
49048
49049 @@ -741,8 +741,8 @@ static void xgbe_packet_info(struct xgbe_ring *ring, struct sk_buff *skb,
49050 static int xgbe_open(struct net_device *netdev)
49051 {
49052 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49053 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49054 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
49055 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49056 + struct xgbe_desc_if *desc_if = pdata->desc_if;
49057 int ret;
49058
49059 DBGPR("-->xgbe_open\n");
49060 @@ -804,8 +804,8 @@ err_clk:
49061 static int xgbe_close(struct net_device *netdev)
49062 {
49063 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49064 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49065 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
49066 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49067 + struct xgbe_desc_if *desc_if = pdata->desc_if;
49068
49069 DBGPR("-->xgbe_close\n");
49070
49071 @@ -835,8 +835,8 @@ static int xgbe_close(struct net_device *netdev)
49072 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
49073 {
49074 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49075 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49076 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
49077 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49078 + struct xgbe_desc_if *desc_if = pdata->desc_if;
49079 struct xgbe_channel *channel;
49080 struct xgbe_ring *ring;
49081 struct xgbe_packet_data *packet;
49082 @@ -903,7 +903,7 @@ tx_netdev_return:
49083 static void xgbe_set_rx_mode(struct net_device *netdev)
49084 {
49085 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49086 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49087 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49088 unsigned int pr_mode, am_mode;
49089
49090 DBGPR("-->xgbe_set_rx_mode\n");
49091 @@ -930,7 +930,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
49092 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
49093 {
49094 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49095 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49096 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49097 struct sockaddr *saddr = addr;
49098
49099 DBGPR("-->xgbe_set_mac_address\n");
49100 @@ -976,7 +976,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
49101
49102 DBGPR("-->%s\n", __func__);
49103
49104 - pdata->hw_if.read_mmc_stats(pdata);
49105 + pdata->hw_if->read_mmc_stats(pdata);
49106
49107 s->rx_packets = pstats->rxframecount_gb;
49108 s->rx_bytes = pstats->rxoctetcount_gb;
49109 @@ -1020,7 +1020,7 @@ static int xgbe_set_features(struct net_device *netdev,
49110 netdev_features_t features)
49111 {
49112 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49113 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49114 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49115 unsigned int rxcsum_enabled, rxvlan_enabled;
49116
49117 rxcsum_enabled = !!(pdata->netdev_features & NETIF_F_RXCSUM);
49118 @@ -1072,8 +1072,8 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
49119 static int xgbe_tx_poll(struct xgbe_channel *channel)
49120 {
49121 struct xgbe_prv_data *pdata = channel->pdata;
49122 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49123 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
49124 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49125 + struct xgbe_desc_if *desc_if = pdata->desc_if;
49126 struct xgbe_ring *ring = channel->tx_ring;
49127 struct xgbe_ring_data *rdata;
49128 struct xgbe_ring_desc *rdesc;
49129 @@ -1124,8 +1124,8 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
49130 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
49131 {
49132 struct xgbe_prv_data *pdata = channel->pdata;
49133 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49134 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
49135 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49136 + struct xgbe_desc_if *desc_if = pdata->desc_if;
49137 struct xgbe_ring *ring = channel->rx_ring;
49138 struct xgbe_ring_data *rdata;
49139 struct xgbe_packet_data *packet;
49140 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
49141 index 8909f2b..719e767 100644
49142 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
49143 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
49144 @@ -202,7 +202,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
49145
49146 DBGPR("-->%s\n", __func__);
49147
49148 - pdata->hw_if.read_mmc_stats(pdata);
49149 + pdata->hw_if->read_mmc_stats(pdata);
49150 for (i = 0; i < XGBE_STATS_COUNT; i++) {
49151 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
49152 *data++ = *(u64 *)stat;
49153 @@ -387,7 +387,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
49154 struct ethtool_coalesce *ec)
49155 {
49156 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49157 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49158 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49159 unsigned int riwt;
49160
49161 DBGPR("-->xgbe_get_coalesce\n");
49162 @@ -410,7 +410,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
49163 struct ethtool_coalesce *ec)
49164 {
49165 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49166 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49167 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49168 unsigned int rx_frames, rx_riwt, rx_usecs;
49169 unsigned int tx_frames, tx_usecs;
49170
49171 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
49172 index 5a1891f..1b7888e 100644
49173 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
49174 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
49175 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
49176 DBGPR("<--xgbe_default_config\n");
49177 }
49178
49179 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
49180 -{
49181 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
49182 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
49183 -}
49184 -
49185 static int xgbe_probe(struct platform_device *pdev)
49186 {
49187 struct xgbe_prv_data *pdata;
49188 @@ -306,9 +300,8 @@ static int xgbe_probe(struct platform_device *pdev)
49189 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
49190
49191 /* Set all the function pointers */
49192 - xgbe_init_all_fptrs(pdata);
49193 - hw_if = &pdata->hw_if;
49194 - desc_if = &pdata->desc_if;
49195 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
49196 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
49197
49198 /* Issue software reset to device */
49199 hw_if->exit(pdata);
49200 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
49201 index ea7a5d6..d10a742 100644
49202 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
49203 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
49204 @@ -128,7 +128,7 @@
49205 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
49206 {
49207 struct xgbe_prv_data *pdata = mii->priv;
49208 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49209 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49210 int mmd_data;
49211
49212 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
49213 @@ -145,7 +145,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
49214 u16 mmd_val)
49215 {
49216 struct xgbe_prv_data *pdata = mii->priv;
49217 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49218 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49219 int mmd_data = mmd_val;
49220
49221 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
49222 @@ -161,7 +161,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
49223 static void xgbe_adjust_link(struct net_device *netdev)
49224 {
49225 struct xgbe_prv_data *pdata = netdev_priv(netdev);
49226 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
49227 + struct xgbe_hw_if *hw_if = pdata->hw_if;
49228 struct phy_device *phydev = pdata->phydev;
49229 unsigned long flags;
49230 int new_state = 0;
49231 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
49232 index ab06271..a560fa7 100644
49233 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
49234 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
49235 @@ -527,8 +527,8 @@ struct xgbe_prv_data {
49236
49237 int irq_number;
49238
49239 - struct xgbe_hw_if hw_if;
49240 - struct xgbe_desc_if desc_if;
49241 + const struct xgbe_hw_if *hw_if;
49242 + const struct xgbe_desc_if *desc_if;
49243
49244 /* Rings for Tx/Rx on a DMA channel */
49245 struct xgbe_channel *channel;
49246 @@ -611,6 +611,9 @@ struct xgbe_prv_data {
49247 #endif
49248 };
49249
49250 +extern const struct xgbe_hw_if default_xgbe_hw_if;
49251 +extern const struct xgbe_desc_if default_xgbe_desc_if;
49252 +
49253 /* Function prototypes*/
49254
49255 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
49256 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
49257 index 571427c..e9fe9e7 100644
49258 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
49259 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
49260 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
49261 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
49262 {
49263 /* RX_MODE controlling object */
49264 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
49265 + bnx2x_init_rx_mode_obj(bp);
49266
49267 /* multicast configuration controlling object */
49268 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
49269 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
49270 index b193604..8873bfd 100644
49271 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
49272 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
49273 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
49274 return rc;
49275 }
49276
49277 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
49278 - struct bnx2x_rx_mode_obj *o)
49279 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
49280 {
49281 if (CHIP_IS_E1x(bp)) {
49282 - o->wait_comp = bnx2x_empty_rx_mode_wait;
49283 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
49284 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
49285 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
49286 } else {
49287 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
49288 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
49289 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
49290 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
49291 }
49292 }
49293
49294 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
49295 index 718ecd2..2183b2f 100644
49296 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
49297 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
49298 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
49299
49300 /********************* RX MODE ****************/
49301
49302 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
49303 - struct bnx2x_rx_mode_obj *o);
49304 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
49305
49306 /**
49307 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
49308 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
49309 index 461acca..2b546ba 100644
49310 --- a/drivers/net/ethernet/broadcom/tg3.h
49311 +++ b/drivers/net/ethernet/broadcom/tg3.h
49312 @@ -150,6 +150,7 @@
49313 #define CHIPREV_ID_5750_A0 0x4000
49314 #define CHIPREV_ID_5750_A1 0x4001
49315 #define CHIPREV_ID_5750_A3 0x4003
49316 +#define CHIPREV_ID_5750_C1 0x4201
49317 #define CHIPREV_ID_5750_C2 0x4202
49318 #define CHIPREV_ID_5752_A0_HW 0x5000
49319 #define CHIPREV_ID_5752_A0 0x6000
49320 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
49321 index 13f9636..228040f 100644
49322 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
49323 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
49324 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
49325 }
49326
49327 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
49328 - bna_cb_ioceth_enable,
49329 - bna_cb_ioceth_disable,
49330 - bna_cb_ioceth_hbfail,
49331 - bna_cb_ioceth_reset
49332 + .enable_cbfn = bna_cb_ioceth_enable,
49333 + .disable_cbfn = bna_cb_ioceth_disable,
49334 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
49335 + .reset_cbfn = bna_cb_ioceth_reset
49336 };
49337
49338 static void bna_attr_init(struct bna_ioceth *ioceth)
49339 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
49340 index 8cffcdf..aadf043 100644
49341 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
49342 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
49343 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
49344 */
49345 struct l2t_skb_cb {
49346 arp_failure_handler_func arp_failure_handler;
49347 -};
49348 +} __no_const;
49349
49350 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
49351
49352 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
49353 index a83271c..cf00874 100644
49354 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
49355 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
49356 @@ -2174,7 +2174,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
49357
49358 int i;
49359 struct adapter *ap = netdev2adap(dev);
49360 - static const unsigned int *reg_ranges;
49361 + const unsigned int *reg_ranges;
49362 int arr_size = 0, buf_size = 0;
49363
49364 if (is_t4(ap->params.chip)) {
49365 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
49366 index c05b66d..ed69872 100644
49367 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
49368 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
49369 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49370 for (i=0; i<ETH_ALEN; i++) {
49371 tmp.addr[i] = dev->dev_addr[i];
49372 }
49373 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49374 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
49375 break;
49376
49377 case DE4X5_SET_HWADDR: /* Set the hardware address */
49378 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
49379 spin_lock_irqsave(&lp->lock, flags);
49380 memcpy(&statbuf, &lp->pktStats, ioc->len);
49381 spin_unlock_irqrestore(&lp->lock, flags);
49382 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
49383 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
49384 return -EFAULT;
49385 break;
49386 }
49387 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
49388 index 1e187fb..d024547 100644
49389 --- a/drivers/net/ethernet/emulex/benet/be_main.c
49390 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
49391 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
49392
49393 if (wrapped)
49394 newacc += 65536;
49395 - ACCESS_ONCE(*acc) = newacc;
49396 + ACCESS_ONCE_RW(*acc) = newacc;
49397 }
49398
49399 static void populate_erx_stats(struct be_adapter *adapter,
49400 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
49401 index c77fa4a..7fd42fc 100644
49402 --- a/drivers/net/ethernet/faraday/ftgmac100.c
49403 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
49404 @@ -30,6 +30,8 @@
49405 #include <linux/netdevice.h>
49406 #include <linux/phy.h>
49407 #include <linux/platform_device.h>
49408 +#include <linux/interrupt.h>
49409 +#include <linux/irqreturn.h>
49410 #include <net/ip.h>
49411
49412 #include "ftgmac100.h"
49413 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
49414 index 4ff1adc..0ea6bf4 100644
49415 --- a/drivers/net/ethernet/faraday/ftmac100.c
49416 +++ b/drivers/net/ethernet/faraday/ftmac100.c
49417 @@ -31,6 +31,8 @@
49418 #include <linux/module.h>
49419 #include <linux/netdevice.h>
49420 #include <linux/platform_device.h>
49421 +#include <linux/interrupt.h>
49422 +#include <linux/irqreturn.h>
49423
49424 #include "ftmac100.h"
49425
49426 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49427 index 101f439..59e7ec6 100644
49428 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49429 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
49430 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
49431 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
49432
49433 /* Update the base adjustement value. */
49434 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
49435 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
49436 smp_mb(); /* Force the above update. */
49437 }
49438
49439 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49440 index 68f87ec..241dbe3 100644
49441 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49442 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
49443 @@ -792,7 +792,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
49444 }
49445
49446 /* update the base incval used to calculate frequency adjustment */
49447 - ACCESS_ONCE(adapter->base_incval) = incval;
49448 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
49449 smp_mb();
49450
49451 /* need lock to prevent incorrect read while modifying cyclecounter */
49452 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49453 index 2bbd01f..e8baa64 100644
49454 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
49455 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
49456 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49457 struct __vxge_hw_fifo *fifo;
49458 struct vxge_hw_fifo_config *config;
49459 u32 txdl_size, txdl_per_memblock;
49460 - struct vxge_hw_mempool_cbs fifo_mp_callback;
49461 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
49462 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
49463 + };
49464 +
49465 struct __vxge_hw_virtualpath *vpath;
49466
49467 if ((vp == NULL) || (attr == NULL)) {
49468 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
49469 goto exit;
49470 }
49471
49472 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
49473 -
49474 fifo->mempool =
49475 __vxge_hw_mempool_create(vpath->hldev,
49476 fifo->config->memblock_size,
49477 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
49478 index 73e6683..464e910 100644
49479 --- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
49480 +++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
49481 @@ -120,6 +120,10 @@ static void pch_gbe_mdio_write(struct net_device *netdev, int addr, int reg,
49482 int data);
49483 static void pch_gbe_set_multi(struct net_device *netdev);
49484
49485 +static struct sock_filter ptp_filter[] = {
49486 + PTP_FILTER
49487 +};
49488 +
49489 static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49490 {
49491 u8 *data = skb->data;
49492 @@ -127,7 +131,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49493 u16 *hi, *id;
49494 u32 lo;
49495
49496 - if (ptp_classify_raw(skb) == PTP_CLASS_NONE)
49497 + if (sk_run_filter(skb, ptp_filter) == PTP_CLASS_NONE)
49498 return 0;
49499
49500 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49501 @@ -2631,6 +2635,11 @@ static int pch_gbe_probe(struct pci_dev *pdev,
49502
49503 adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
49504 PCI_DEVFN(12, 4));
49505 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49506 + dev_err(&pdev->dev, "Bad ptp filter\n");
49507 + ret = -EINVAL;
49508 + goto err_free_netdev;
49509 + }
49510
49511 netdev->netdev_ops = &pch_gbe_netdev_ops;
49512 netdev->watchdog_timeo = PCH_GBE_WATCHDOG_PERIOD;
49513 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49514 index f33559b..c7f50ac 100644
49515 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49516 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
49517 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
49518 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
49519 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
49520 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
49521 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49522 + pax_open_kernel();
49523 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
49524 + pax_close_kernel();
49525 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49526 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
49527 max_tx_rings = QLCNIC_MAX_TX_RINGS;
49528 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49529 index be7d7a6..a8983f8 100644
49530 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49531 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
49532 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
49533 case QLCNIC_NON_PRIV_FUNC:
49534 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
49535 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49536 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49537 + pax_open_kernel();
49538 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
49539 + pax_close_kernel();
49540 break;
49541 case QLCNIC_PRIV_FUNC:
49542 ahw->op_mode = QLCNIC_PRIV_FUNC;
49543 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
49544 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49545 + pax_open_kernel();
49546 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
49547 + pax_close_kernel();
49548 break;
49549 case QLCNIC_MGMT_FUNC:
49550 ahw->op_mode = QLCNIC_MGMT_FUNC;
49551 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
49552 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49553 + pax_open_kernel();
49554 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
49555 + pax_close_kernel();
49556 break;
49557 default:
49558 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
49559 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49560 index e46fc39..abe135b 100644
49561 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49562 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
49563 @@ -1228,7 +1228,7 @@ flash_temp:
49564 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
49565 {
49566 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
49567 - static const struct qlcnic_dump_operations *fw_dump_ops;
49568 + const struct qlcnic_dump_operations *fw_dump_ops;
49569 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
49570 u32 entry_offset, dump, no_entries, buf_offset = 0;
49571 int i, k, ops_cnt, ops_index, dump_size = 0;
49572 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
49573 index 61623e9..ac97c27 100644
49574 --- a/drivers/net/ethernet/realtek/r8169.c
49575 +++ b/drivers/net/ethernet/realtek/r8169.c
49576 @@ -759,22 +759,22 @@ struct rtl8169_private {
49577 struct mdio_ops {
49578 void (*write)(struct rtl8169_private *, int, int);
49579 int (*read)(struct rtl8169_private *, int);
49580 - } mdio_ops;
49581 + } __no_const mdio_ops;
49582
49583 struct pll_power_ops {
49584 void (*down)(struct rtl8169_private *);
49585 void (*up)(struct rtl8169_private *);
49586 - } pll_power_ops;
49587 + } __no_const pll_power_ops;
49588
49589 struct jumbo_ops {
49590 void (*enable)(struct rtl8169_private *);
49591 void (*disable)(struct rtl8169_private *);
49592 - } jumbo_ops;
49593 + } __no_const jumbo_ops;
49594
49595 struct csi_ops {
49596 void (*write)(struct rtl8169_private *, int, int);
49597 u32 (*read)(struct rtl8169_private *, int);
49598 - } csi_ops;
49599 + } __no_const csi_ops;
49600
49601 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
49602 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
49603 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
49604 index 6b861e3..204ac86 100644
49605 --- a/drivers/net/ethernet/sfc/ptp.c
49606 +++ b/drivers/net/ethernet/sfc/ptp.c
49607 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
49608 ptp->start.dma_addr);
49609
49610 /* Clear flag that signals MC ready */
49611 - ACCESS_ONCE(*start) = 0;
49612 + ACCESS_ONCE_RW(*start) = 0;
49613 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
49614 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
49615 EFX_BUG_ON_PARANOID(rc);
49616 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49617 index 50617c5..b13724c 100644
49618 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49619 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
49620 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
49621
49622 writel(value, ioaddr + MMC_CNTRL);
49623
49624 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49625 - MMC_CNTRL, value);
49626 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
49627 +// MMC_CNTRL, value);
49628 }
49629
49630 /* To mask all all interrupts.*/
49631 diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
49632 index 6b56f85..50e285f 100644
49633 --- a/drivers/net/ethernet/ti/cpts.c
49634 +++ b/drivers/net/ethernet/ti/cpts.c
49635 @@ -33,6 +33,10 @@
49636
49637 #ifdef CONFIG_TI_CPTS
49638
49639 +static struct sock_filter ptp_filter[] = {
49640 + PTP_FILTER
49641 +};
49642 +
49643 #define cpts_read32(c, r) __raw_readl(&c->reg->r)
49644 #define cpts_write32(c, v, r) __raw_writel(v, &c->reg->r)
49645
49646 @@ -296,7 +300,7 @@ static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type)
49647 u64 ns = 0;
49648 struct cpts_event *event;
49649 struct list_head *this, *next;
49650 - unsigned int class = ptp_classify_raw(skb);
49651 + unsigned int class = sk_run_filter(skb, ptp_filter);
49652 unsigned long flags;
49653 u16 seqid;
49654 u8 mtype;
49655 @@ -367,6 +371,10 @@ int cpts_register(struct device *dev, struct cpts *cpts,
49656 int err, i;
49657 unsigned long flags;
49658
49659 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49660 + pr_err("cpts: bad ptp filter\n");
49661 + return -EINVAL;
49662 + }
49663 cpts->info = cpts_info;
49664 cpts->clock = ptp_clock_register(&cpts->info, dev);
49665 if (IS_ERR(cpts->clock)) {
49666 diff --git a/drivers/net/ethernet/xscale/Kconfig b/drivers/net/ethernet/xscale/Kconfig
49667 index b81bc9f..3f43101 100644
49668 --- a/drivers/net/ethernet/xscale/Kconfig
49669 +++ b/drivers/net/ethernet/xscale/Kconfig
49670 @@ -23,7 +23,6 @@ config IXP4XX_ETH
49671 tristate "Intel IXP4xx Ethernet support"
49672 depends on ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR
49673 select PHYLIB
49674 - select NET_PTP_CLASSIFY
49675 ---help---
49676 Say Y here if you want to use built-in Ethernet ports
49677 on IXP4xx processor.
49678 diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49679 index f7e0f0f..25283f1 100644
49680 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
49681 +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
49682 @@ -256,6 +256,10 @@ static int ports_open;
49683 static struct port *npe_port_tab[MAX_NPES];
49684 static struct dma_pool *dma_pool;
49685
49686 +static struct sock_filter ptp_filter[] = {
49687 + PTP_FILTER
49688 +};
49689 +
49690 static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49691 {
49692 u8 *data = skb->data;
49693 @@ -263,7 +267,7 @@ static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
49694 u16 *hi, *id;
49695 u32 lo;
49696
49697 - if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
49698 + if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
49699 return 0;
49700
49701 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
49702 @@ -1409,6 +1413,11 @@ static int eth_init_one(struct platform_device *pdev)
49703 char phy_id[MII_BUS_ID_SIZE + 3];
49704 int err;
49705
49706 + if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
49707 + pr_err("ixp4xx_eth: bad ptp filter\n");
49708 + return -EINVAL;
49709 + }
49710 +
49711 if (!(dev = alloc_etherdev(sizeof(struct port))))
49712 return -ENOMEM;
49713
49714 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
49715 index 6cc37c1..fdd9d77 100644
49716 --- a/drivers/net/hyperv/hyperv_net.h
49717 +++ b/drivers/net/hyperv/hyperv_net.h
49718 @@ -170,7 +170,7 @@ struct rndis_device {
49719
49720 enum rndis_device_state state;
49721 bool link_state;
49722 - atomic_t new_req_id;
49723 + atomic_unchecked_t new_req_id;
49724
49725 spinlock_t request_lock;
49726 struct list_head req_list;
49727 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
49728 index 99c527a..6a2ce38 100644
49729 --- a/drivers/net/hyperv/rndis_filter.c
49730 +++ b/drivers/net/hyperv/rndis_filter.c
49731 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
49732 * template
49733 */
49734 set = &rndis_msg->msg.set_req;
49735 - set->req_id = atomic_inc_return(&dev->new_req_id);
49736 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49737
49738 /* Add to the request list */
49739 spin_lock_irqsave(&dev->request_lock, flags);
49740 @@ -930,7 +930,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
49741
49742 /* Setup the rndis set */
49743 halt = &request->request_msg.msg.halt_req;
49744 - halt->req_id = atomic_inc_return(&dev->new_req_id);
49745 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49746
49747 /* Ignore return since this msg is optional. */
49748 rndis_filter_send_request(dev, request);
49749 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
49750 index 78f18be..1d19c62 100644
49751 --- a/drivers/net/ieee802154/fakehard.c
49752 +++ b/drivers/net/ieee802154/fakehard.c
49753 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49754 phy->transmit_power = 0xbf;
49755
49756 dev->netdev_ops = &fake_ops;
49757 - dev->ml_priv = &fake_mlme;
49758 + dev->ml_priv = (void *)&fake_mlme;
49759
49760 priv = netdev_priv(dev);
49761 priv->phy = phy;
49762 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49763 index ef8a5c2..76877d6 100644
49764 --- a/drivers/net/macvlan.c
49765 +++ b/drivers/net/macvlan.c
49766 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49767 free_nskb:
49768 kfree_skb(nskb);
49769 err:
49770 - atomic_long_inc(&skb->dev->rx_dropped);
49771 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49772 }
49773
49774 /* called under rcu_read_lock() from netif_receive_skb */
49775 @@ -1134,13 +1134,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49776 int macvlan_link_register(struct rtnl_link_ops *ops)
49777 {
49778 /* common fields */
49779 - ops->priv_size = sizeof(struct macvlan_dev);
49780 - ops->validate = macvlan_validate;
49781 - ops->maxtype = IFLA_MACVLAN_MAX;
49782 - ops->policy = macvlan_policy;
49783 - ops->changelink = macvlan_changelink;
49784 - ops->get_size = macvlan_get_size;
49785 - ops->fill_info = macvlan_fill_info;
49786 + pax_open_kernel();
49787 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49788 + *(void **)&ops->validate = macvlan_validate;
49789 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49790 + *(const void **)&ops->policy = macvlan_policy;
49791 + *(void **)&ops->changelink = macvlan_changelink;
49792 + *(void **)&ops->get_size = macvlan_get_size;
49793 + *(void **)&ops->fill_info = macvlan_fill_info;
49794 + pax_close_kernel();
49795
49796 return rtnl_link_register(ops);
49797 };
49798 @@ -1220,7 +1222,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49799 return NOTIFY_DONE;
49800 }
49801
49802 -static struct notifier_block macvlan_notifier_block __read_mostly = {
49803 +static struct notifier_block macvlan_notifier_block = {
49804 .notifier_call = macvlan_device_event,
49805 };
49806
49807 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49808 index 3381c4f..dea5fd5 100644
49809 --- a/drivers/net/macvtap.c
49810 +++ b/drivers/net/macvtap.c
49811 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49812 }
49813
49814 ret = 0;
49815 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49816 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49817 put_user(q->flags, &ifr->ifr_flags))
49818 ret = -EFAULT;
49819 macvtap_put_vlan(vlan);
49820 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49821 return NOTIFY_DONE;
49822 }
49823
49824 -static struct notifier_block macvtap_notifier_block __read_mostly = {
49825 +static struct notifier_block macvtap_notifier_block = {
49826 .notifier_call = macvtap_device_event,
49827 };
49828
49829 diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
49830 index 9408157..d53b924 100644
49831 --- a/drivers/net/phy/dp83640.c
49832 +++ b/drivers/net/phy/dp83640.c
49833 @@ -27,7 +27,6 @@
49834 #include <linux/module.h>
49835 #include <linux/net_tstamp.h>
49836 #include <linux/netdevice.h>
49837 -#include <linux/if_vlan.h>
49838 #include <linux/phy.h>
49839 #include <linux/ptp_classify.h>
49840 #include <linux/ptp_clock_kernel.h>
49841 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49842 index d5b77ef..72ff14b 100644
49843 --- a/drivers/net/ppp/ppp_generic.c
49844 +++ b/drivers/net/ppp/ppp_generic.c
49845 @@ -143,8 +143,9 @@ struct ppp {
49846 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
49847 #endif /* CONFIG_PPP_MULTILINK */
49848 #ifdef CONFIG_PPP_FILTER
49849 - struct sk_filter *pass_filter; /* filter for packets to pass */
49850 - struct sk_filter *active_filter;/* filter for pkts to reset idle */
49851 + struct sock_filter *pass_filter; /* filter for packets to pass */
49852 + struct sock_filter *active_filter;/* filter for pkts to reset idle */
49853 + unsigned pass_len, active_len;
49854 #endif /* CONFIG_PPP_FILTER */
49855 struct net *ppp_net; /* the net we belong to */
49856 struct ppp_link_stats stats64; /* 64 bit network stats */
49857 @@ -539,7 +540,7 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49858 {
49859 struct sock_fprog uprog;
49860 struct sock_filter *code = NULL;
49861 - int len;
49862 + int len, err;
49863
49864 if (copy_from_user(&uprog, arg, sizeof(uprog)))
49865 return -EFAULT;
49866 @@ -554,6 +555,12 @@ static int get_filter(void __user *arg, struct sock_filter **p)
49867 if (IS_ERR(code))
49868 return PTR_ERR(code);
49869
49870 + err = sk_chk_filter(code, uprog.len);
49871 + if (err) {
49872 + kfree(code);
49873 + return err;
49874 + }
49875 +
49876 *p = code;
49877 return uprog.len;
49878 }
49879 @@ -748,52 +755,28 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
49880 case PPPIOCSPASS:
49881 {
49882 struct sock_filter *code;
49883 -
49884 err = get_filter(argp, &code);
49885 if (err >= 0) {
49886 - struct sock_fprog_kern fprog = {
49887 - .len = err,
49888 - .filter = code,
49889 - };
49890 -
49891 ppp_lock(ppp);
49892 - if (ppp->pass_filter) {
49893 - sk_unattached_filter_destroy(ppp->pass_filter);
49894 - ppp->pass_filter = NULL;
49895 - }
49896 - if (fprog.filter != NULL)
49897 - err = sk_unattached_filter_create(&ppp->pass_filter,
49898 - &fprog);
49899 - else
49900 - err = 0;
49901 - kfree(code);
49902 + kfree(ppp->pass_filter);
49903 + ppp->pass_filter = code;
49904 + ppp->pass_len = err;
49905 ppp_unlock(ppp);
49906 + err = 0;
49907 }
49908 break;
49909 }
49910 case PPPIOCSACTIVE:
49911 {
49912 struct sock_filter *code;
49913 -
49914 err = get_filter(argp, &code);
49915 if (err >= 0) {
49916 - struct sock_fprog_kern fprog = {
49917 - .len = err,
49918 - .filter = code,
49919 - };
49920 -
49921 ppp_lock(ppp);
49922 - if (ppp->active_filter) {
49923 - sk_unattached_filter_destroy(ppp->active_filter);
49924 - ppp->active_filter = NULL;
49925 - }
49926 - if (fprog.filter != NULL)
49927 - err = sk_unattached_filter_create(&ppp->active_filter,
49928 - &fprog);
49929 - else
49930 - err = 0;
49931 - kfree(code);
49932 + kfree(ppp->active_filter);
49933 + ppp->active_filter = code;
49934 + ppp->active_len = err;
49935 ppp_unlock(ppp);
49936 + err = 0;
49937 }
49938 break;
49939 }
49940 @@ -1201,7 +1184,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49941 a four-byte PPP header on each packet */
49942 *skb_push(skb, 2) = 1;
49943 if (ppp->pass_filter &&
49944 - SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49945 + sk_run_filter(skb, ppp->pass_filter) == 0) {
49946 if (ppp->debug & 1)
49947 netdev_printk(KERN_DEBUG, ppp->dev,
49948 "PPP: outbound frame "
49949 @@ -1211,7 +1194,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
49950 }
49951 /* if this packet passes the active filter, record the time */
49952 if (!(ppp->active_filter &&
49953 - SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49954 + sk_run_filter(skb, ppp->active_filter) == 0))
49955 ppp->last_xmit = jiffies;
49956 skb_pull(skb, 2);
49957 #else
49958 @@ -1835,7 +1818,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49959
49960 *skb_push(skb, 2) = 0;
49961 if (ppp->pass_filter &&
49962 - SK_RUN_FILTER(ppp->pass_filter, skb) == 0) {
49963 + sk_run_filter(skb, ppp->pass_filter) == 0) {
49964 if (ppp->debug & 1)
49965 netdev_printk(KERN_DEBUG, ppp->dev,
49966 "PPP: inbound frame "
49967 @@ -1844,7 +1827,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
49968 return;
49969 }
49970 if (!(ppp->active_filter &&
49971 - SK_RUN_FILTER(ppp->active_filter, skb) == 0))
49972 + sk_run_filter(skb, ppp->active_filter) == 0))
49973 ppp->last_recv = jiffies;
49974 __skb_pull(skb, 2);
49975 } else
49976 @@ -2689,10 +2672,6 @@ ppp_create_interface(struct net *net, int unit, int *retp)
49977 ppp->minseq = -1;
49978 skb_queue_head_init(&ppp->mrq);
49979 #endif /* CONFIG_PPP_MULTILINK */
49980 -#ifdef CONFIG_PPP_FILTER
49981 - ppp->pass_filter = NULL;
49982 - ppp->active_filter = NULL;
49983 -#endif /* CONFIG_PPP_FILTER */
49984
49985 /*
49986 * drum roll: don't forget to set
49987 @@ -2823,15 +2802,10 @@ static void ppp_destroy_interface(struct ppp *ppp)
49988 skb_queue_purge(&ppp->mrq);
49989 #endif /* CONFIG_PPP_MULTILINK */
49990 #ifdef CONFIG_PPP_FILTER
49991 - if (ppp->pass_filter) {
49992 - sk_unattached_filter_destroy(ppp->pass_filter);
49993 - ppp->pass_filter = NULL;
49994 - }
49995 -
49996 - if (ppp->active_filter) {
49997 - sk_unattached_filter_destroy(ppp->active_filter);
49998 - ppp->active_filter = NULL;
49999 - }
50000 + kfree(ppp->pass_filter);
50001 + ppp->pass_filter = NULL;
50002 + kfree(ppp->active_filter);
50003 + ppp->active_filter = NULL;
50004 #endif /* CONFIG_PPP_FILTER */
50005
50006 kfree_skb(ppp->xmit_pending);
50007 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
50008 index 1252d9c..80e660b 100644
50009 --- a/drivers/net/slip/slhc.c
50010 +++ b/drivers/net/slip/slhc.c
50011 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
50012 register struct tcphdr *thp;
50013 register struct iphdr *ip;
50014 register struct cstate *cs;
50015 - int len, hdrlen;
50016 + long len, hdrlen;
50017 unsigned char *cp = icp;
50018
50019 /* We've got a compressed packet; read the change byte */
50020 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
50021 index b4958c7..277cb96 100644
50022 --- a/drivers/net/team/team.c
50023 +++ b/drivers/net/team/team.c
50024 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
50025 return NOTIFY_DONE;
50026 }
50027
50028 -static struct notifier_block team_notifier_block __read_mostly = {
50029 +static struct notifier_block team_notifier_block = {
50030 .notifier_call = team_device_event,
50031 };
50032
50033 diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c
50034 index a58dfeb..dbde341 100644
50035 --- a/drivers/net/team/team_mode_loadbalance.c
50036 +++ b/drivers/net/team/team_mode_loadbalance.c
50037 @@ -49,7 +49,7 @@ struct lb_port_mapping {
50038 struct lb_priv_ex {
50039 struct team *team;
50040 struct lb_port_mapping tx_hash_to_port_mapping[LB_TX_HASHTABLE_SIZE];
50041 - struct sock_fprog_kern *orig_fprog;
50042 + struct sock_fprog *orig_fprog;
50043 struct {
50044 unsigned int refresh_interval; /* in tenths of second */
50045 struct delayed_work refresh_dw;
50046 @@ -241,15 +241,15 @@ static int lb_bpf_func_get(struct team *team, struct team_gsetter_ctx *ctx)
50047 return 0;
50048 }
50049
50050 -static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
50051 +static int __fprog_create(struct sock_fprog **pfprog, u32 data_len,
50052 const void *data)
50053 {
50054 - struct sock_fprog_kern *fprog;
50055 + struct sock_fprog *fprog;
50056 struct sock_filter *filter = (struct sock_filter *) data;
50057
50058 if (data_len % sizeof(struct sock_filter))
50059 return -EINVAL;
50060 - fprog = kmalloc(sizeof(*fprog), GFP_KERNEL);
50061 + fprog = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
50062 if (!fprog)
50063 return -ENOMEM;
50064 fprog->filter = kmemdup(filter, data_len, GFP_KERNEL);
50065 @@ -262,7 +262,7 @@ static int __fprog_create(struct sock_fprog_kern **pfprog, u32 data_len,
50066 return 0;
50067 }
50068
50069 -static void __fprog_destroy(struct sock_fprog_kern *fprog)
50070 +static void __fprog_destroy(struct sock_fprog *fprog)
50071 {
50072 kfree(fprog->filter);
50073 kfree(fprog);
50074 @@ -273,7 +273,7 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
50075 struct lb_priv *lb_priv = get_lb_priv(team);
50076 struct sk_filter *fp = NULL;
50077 struct sk_filter *orig_fp;
50078 - struct sock_fprog_kern *fprog = NULL;
50079 + struct sock_fprog *fprog = NULL;
50080 int err;
50081
50082 if (ctx->data.bin_val.len) {
50083 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
50084 index 98bad1f..f197d7a 100644
50085 --- a/drivers/net/tun.c
50086 +++ b/drivers/net/tun.c
50087 @@ -1854,7 +1854,7 @@ unlock:
50088 }
50089
50090 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
50091 - unsigned long arg, int ifreq_len)
50092 + unsigned long arg, size_t ifreq_len)
50093 {
50094 struct tun_file *tfile = file->private_data;
50095 struct tun_struct *tun;
50096 @@ -1867,6 +1867,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
50097 unsigned int ifindex;
50098 int ret;
50099
50100 + if (ifreq_len > sizeof ifr)
50101 + return -EFAULT;
50102 +
50103 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
50104 if (copy_from_user(&ifr, argp, ifreq_len))
50105 return -EFAULT;
50106 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
50107 index a4272ed..cdd69ff 100644
50108 --- a/drivers/net/usb/hso.c
50109 +++ b/drivers/net/usb/hso.c
50110 @@ -71,7 +71,7 @@
50111 #include <asm/byteorder.h>
50112 #include <linux/serial_core.h>
50113 #include <linux/serial.h>
50114 -
50115 +#include <asm/local.h>
50116
50117 #define MOD_AUTHOR "Option Wireless"
50118 #define MOD_DESCRIPTION "USB High Speed Option driver"
50119 @@ -1177,7 +1177,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
50120 struct urb *urb;
50121
50122 urb = serial->rx_urb[0];
50123 - if (serial->port.count > 0) {
50124 + if (atomic_read(&serial->port.count) > 0) {
50125 count = put_rxbuf_data(urb, serial);
50126 if (count == -1)
50127 return;
50128 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
50129 DUMP1(urb->transfer_buffer, urb->actual_length);
50130
50131 /* Anyone listening? */
50132 - if (serial->port.count == 0)
50133 + if (atomic_read(&serial->port.count) == 0)
50134 return;
50135
50136 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
50137 @@ -1277,8 +1277,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
50138 tty_port_tty_set(&serial->port, tty);
50139
50140 /* check for port already opened, if not set the termios */
50141 - serial->port.count++;
50142 - if (serial->port.count == 1) {
50143 + if (atomic_inc_return(&serial->port.count) == 1) {
50144 serial->rx_state = RX_IDLE;
50145 /* Force default termio settings */
50146 _hso_serial_set_termios(tty, NULL);
50147 @@ -1288,7 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
50148 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
50149 if (result) {
50150 hso_stop_serial_device(serial->parent);
50151 - serial->port.count--;
50152 + atomic_dec(&serial->port.count);
50153 kref_put(&serial->parent->ref, hso_serial_ref_free);
50154 }
50155 } else {
50156 @@ -1325,10 +1324,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
50157
50158 /* reset the rts and dtr */
50159 /* do the actual close */
50160 - serial->port.count--;
50161 + atomic_dec(&serial->port.count);
50162
50163 - if (serial->port.count <= 0) {
50164 - serial->port.count = 0;
50165 + if (atomic_read(&serial->port.count) <= 0) {
50166 + atomic_set(&serial->port.count, 0);
50167 tty_port_tty_set(&serial->port, NULL);
50168 if (!usb_gone)
50169 hso_stop_serial_device(serial->parent);
50170 @@ -1403,7 +1402,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
50171
50172 /* the actual setup */
50173 spin_lock_irqsave(&serial->serial_lock, flags);
50174 - if (serial->port.count)
50175 + if (atomic_read(&serial->port.count))
50176 _hso_serial_set_termios(tty, old);
50177 else
50178 tty->termios = *old;
50179 @@ -1872,7 +1871,7 @@ static void intr_callback(struct urb *urb)
50180 D1("Pending read interrupt on port %d\n", i);
50181 spin_lock(&serial->serial_lock);
50182 if (serial->rx_state == RX_IDLE &&
50183 - serial->port.count > 0) {
50184 + atomic_read(&serial->port.count) > 0) {
50185 /* Setup and send a ctrl req read on
50186 * port i */
50187 if (!serial->rx_urb_filled[0]) {
50188 @@ -3045,7 +3044,7 @@ static int hso_resume(struct usb_interface *iface)
50189 /* Start all serial ports */
50190 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
50191 if (serial_table[i] && (serial_table[i]->interface == iface)) {
50192 - if (dev2ser(serial_table[i])->port.count) {
50193 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
50194 result =
50195 hso_start_serial_device(serial_table[i], GFP_NOIO);
50196 hso_kick_transmit(dev2ser(serial_table[i]));
50197 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
50198 index 3eab74c..fb6097c 100644
50199 --- a/drivers/net/usb/r8152.c
50200 +++ b/drivers/net/usb/r8152.c
50201 @@ -567,7 +567,7 @@ struct r8152 {
50202 void (*up)(struct r8152 *);
50203 void (*down)(struct r8152 *);
50204 void (*unload)(struct r8152 *);
50205 - } rtl_ops;
50206 + } __no_const rtl_ops;
50207
50208 int intr_interval;
50209 u32 saved_wolopts;
50210 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
50211 index a2515887..6d13233 100644
50212 --- a/drivers/net/usb/sierra_net.c
50213 +++ b/drivers/net/usb/sierra_net.c
50214 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
50215 /* atomic counter partially included in MAC address to make sure 2 devices
50216 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
50217 */
50218 -static atomic_t iface_counter = ATOMIC_INIT(0);
50219 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
50220
50221 /*
50222 * SYNC Timer Delay definition used to set the expiry time
50223 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
50224 dev->net->netdev_ops = &sierra_net_device_ops;
50225
50226 /* change MAC addr to include, ifacenum, and to be unique */
50227 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
50228 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
50229 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
50230
50231 /* we will have to manufacture ethernet headers, prepare template */
50232 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
50233 index 7d9f84a..7f690da 100644
50234 --- a/drivers/net/virtio_net.c
50235 +++ b/drivers/net/virtio_net.c
50236 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
50237 #define RECEIVE_AVG_WEIGHT 64
50238
50239 /* Minimum alignment for mergeable packet buffers. */
50240 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
50241 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
50242
50243 #define VIRTNET_DRIVER_VERSION "1.0.0"
50244
50245 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
50246 index 9f79192..838cf95 100644
50247 --- a/drivers/net/vxlan.c
50248 +++ b/drivers/net/vxlan.c
50249 @@ -2838,7 +2838,7 @@ nla_put_failure:
50250 return -EMSGSIZE;
50251 }
50252
50253 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
50254 +static struct rtnl_link_ops vxlan_link_ops = {
50255 .kind = "vxlan",
50256 .maxtype = IFLA_VXLAN_MAX,
50257 .policy = vxlan_policy,
50258 @@ -2885,7 +2885,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
50259 return NOTIFY_DONE;
50260 }
50261
50262 -static struct notifier_block vxlan_notifier_block __read_mostly = {
50263 +static struct notifier_block vxlan_notifier_block = {
50264 .notifier_call = vxlan_lowerdev_event,
50265 };
50266
50267 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
50268 index 5920c99..ff2e4a5 100644
50269 --- a/drivers/net/wan/lmc/lmc_media.c
50270 +++ b/drivers/net/wan/lmc/lmc_media.c
50271 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
50272 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
50273
50274 lmc_media_t lmc_ds3_media = {
50275 - lmc_ds3_init, /* special media init stuff */
50276 - lmc_ds3_default, /* reset to default state */
50277 - lmc_ds3_set_status, /* reset status to state provided */
50278 - lmc_dummy_set_1, /* set clock source */
50279 - lmc_dummy_set2_1, /* set line speed */
50280 - lmc_ds3_set_100ft, /* set cable length */
50281 - lmc_ds3_set_scram, /* set scrambler */
50282 - lmc_ds3_get_link_status, /* get link status */
50283 - lmc_dummy_set_1, /* set link status */
50284 - lmc_ds3_set_crc_length, /* set CRC length */
50285 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
50286 - lmc_ds3_watchdog
50287 + .init = lmc_ds3_init, /* special media init stuff */
50288 + .defaults = lmc_ds3_default, /* reset to default state */
50289 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
50290 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
50291 + .set_speed = lmc_dummy_set2_1, /* set line speed */
50292 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
50293 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
50294 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
50295 + .set_link_status = lmc_dummy_set_1, /* set link status */
50296 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
50297 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
50298 + .watchdog = lmc_ds3_watchdog
50299 };
50300
50301 lmc_media_t lmc_hssi_media = {
50302 - lmc_hssi_init, /* special media init stuff */
50303 - lmc_hssi_default, /* reset to default state */
50304 - lmc_hssi_set_status, /* reset status to state provided */
50305 - lmc_hssi_set_clock, /* set clock source */
50306 - lmc_dummy_set2_1, /* set line speed */
50307 - lmc_dummy_set_1, /* set cable length */
50308 - lmc_dummy_set_1, /* set scrambler */
50309 - lmc_hssi_get_link_status, /* get link status */
50310 - lmc_hssi_set_link_status, /* set link status */
50311 - lmc_hssi_set_crc_length, /* set CRC length */
50312 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
50313 - lmc_hssi_watchdog
50314 + .init = lmc_hssi_init, /* special media init stuff */
50315 + .defaults = lmc_hssi_default, /* reset to default state */
50316 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
50317 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
50318 + .set_speed = lmc_dummy_set2_1, /* set line speed */
50319 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
50320 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
50321 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
50322 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
50323 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
50324 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
50325 + .watchdog = lmc_hssi_watchdog
50326 };
50327
50328 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
50329 - lmc_ssi_default, /* reset to default state */
50330 - lmc_ssi_set_status, /* reset status to state provided */
50331 - lmc_ssi_set_clock, /* set clock source */
50332 - lmc_ssi_set_speed, /* set line speed */
50333 - lmc_dummy_set_1, /* set cable length */
50334 - lmc_dummy_set_1, /* set scrambler */
50335 - lmc_ssi_get_link_status, /* get link status */
50336 - lmc_ssi_set_link_status, /* set link status */
50337 - lmc_ssi_set_crc_length, /* set CRC length */
50338 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
50339 - lmc_ssi_watchdog
50340 +lmc_media_t lmc_ssi_media = {
50341 + .init = lmc_ssi_init, /* special media init stuff */
50342 + .defaults = lmc_ssi_default, /* reset to default state */
50343 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
50344 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
50345 + .set_speed = lmc_ssi_set_speed, /* set line speed */
50346 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
50347 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
50348 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
50349 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
50350 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
50351 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
50352 + .watchdog = lmc_ssi_watchdog
50353 };
50354
50355 lmc_media_t lmc_t1_media = {
50356 - lmc_t1_init, /* special media init stuff */
50357 - lmc_t1_default, /* reset to default state */
50358 - lmc_t1_set_status, /* reset status to state provided */
50359 - lmc_t1_set_clock, /* set clock source */
50360 - lmc_dummy_set2_1, /* set line speed */
50361 - lmc_dummy_set_1, /* set cable length */
50362 - lmc_dummy_set_1, /* set scrambler */
50363 - lmc_t1_get_link_status, /* get link status */
50364 - lmc_dummy_set_1, /* set link status */
50365 - lmc_t1_set_crc_length, /* set CRC length */
50366 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
50367 - lmc_t1_watchdog
50368 + .init = lmc_t1_init, /* special media init stuff */
50369 + .defaults = lmc_t1_default, /* reset to default state */
50370 + .set_status = lmc_t1_set_status, /* reset status to state provided */
50371 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
50372 + .set_speed = lmc_dummy_set2_1, /* set line speed */
50373 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
50374 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
50375 + .get_link_status = lmc_t1_get_link_status, /* get link status */
50376 + .set_link_status = lmc_dummy_set_1, /* set link status */
50377 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
50378 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
50379 + .watchdog = lmc_t1_watchdog
50380 };
50381
50382 static void
50383 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
50384 index feacc3b..5bac0de 100644
50385 --- a/drivers/net/wan/z85230.c
50386 +++ b/drivers/net/wan/z85230.c
50387 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
50388
50389 struct z8530_irqhandler z8530_sync =
50390 {
50391 - z8530_rx,
50392 - z8530_tx,
50393 - z8530_status
50394 + .rx = z8530_rx,
50395 + .tx = z8530_tx,
50396 + .status = z8530_status
50397 };
50398
50399 EXPORT_SYMBOL(z8530_sync);
50400 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
50401 }
50402
50403 static struct z8530_irqhandler z8530_dma_sync = {
50404 - z8530_dma_rx,
50405 - z8530_dma_tx,
50406 - z8530_dma_status
50407 + .rx = z8530_dma_rx,
50408 + .tx = z8530_dma_tx,
50409 + .status = z8530_dma_status
50410 };
50411
50412 static struct z8530_irqhandler z8530_txdma_sync = {
50413 - z8530_rx,
50414 - z8530_dma_tx,
50415 - z8530_dma_status
50416 + .rx = z8530_rx,
50417 + .tx = z8530_dma_tx,
50418 + .status = z8530_dma_status
50419 };
50420
50421 /**
50422 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
50423
50424 struct z8530_irqhandler z8530_nop=
50425 {
50426 - z8530_rx_clear,
50427 - z8530_tx_clear,
50428 - z8530_status_clear
50429 + .rx = z8530_rx_clear,
50430 + .tx = z8530_tx_clear,
50431 + .status = z8530_status_clear
50432 };
50433
50434
50435 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
50436 index 0b60295..b8bfa5b 100644
50437 --- a/drivers/net/wimax/i2400m/rx.c
50438 +++ b/drivers/net/wimax/i2400m/rx.c
50439 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
50440 if (i2400m->rx_roq == NULL)
50441 goto error_roq_alloc;
50442
50443 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
50444 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
50445 GFP_KERNEL);
50446 if (rd == NULL) {
50447 result = -ENOMEM;
50448 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
50449 index 64747d4..17c4cf3 100644
50450 --- a/drivers/net/wireless/airo.c
50451 +++ b/drivers/net/wireless/airo.c
50452 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
50453 struct airo_info *ai = dev->ml_priv;
50454 int ridcode;
50455 int enabled;
50456 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50457 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
50458 unsigned char *iobuf;
50459
50460 /* Only super-user can write RIDs */
50461 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
50462 index d48776e..373d049 100644
50463 --- a/drivers/net/wireless/at76c50x-usb.c
50464 +++ b/drivers/net/wireless/at76c50x-usb.c
50465 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
50466 }
50467
50468 /* Convert timeout from the DFU status to jiffies */
50469 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
50470 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
50471 {
50472 return msecs_to_jiffies((s->poll_timeout[2] << 16)
50473 | (s->poll_timeout[1] << 8)
50474 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
50475 index e493db4..2c1853a 100644
50476 --- a/drivers/net/wireless/ath/ath10k/htc.c
50477 +++ b/drivers/net/wireless/ath/ath10k/htc.c
50478 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
50479 /* registered target arrival callback from the HIF layer */
50480 int ath10k_htc_init(struct ath10k *ar)
50481 {
50482 - struct ath10k_hif_cb htc_callbacks;
50483 + static struct ath10k_hif_cb htc_callbacks = {
50484 + .rx_completion = ath10k_htc_rx_completion_handler,
50485 + .tx_completion = ath10k_htc_tx_completion_handler,
50486 + };
50487 struct ath10k_htc_ep *ep = NULL;
50488 struct ath10k_htc *htc = &ar->htc;
50489
50490 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
50491 ath10k_htc_reset_endpoint_states(htc);
50492
50493 /* setup HIF layer callbacks */
50494 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
50495 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
50496 htc->ar = ar;
50497
50498 /* Get HIF default pipe for HTC message exchange */
50499 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
50500 index 4716d33..a688310 100644
50501 --- a/drivers/net/wireless/ath/ath10k/htc.h
50502 +++ b/drivers/net/wireless/ath/ath10k/htc.h
50503 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
50504
50505 struct ath10k_htc_ops {
50506 void (*target_send_suspend_complete)(struct ath10k *ar);
50507 -};
50508 +} __no_const;
50509
50510 struct ath10k_htc_ep_ops {
50511 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
50512 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
50513 void (*ep_tx_credits)(struct ath10k *);
50514 -};
50515 +} __no_const;
50516
50517 /* service connection information */
50518 struct ath10k_htc_svc_conn_req {
50519 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50520 index 741b38d..b7ae41b 100644
50521 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50522 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
50523 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50524 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
50525 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
50526
50527 - ACCESS_ONCE(ads->ds_link) = i->link;
50528 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
50529 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
50530 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
50531
50532 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
50533 ctl6 = SM(i->keytype, AR_EncrType);
50534 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50535
50536 if ((i->is_first || i->is_last) &&
50537 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
50538 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
50539 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
50540 | set11nTries(i->rates, 1)
50541 | set11nTries(i->rates, 2)
50542 | set11nTries(i->rates, 3)
50543 | (i->dur_update ? AR_DurUpdateEna : 0)
50544 | SM(0, AR_BurstDur);
50545
50546 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
50547 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
50548 | set11nRate(i->rates, 1)
50549 | set11nRate(i->rates, 2)
50550 | set11nRate(i->rates, 3);
50551 } else {
50552 - ACCESS_ONCE(ads->ds_ctl2) = 0;
50553 - ACCESS_ONCE(ads->ds_ctl3) = 0;
50554 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
50555 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
50556 }
50557
50558 if (!i->is_first) {
50559 - ACCESS_ONCE(ads->ds_ctl0) = 0;
50560 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50561 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50562 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
50563 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50564 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50565 return;
50566 }
50567
50568 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50569 break;
50570 }
50571
50572 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50573 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
50574 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50575 | SM(i->txpower, AR_XmitPower)
50576 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50577 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50578 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
50579 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
50580
50581 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
50582 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
50583 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
50584 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
50585
50586 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
50587 return;
50588
50589 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50590 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
50591 | set11nPktDurRTSCTS(i->rates, 1);
50592
50593 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50594 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
50595 | set11nPktDurRTSCTS(i->rates, 3);
50596
50597 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50598 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
50599 | set11nRateFlags(i->rates, 1)
50600 | set11nRateFlags(i->rates, 2)
50601 | set11nRateFlags(i->rates, 3)
50602 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50603 index 729ffbf..49f50e3 100644
50604 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50605 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
50606 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50607 (i->qcu << AR_TxQcuNum_S) | desc_len;
50608
50609 checksum += val;
50610 - ACCESS_ONCE(ads->info) = val;
50611 + ACCESS_ONCE_RW(ads->info) = val;
50612
50613 checksum += i->link;
50614 - ACCESS_ONCE(ads->link) = i->link;
50615 + ACCESS_ONCE_RW(ads->link) = i->link;
50616
50617 checksum += i->buf_addr[0];
50618 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
50619 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
50620 checksum += i->buf_addr[1];
50621 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
50622 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
50623 checksum += i->buf_addr[2];
50624 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
50625 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
50626 checksum += i->buf_addr[3];
50627 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
50628 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
50629
50630 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
50631 - ACCESS_ONCE(ads->ctl3) = val;
50632 + ACCESS_ONCE_RW(ads->ctl3) = val;
50633 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
50634 - ACCESS_ONCE(ads->ctl5) = val;
50635 + ACCESS_ONCE_RW(ads->ctl5) = val;
50636 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
50637 - ACCESS_ONCE(ads->ctl7) = val;
50638 + ACCESS_ONCE_RW(ads->ctl7) = val;
50639 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
50640 - ACCESS_ONCE(ads->ctl9) = val;
50641 + ACCESS_ONCE_RW(ads->ctl9) = val;
50642
50643 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
50644 - ACCESS_ONCE(ads->ctl10) = checksum;
50645 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
50646
50647 if (i->is_first || i->is_last) {
50648 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
50649 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
50650 | set11nTries(i->rates, 1)
50651 | set11nTries(i->rates, 2)
50652 | set11nTries(i->rates, 3)
50653 | (i->dur_update ? AR_DurUpdateEna : 0)
50654 | SM(0, AR_BurstDur);
50655
50656 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
50657 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
50658 | set11nRate(i->rates, 1)
50659 | set11nRate(i->rates, 2)
50660 | set11nRate(i->rates, 3);
50661 } else {
50662 - ACCESS_ONCE(ads->ctl13) = 0;
50663 - ACCESS_ONCE(ads->ctl14) = 0;
50664 + ACCESS_ONCE_RW(ads->ctl13) = 0;
50665 + ACCESS_ONCE_RW(ads->ctl14) = 0;
50666 }
50667
50668 ads->ctl20 = 0;
50669 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50670
50671 ctl17 = SM(i->keytype, AR_EncrType);
50672 if (!i->is_first) {
50673 - ACCESS_ONCE(ads->ctl11) = 0;
50674 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50675 - ACCESS_ONCE(ads->ctl15) = 0;
50676 - ACCESS_ONCE(ads->ctl16) = 0;
50677 - ACCESS_ONCE(ads->ctl17) = ctl17;
50678 - ACCESS_ONCE(ads->ctl18) = 0;
50679 - ACCESS_ONCE(ads->ctl19) = 0;
50680 + ACCESS_ONCE_RW(ads->ctl11) = 0;
50681 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
50682 + ACCESS_ONCE_RW(ads->ctl15) = 0;
50683 + ACCESS_ONCE_RW(ads->ctl16) = 0;
50684 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50685 + ACCESS_ONCE_RW(ads->ctl18) = 0;
50686 + ACCESS_ONCE_RW(ads->ctl19) = 0;
50687 return;
50688 }
50689
50690 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50691 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
50692 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
50693 | SM(i->txpower, AR_XmitPower)
50694 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
50695 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
50696 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
50697 ctl12 |= SM(val, AR_PAPRDChainMask);
50698
50699 - ACCESS_ONCE(ads->ctl12) = ctl12;
50700 - ACCESS_ONCE(ads->ctl17) = ctl17;
50701 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
50702 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
50703
50704 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50705 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
50706 | set11nPktDurRTSCTS(i->rates, 1);
50707
50708 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50709 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
50710 | set11nPktDurRTSCTS(i->rates, 3);
50711
50712 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
50713 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
50714 | set11nRateFlags(i->rates, 1)
50715 | set11nRateFlags(i->rates, 2)
50716 | set11nRateFlags(i->rates, 3)
50717 | SM(i->rtscts_rate, AR_RTSCTSRate);
50718
50719 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
50720 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
50721 }
50722
50723 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
50724 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
50725 index 0acd4b5..0591c91 100644
50726 --- a/drivers/net/wireless/ath/ath9k/hw.h
50727 +++ b/drivers/net/wireless/ath/ath9k/hw.h
50728 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
50729
50730 /* ANI */
50731 void (*ani_cache_ini_regs)(struct ath_hw *ah);
50732 -};
50733 +} __no_const;
50734
50735 /**
50736 * struct ath_spec_scan - parameters for Atheros spectral scan
50737 @@ -706,7 +706,7 @@ struct ath_hw_ops {
50738 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
50739 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
50740 #endif
50741 -};
50742 +} __no_const;
50743
50744 struct ath_nf_limits {
50745 s16 max;
50746 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
50747 index 92190da..f3a4c4c 100644
50748 --- a/drivers/net/wireless/b43/phy_lp.c
50749 +++ b/drivers/net/wireless/b43/phy_lp.c
50750 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
50751 {
50752 struct ssb_bus *bus = dev->dev->sdev->bus;
50753
50754 - static const struct b206x_channel *chandata = NULL;
50755 + const struct b206x_channel *chandata = NULL;
50756 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
50757 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
50758 u16 old_comm15, scale;
50759 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
50760 index dc1d20c..f7a4f06 100644
50761 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
50762 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
50763 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50764 */
50765 if (il3945_mod_params.disable_hw_scan) {
50766 D_INFO("Disabling hw_scan\n");
50767 - il3945_mac_ops.hw_scan = NULL;
50768 + pax_open_kernel();
50769 + *(void **)&il3945_mac_ops.hw_scan = NULL;
50770 + pax_close_kernel();
50771 }
50772
50773 D_INFO("*** LOAD DRIVER ***\n");
50774 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50775 index 0ffb6ff..c0b7f0e 100644
50776 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50777 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
50778 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
50779 {
50780 struct iwl_priv *priv = file->private_data;
50781 char buf[64];
50782 - int buf_size;
50783 + size_t buf_size;
50784 u32 offset, len;
50785
50786 memset(buf, 0, sizeof(buf));
50787 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
50788 struct iwl_priv *priv = file->private_data;
50789
50790 char buf[8];
50791 - int buf_size;
50792 + size_t buf_size;
50793 u32 reset_flag;
50794
50795 memset(buf, 0, sizeof(buf));
50796 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
50797 {
50798 struct iwl_priv *priv = file->private_data;
50799 char buf[8];
50800 - int buf_size;
50801 + size_t buf_size;
50802 int ht40;
50803
50804 memset(buf, 0, sizeof(buf));
50805 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
50806 {
50807 struct iwl_priv *priv = file->private_data;
50808 char buf[8];
50809 - int buf_size;
50810 + size_t buf_size;
50811 int value;
50812
50813 memset(buf, 0, sizeof(buf));
50814 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
50815 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
50816 DEBUGFS_READ_FILE_OPS(current_sleep_command);
50817
50818 -static const char *fmt_value = " %-30s %10u\n";
50819 -static const char *fmt_hex = " %-30s 0x%02X\n";
50820 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
50821 -static const char *fmt_header =
50822 +static const char fmt_value[] = " %-30s %10u\n";
50823 +static const char fmt_hex[] = " %-30s 0x%02X\n";
50824 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
50825 +static const char fmt_header[] =
50826 "%-32s current cumulative delta max\n";
50827
50828 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
50829 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
50830 {
50831 struct iwl_priv *priv = file->private_data;
50832 char buf[8];
50833 - int buf_size;
50834 + size_t buf_size;
50835 int clear;
50836
50837 memset(buf, 0, sizeof(buf));
50838 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
50839 {
50840 struct iwl_priv *priv = file->private_data;
50841 char buf[8];
50842 - int buf_size;
50843 + size_t buf_size;
50844 int trace;
50845
50846 memset(buf, 0, sizeof(buf));
50847 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
50848 {
50849 struct iwl_priv *priv = file->private_data;
50850 char buf[8];
50851 - int buf_size;
50852 + size_t buf_size;
50853 int missed;
50854
50855 memset(buf, 0, sizeof(buf));
50856 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50857
50858 struct iwl_priv *priv = file->private_data;
50859 char buf[8];
50860 - int buf_size;
50861 + size_t buf_size;
50862 int plcp;
50863
50864 memset(buf, 0, sizeof(buf));
50865 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50866
50867 struct iwl_priv *priv = file->private_data;
50868 char buf[8];
50869 - int buf_size;
50870 + size_t buf_size;
50871 int flush;
50872
50873 memset(buf, 0, sizeof(buf));
50874 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50875
50876 struct iwl_priv *priv = file->private_data;
50877 char buf[8];
50878 - int buf_size;
50879 + size_t buf_size;
50880 int rts;
50881
50882 if (!priv->cfg->ht_params)
50883 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50884 {
50885 struct iwl_priv *priv = file->private_data;
50886 char buf[8];
50887 - int buf_size;
50888 + size_t buf_size;
50889
50890 memset(buf, 0, sizeof(buf));
50891 buf_size = min(count, sizeof(buf) - 1);
50892 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50893 struct iwl_priv *priv = file->private_data;
50894 u32 event_log_flag;
50895 char buf[8];
50896 - int buf_size;
50897 + size_t buf_size;
50898
50899 /* check that the interface is up */
50900 if (!iwl_is_ready(priv))
50901 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50902 struct iwl_priv *priv = file->private_data;
50903 char buf[8];
50904 u32 calib_disabled;
50905 - int buf_size;
50906 + size_t buf_size;
50907
50908 memset(buf, 0, sizeof(buf));
50909 buf_size = min(count, sizeof(buf) - 1);
50910 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50911 index 788085b..0bc852a 100644
50912 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50913 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50914 @@ -1598,7 +1598,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50915 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50916
50917 char buf[8];
50918 - int buf_size;
50919 + size_t buf_size;
50920 u32 reset_flag;
50921
50922 memset(buf, 0, sizeof(buf));
50923 @@ -1619,7 +1619,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50924 {
50925 struct iwl_trans *trans = file->private_data;
50926 char buf[8];
50927 - int buf_size;
50928 + size_t buf_size;
50929 int csr;
50930
50931 memset(buf, 0, sizeof(buf));
50932 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50933 index a312c65..162b13a 100644
50934 --- a/drivers/net/wireless/mac80211_hwsim.c
50935 +++ b/drivers/net/wireless/mac80211_hwsim.c
50936 @@ -2573,20 +2573,20 @@ static int __init init_mac80211_hwsim(void)
50937 if (channels < 1)
50938 return -EINVAL;
50939
50940 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50941 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50942 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50943 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50944 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50945 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50946 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50947 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50948 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50949 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50950 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50951 - mac80211_hwsim_assign_vif_chanctx;
50952 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50953 - mac80211_hwsim_unassign_vif_chanctx;
50954 + pax_open_kernel();
50955 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50956 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50957 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50958 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50959 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50960 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50961 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50962 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50963 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50964 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50965 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50966 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50967 + pax_close_kernel();
50968
50969 spin_lock_init(&hwsim_radio_lock);
50970 INIT_LIST_HEAD(&hwsim_radios);
50971 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50972 index d2a9a08..0cb175d 100644
50973 --- a/drivers/net/wireless/rndis_wlan.c
50974 +++ b/drivers/net/wireless/rndis_wlan.c
50975 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50976
50977 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50978
50979 - if (rts_threshold < 0 || rts_threshold > 2347)
50980 + if (rts_threshold > 2347)
50981 rts_threshold = 2347;
50982
50983 tmp = cpu_to_le32(rts_threshold);
50984 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50985 index d13f25c..2573994 100644
50986 --- a/drivers/net/wireless/rt2x00/rt2x00.h
50987 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
50988 @@ -375,7 +375,7 @@ struct rt2x00_intf {
50989 * for hardware which doesn't support hardware
50990 * sequence counting.
50991 */
50992 - atomic_t seqno;
50993 + atomic_unchecked_t seqno;
50994 };
50995
50996 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50997 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50998 index 5642ccc..01f03eb 100644
50999 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
51000 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
51001 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
51002 * sequence counter given by mac80211.
51003 */
51004 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
51005 - seqno = atomic_add_return(0x10, &intf->seqno);
51006 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
51007 else
51008 - seqno = atomic_read(&intf->seqno);
51009 + seqno = atomic_read_unchecked(&intf->seqno);
51010
51011 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
51012 hdr->seq_ctrl |= cpu_to_le16(seqno);
51013 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
51014 index b661f896..ddf7d2b 100644
51015 --- a/drivers/net/wireless/ti/wl1251/sdio.c
51016 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
51017 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
51018
51019 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
51020
51021 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
51022 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
51023 + pax_open_kernel();
51024 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
51025 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
51026 + pax_close_kernel();
51027
51028 wl1251_info("using dedicated interrupt line");
51029 } else {
51030 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
51031 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
51032 + pax_open_kernel();
51033 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
51034 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
51035 + pax_close_kernel();
51036
51037 wl1251_info("using SDIO interrupt");
51038 }
51039 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
51040 index d50dfac..0a6f5be3 100644
51041 --- a/drivers/net/wireless/ti/wl12xx/main.c
51042 +++ b/drivers/net/wireless/ti/wl12xx/main.c
51043 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
51044 sizeof(wl->conf.mem));
51045
51046 /* read data preparation is only needed by wl127x */
51047 - wl->ops->prepare_read = wl127x_prepare_read;
51048 + pax_open_kernel();
51049 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
51050 + pax_close_kernel();
51051
51052 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
51053 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
51054 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
51055 sizeof(wl->conf.mem));
51056
51057 /* read data preparation is only needed by wl127x */
51058 - wl->ops->prepare_read = wl127x_prepare_read;
51059 + pax_open_kernel();
51060 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
51061 + pax_close_kernel();
51062
51063 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
51064 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
51065 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
51066 index de5b4fa..7996ec6 100644
51067 --- a/drivers/net/wireless/ti/wl18xx/main.c
51068 +++ b/drivers/net/wireless/ti/wl18xx/main.c
51069 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
51070 }
51071
51072 if (!checksum_param) {
51073 - wl18xx_ops.set_rx_csum = NULL;
51074 - wl18xx_ops.init_vif = NULL;
51075 + pax_open_kernel();
51076 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
51077 + *(void **)&wl18xx_ops.init_vif = NULL;
51078 + pax_close_kernel();
51079 }
51080
51081 /* Enable 11a Band only if we have 5G antennas */
51082 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
51083 index a912dc0..a8225ba 100644
51084 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
51085 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
51086 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
51087 {
51088 struct zd_usb *usb = urb->context;
51089 struct zd_usb_interrupt *intr = &usb->intr;
51090 - int len;
51091 + unsigned int len;
51092 u16 int_num;
51093
51094 ZD_ASSERT(in_interrupt());
51095 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
51096 index 683671a..4519fc2 100644
51097 --- a/drivers/nfc/nfcwilink.c
51098 +++ b/drivers/nfc/nfcwilink.c
51099 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
51100
51101 static int nfcwilink_probe(struct platform_device *pdev)
51102 {
51103 - static struct nfcwilink *drv;
51104 + struct nfcwilink *drv;
51105 int rc;
51106 __u32 protocols;
51107
51108 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
51109 index d93b2b6..ae50401 100644
51110 --- a/drivers/oprofile/buffer_sync.c
51111 +++ b/drivers/oprofile/buffer_sync.c
51112 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
51113 if (cookie == NO_COOKIE)
51114 offset = pc;
51115 if (cookie == INVALID_COOKIE) {
51116 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
51117 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
51118 offset = pc;
51119 }
51120 if (cookie != last_cookie) {
51121 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
51122 /* add userspace sample */
51123
51124 if (!mm) {
51125 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
51126 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
51127 return 0;
51128 }
51129
51130 cookie = lookup_dcookie(mm, s->eip, &offset);
51131
51132 if (cookie == INVALID_COOKIE) {
51133 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
51134 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
51135 return 0;
51136 }
51137
51138 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
51139 /* ignore backtraces if failed to add a sample */
51140 if (state == sb_bt_start) {
51141 state = sb_bt_ignore;
51142 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
51143 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
51144 }
51145 }
51146 release_mm(mm);
51147 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
51148 index c0cc4e7..44d4e54 100644
51149 --- a/drivers/oprofile/event_buffer.c
51150 +++ b/drivers/oprofile/event_buffer.c
51151 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
51152 }
51153
51154 if (buffer_pos == buffer_size) {
51155 - atomic_inc(&oprofile_stats.event_lost_overflow);
51156 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
51157 return;
51158 }
51159
51160 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
51161 index ed2c3ec..deda85a 100644
51162 --- a/drivers/oprofile/oprof.c
51163 +++ b/drivers/oprofile/oprof.c
51164 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
51165 if (oprofile_ops.switch_events())
51166 return;
51167
51168 - atomic_inc(&oprofile_stats.multiplex_counter);
51169 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
51170 start_switch_worker();
51171 }
51172
51173 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
51174 index ee2cfce..7f8f699 100644
51175 --- a/drivers/oprofile/oprofile_files.c
51176 +++ b/drivers/oprofile/oprofile_files.c
51177 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
51178
51179 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
51180
51181 -static ssize_t timeout_read(struct file *file, char __user *buf,
51182 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
51183 size_t count, loff_t *offset)
51184 {
51185 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
51186 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
51187 index 59659ce..6c860a0 100644
51188 --- a/drivers/oprofile/oprofile_stats.c
51189 +++ b/drivers/oprofile/oprofile_stats.c
51190 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
51191 cpu_buf->sample_invalid_eip = 0;
51192 }
51193
51194 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
51195 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
51196 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
51197 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
51198 - atomic_set(&oprofile_stats.multiplex_counter, 0);
51199 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
51200 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
51201 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
51202 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
51203 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
51204 }
51205
51206
51207 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
51208 index 1fc622b..8c48fc3 100644
51209 --- a/drivers/oprofile/oprofile_stats.h
51210 +++ b/drivers/oprofile/oprofile_stats.h
51211 @@ -13,11 +13,11 @@
51212 #include <linux/atomic.h>
51213
51214 struct oprofile_stat_struct {
51215 - atomic_t sample_lost_no_mm;
51216 - atomic_t sample_lost_no_mapping;
51217 - atomic_t bt_lost_no_mapping;
51218 - atomic_t event_lost_overflow;
51219 - atomic_t multiplex_counter;
51220 + atomic_unchecked_t sample_lost_no_mm;
51221 + atomic_unchecked_t sample_lost_no_mapping;
51222 + atomic_unchecked_t bt_lost_no_mapping;
51223 + atomic_unchecked_t event_lost_overflow;
51224 + atomic_unchecked_t multiplex_counter;
51225 };
51226
51227 extern struct oprofile_stat_struct oprofile_stats;
51228 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
51229 index 3f49345..c750d0b 100644
51230 --- a/drivers/oprofile/oprofilefs.c
51231 +++ b/drivers/oprofile/oprofilefs.c
51232 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
51233
51234 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
51235 {
51236 - atomic_t *val = file->private_data;
51237 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
51238 + atomic_unchecked_t *val = file->private_data;
51239 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
51240 }
51241
51242
51243 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
51244
51245
51246 int oprofilefs_create_ro_atomic(struct dentry *root,
51247 - char const *name, atomic_t *val)
51248 + char const *name, atomic_unchecked_t *val)
51249 {
51250 return __oprofilefs_create_file(root, name,
51251 &atomic_ro_fops, 0444, val);
51252 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
51253 index 61be1d9..dec05d7 100644
51254 --- a/drivers/oprofile/timer_int.c
51255 +++ b/drivers/oprofile/timer_int.c
51256 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
51257 return NOTIFY_OK;
51258 }
51259
51260 -static struct notifier_block __refdata oprofile_cpu_notifier = {
51261 +static struct notifier_block oprofile_cpu_notifier = {
51262 .notifier_call = oprofile_cpu_notify,
51263 };
51264
51265 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
51266 index 3b47080..6cd05dd 100644
51267 --- a/drivers/parport/procfs.c
51268 +++ b/drivers/parport/procfs.c
51269 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
51270
51271 *ppos += len;
51272
51273 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
51274 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
51275 }
51276
51277 #ifdef CONFIG_PARPORT_1284
51278 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
51279
51280 *ppos += len;
51281
51282 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
51283 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
51284 }
51285 #endif /* IEEE1284.3 support. */
51286
51287 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
51288 index 8dcccff..35d701d 100644
51289 --- a/drivers/pci/hotplug/acpiphp_ibm.c
51290 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
51291 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
51292 goto init_cleanup;
51293 }
51294
51295 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
51296 + pax_open_kernel();
51297 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
51298 + pax_close_kernel();
51299 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
51300
51301 return retval;
51302 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
51303 index 04fcd78..39e83f1 100644
51304 --- a/drivers/pci/hotplug/cpcihp_generic.c
51305 +++ b/drivers/pci/hotplug/cpcihp_generic.c
51306 @@ -73,7 +73,6 @@ static u16 port;
51307 static unsigned int enum_bit;
51308 static u8 enum_mask;
51309
51310 -static struct cpci_hp_controller_ops generic_hpc_ops;
51311 static struct cpci_hp_controller generic_hpc;
51312
51313 static int __init validate_parameters(void)
51314 @@ -139,6 +138,10 @@ static int query_enum(void)
51315 return ((value & enum_mask) == enum_mask);
51316 }
51317
51318 +static struct cpci_hp_controller_ops generic_hpc_ops = {
51319 + .query_enum = query_enum,
51320 +};
51321 +
51322 static int __init cpcihp_generic_init(void)
51323 {
51324 int status;
51325 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
51326 pci_dev_put(dev);
51327
51328 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
51329 - generic_hpc_ops.query_enum = query_enum;
51330 generic_hpc.ops = &generic_hpc_ops;
51331
51332 status = cpci_hp_register_controller(&generic_hpc);
51333 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
51334 index 6757b3e..d3bad62 100644
51335 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
51336 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
51337 @@ -59,7 +59,6 @@
51338 /* local variables */
51339 static bool debug;
51340 static bool poll;
51341 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
51342 static struct cpci_hp_controller zt5550_hpc;
51343
51344 /* Primary cPCI bus bridge device */
51345 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
51346 return 0;
51347 }
51348
51349 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
51350 + .query_enum = zt5550_hc_query_enum,
51351 +};
51352 +
51353 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
51354 {
51355 int status;
51356 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
51357 dbg("returned from zt5550_hc_config");
51358
51359 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
51360 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
51361 zt5550_hpc.ops = &zt5550_hpc_ops;
51362 if(!poll) {
51363 zt5550_hpc.irq = hc_dev->irq;
51364 zt5550_hpc.irq_flags = IRQF_SHARED;
51365 zt5550_hpc.dev_id = hc_dev;
51366
51367 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51368 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51369 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51370 + pax_open_kernel();
51371 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
51372 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
51373 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
51374 + pax_open_kernel();
51375 } else {
51376 info("using ENUM# polling mode");
51377 }
51378 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
51379 index 0968a9b..5a00edf 100644
51380 --- a/drivers/pci/hotplug/cpqphp_nvram.c
51381 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
51382 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
51383
51384 void compaq_nvram_init (void __iomem *rom_start)
51385 {
51386 +
51387 +#ifndef CONFIG_PAX_KERNEXEC
51388 if (rom_start) {
51389 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
51390 }
51391 +#endif
51392 +
51393 dbg("int15 entry = %p\n", compaq_int15_entry_point);
51394
51395 /* initialize our int15 lock */
51396 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
51397 index 56d8486..f26113f 100644
51398 --- a/drivers/pci/hotplug/pci_hotplug_core.c
51399 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
51400 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
51401 return -EINVAL;
51402 }
51403
51404 - slot->ops->owner = owner;
51405 - slot->ops->mod_name = mod_name;
51406 + pax_open_kernel();
51407 + *(struct module **)&slot->ops->owner = owner;
51408 + *(const char **)&slot->ops->mod_name = mod_name;
51409 + pax_close_kernel();
51410
51411 mutex_lock(&pci_hp_mutex);
51412 /*
51413 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
51414 index a2297db..7c7d161 100644
51415 --- a/drivers/pci/hotplug/pciehp_core.c
51416 +++ b/drivers/pci/hotplug/pciehp_core.c
51417 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
51418 struct slot *slot = ctrl->slot;
51419 struct hotplug_slot *hotplug = NULL;
51420 struct hotplug_slot_info *info = NULL;
51421 - struct hotplug_slot_ops *ops = NULL;
51422 + hotplug_slot_ops_no_const *ops = NULL;
51423 char name[SLOT_NAME_SIZE];
51424 int retval = -ENOMEM;
51425
51426 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
51427 index 13f3d30..363cb44 100644
51428 --- a/drivers/pci/msi.c
51429 +++ b/drivers/pci/msi.c
51430 @@ -523,8 +523,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
51431 {
51432 struct attribute **msi_attrs;
51433 struct attribute *msi_attr;
51434 - struct device_attribute *msi_dev_attr;
51435 - struct attribute_group *msi_irq_group;
51436 + device_attribute_no_const *msi_dev_attr;
51437 + attribute_group_no_const *msi_irq_group;
51438 const struct attribute_group **msi_irq_groups;
51439 struct msi_desc *entry;
51440 int ret = -ENOMEM;
51441 @@ -584,7 +584,7 @@ error_attrs:
51442 count = 0;
51443 msi_attr = msi_attrs[count];
51444 while (msi_attr) {
51445 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
51446 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
51447 kfree(msi_attr->name);
51448 kfree(msi_dev_attr);
51449 ++count;
51450 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
51451 index 9ff0a90..e819dda 100644
51452 --- a/drivers/pci/pci-sysfs.c
51453 +++ b/drivers/pci/pci-sysfs.c
51454 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
51455 {
51456 /* allocate attribute structure, piggyback attribute name */
51457 int name_len = write_combine ? 13 : 10;
51458 - struct bin_attribute *res_attr;
51459 + bin_attribute_no_const *res_attr;
51460 int retval;
51461
51462 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
51463 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
51464 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
51465 {
51466 int retval;
51467 - struct bin_attribute *attr;
51468 + bin_attribute_no_const *attr;
51469
51470 /* If the device has VPD, try to expose it in sysfs. */
51471 if (dev->vpd) {
51472 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
51473 {
51474 int retval;
51475 int rom_size = 0;
51476 - struct bin_attribute *attr;
51477 + bin_attribute_no_const *attr;
51478
51479 if (!sysfs_initialized)
51480 return -EACCES;
51481 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
51482 index 0601890..dc15007 100644
51483 --- a/drivers/pci/pci.h
51484 +++ b/drivers/pci/pci.h
51485 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
51486 struct pci_vpd {
51487 unsigned int len;
51488 const struct pci_vpd_ops *ops;
51489 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
51490 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
51491 };
51492
51493 int pci_vpd_pci22_init(struct pci_dev *dev);
51494 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
51495 index e1e7026..d28dd33 100644
51496 --- a/drivers/pci/pcie/aspm.c
51497 +++ b/drivers/pci/pcie/aspm.c
51498 @@ -27,9 +27,9 @@
51499 #define MODULE_PARAM_PREFIX "pcie_aspm."
51500
51501 /* Note: those are not register definitions */
51502 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
51503 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
51504 -#define ASPM_STATE_L1 (4) /* L1 state */
51505 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
51506 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
51507 +#define ASPM_STATE_L1 (4U) /* L1 state */
51508 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
51509 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
51510
51511 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
51512 index e3cf8a2..be1baf0 100644
51513 --- a/drivers/pci/probe.c
51514 +++ b/drivers/pci/probe.c
51515 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
51516 struct pci_bus_region region, inverted_region;
51517 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
51518
51519 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
51520 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
51521
51522 /* No printks while decoding is disabled! */
51523 if (!dev->mmio_always_on) {
51524 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
51525 index 3f155e7..0f4b1f0 100644
51526 --- a/drivers/pci/proc.c
51527 +++ b/drivers/pci/proc.c
51528 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
51529 static int __init pci_proc_init(void)
51530 {
51531 struct pci_dev *dev = NULL;
51532 +
51533 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51534 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51535 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
51536 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51537 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51538 +#endif
51539 +#else
51540 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
51541 +#endif
51542 proc_create("devices", 0, proc_bus_pci_dir,
51543 &proc_bus_pci_dev_operations);
51544 proc_initialized = 1;
51545 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
51546 index 7f1a2e2..bc4b405 100644
51547 --- a/drivers/platform/chrome/chromeos_laptop.c
51548 +++ b/drivers/platform/chrome/chromeos_laptop.c
51549 @@ -395,7 +395,7 @@ static struct chromeos_laptop cr48 = {
51550 .callback = chromeos_laptop_dmi_matched, \
51551 .driver_data = (void *)&board_
51552
51553 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
51554 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
51555 {
51556 .ident = "Samsung Series 5 550",
51557 .matches = {
51558 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
51559 index 297b664..ab91e39 100644
51560 --- a/drivers/platform/x86/alienware-wmi.c
51561 +++ b/drivers/platform/x86/alienware-wmi.c
51562 @@ -133,7 +133,7 @@ struct wmax_led_args {
51563 } __packed;
51564
51565 static struct platform_device *platform_device;
51566 -static struct device_attribute *zone_dev_attrs;
51567 +static device_attribute_no_const *zone_dev_attrs;
51568 static struct attribute **zone_attrs;
51569 static struct platform_zone *zone_data;
51570
51571 @@ -144,7 +144,7 @@ static struct platform_driver platform_driver = {
51572 }
51573 };
51574
51575 -static struct attribute_group zone_attribute_group = {
51576 +static attribute_group_no_const zone_attribute_group = {
51577 .name = "rgb_zones",
51578 };
51579
51580 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
51581 index 3c6cced..12e0771 100644
51582 --- a/drivers/platform/x86/asus-wmi.c
51583 +++ b/drivers/platform/x86/asus-wmi.c
51584 @@ -1592,6 +1592,10 @@ static int show_dsts(struct seq_file *m, void *data)
51585 int err;
51586 u32 retval = -1;
51587
51588 +#ifdef CONFIG_GRKERNSEC_KMEM
51589 + return -EPERM;
51590 +#endif
51591 +
51592 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
51593
51594 if (err < 0)
51595 @@ -1608,6 +1612,10 @@ static int show_devs(struct seq_file *m, void *data)
51596 int err;
51597 u32 retval = -1;
51598
51599 +#ifdef CONFIG_GRKERNSEC_KMEM
51600 + return -EPERM;
51601 +#endif
51602 +
51603 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
51604 &retval);
51605
51606 @@ -1632,6 +1640,10 @@ static int show_call(struct seq_file *m, void *data)
51607 union acpi_object *obj;
51608 acpi_status status;
51609
51610 +#ifdef CONFIG_GRKERNSEC_KMEM
51611 + return -EPERM;
51612 +#endif
51613 +
51614 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
51615 1, asus->debug.method_id,
51616 &input, &output);
51617 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
51618 index 62f8030..c7f2a45 100644
51619 --- a/drivers/platform/x86/msi-laptop.c
51620 +++ b/drivers/platform/x86/msi-laptop.c
51621 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
51622
51623 if (!quirks->ec_read_only) {
51624 /* allow userland write sysfs file */
51625 - dev_attr_bluetooth.store = store_bluetooth;
51626 - dev_attr_wlan.store = store_wlan;
51627 - dev_attr_threeg.store = store_threeg;
51628 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
51629 - dev_attr_wlan.attr.mode |= S_IWUSR;
51630 - dev_attr_threeg.attr.mode |= S_IWUSR;
51631 + pax_open_kernel();
51632 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
51633 + *(void **)&dev_attr_wlan.store = store_wlan;
51634 + *(void **)&dev_attr_threeg.store = store_threeg;
51635 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
51636 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
51637 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
51638 + pax_close_kernel();
51639 }
51640
51641 /* disable hardware control by fn key */
51642 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
51643 index 70222f2..8c8ce66 100644
51644 --- a/drivers/platform/x86/msi-wmi.c
51645 +++ b/drivers/platform/x86/msi-wmi.c
51646 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
51647 static void msi_wmi_notify(u32 value, void *context)
51648 {
51649 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
51650 - static struct key_entry *key;
51651 + struct key_entry *key;
51652 union acpi_object *obj;
51653 acpi_status status;
51654
51655 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
51656 index 9c5a074..06c976a 100644
51657 --- a/drivers/platform/x86/sony-laptop.c
51658 +++ b/drivers/platform/x86/sony-laptop.c
51659 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
51660 }
51661
51662 /* High speed charging function */
51663 -static struct device_attribute *hsc_handle;
51664 +static device_attribute_no_const *hsc_handle;
51665
51666 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
51667 struct device_attribute *attr,
51668 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
51669 }
51670
51671 /* low battery function */
51672 -static struct device_attribute *lowbatt_handle;
51673 +static device_attribute_no_const *lowbatt_handle;
51674
51675 static ssize_t sony_nc_lowbatt_store(struct device *dev,
51676 struct device_attribute *attr,
51677 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
51678 }
51679
51680 /* fan speed function */
51681 -static struct device_attribute *fan_handle, *hsf_handle;
51682 +static device_attribute_no_const *fan_handle, *hsf_handle;
51683
51684 static ssize_t sony_nc_hsfan_store(struct device *dev,
51685 struct device_attribute *attr,
51686 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
51687 }
51688
51689 /* USB charge function */
51690 -static struct device_attribute *uc_handle;
51691 +static device_attribute_no_const *uc_handle;
51692
51693 static ssize_t sony_nc_usb_charge_store(struct device *dev,
51694 struct device_attribute *attr,
51695 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
51696 }
51697
51698 /* Panel ID function */
51699 -static struct device_attribute *panel_handle;
51700 +static device_attribute_no_const *panel_handle;
51701
51702 static ssize_t sony_nc_panelid_show(struct device *dev,
51703 struct device_attribute *attr, char *buffer)
51704 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
51705 }
51706
51707 /* smart connect function */
51708 -static struct device_attribute *sc_handle;
51709 +static device_attribute_no_const *sc_handle;
51710
51711 static ssize_t sony_nc_smart_conn_store(struct device *dev,
51712 struct device_attribute *attr,
51713 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
51714 index d82f196..5458f34 100644
51715 --- a/drivers/platform/x86/thinkpad_acpi.c
51716 +++ b/drivers/platform/x86/thinkpad_acpi.c
51717 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
51718 return 0;
51719 }
51720
51721 -void static hotkey_mask_warn_incomplete_mask(void)
51722 +static void hotkey_mask_warn_incomplete_mask(void)
51723 {
51724 /* log only what the user can fix... */
51725 const u32 wantedmask = hotkey_driver_mask &
51726 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
51727 && !tp_features.bright_unkfw)
51728 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
51729 }
51730 +}
51731
51732 #undef TPACPI_COMPARE_KEY
51733 #undef TPACPI_MAY_SEND_KEY
51734 -}
51735
51736 /*
51737 * Polling driver
51738 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
51739 index 438d4c7..ca8a2fb 100644
51740 --- a/drivers/pnp/pnpbios/bioscalls.c
51741 +++ b/drivers/pnp/pnpbios/bioscalls.c
51742 @@ -59,7 +59,7 @@ do { \
51743 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
51744 } while(0)
51745
51746 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
51747 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
51748 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
51749
51750 /*
51751 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51752
51753 cpu = get_cpu();
51754 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
51755 +
51756 + pax_open_kernel();
51757 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
51758 + pax_close_kernel();
51759
51760 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
51761 spin_lock_irqsave(&pnp_bios_lock, flags);
51762 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
51763 :"memory");
51764 spin_unlock_irqrestore(&pnp_bios_lock, flags);
51765
51766 + pax_open_kernel();
51767 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
51768 + pax_close_kernel();
51769 +
51770 put_cpu();
51771
51772 /* If we get here and this is set then the PnP BIOS faulted on us. */
51773 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
51774 return status;
51775 }
51776
51777 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
51778 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
51779 {
51780 int i;
51781
51782 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51783 pnp_bios_callpoint.offset = header->fields.pm16offset;
51784 pnp_bios_callpoint.segment = PNP_CS16;
51785
51786 + pax_open_kernel();
51787 +
51788 for_each_possible_cpu(i) {
51789 struct desc_struct *gdt = get_cpu_gdt_table(i);
51790 if (!gdt)
51791 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
51792 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
51793 (unsigned long)__va(header->fields.pm16dseg));
51794 }
51795 +
51796 + pax_close_kernel();
51797 }
51798 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
51799 index 0c52e2a..3421ab7 100644
51800 --- a/drivers/power/pda_power.c
51801 +++ b/drivers/power/pda_power.c
51802 @@ -37,7 +37,11 @@ static int polling;
51803
51804 #if IS_ENABLED(CONFIG_USB_PHY)
51805 static struct usb_phy *transceiver;
51806 -static struct notifier_block otg_nb;
51807 +static int otg_handle_notification(struct notifier_block *nb,
51808 + unsigned long event, void *unused);
51809 +static struct notifier_block otg_nb = {
51810 + .notifier_call = otg_handle_notification
51811 +};
51812 #endif
51813
51814 static struct regulator *ac_draw;
51815 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
51816
51817 #if IS_ENABLED(CONFIG_USB_PHY)
51818 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
51819 - otg_nb.notifier_call = otg_handle_notification;
51820 ret = usb_register_notifier(transceiver, &otg_nb);
51821 if (ret) {
51822 dev_err(dev, "failure to register otg notifier\n");
51823 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
51824 index cc439fd..8fa30df 100644
51825 --- a/drivers/power/power_supply.h
51826 +++ b/drivers/power/power_supply.h
51827 @@ -16,12 +16,12 @@ struct power_supply;
51828
51829 #ifdef CONFIG_SYSFS
51830
51831 -extern void power_supply_init_attrs(struct device_type *dev_type);
51832 +extern void power_supply_init_attrs(void);
51833 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
51834
51835 #else
51836
51837 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
51838 +static inline void power_supply_init_attrs(void) {}
51839 #define power_supply_uevent NULL
51840
51841 #endif /* CONFIG_SYSFS */
51842 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
51843 index 5a5a24e..f7a3754 100644
51844 --- a/drivers/power/power_supply_core.c
51845 +++ b/drivers/power/power_supply_core.c
51846 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
51847 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
51848 EXPORT_SYMBOL_GPL(power_supply_notifier);
51849
51850 -static struct device_type power_supply_dev_type;
51851 +extern const struct attribute_group *power_supply_attr_groups[];
51852 +static struct device_type power_supply_dev_type = {
51853 + .groups = power_supply_attr_groups,
51854 +};
51855
51856 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51857 struct power_supply *supply)
51858 @@ -639,7 +642,7 @@ static int __init power_supply_class_init(void)
51859 return PTR_ERR(power_supply_class);
51860
51861 power_supply_class->dev_uevent = power_supply_uevent;
51862 - power_supply_init_attrs(&power_supply_dev_type);
51863 + power_supply_init_attrs();
51864
51865 return 0;
51866 }
51867 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51868 index 44420d1..967126e 100644
51869 --- a/drivers/power/power_supply_sysfs.c
51870 +++ b/drivers/power/power_supply_sysfs.c
51871 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
51872 .is_visible = power_supply_attr_is_visible,
51873 };
51874
51875 -static const struct attribute_group *power_supply_attr_groups[] = {
51876 +const struct attribute_group *power_supply_attr_groups[] = {
51877 &power_supply_attr_group,
51878 NULL,
51879 };
51880
51881 -void power_supply_init_attrs(struct device_type *dev_type)
51882 +void power_supply_init_attrs(void)
51883 {
51884 int i;
51885
51886 - dev_type->groups = power_supply_attr_groups;
51887 -
51888 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51889 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51890 }
51891 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51892 index 84419af..268ede8 100644
51893 --- a/drivers/powercap/powercap_sys.c
51894 +++ b/drivers/powercap/powercap_sys.c
51895 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51896 struct device_attribute name_attr;
51897 };
51898
51899 +static ssize_t show_constraint_name(struct device *dev,
51900 + struct device_attribute *dev_attr,
51901 + char *buf);
51902 +
51903 static struct powercap_constraint_attr
51904 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51905 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51906 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51907 + .power_limit_attr = {
51908 + .attr = {
51909 + .name = NULL,
51910 + .mode = S_IWUSR | S_IRUGO
51911 + },
51912 + .show = show_constraint_power_limit_uw,
51913 + .store = store_constraint_power_limit_uw
51914 + },
51915 +
51916 + .time_window_attr = {
51917 + .attr = {
51918 + .name = NULL,
51919 + .mode = S_IWUSR | S_IRUGO
51920 + },
51921 + .show = show_constraint_time_window_us,
51922 + .store = store_constraint_time_window_us
51923 + },
51924 +
51925 + .max_power_attr = {
51926 + .attr = {
51927 + .name = NULL,
51928 + .mode = S_IRUGO
51929 + },
51930 + .show = show_constraint_max_power_uw,
51931 + .store = NULL
51932 + },
51933 +
51934 + .min_power_attr = {
51935 + .attr = {
51936 + .name = NULL,
51937 + .mode = S_IRUGO
51938 + },
51939 + .show = show_constraint_min_power_uw,
51940 + .store = NULL
51941 + },
51942 +
51943 + .max_time_window_attr = {
51944 + .attr = {
51945 + .name = NULL,
51946 + .mode = S_IRUGO
51947 + },
51948 + .show = show_constraint_max_time_window_us,
51949 + .store = NULL
51950 + },
51951 +
51952 + .min_time_window_attr = {
51953 + .attr = {
51954 + .name = NULL,
51955 + .mode = S_IRUGO
51956 + },
51957 + .show = show_constraint_min_time_window_us,
51958 + .store = NULL
51959 + },
51960 +
51961 + .name_attr = {
51962 + .attr = {
51963 + .name = NULL,
51964 + .mode = S_IRUGO
51965 + },
51966 + .show = show_constraint_name,
51967 + .store = NULL
51968 + }
51969 + }
51970 +};
51971
51972 /* A list of powercap control_types */
51973 static LIST_HEAD(powercap_cntrl_list);
51974 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51975 }
51976
51977 static int create_constraint_attribute(int id, const char *name,
51978 - int mode,
51979 - struct device_attribute *dev_attr,
51980 - ssize_t (*show)(struct device *,
51981 - struct device_attribute *, char *),
51982 - ssize_t (*store)(struct device *,
51983 - struct device_attribute *,
51984 - const char *, size_t)
51985 - )
51986 + struct device_attribute *dev_attr)
51987 {
51988 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51989
51990 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51991 - id, name);
51992 - if (!dev_attr->attr.name)
51993 + if (!name)
51994 return -ENOMEM;
51995 - dev_attr->attr.mode = mode;
51996 - dev_attr->show = show;
51997 - dev_attr->store = store;
51998 +
51999 + pax_open_kernel();
52000 + *(const char **)&dev_attr->attr.name = name;
52001 + pax_close_kernel();
52002
52003 return 0;
52004 }
52005 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
52006
52007 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
52008 ret = create_constraint_attribute(i, "power_limit_uw",
52009 - S_IWUSR | S_IRUGO,
52010 - &constraint_attrs[i].power_limit_attr,
52011 - show_constraint_power_limit_uw,
52012 - store_constraint_power_limit_uw);
52013 + &constraint_attrs[i].power_limit_attr);
52014 if (ret)
52015 goto err_alloc;
52016 ret = create_constraint_attribute(i, "time_window_us",
52017 - S_IWUSR | S_IRUGO,
52018 - &constraint_attrs[i].time_window_attr,
52019 - show_constraint_time_window_us,
52020 - store_constraint_time_window_us);
52021 + &constraint_attrs[i].time_window_attr);
52022 if (ret)
52023 goto err_alloc;
52024 - ret = create_constraint_attribute(i, "name", S_IRUGO,
52025 - &constraint_attrs[i].name_attr,
52026 - show_constraint_name,
52027 - NULL);
52028 + ret = create_constraint_attribute(i, "name",
52029 + &constraint_attrs[i].name_attr);
52030 if (ret)
52031 goto err_alloc;
52032 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
52033 - &constraint_attrs[i].max_power_attr,
52034 - show_constraint_max_power_uw,
52035 - NULL);
52036 + ret = create_constraint_attribute(i, "max_power_uw",
52037 + &constraint_attrs[i].max_power_attr);
52038 if (ret)
52039 goto err_alloc;
52040 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
52041 - &constraint_attrs[i].min_power_attr,
52042 - show_constraint_min_power_uw,
52043 - NULL);
52044 + ret = create_constraint_attribute(i, "min_power_uw",
52045 + &constraint_attrs[i].min_power_attr);
52046 if (ret)
52047 goto err_alloc;
52048 ret = create_constraint_attribute(i, "max_time_window_us",
52049 - S_IRUGO,
52050 - &constraint_attrs[i].max_time_window_attr,
52051 - show_constraint_max_time_window_us,
52052 - NULL);
52053 + &constraint_attrs[i].max_time_window_attr);
52054 if (ret)
52055 goto err_alloc;
52056 ret = create_constraint_attribute(i, "min_time_window_us",
52057 - S_IRUGO,
52058 - &constraint_attrs[i].min_time_window_attr,
52059 - show_constraint_min_time_window_us,
52060 - NULL);
52061 + &constraint_attrs[i].min_time_window_attr);
52062 if (ret)
52063 goto err_alloc;
52064
52065 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
52066 power_zone->zone_dev_attrs[count++] =
52067 &dev_attr_max_energy_range_uj.attr;
52068 if (power_zone->ops->get_energy_uj) {
52069 + pax_open_kernel();
52070 if (power_zone->ops->reset_energy_uj)
52071 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
52072 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
52073 else
52074 - dev_attr_energy_uj.attr.mode = S_IRUGO;
52075 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
52076 + pax_close_kernel();
52077 power_zone->zone_dev_attrs[count++] =
52078 &dev_attr_energy_uj.attr;
52079 }
52080 diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig
52081 index ee3de34..bec7285 100644
52082 --- a/drivers/ptp/Kconfig
52083 +++ b/drivers/ptp/Kconfig
52084 @@ -8,7 +8,6 @@ config PTP_1588_CLOCK
52085 tristate "PTP clock support"
52086 depends on NET
52087 select PPS
52088 - select NET_PTP_CLASSIFY
52089 help
52090 The IEEE 1588 standard defines a method to precisely
52091 synchronize distributed clocks over Ethernet networks. The
52092 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
52093 index 9c5d414..c7900ce 100644
52094 --- a/drivers/ptp/ptp_private.h
52095 +++ b/drivers/ptp/ptp_private.h
52096 @@ -51,7 +51,7 @@ struct ptp_clock {
52097 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
52098 wait_queue_head_t tsev_wq;
52099 int defunct; /* tells readers to go away when clock is being removed */
52100 - struct device_attribute *pin_dev_attr;
52101 + device_attribute_no_const *pin_dev_attr;
52102 struct attribute **pin_attr;
52103 struct attribute_group pin_attr_group;
52104 };
52105 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
52106 index 302e626..12579af 100644
52107 --- a/drivers/ptp/ptp_sysfs.c
52108 +++ b/drivers/ptp/ptp_sysfs.c
52109 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
52110 goto no_pin_attr;
52111
52112 for (i = 0; i < n_pins; i++) {
52113 - struct device_attribute *da = &ptp->pin_dev_attr[i];
52114 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
52115 sysfs_attr_init(&da->attr);
52116 da->attr.name = info->pin_config[i].name;
52117 da->attr.mode = 0644;
52118 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
52119 index 4c1f999..11078c9 100644
52120 --- a/drivers/regulator/core.c
52121 +++ b/drivers/regulator/core.c
52122 @@ -3391,7 +3391,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
52123 {
52124 const struct regulation_constraints *constraints = NULL;
52125 const struct regulator_init_data *init_data;
52126 - static atomic_t regulator_no = ATOMIC_INIT(0);
52127 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
52128 struct regulator_dev *rdev;
52129 struct device *dev;
52130 int ret, i;
52131 @@ -3461,7 +3461,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
52132 rdev->dev.of_node = of_node_get(config->of_node);
52133 rdev->dev.parent = dev;
52134 dev_set_name(&rdev->dev, "regulator.%d",
52135 - atomic_inc_return(&regulator_no) - 1);
52136 + atomic_inc_return_unchecked(&regulator_no) - 1);
52137 ret = device_register(&rdev->dev);
52138 if (ret != 0) {
52139 put_device(&rdev->dev);
52140 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
52141 index 2fc4111..6aa88ca 100644
52142 --- a/drivers/regulator/max8660.c
52143 +++ b/drivers/regulator/max8660.c
52144 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
52145 max8660->shadow_regs[MAX8660_OVER1] = 5;
52146 } else {
52147 /* Otherwise devices can be toggled via software */
52148 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
52149 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
52150 + pax_open_kernel();
52151 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
52152 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
52153 + pax_close_kernel();
52154 }
52155
52156 /*
52157 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
52158 index dbedf17..18ff6b7 100644
52159 --- a/drivers/regulator/max8973-regulator.c
52160 +++ b/drivers/regulator/max8973-regulator.c
52161 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
52162 if (!pdata || !pdata->enable_ext_control) {
52163 max->desc.enable_reg = MAX8973_VOUT;
52164 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
52165 - max->ops.enable = regulator_enable_regmap;
52166 - max->ops.disable = regulator_disable_regmap;
52167 - max->ops.is_enabled = regulator_is_enabled_regmap;
52168 + pax_open_kernel();
52169 + *(void **)&max->ops.enable = regulator_enable_regmap;
52170 + *(void **)&max->ops.disable = regulator_disable_regmap;
52171 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
52172 + pax_close_kernel();
52173 }
52174
52175 if (pdata) {
52176 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
52177 index f374fa5..26f0683 100644
52178 --- a/drivers/regulator/mc13892-regulator.c
52179 +++ b/drivers/regulator/mc13892-regulator.c
52180 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
52181 }
52182 mc13xxx_unlock(mc13892);
52183
52184 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
52185 + pax_open_kernel();
52186 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
52187 = mc13892_vcam_set_mode;
52188 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
52189 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
52190 = mc13892_vcam_get_mode;
52191 + pax_close_kernel();
52192
52193 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
52194 ARRAY_SIZE(mc13892_regulators));
52195 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
52196 index b0e4a3e..e5dc11e 100644
52197 --- a/drivers/rtc/rtc-cmos.c
52198 +++ b/drivers/rtc/rtc-cmos.c
52199 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
52200 hpet_rtc_timer_init();
52201
52202 /* export at least the first block of NVRAM */
52203 - nvram.size = address_space - NVRAM_OFFSET;
52204 + pax_open_kernel();
52205 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
52206 + pax_close_kernel();
52207 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
52208 if (retval < 0) {
52209 dev_dbg(dev, "can't create nvram file? %d\n", retval);
52210 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
52211 index d049393..bb20be0 100644
52212 --- a/drivers/rtc/rtc-dev.c
52213 +++ b/drivers/rtc/rtc-dev.c
52214 @@ -16,6 +16,7 @@
52215 #include <linux/module.h>
52216 #include <linux/rtc.h>
52217 #include <linux/sched.h>
52218 +#include <linux/grsecurity.h>
52219 #include "rtc-core.h"
52220
52221 static dev_t rtc_devt;
52222 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
52223 if (copy_from_user(&tm, uarg, sizeof(tm)))
52224 return -EFAULT;
52225
52226 + gr_log_timechange();
52227 +
52228 return rtc_set_time(rtc, &tm);
52229
52230 case RTC_PIE_ON:
52231 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
52232 index f03d5ba..8325bf6 100644
52233 --- a/drivers/rtc/rtc-ds1307.c
52234 +++ b/drivers/rtc/rtc-ds1307.c
52235 @@ -107,7 +107,7 @@ struct ds1307 {
52236 u8 offset; /* register's offset */
52237 u8 regs[11];
52238 u16 nvram_offset;
52239 - struct bin_attribute *nvram;
52240 + bin_attribute_no_const *nvram;
52241 enum ds_type type;
52242 unsigned long flags;
52243 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
52244 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
52245 index 11880c1..b823aa4 100644
52246 --- a/drivers/rtc/rtc-m48t59.c
52247 +++ b/drivers/rtc/rtc-m48t59.c
52248 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
52249 if (IS_ERR(m48t59->rtc))
52250 return PTR_ERR(m48t59->rtc);
52251
52252 - m48t59_nvram_attr.size = pdata->offset;
52253 + pax_open_kernel();
52254 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
52255 + pax_close_kernel();
52256
52257 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
52258 if (ret)
52259 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
52260 index e693af6..2e525b6 100644
52261 --- a/drivers/scsi/bfa/bfa_fcpim.h
52262 +++ b/drivers/scsi/bfa/bfa_fcpim.h
52263 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
52264
52265 struct bfa_itn_s {
52266 bfa_isr_func_t isr;
52267 -};
52268 +} __no_const;
52269
52270 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
52271 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
52272 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
52273 index a3ab5cc..8143622 100644
52274 --- a/drivers/scsi/bfa/bfa_fcs.c
52275 +++ b/drivers/scsi/bfa/bfa_fcs.c
52276 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
52277 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
52278
52279 static struct bfa_fcs_mod_s fcs_modules[] = {
52280 - { bfa_fcs_port_attach, NULL, NULL },
52281 - { bfa_fcs_uf_attach, NULL, NULL },
52282 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
52283 - bfa_fcs_fabric_modexit },
52284 + {
52285 + .attach = bfa_fcs_port_attach,
52286 + .modinit = NULL,
52287 + .modexit = NULL
52288 + },
52289 + {
52290 + .attach = bfa_fcs_uf_attach,
52291 + .modinit = NULL,
52292 + .modexit = NULL
52293 + },
52294 + {
52295 + .attach = bfa_fcs_fabric_attach,
52296 + .modinit = bfa_fcs_fabric_modinit,
52297 + .modexit = bfa_fcs_fabric_modexit
52298 + },
52299 };
52300
52301 /*
52302 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
52303 index ff75ef8..2dfe00a 100644
52304 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
52305 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
52306 @@ -89,15 +89,26 @@ static struct {
52307 void (*offline) (struct bfa_fcs_lport_s *port);
52308 } __port_action[] = {
52309 {
52310 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
52311 - bfa_fcs_lport_unknown_offline}, {
52312 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
52313 - bfa_fcs_lport_fab_offline}, {
52314 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
52315 - bfa_fcs_lport_n2n_offline}, {
52316 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
52317 - bfa_fcs_lport_loop_offline},
52318 - };
52319 + .init = bfa_fcs_lport_unknown_init,
52320 + .online = bfa_fcs_lport_unknown_online,
52321 + .offline = bfa_fcs_lport_unknown_offline
52322 + },
52323 + {
52324 + .init = bfa_fcs_lport_fab_init,
52325 + .online = bfa_fcs_lport_fab_online,
52326 + .offline = bfa_fcs_lport_fab_offline
52327 + },
52328 + {
52329 + .init = bfa_fcs_lport_n2n_init,
52330 + .online = bfa_fcs_lport_n2n_online,
52331 + .offline = bfa_fcs_lport_n2n_offline
52332 + },
52333 + {
52334 + .init = bfa_fcs_lport_loop_init,
52335 + .online = bfa_fcs_lport_loop_online,
52336 + .offline = bfa_fcs_lport_loop_offline
52337 + },
52338 +};
52339
52340 /*
52341 * fcs_port_sm FCS logical port state machine
52342 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
52343 index 2e28392..9d865b6 100644
52344 --- a/drivers/scsi/bfa/bfa_ioc.h
52345 +++ b/drivers/scsi/bfa/bfa_ioc.h
52346 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
52347 bfa_ioc_disable_cbfn_t disable_cbfn;
52348 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
52349 bfa_ioc_reset_cbfn_t reset_cbfn;
52350 -};
52351 +} __no_const;
52352
52353 /*
52354 * IOC event notification mechanism.
52355 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
52356 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
52357 enum bfi_ioc_state fwstate);
52358 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
52359 -};
52360 +} __no_const;
52361
52362 /*
52363 * Queue element to wait for room in request queue. FIFO order is
52364 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
52365 index a14c784..6de6790 100644
52366 --- a/drivers/scsi/bfa/bfa_modules.h
52367 +++ b/drivers/scsi/bfa/bfa_modules.h
52368 @@ -78,12 +78,12 @@ enum {
52369 \
52370 extern struct bfa_module_s hal_mod_ ## __mod; \
52371 struct bfa_module_s hal_mod_ ## __mod = { \
52372 - bfa_ ## __mod ## _meminfo, \
52373 - bfa_ ## __mod ## _attach, \
52374 - bfa_ ## __mod ## _detach, \
52375 - bfa_ ## __mod ## _start, \
52376 - bfa_ ## __mod ## _stop, \
52377 - bfa_ ## __mod ## _iocdisable, \
52378 + .meminfo = bfa_ ## __mod ## _meminfo, \
52379 + .attach = bfa_ ## __mod ## _attach, \
52380 + .detach = bfa_ ## __mod ## _detach, \
52381 + .start = bfa_ ## __mod ## _start, \
52382 + .stop = bfa_ ## __mod ## _stop, \
52383 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
52384 }
52385
52386 #define BFA_CACHELINE_SZ (256)
52387 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
52388 index 045c4e1..13de803 100644
52389 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
52390 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
52391 @@ -33,8 +33,8 @@
52392 */
52393 #include "libfcoe.h"
52394
52395 -static atomic_t ctlr_num;
52396 -static atomic_t fcf_num;
52397 +static atomic_unchecked_t ctlr_num;
52398 +static atomic_unchecked_t fcf_num;
52399
52400 /*
52401 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
52402 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
52403 if (!ctlr)
52404 goto out;
52405
52406 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
52407 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
52408 ctlr->f = f;
52409 ctlr->mode = FIP_CONN_TYPE_FABRIC;
52410 INIT_LIST_HEAD(&ctlr->fcfs);
52411 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
52412 fcf->dev.parent = &ctlr->dev;
52413 fcf->dev.bus = &fcoe_bus_type;
52414 fcf->dev.type = &fcoe_fcf_device_type;
52415 - fcf->id = atomic_inc_return(&fcf_num) - 1;
52416 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
52417 fcf->state = FCOE_FCF_STATE_UNKNOWN;
52418
52419 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
52420 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
52421 {
52422 int error;
52423
52424 - atomic_set(&ctlr_num, 0);
52425 - atomic_set(&fcf_num, 0);
52426 + atomic_set_unchecked(&ctlr_num, 0);
52427 + atomic_set_unchecked(&fcf_num, 0);
52428
52429 error = bus_register(&fcoe_bus_type);
52430 if (error)
52431 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
52432 index 3cbb57a..95e47a3 100644
52433 --- a/drivers/scsi/hosts.c
52434 +++ b/drivers/scsi/hosts.c
52435 @@ -42,7 +42,7 @@
52436 #include "scsi_logging.h"
52437
52438
52439 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52440 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
52441
52442
52443 static void scsi_host_cls_release(struct device *dev)
52444 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
52445 * subtract one because we increment first then return, but we need to
52446 * know what the next host number was before increment
52447 */
52448 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
52449 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
52450 shost->dma_channel = 0xff;
52451
52452 /* These three are default values which can be overridden */
52453 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
52454 index 489e83b..193815b 100644
52455 --- a/drivers/scsi/hpsa.c
52456 +++ b/drivers/scsi/hpsa.c
52457 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
52458 unsigned long flags;
52459
52460 if (h->transMethod & CFGTBL_Trans_io_accel1)
52461 - return h->access.command_completed(h, q);
52462 + return h->access->command_completed(h, q);
52463
52464 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
52465 - return h->access.command_completed(h, q);
52466 + return h->access->command_completed(h, q);
52467
52468 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
52469 a = rq->head[rq->current_entry];
52470 @@ -5455,7 +5455,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52471 while (!list_empty(&h->reqQ)) {
52472 c = list_entry(h->reqQ.next, struct CommandList, list);
52473 /* can't do anything if fifo is full */
52474 - if ((h->access.fifo_full(h))) {
52475 + if ((h->access->fifo_full(h))) {
52476 h->fifo_recently_full = 1;
52477 dev_warn(&h->pdev->dev, "fifo full\n");
52478 break;
52479 @@ -5477,7 +5477,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
52480
52481 /* Tell the controller execute command */
52482 spin_unlock_irqrestore(&h->lock, *flags);
52483 - h->access.submit_command(h, c);
52484 + h->access->submit_command(h, c);
52485 spin_lock_irqsave(&h->lock, *flags);
52486 }
52487 }
52488 @@ -5493,17 +5493,17 @@ static void lock_and_start_io(struct ctlr_info *h)
52489
52490 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
52491 {
52492 - return h->access.command_completed(h, q);
52493 + return h->access->command_completed(h, q);
52494 }
52495
52496 static inline bool interrupt_pending(struct ctlr_info *h)
52497 {
52498 - return h->access.intr_pending(h);
52499 + return h->access->intr_pending(h);
52500 }
52501
52502 static inline long interrupt_not_for_us(struct ctlr_info *h)
52503 {
52504 - return (h->access.intr_pending(h) == 0) ||
52505 + return (h->access->intr_pending(h) == 0) ||
52506 (h->interrupts_enabled == 0);
52507 }
52508
52509 @@ -6459,7 +6459,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
52510 if (prod_index < 0)
52511 return -ENODEV;
52512 h->product_name = products[prod_index].product_name;
52513 - h->access = *(products[prod_index].access);
52514 + h->access = products[prod_index].access;
52515
52516 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
52517 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
52518 @@ -6781,7 +6781,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
52519 unsigned long flags;
52520 u32 lockup_detected;
52521
52522 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52523 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52524 spin_lock_irqsave(&h->lock, flags);
52525 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
52526 if (!lockup_detected) {
52527 @@ -7022,7 +7022,7 @@ reinit_after_soft_reset:
52528 }
52529
52530 /* make sure the board interrupts are off */
52531 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52532 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52533
52534 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
52535 goto clean2;
52536 @@ -7057,7 +7057,7 @@ reinit_after_soft_reset:
52537 * fake ones to scoop up any residual completions.
52538 */
52539 spin_lock_irqsave(&h->lock, flags);
52540 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52541 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52542 spin_unlock_irqrestore(&h->lock, flags);
52543 free_irqs(h);
52544 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
52545 @@ -7076,9 +7076,9 @@ reinit_after_soft_reset:
52546 dev_info(&h->pdev->dev, "Board READY.\n");
52547 dev_info(&h->pdev->dev,
52548 "Waiting for stale completions to drain.\n");
52549 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52550 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52551 msleep(10000);
52552 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52553 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52554
52555 rc = controller_reset_failed(h->cfgtable);
52556 if (rc)
52557 @@ -7104,7 +7104,7 @@ reinit_after_soft_reset:
52558 h->drv_req_rescan = 0;
52559
52560 /* Turn the interrupts on so we can service requests */
52561 - h->access.set_intr_mask(h, HPSA_INTR_ON);
52562 + h->access->set_intr_mask(h, HPSA_INTR_ON);
52563
52564 hpsa_hba_inquiry(h);
52565 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
52566 @@ -7169,7 +7169,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
52567 * To write all data in the battery backed cache to disks
52568 */
52569 hpsa_flush_cache(h);
52570 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
52571 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
52572 hpsa_free_irqs_and_disable_msix(h);
52573 }
52574
52575 @@ -7287,7 +7287,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52576 CFGTBL_Trans_enable_directed_msix |
52577 (trans_support & (CFGTBL_Trans_io_accel1 |
52578 CFGTBL_Trans_io_accel2));
52579 - struct access_method access = SA5_performant_access;
52580 + struct access_method *access = &SA5_performant_access;
52581
52582 /* This is a bit complicated. There are 8 registers on
52583 * the controller which we write to to tell it 8 different
52584 @@ -7329,7 +7329,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52585 * perform the superfluous readl() after each command submission.
52586 */
52587 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
52588 - access = SA5_performant_access_no_read;
52589 + access = &SA5_performant_access_no_read;
52590
52591 /* Controller spec: zero out this buffer. */
52592 for (i = 0; i < h->nreply_queues; i++)
52593 @@ -7359,12 +7359,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
52594 * enable outbound interrupt coalescing in accelerator mode;
52595 */
52596 if (trans_support & CFGTBL_Trans_io_accel1) {
52597 - access = SA5_ioaccel_mode1_access;
52598 + access = &SA5_ioaccel_mode1_access;
52599 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52600 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52601 } else {
52602 if (trans_support & CFGTBL_Trans_io_accel2) {
52603 - access = SA5_ioaccel_mode2_access;
52604 + access = &SA5_ioaccel_mode2_access;
52605 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
52606 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
52607 }
52608 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
52609 index 24472ce..8782caf 100644
52610 --- a/drivers/scsi/hpsa.h
52611 +++ b/drivers/scsi/hpsa.h
52612 @@ -127,7 +127,7 @@ struct ctlr_info {
52613 unsigned int msix_vector;
52614 unsigned int msi_vector;
52615 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
52616 - struct access_method access;
52617 + struct access_method *access;
52618 char hba_mode_enabled;
52619
52620 /* queue and queue Info */
52621 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
52622 }
52623
52624 static struct access_method SA5_access = {
52625 - SA5_submit_command,
52626 - SA5_intr_mask,
52627 - SA5_fifo_full,
52628 - SA5_intr_pending,
52629 - SA5_completed,
52630 + .submit_command = SA5_submit_command,
52631 + .set_intr_mask = SA5_intr_mask,
52632 + .fifo_full = SA5_fifo_full,
52633 + .intr_pending = SA5_intr_pending,
52634 + .command_completed = SA5_completed,
52635 };
52636
52637 static struct access_method SA5_ioaccel_mode1_access = {
52638 - SA5_submit_command,
52639 - SA5_performant_intr_mask,
52640 - SA5_fifo_full,
52641 - SA5_ioaccel_mode1_intr_pending,
52642 - SA5_ioaccel_mode1_completed,
52643 + .submit_command = SA5_submit_command,
52644 + .set_intr_mask = SA5_performant_intr_mask,
52645 + .fifo_full = SA5_fifo_full,
52646 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
52647 + .command_completed = SA5_ioaccel_mode1_completed,
52648 };
52649
52650 static struct access_method SA5_ioaccel_mode2_access = {
52651 - SA5_submit_command_ioaccel2,
52652 - SA5_performant_intr_mask,
52653 - SA5_fifo_full,
52654 - SA5_performant_intr_pending,
52655 - SA5_performant_completed,
52656 + .submit_command = SA5_submit_command_ioaccel2,
52657 + .set_intr_mask = SA5_performant_intr_mask,
52658 + .fifo_full = SA5_fifo_full,
52659 + .intr_pending = SA5_performant_intr_pending,
52660 + .command_completed = SA5_performant_completed,
52661 };
52662
52663 static struct access_method SA5_performant_access = {
52664 - SA5_submit_command,
52665 - SA5_performant_intr_mask,
52666 - SA5_fifo_full,
52667 - SA5_performant_intr_pending,
52668 - SA5_performant_completed,
52669 + .submit_command = SA5_submit_command,
52670 + .set_intr_mask = SA5_performant_intr_mask,
52671 + .fifo_full = SA5_fifo_full,
52672 + .intr_pending = SA5_performant_intr_pending,
52673 + .command_completed = SA5_performant_completed,
52674 };
52675
52676 static struct access_method SA5_performant_access_no_read = {
52677 - SA5_submit_command_no_read,
52678 - SA5_performant_intr_mask,
52679 - SA5_fifo_full,
52680 - SA5_performant_intr_pending,
52681 - SA5_performant_completed,
52682 + .submit_command = SA5_submit_command_no_read,
52683 + .set_intr_mask = SA5_performant_intr_mask,
52684 + .fifo_full = SA5_fifo_full,
52685 + .intr_pending = SA5_performant_intr_pending,
52686 + .command_completed = SA5_performant_completed,
52687 };
52688
52689 struct board_type {
52690 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
52691 index 1b3a094..068e683 100644
52692 --- a/drivers/scsi/libfc/fc_exch.c
52693 +++ b/drivers/scsi/libfc/fc_exch.c
52694 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
52695 u16 pool_max_index;
52696
52697 struct {
52698 - atomic_t no_free_exch;
52699 - atomic_t no_free_exch_xid;
52700 - atomic_t xid_not_found;
52701 - atomic_t xid_busy;
52702 - atomic_t seq_not_found;
52703 - atomic_t non_bls_resp;
52704 + atomic_unchecked_t no_free_exch;
52705 + atomic_unchecked_t no_free_exch_xid;
52706 + atomic_unchecked_t xid_not_found;
52707 + atomic_unchecked_t xid_busy;
52708 + atomic_unchecked_t seq_not_found;
52709 + atomic_unchecked_t non_bls_resp;
52710 } stats;
52711 };
52712
52713 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
52714 /* allocate memory for exchange */
52715 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
52716 if (!ep) {
52717 - atomic_inc(&mp->stats.no_free_exch);
52718 + atomic_inc_unchecked(&mp->stats.no_free_exch);
52719 goto out;
52720 }
52721 memset(ep, 0, sizeof(*ep));
52722 @@ -874,7 +874,7 @@ out:
52723 return ep;
52724 err:
52725 spin_unlock_bh(&pool->lock);
52726 - atomic_inc(&mp->stats.no_free_exch_xid);
52727 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
52728 mempool_free(ep, mp->ep_pool);
52729 return NULL;
52730 }
52731 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52732 xid = ntohs(fh->fh_ox_id); /* we originated exch */
52733 ep = fc_exch_find(mp, xid);
52734 if (!ep) {
52735 - atomic_inc(&mp->stats.xid_not_found);
52736 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52737 reject = FC_RJT_OX_ID;
52738 goto out;
52739 }
52740 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52741 ep = fc_exch_find(mp, xid);
52742 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
52743 if (ep) {
52744 - atomic_inc(&mp->stats.xid_busy);
52745 + atomic_inc_unchecked(&mp->stats.xid_busy);
52746 reject = FC_RJT_RX_ID;
52747 goto rel;
52748 }
52749 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52750 }
52751 xid = ep->xid; /* get our XID */
52752 } else if (!ep) {
52753 - atomic_inc(&mp->stats.xid_not_found);
52754 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52755 reject = FC_RJT_RX_ID; /* XID not found */
52756 goto out;
52757 }
52758 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
52759 } else {
52760 sp = &ep->seq;
52761 if (sp->id != fh->fh_seq_id) {
52762 - atomic_inc(&mp->stats.seq_not_found);
52763 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52764 if (f_ctl & FC_FC_END_SEQ) {
52765 /*
52766 * Update sequence_id based on incoming last
52767 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52768
52769 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
52770 if (!ep) {
52771 - atomic_inc(&mp->stats.xid_not_found);
52772 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52773 goto out;
52774 }
52775 if (ep->esb_stat & ESB_ST_COMPLETE) {
52776 - atomic_inc(&mp->stats.xid_not_found);
52777 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52778 goto rel;
52779 }
52780 if (ep->rxid == FC_XID_UNKNOWN)
52781 ep->rxid = ntohs(fh->fh_rx_id);
52782 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
52783 - atomic_inc(&mp->stats.xid_not_found);
52784 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52785 goto rel;
52786 }
52787 if (ep->did != ntoh24(fh->fh_s_id) &&
52788 ep->did != FC_FID_FLOGI) {
52789 - atomic_inc(&mp->stats.xid_not_found);
52790 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52791 goto rel;
52792 }
52793 sof = fr_sof(fp);
52794 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52795 sp->ssb_stat |= SSB_ST_RESP;
52796 sp->id = fh->fh_seq_id;
52797 } else if (sp->id != fh->fh_seq_id) {
52798 - atomic_inc(&mp->stats.seq_not_found);
52799 + atomic_inc_unchecked(&mp->stats.seq_not_found);
52800 goto rel;
52801 }
52802
52803 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
52804 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
52805
52806 if (!sp)
52807 - atomic_inc(&mp->stats.xid_not_found);
52808 + atomic_inc_unchecked(&mp->stats.xid_not_found);
52809 else
52810 - atomic_inc(&mp->stats.non_bls_resp);
52811 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
52812
52813 fc_frame_free(fp);
52814 }
52815 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
52816
52817 list_for_each_entry(ema, &lport->ema_list, ema_list) {
52818 mp = ema->mp;
52819 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
52820 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
52821 st->fc_no_free_exch_xid +=
52822 - atomic_read(&mp->stats.no_free_exch_xid);
52823 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
52824 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
52825 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
52826 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
52827 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
52828 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
52829 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
52830 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
52831 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
52832 }
52833 }
52834 EXPORT_SYMBOL(fc_exch_update_stats);
52835 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
52836 index 766098a..1c6c971 100644
52837 --- a/drivers/scsi/libsas/sas_ata.c
52838 +++ b/drivers/scsi/libsas/sas_ata.c
52839 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
52840 .postreset = ata_std_postreset,
52841 .error_handler = ata_std_error_handler,
52842 .post_internal_cmd = sas_ata_post_internal,
52843 - .qc_defer = ata_std_qc_defer,
52844 + .qc_defer = ata_std_qc_defer,
52845 .qc_prep = ata_noop_qc_prep,
52846 .qc_issue = sas_ata_qc_issue,
52847 .qc_fill_rtf = sas_ata_qc_fill_rtf,
52848 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
52849 index 434e903..5a4a79b 100644
52850 --- a/drivers/scsi/lpfc/lpfc.h
52851 +++ b/drivers/scsi/lpfc/lpfc.h
52852 @@ -430,7 +430,7 @@ struct lpfc_vport {
52853 struct dentry *debug_nodelist;
52854 struct dentry *vport_debugfs_root;
52855 struct lpfc_debugfs_trc *disc_trc;
52856 - atomic_t disc_trc_cnt;
52857 + atomic_unchecked_t disc_trc_cnt;
52858 #endif
52859 uint8_t stat_data_enabled;
52860 uint8_t stat_data_blocked;
52861 @@ -880,8 +880,8 @@ struct lpfc_hba {
52862 struct timer_list fabric_block_timer;
52863 unsigned long bit_flags;
52864 #define FABRIC_COMANDS_BLOCKED 0
52865 - atomic_t num_rsrc_err;
52866 - atomic_t num_cmd_success;
52867 + atomic_unchecked_t num_rsrc_err;
52868 + atomic_unchecked_t num_cmd_success;
52869 unsigned long last_rsrc_error_time;
52870 unsigned long last_ramp_down_time;
52871 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52872 @@ -916,7 +916,7 @@ struct lpfc_hba {
52873
52874 struct dentry *debug_slow_ring_trc;
52875 struct lpfc_debugfs_trc *slow_ring_trc;
52876 - atomic_t slow_ring_trc_cnt;
52877 + atomic_unchecked_t slow_ring_trc_cnt;
52878 /* iDiag debugfs sub-directory */
52879 struct dentry *idiag_root;
52880 struct dentry *idiag_pci_cfg;
52881 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52882 index b0aedce..89c6ca6 100644
52883 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
52884 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52885 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52886
52887 #include <linux/debugfs.h>
52888
52889 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52890 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52891 static unsigned long lpfc_debugfs_start_time = 0L;
52892
52893 /* iDiag */
52894 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52895 lpfc_debugfs_enable = 0;
52896
52897 len = 0;
52898 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52899 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52900 (lpfc_debugfs_max_disc_trc - 1);
52901 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52902 dtp = vport->disc_trc + i;
52903 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52904 lpfc_debugfs_enable = 0;
52905
52906 len = 0;
52907 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52908 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52909 (lpfc_debugfs_max_slow_ring_trc - 1);
52910 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52911 dtp = phba->slow_ring_trc + i;
52912 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52913 !vport || !vport->disc_trc)
52914 return;
52915
52916 - index = atomic_inc_return(&vport->disc_trc_cnt) &
52917 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52918 (lpfc_debugfs_max_disc_trc - 1);
52919 dtp = vport->disc_trc + index;
52920 dtp->fmt = fmt;
52921 dtp->data1 = data1;
52922 dtp->data2 = data2;
52923 dtp->data3 = data3;
52924 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52925 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52926 dtp->jif = jiffies;
52927 #endif
52928 return;
52929 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52930 !phba || !phba->slow_ring_trc)
52931 return;
52932
52933 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52934 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52935 (lpfc_debugfs_max_slow_ring_trc - 1);
52936 dtp = phba->slow_ring_trc + index;
52937 dtp->fmt = fmt;
52938 dtp->data1 = data1;
52939 dtp->data2 = data2;
52940 dtp->data3 = data3;
52941 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52942 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52943 dtp->jif = jiffies;
52944 #endif
52945 return;
52946 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52947 "slow_ring buffer\n");
52948 goto debug_failed;
52949 }
52950 - atomic_set(&phba->slow_ring_trc_cnt, 0);
52951 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52952 memset(phba->slow_ring_trc, 0,
52953 (sizeof(struct lpfc_debugfs_trc) *
52954 lpfc_debugfs_max_slow_ring_trc));
52955 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52956 "buffer\n");
52957 goto debug_failed;
52958 }
52959 - atomic_set(&vport->disc_trc_cnt, 0);
52960 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52961
52962 snprintf(name, sizeof(name), "discovery_trace");
52963 vport->debug_disc_trc =
52964 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52965 index 06f9a5b..82812092 100644
52966 --- a/drivers/scsi/lpfc/lpfc_init.c
52967 +++ b/drivers/scsi/lpfc/lpfc_init.c
52968 @@ -11296,8 +11296,10 @@ lpfc_init(void)
52969 "misc_register returned with status %d", error);
52970
52971 if (lpfc_enable_npiv) {
52972 - lpfc_transport_functions.vport_create = lpfc_vport_create;
52973 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52974 + pax_open_kernel();
52975 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52976 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52977 + pax_close_kernel();
52978 }
52979 lpfc_transport_template =
52980 fc_attach_transport(&lpfc_transport_functions);
52981 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52982 index 2df11da..e660a2c 100644
52983 --- a/drivers/scsi/lpfc/lpfc_scsi.c
52984 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
52985 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52986 uint32_t evt_posted;
52987
52988 spin_lock_irqsave(&phba->hbalock, flags);
52989 - atomic_inc(&phba->num_rsrc_err);
52990 + atomic_inc_unchecked(&phba->num_rsrc_err);
52991 phba->last_rsrc_error_time = jiffies;
52992
52993 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52994 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52995 unsigned long num_rsrc_err, num_cmd_success;
52996 int i;
52997
52998 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52999 - num_cmd_success = atomic_read(&phba->num_cmd_success);
53000 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
53001 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
53002
53003 /*
53004 * The error and success command counters are global per
53005 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
53006 }
53007 }
53008 lpfc_destroy_vport_work_array(phba, vports);
53009 - atomic_set(&phba->num_rsrc_err, 0);
53010 - atomic_set(&phba->num_cmd_success, 0);
53011 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
53012 + atomic_set_unchecked(&phba->num_cmd_success, 0);
53013 }
53014
53015 /**
53016 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
53017 index 5055f92..376cd98 100644
53018 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
53019 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
53020 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
53021 {
53022 struct scsi_device *sdev = to_scsi_device(dev);
53023 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
53024 - static struct _raid_device *raid_device;
53025 + struct _raid_device *raid_device;
53026 unsigned long flags;
53027 Mpi2RaidVolPage0_t vol_pg0;
53028 Mpi2ConfigReply_t mpi_reply;
53029 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
53030 {
53031 struct scsi_device *sdev = to_scsi_device(dev);
53032 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
53033 - static struct _raid_device *raid_device;
53034 + struct _raid_device *raid_device;
53035 unsigned long flags;
53036 Mpi2RaidVolPage0_t vol_pg0;
53037 Mpi2ConfigReply_t mpi_reply;
53038 @@ -6631,7 +6631,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
53039 struct fw_event_work *fw_event)
53040 {
53041 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
53042 - static struct _raid_device *raid_device;
53043 + struct _raid_device *raid_device;
53044 unsigned long flags;
53045 u16 handle;
53046
53047 @@ -7102,7 +7102,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
53048 u64 sas_address;
53049 struct _sas_device *sas_device;
53050 struct _sas_node *expander_device;
53051 - static struct _raid_device *raid_device;
53052 + struct _raid_device *raid_device;
53053 u8 retry_count;
53054 unsigned long flags;
53055
53056 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
53057 index be8ce54..94ed33a 100644
53058 --- a/drivers/scsi/pmcraid.c
53059 +++ b/drivers/scsi/pmcraid.c
53060 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
53061 res->scsi_dev = scsi_dev;
53062 scsi_dev->hostdata = res;
53063 res->change_detected = 0;
53064 - atomic_set(&res->read_failures, 0);
53065 - atomic_set(&res->write_failures, 0);
53066 + atomic_set_unchecked(&res->read_failures, 0);
53067 + atomic_set_unchecked(&res->write_failures, 0);
53068 rc = 0;
53069 }
53070 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
53071 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
53072
53073 /* If this was a SCSI read/write command keep count of errors */
53074 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
53075 - atomic_inc(&res->read_failures);
53076 + atomic_inc_unchecked(&res->read_failures);
53077 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
53078 - atomic_inc(&res->write_failures);
53079 + atomic_inc_unchecked(&res->write_failures);
53080
53081 if (!RES_IS_GSCSI(res->cfg_entry) &&
53082 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
53083 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
53084 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
53085 * hrrq_id assigned here in queuecommand
53086 */
53087 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
53088 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
53089 pinstance->num_hrrq;
53090 cmd->cmd_done = pmcraid_io_done;
53091
53092 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
53093 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
53094 * hrrq_id assigned here in queuecommand
53095 */
53096 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
53097 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
53098 pinstance->num_hrrq;
53099
53100 if (request_size) {
53101 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
53102
53103 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
53104 /* add resources only after host is added into system */
53105 - if (!atomic_read(&pinstance->expose_resources))
53106 + if (!atomic_read_unchecked(&pinstance->expose_resources))
53107 return;
53108
53109 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
53110 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
53111 init_waitqueue_head(&pinstance->reset_wait_q);
53112
53113 atomic_set(&pinstance->outstanding_cmds, 0);
53114 - atomic_set(&pinstance->last_message_id, 0);
53115 - atomic_set(&pinstance->expose_resources, 0);
53116 + atomic_set_unchecked(&pinstance->last_message_id, 0);
53117 + atomic_set_unchecked(&pinstance->expose_resources, 0);
53118
53119 INIT_LIST_HEAD(&pinstance->free_res_q);
53120 INIT_LIST_HEAD(&pinstance->used_res_q);
53121 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
53122 /* Schedule worker thread to handle CCN and take care of adding and
53123 * removing devices to OS
53124 */
53125 - atomic_set(&pinstance->expose_resources, 1);
53126 + atomic_set_unchecked(&pinstance->expose_resources, 1);
53127 schedule_work(&pinstance->worker_q);
53128 return rc;
53129
53130 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
53131 index e1d150f..6c6df44 100644
53132 --- a/drivers/scsi/pmcraid.h
53133 +++ b/drivers/scsi/pmcraid.h
53134 @@ -748,7 +748,7 @@ struct pmcraid_instance {
53135 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
53136
53137 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
53138 - atomic_t last_message_id;
53139 + atomic_unchecked_t last_message_id;
53140
53141 /* configuration table */
53142 struct pmcraid_config_table *cfg_table;
53143 @@ -777,7 +777,7 @@ struct pmcraid_instance {
53144 atomic_t outstanding_cmds;
53145
53146 /* should add/delete resources to mid-layer now ?*/
53147 - atomic_t expose_resources;
53148 + atomic_unchecked_t expose_resources;
53149
53150
53151
53152 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
53153 struct pmcraid_config_table_entry_ext cfg_entry_ext;
53154 };
53155 struct scsi_device *scsi_dev; /* Link scsi_device structure */
53156 - atomic_t read_failures; /* count of failed READ commands */
53157 - atomic_t write_failures; /* count of failed WRITE commands */
53158 + atomic_unchecked_t read_failures; /* count of failed READ commands */
53159 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
53160
53161 /* To indicate add/delete/modify during CCN */
53162 u8 change_detected;
53163 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
53164 index 16fe519..3b1ec82 100644
53165 --- a/drivers/scsi/qla2xxx/qla_attr.c
53166 +++ b/drivers/scsi/qla2xxx/qla_attr.c
53167 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
53168 return 0;
53169 }
53170
53171 -struct fc_function_template qla2xxx_transport_functions = {
53172 +fc_function_template_no_const qla2xxx_transport_functions = {
53173
53174 .show_host_node_name = 1,
53175 .show_host_port_name = 1,
53176 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
53177 .bsg_timeout = qla24xx_bsg_timeout,
53178 };
53179
53180 -struct fc_function_template qla2xxx_transport_vport_functions = {
53181 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
53182
53183 .show_host_node_name = 1,
53184 .show_host_port_name = 1,
53185 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
53186 index d48dea8..0845f78 100644
53187 --- a/drivers/scsi/qla2xxx/qla_gbl.h
53188 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
53189 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
53190 struct device_attribute;
53191 extern struct device_attribute *qla2x00_host_attrs[];
53192 struct fc_function_template;
53193 -extern struct fc_function_template qla2xxx_transport_functions;
53194 -extern struct fc_function_template qla2xxx_transport_vport_functions;
53195 +extern fc_function_template_no_const qla2xxx_transport_functions;
53196 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
53197 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
53198 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
53199 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
53200 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
53201 index d96bfb5..d7afe90 100644
53202 --- a/drivers/scsi/qla2xxx/qla_os.c
53203 +++ b/drivers/scsi/qla2xxx/qla_os.c
53204 @@ -1490,8 +1490,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
53205 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
53206 /* Ok, a 64bit DMA mask is applicable. */
53207 ha->flags.enable_64bit_addressing = 1;
53208 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
53209 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
53210 + pax_open_kernel();
53211 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
53212 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
53213 + pax_close_kernel();
53214 return;
53215 }
53216 }
53217 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
53218 index 8f6d0fb..1b21097 100644
53219 --- a/drivers/scsi/qla4xxx/ql4_def.h
53220 +++ b/drivers/scsi/qla4xxx/ql4_def.h
53221 @@ -305,7 +305,7 @@ struct ddb_entry {
53222 * (4000 only) */
53223 atomic_t relogin_timer; /* Max Time to wait for
53224 * relogin to complete */
53225 - atomic_t relogin_retry_count; /* Num of times relogin has been
53226 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
53227 * retried */
53228 uint32_t default_time2wait; /* Default Min time between
53229 * relogins (+aens) */
53230 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
53231 index 3202063..f9f0ff6 100644
53232 --- a/drivers/scsi/qla4xxx/ql4_os.c
53233 +++ b/drivers/scsi/qla4xxx/ql4_os.c
53234 @@ -4494,12 +4494,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
53235 */
53236 if (!iscsi_is_session_online(cls_sess)) {
53237 /* Reset retry relogin timer */
53238 - atomic_inc(&ddb_entry->relogin_retry_count);
53239 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
53240 DEBUG2(ql4_printk(KERN_INFO, ha,
53241 "%s: index[%d] relogin timed out-retrying"
53242 " relogin (%d), retry (%d)\n", __func__,
53243 ddb_entry->fw_ddb_index,
53244 - atomic_read(&ddb_entry->relogin_retry_count),
53245 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
53246 ddb_entry->default_time2wait + 4));
53247 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
53248 atomic_set(&ddb_entry->retry_relogin_timer,
53249 @@ -6607,7 +6607,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
53250
53251 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
53252 atomic_set(&ddb_entry->relogin_timer, 0);
53253 - atomic_set(&ddb_entry->relogin_retry_count, 0);
53254 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
53255 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
53256 ddb_entry->default_relogin_timeout =
53257 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
53258 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
53259 index 88d46fe..7351be5 100644
53260 --- a/drivers/scsi/scsi.c
53261 +++ b/drivers/scsi/scsi.c
53262 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
53263 struct Scsi_Host *host = cmd->device->host;
53264 int rtn = 0;
53265
53266 - atomic_inc(&cmd->device->iorequest_cnt);
53267 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
53268
53269 /* check if the device is still usable */
53270 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
53271 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
53272 index 3f50dfc..86af487 100644
53273 --- a/drivers/scsi/scsi_lib.c
53274 +++ b/drivers/scsi/scsi_lib.c
53275 @@ -1423,7 +1423,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
53276 shost = sdev->host;
53277 scsi_init_cmd_errh(cmd);
53278 cmd->result = DID_NO_CONNECT << 16;
53279 - atomic_inc(&cmd->device->iorequest_cnt);
53280 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
53281
53282 /*
53283 * SCSI request completion path will do scsi_device_unbusy(),
53284 @@ -1449,9 +1449,9 @@ static void scsi_softirq_done(struct request *rq)
53285
53286 INIT_LIST_HEAD(&cmd->eh_entry);
53287
53288 - atomic_inc(&cmd->device->iodone_cnt);
53289 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
53290 if (cmd->result)
53291 - atomic_inc(&cmd->device->ioerr_cnt);
53292 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
53293
53294 disposition = scsi_decide_disposition(cmd);
53295 if (disposition != SUCCESS &&
53296 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
53297 index 074e8cc..f612e5c 100644
53298 --- a/drivers/scsi/scsi_sysfs.c
53299 +++ b/drivers/scsi/scsi_sysfs.c
53300 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
53301 char *buf) \
53302 { \
53303 struct scsi_device *sdev = to_scsi_device(dev); \
53304 - unsigned long long count = atomic_read(&sdev->field); \
53305 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
53306 return snprintf(buf, 20, "0x%llx\n", count); \
53307 } \
53308 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
53309 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
53310 index e51add0..1e06a96 100644
53311 --- a/drivers/scsi/scsi_tgt_lib.c
53312 +++ b/drivers/scsi/scsi_tgt_lib.c
53313 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
53314 int err;
53315
53316 dprintk("%lx %u\n", uaddr, len);
53317 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
53318 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
53319 if (err) {
53320 /*
53321 * TODO: need to fixup sg_tablesize, max_segment_size,
53322 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
53323 index 521f583..6b15966 100644
53324 --- a/drivers/scsi/scsi_transport_fc.c
53325 +++ b/drivers/scsi/scsi_transport_fc.c
53326 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
53327 * Netlink Infrastructure
53328 */
53329
53330 -static atomic_t fc_event_seq;
53331 +static atomic_unchecked_t fc_event_seq;
53332
53333 /**
53334 * fc_get_event_number - Obtain the next sequential FC event number
53335 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
53336 u32
53337 fc_get_event_number(void)
53338 {
53339 - return atomic_add_return(1, &fc_event_seq);
53340 + return atomic_add_return_unchecked(1, &fc_event_seq);
53341 }
53342 EXPORT_SYMBOL(fc_get_event_number);
53343
53344 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
53345 {
53346 int error;
53347
53348 - atomic_set(&fc_event_seq, 0);
53349 + atomic_set_unchecked(&fc_event_seq, 0);
53350
53351 error = transport_class_register(&fc_host_class);
53352 if (error)
53353 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
53354 char *cp;
53355
53356 *val = simple_strtoul(buf, &cp, 0);
53357 - if ((*cp && (*cp != '\n')) || (*val < 0))
53358 + if (*cp && (*cp != '\n'))
53359 return -EINVAL;
53360 /*
53361 * Check for overflow; dev_loss_tmo is u32
53362 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
53363 index 0102a2d..cc3f8e9 100644
53364 --- a/drivers/scsi/scsi_transport_iscsi.c
53365 +++ b/drivers/scsi/scsi_transport_iscsi.c
53366 @@ -79,7 +79,7 @@ struct iscsi_internal {
53367 struct transport_container session_cont;
53368 };
53369
53370 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
53371 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
53372 static struct workqueue_struct *iscsi_eh_timer_workq;
53373
53374 static DEFINE_IDA(iscsi_sess_ida);
53375 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
53376 int err;
53377
53378 ihost = shost->shost_data;
53379 - session->sid = atomic_add_return(1, &iscsi_session_nr);
53380 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
53381
53382 if (target_id == ISCSI_MAX_TARGET) {
53383 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
53384 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
53385 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
53386 ISCSI_TRANSPORT_VERSION);
53387
53388 - atomic_set(&iscsi_session_nr, 0);
53389 + atomic_set_unchecked(&iscsi_session_nr, 0);
53390
53391 err = class_register(&iscsi_transport_class);
53392 if (err)
53393 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
53394 index 13e8983..d306a68 100644
53395 --- a/drivers/scsi/scsi_transport_srp.c
53396 +++ b/drivers/scsi/scsi_transport_srp.c
53397 @@ -36,7 +36,7 @@
53398 #include "scsi_transport_srp_internal.h"
53399
53400 struct srp_host_attrs {
53401 - atomic_t next_port_id;
53402 + atomic_unchecked_t next_port_id;
53403 };
53404 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
53405
53406 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
53407 struct Scsi_Host *shost = dev_to_shost(dev);
53408 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
53409
53410 - atomic_set(&srp_host->next_port_id, 0);
53411 + atomic_set_unchecked(&srp_host->next_port_id, 0);
53412 return 0;
53413 }
53414
53415 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
53416 rport_fast_io_fail_timedout);
53417 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
53418
53419 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
53420 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
53421 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
53422
53423 transport_setup_device(&rport->dev);
53424 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
53425 index 6825eda..be470c4 100644
53426 --- a/drivers/scsi/sd.c
53427 +++ b/drivers/scsi/sd.c
53428 @@ -2954,7 +2954,7 @@ static int sd_probe(struct device *dev)
53429 sdkp->disk = gd;
53430 sdkp->index = index;
53431 atomic_set(&sdkp->openers, 0);
53432 - atomic_set(&sdkp->device->ioerr_cnt, 0);
53433 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
53434
53435 if (!sdp->request_queue->rq_timeout) {
53436 if (sdp->type != TYPE_MOD)
53437 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
53438 index 53268aab..17c2764 100644
53439 --- a/drivers/scsi/sg.c
53440 +++ b/drivers/scsi/sg.c
53441 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
53442 sdp->disk->disk_name,
53443 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
53444 NULL,
53445 - (char *)arg);
53446 + (char __user *)arg);
53447 case BLKTRACESTART:
53448 return blk_trace_startstop(sdp->device->request_queue, 1);
53449 case BLKTRACESTOP:
53450 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
53451 index d4f9670..d37b662 100644
53452 --- a/drivers/spi/spi.c
53453 +++ b/drivers/spi/spi.c
53454 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
53455 EXPORT_SYMBOL_GPL(spi_bus_unlock);
53456
53457 /* portable code must never pass more than 32 bytes */
53458 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
53459 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
53460
53461 static u8 *buf;
53462
53463 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
53464 index c341ac1..bf9799f 100644
53465 --- a/drivers/staging/android/timed_output.c
53466 +++ b/drivers/staging/android/timed_output.c
53467 @@ -25,7 +25,7 @@
53468 #include "timed_output.h"
53469
53470 static struct class *timed_output_class;
53471 -static atomic_t device_count;
53472 +static atomic_unchecked_t device_count;
53473
53474 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
53475 char *buf)
53476 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
53477 timed_output_class = class_create(THIS_MODULE, "timed_output");
53478 if (IS_ERR(timed_output_class))
53479 return PTR_ERR(timed_output_class);
53480 - atomic_set(&device_count, 0);
53481 + atomic_set_unchecked(&device_count, 0);
53482 timed_output_class->dev_groups = timed_output_groups;
53483 }
53484
53485 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
53486 if (ret < 0)
53487 return ret;
53488
53489 - tdev->index = atomic_inc_return(&device_count);
53490 + tdev->index = atomic_inc_return_unchecked(&device_count);
53491 tdev->dev = device_create(timed_output_class, NULL,
53492 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
53493 if (IS_ERR(tdev->dev))
53494 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
53495 index fe47cd3..19a1bd1 100644
53496 --- a/drivers/staging/gdm724x/gdm_tty.c
53497 +++ b/drivers/staging/gdm724x/gdm_tty.c
53498 @@ -44,7 +44,7 @@
53499 #define gdm_tty_send_control(n, r, v, d, l) (\
53500 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
53501
53502 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
53503 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
53504
53505 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
53506 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
53507 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
53508 index def8280..e3fd96a 100644
53509 --- a/drivers/staging/imx-drm/imx-drm-core.c
53510 +++ b/drivers/staging/imx-drm/imx-drm-core.c
53511 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
53512 if (imxdrm->pipes >= MAX_CRTC)
53513 return -EINVAL;
53514
53515 - if (imxdrm->drm->open_count)
53516 + if (local_read(&imxdrm->drm->open_count))
53517 return -EBUSY;
53518
53519 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
53520 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
53521 index 3f8020c..649fded 100644
53522 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
53523 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
53524 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
53525 return 0;
53526 }
53527
53528 -sfw_test_client_ops_t brw_test_client;
53529 -void brw_init_test_client(void)
53530 -{
53531 - brw_test_client.tso_init = brw_client_init;
53532 - brw_test_client.tso_fini = brw_client_fini;
53533 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
53534 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
53535 +sfw_test_client_ops_t brw_test_client = {
53536 + .tso_init = brw_client_init,
53537 + .tso_fini = brw_client_fini,
53538 + .tso_prep_rpc = brw_client_prep_rpc,
53539 + .tso_done_rpc = brw_client_done_rpc,
53540 };
53541
53542 srpc_service_t brw_test_service;
53543 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
53544 index 050723a..fa6fdf1 100644
53545 --- a/drivers/staging/lustre/lnet/selftest/framework.c
53546 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
53547 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
53548
53549 extern sfw_test_client_ops_t ping_test_client;
53550 extern srpc_service_t ping_test_service;
53551 -extern void ping_init_test_client(void);
53552 extern void ping_init_test_service(void);
53553
53554 extern sfw_test_client_ops_t brw_test_client;
53555 extern srpc_service_t brw_test_service;
53556 -extern void brw_init_test_client(void);
53557 extern void brw_init_test_service(void);
53558
53559
53560 @@ -1684,12 +1682,10 @@ sfw_startup (void)
53561 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
53562 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
53563
53564 - brw_init_test_client();
53565 brw_init_test_service();
53566 rc = sfw_register_test(&brw_test_service, &brw_test_client);
53567 LASSERT (rc == 0);
53568
53569 - ping_init_test_client();
53570 ping_init_test_service();
53571 rc = sfw_register_test(&ping_test_service, &ping_test_client);
53572 LASSERT (rc == 0);
53573 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
53574 index 750cac4..e4d751f 100644
53575 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
53576 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
53577 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
53578 return 0;
53579 }
53580
53581 -sfw_test_client_ops_t ping_test_client;
53582 -void ping_init_test_client(void)
53583 -{
53584 - ping_test_client.tso_init = ping_client_init;
53585 - ping_test_client.tso_fini = ping_client_fini;
53586 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
53587 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
53588 -}
53589 +sfw_test_client_ops_t ping_test_client = {
53590 + .tso_init = ping_client_init,
53591 + .tso_fini = ping_client_fini,
53592 + .tso_prep_rpc = ping_client_prep_rpc,
53593 + .tso_done_rpc = ping_client_done_rpc,
53594 +};
53595
53596 srpc_service_t ping_test_service;
53597 void ping_init_test_service(void)
53598 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53599 index 0c6b784..c64235c 100644
53600 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
53601 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
53602 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
53603 ldlm_completion_callback lcs_completion;
53604 ldlm_blocking_callback lcs_blocking;
53605 ldlm_glimpse_callback lcs_glimpse;
53606 -};
53607 +} __no_const;
53608
53609 /* ldlm_lockd.c */
53610 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
53611 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
53612 index d5c4613..a341678 100644
53613 --- a/drivers/staging/lustre/lustre/include/obd.h
53614 +++ b/drivers/staging/lustre/lustre/include/obd.h
53615 @@ -1439,7 +1439,7 @@ struct md_ops {
53616 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
53617 * wrapper function in include/linux/obd_class.h.
53618 */
53619 -};
53620 +} __no_const;
53621
53622 struct lsm_operations {
53623 void (*lsm_free)(struct lov_stripe_md *);
53624 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53625 index 986bf38..eab2558f 100644
53626 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53627 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
53628 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
53629 int added = (mode == LCK_NL);
53630 int overlaps = 0;
53631 int splitted = 0;
53632 - const struct ldlm_callback_suite null_cbs = { NULL };
53633 + const struct ldlm_callback_suite null_cbs = { };
53634
53635 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
53636 LPU64" end "LPU64"\n", *flags,
53637 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53638 index e947b91..f408990 100644
53639 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53640 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
53641 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
53642 int LL_PROC_PROTO(proc_console_max_delay_cs)
53643 {
53644 int rc, max_delay_cs;
53645 - ctl_table_t dummy = *table;
53646 + ctl_table_no_const dummy = *table;
53647 cfs_duration_t d;
53648
53649 dummy.data = &max_delay_cs;
53650 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
53651 int LL_PROC_PROTO(proc_console_min_delay_cs)
53652 {
53653 int rc, min_delay_cs;
53654 - ctl_table_t dummy = *table;
53655 + ctl_table_no_const dummy = *table;
53656 cfs_duration_t d;
53657
53658 dummy.data = &min_delay_cs;
53659 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
53660 int LL_PROC_PROTO(proc_console_backoff)
53661 {
53662 int rc, backoff;
53663 - ctl_table_t dummy = *table;
53664 + ctl_table_no_const dummy = *table;
53665
53666 dummy.data = &backoff;
53667 dummy.proc_handler = &proc_dointvec;
53668 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
53669 index b16ee08..a3db5c6 100644
53670 --- a/drivers/staging/lustre/lustre/libcfs/module.c
53671 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
53672 @@ -314,11 +314,11 @@ out:
53673
53674
53675 struct cfs_psdev_ops libcfs_psdev_ops = {
53676 - libcfs_psdev_open,
53677 - libcfs_psdev_release,
53678 - NULL,
53679 - NULL,
53680 - libcfs_ioctl
53681 + .p_open = libcfs_psdev_open,
53682 + .p_close = libcfs_psdev_release,
53683 + .p_read = NULL,
53684 + .p_write = NULL,
53685 + .p_ioctl = libcfs_ioctl
53686 };
53687
53688 extern int insert_proc(void);
53689 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
53690 index ae6f61a..03c3d5d 100644
53691 --- a/drivers/staging/lustre/lustre/llite/dir.c
53692 +++ b/drivers/staging/lustre/lustre/llite/dir.c
53693 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
53694 int mode;
53695 int err;
53696
53697 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
53698 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
53699 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
53700 strlen(filename), mode, LUSTRE_OPC_MKDIR,
53701 lump);
53702 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
53703 index f670469..03b7438 100644
53704 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
53705 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
53706 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
53707
53708 static int solo_sysfs_init(struct solo_dev *solo_dev)
53709 {
53710 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
53711 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
53712 struct device *dev = &solo_dev->dev;
53713 const char *driver;
53714 int i;
53715 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
53716 index 74f037b..5b5bb76 100644
53717 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
53718 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
53719 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
53720
53721 int solo_g723_init(struct solo_dev *solo_dev)
53722 {
53723 - static struct snd_device_ops ops = { NULL };
53724 + static struct snd_device_ops ops = { };
53725 struct snd_card *card;
53726 struct snd_kcontrol_new kctl;
53727 char name[32];
53728 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53729 index 7f2f247..d999137 100644
53730 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
53731 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
53732 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
53733
53734 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
53735 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
53736 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
53737 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
53738 if (p2m_id < 0)
53739 p2m_id = -p2m_id;
53740 }
53741 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
53742 index 8964f8b..36eb087 100644
53743 --- a/drivers/staging/media/solo6x10/solo6x10.h
53744 +++ b/drivers/staging/media/solo6x10/solo6x10.h
53745 @@ -237,7 +237,7 @@ struct solo_dev {
53746
53747 /* P2M DMA Engine */
53748 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
53749 - atomic_t p2m_count;
53750 + atomic_unchecked_t p2m_count;
53751 int p2m_jiffies;
53752 unsigned int p2m_timeouts;
53753
53754 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
53755 index a0f4868..139f1fb 100644
53756 --- a/drivers/staging/octeon/ethernet-rx.c
53757 +++ b/drivers/staging/octeon/ethernet-rx.c
53758 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53759 /* Increment RX stats for virtual ports */
53760 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
53761 #ifdef CONFIG_64BIT
53762 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
53763 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
53764 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
53765 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
53766 #else
53767 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
53768 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
53769 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
53770 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
53771 #endif
53772 }
53773 netif_receive_skb(skb);
53774 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
53775 dev->name);
53776 */
53777 #ifdef CONFIG_64BIT
53778 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
53779 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53780 #else
53781 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
53782 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
53783 #endif
53784 dev_kfree_skb_irq(skb);
53785 }
53786 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
53787 index da9dd6b..8e3e0f5 100644
53788 --- a/drivers/staging/octeon/ethernet.c
53789 +++ b/drivers/staging/octeon/ethernet.c
53790 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
53791 * since the RX tasklet also increments it.
53792 */
53793 #ifdef CONFIG_64BIT
53794 - atomic64_add(rx_status.dropped_packets,
53795 - (atomic64_t *)&priv->stats.rx_dropped);
53796 + atomic64_add_unchecked(rx_status.dropped_packets,
53797 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
53798 #else
53799 - atomic_add(rx_status.dropped_packets,
53800 - (atomic_t *)&priv->stats.rx_dropped);
53801 + atomic_add_unchecked(rx_status.dropped_packets,
53802 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
53803 #endif
53804 }
53805
53806 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
53807 index c59fccd..79f8fc2 100644
53808 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
53809 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
53810 @@ -267,7 +267,7 @@ struct hal_ops {
53811 s32 (*c2h_handler)(struct adapter *padapter,
53812 struct c2h_evt_hdr *c2h_evt);
53813 c2h_id_filter c2h_id_filter_ccx;
53814 -};
53815 +} __no_const;
53816
53817 enum rt_eeprom_type {
53818 EEPROM_93C46,
53819 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
53820 index e8790f8..b4a5980 100644
53821 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
53822 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
53823 @@ -124,7 +124,7 @@ struct _io_ops {
53824 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
53825 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
53826 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
53827 -};
53828 +} __no_const;
53829
53830 struct io_req {
53831 struct list_head list;
53832 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
53833 index dc23395..cf7e9b1 100644
53834 --- a/drivers/staging/rtl8712/rtl871x_io.h
53835 +++ b/drivers/staging/rtl8712/rtl871x_io.h
53836 @@ -108,7 +108,7 @@ struct _io_ops {
53837 u8 *pmem);
53838 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
53839 u8 *pmem);
53840 -};
53841 +} __no_const;
53842
53843 struct io_req {
53844 struct list_head list;
53845 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
53846 index a863a98..d272795 100644
53847 --- a/drivers/staging/usbip/vhci.h
53848 +++ b/drivers/staging/usbip/vhci.h
53849 @@ -83,7 +83,7 @@ struct vhci_hcd {
53850 unsigned resuming:1;
53851 unsigned long re_timeout;
53852
53853 - atomic_t seqnum;
53854 + atomic_unchecked_t seqnum;
53855
53856 /*
53857 * NOTE:
53858 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
53859 index 0007d30..c06a693 100644
53860 --- a/drivers/staging/usbip/vhci_hcd.c
53861 +++ b/drivers/staging/usbip/vhci_hcd.c
53862 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
53863
53864 spin_lock(&vdev->priv_lock);
53865
53866 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
53867 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53868 if (priv->seqnum == 0xffff)
53869 dev_info(&urb->dev->dev, "seqnum max\n");
53870
53871 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
53872 return -ENOMEM;
53873 }
53874
53875 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
53876 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
53877 if (unlink->seqnum == 0xffff)
53878 pr_info("seqnum max\n");
53879
53880 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
53881 vdev->rhport = rhport;
53882 }
53883
53884 - atomic_set(&vhci->seqnum, 0);
53885 + atomic_set_unchecked(&vhci->seqnum, 0);
53886 spin_lock_init(&vhci->lock);
53887
53888 hcd->power_budget = 0; /* no limit */
53889 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
53890 index d07fcb5..358e1e1 100644
53891 --- a/drivers/staging/usbip/vhci_rx.c
53892 +++ b/drivers/staging/usbip/vhci_rx.c
53893 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
53894 if (!urb) {
53895 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
53896 pr_info("max seqnum %d\n",
53897 - atomic_read(&the_controller->seqnum));
53898 + atomic_read_unchecked(&the_controller->seqnum));
53899 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
53900 return;
53901 }
53902 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
53903 index 317c2a8..ffeb4ef 100644
53904 --- a/drivers/staging/vt6655/hostap.c
53905 +++ b/drivers/staging/vt6655/hostap.c
53906 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
53907 *
53908 */
53909
53910 +static net_device_ops_no_const apdev_netdev_ops;
53911 +
53912 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53913 {
53914 PSDevice apdev_priv;
53915 struct net_device *dev = pDevice->dev;
53916 int ret;
53917 - const struct net_device_ops apdev_netdev_ops = {
53918 - .ndo_start_xmit = pDevice->tx_80211,
53919 - };
53920
53921 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53922
53923 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53924 *apdev_priv = *pDevice;
53925 eth_hw_addr_inherit(pDevice->apdev, dev);
53926
53927 + /* only half broken now */
53928 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53929 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53930
53931 pDevice->apdev->type = ARPHRD_IEEE80211;
53932 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53933 index e7e9372..161f530 100644
53934 --- a/drivers/target/sbp/sbp_target.c
53935 +++ b/drivers/target/sbp/sbp_target.c
53936 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53937
53938 #define SESSION_MAINTENANCE_INTERVAL HZ
53939
53940 -static atomic_t login_id = ATOMIC_INIT(0);
53941 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53942
53943 static void session_maintenance_work(struct work_struct *);
53944 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53945 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
53946 login->lun = se_lun;
53947 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53948 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53949 - login->login_id = atomic_inc_return(&login_id);
53950 + login->login_id = atomic_inc_return_unchecked(&login_id);
53951
53952 login->tgt_agt = sbp_target_agent_register(login);
53953 if (IS_ERR(login->tgt_agt)) {
53954 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53955 index 98da901..bb443e8 100644
53956 --- a/drivers/target/target_core_device.c
53957 +++ b/drivers/target/target_core_device.c
53958 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53959 spin_lock_init(&dev->se_tmr_lock);
53960 spin_lock_init(&dev->qf_cmd_lock);
53961 sema_init(&dev->caw_sem, 1);
53962 - atomic_set(&dev->dev_ordered_id, 0);
53963 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
53964 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53965 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53966 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53967 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53968 index 7fa62fc..abdd041 100644
53969 --- a/drivers/target/target_core_transport.c
53970 +++ b/drivers/target/target_core_transport.c
53971 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53972 * Used to determine when ORDERED commands should go from
53973 * Dormant to Active status.
53974 */
53975 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53976 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53977 smp_mb__after_atomic();
53978 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53979 cmd->se_ordered_id, cmd->sam_task_attr,
53980 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53981 index 4b2b999..cad9fa5 100644
53982 --- a/drivers/thermal/of-thermal.c
53983 +++ b/drivers/thermal/of-thermal.c
53984 @@ -30,6 +30,7 @@
53985 #include <linux/err.h>
53986 #include <linux/export.h>
53987 #include <linux/string.h>
53988 +#include <linux/mm.h>
53989
53990 #include "thermal_core.h"
53991
53992 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53993 tz->get_trend = get_trend;
53994 tz->sensor_data = data;
53995
53996 - tzd->ops->get_temp = of_thermal_get_temp;
53997 - tzd->ops->get_trend = of_thermal_get_trend;
53998 + pax_open_kernel();
53999 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
54000 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
54001 + pax_close_kernel();
54002 mutex_unlock(&tzd->lock);
54003
54004 return tzd;
54005 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
54006 return;
54007
54008 mutex_lock(&tzd->lock);
54009 - tzd->ops->get_temp = NULL;
54010 - tzd->ops->get_trend = NULL;
54011 + pax_open_kernel();
54012 + *(void **)&tzd->ops->get_temp = NULL;
54013 + *(void **)&tzd->ops->get_trend = NULL;
54014 + pax_close_kernel();
54015
54016 tz->get_temp = NULL;
54017 tz->get_trend = NULL;
54018 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
54019 index a57bb5a..1f727d33 100644
54020 --- a/drivers/tty/cyclades.c
54021 +++ b/drivers/tty/cyclades.c
54022 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
54023 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
54024 info->port.count);
54025 #endif
54026 - info->port.count++;
54027 + atomic_inc(&info->port.count);
54028 #ifdef CY_DEBUG_COUNT
54029 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
54030 - current->pid, info->port.count);
54031 + current->pid, atomic_read(&info->port.count));
54032 #endif
54033
54034 /*
54035 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
54036 for (j = 0; j < cy_card[i].nports; j++) {
54037 info = &cy_card[i].ports[j];
54038
54039 - if (info->port.count) {
54040 + if (atomic_read(&info->port.count)) {
54041 /* XXX is the ldisc num worth this? */
54042 struct tty_struct *tty;
54043 struct tty_ldisc *ld;
54044 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
54045 index 4fcec1d..5a036f7 100644
54046 --- a/drivers/tty/hvc/hvc_console.c
54047 +++ b/drivers/tty/hvc/hvc_console.c
54048 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
54049
54050 spin_lock_irqsave(&hp->port.lock, flags);
54051 /* Check and then increment for fast path open. */
54052 - if (hp->port.count++ > 0) {
54053 + if (atomic_inc_return(&hp->port.count) > 1) {
54054 spin_unlock_irqrestore(&hp->port.lock, flags);
54055 hvc_kick();
54056 return 0;
54057 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
54058
54059 spin_lock_irqsave(&hp->port.lock, flags);
54060
54061 - if (--hp->port.count == 0) {
54062 + if (atomic_dec_return(&hp->port.count) == 0) {
54063 spin_unlock_irqrestore(&hp->port.lock, flags);
54064 /* We are done with the tty pointer now. */
54065 tty_port_tty_set(&hp->port, NULL);
54066 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
54067 */
54068 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
54069 } else {
54070 - if (hp->port.count < 0)
54071 + if (atomic_read(&hp->port.count) < 0)
54072 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
54073 - hp->vtermno, hp->port.count);
54074 + hp->vtermno, atomic_read(&hp->port.count));
54075 spin_unlock_irqrestore(&hp->port.lock, flags);
54076 }
54077 }
54078 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
54079 * open->hangup case this can be called after the final close so prevent
54080 * that from happening for now.
54081 */
54082 - if (hp->port.count <= 0) {
54083 + if (atomic_read(&hp->port.count) <= 0) {
54084 spin_unlock_irqrestore(&hp->port.lock, flags);
54085 return;
54086 }
54087
54088 - hp->port.count = 0;
54089 + atomic_set(&hp->port.count, 0);
54090 spin_unlock_irqrestore(&hp->port.lock, flags);
54091 tty_port_tty_set(&hp->port, NULL);
54092
54093 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
54094 return -EPIPE;
54095
54096 /* FIXME what's this (unprotected) check for? */
54097 - if (hp->port.count <= 0)
54098 + if (atomic_read(&hp->port.count) <= 0)
54099 return -EIO;
54100
54101 spin_lock_irqsave(&hp->lock, flags);
54102 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
54103 index 81e939e..95ead10 100644
54104 --- a/drivers/tty/hvc/hvcs.c
54105 +++ b/drivers/tty/hvc/hvcs.c
54106 @@ -83,6 +83,7 @@
54107 #include <asm/hvcserver.h>
54108 #include <asm/uaccess.h>
54109 #include <asm/vio.h>
54110 +#include <asm/local.h>
54111
54112 /*
54113 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
54114 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
54115
54116 spin_lock_irqsave(&hvcsd->lock, flags);
54117
54118 - if (hvcsd->port.count > 0) {
54119 + if (atomic_read(&hvcsd->port.count) > 0) {
54120 spin_unlock_irqrestore(&hvcsd->lock, flags);
54121 printk(KERN_INFO "HVCS: vterm state unchanged. "
54122 "The hvcs device node is still in use.\n");
54123 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
54124 }
54125 }
54126
54127 - hvcsd->port.count = 0;
54128 + atomic_set(&hvcsd->port.count, 0);
54129 hvcsd->port.tty = tty;
54130 tty->driver_data = hvcsd;
54131
54132 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
54133 unsigned long flags;
54134
54135 spin_lock_irqsave(&hvcsd->lock, flags);
54136 - hvcsd->port.count++;
54137 + atomic_inc(&hvcsd->port.count);
54138 hvcsd->todo_mask |= HVCS_SCHED_READ;
54139 spin_unlock_irqrestore(&hvcsd->lock, flags);
54140
54141 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
54142 hvcsd = tty->driver_data;
54143
54144 spin_lock_irqsave(&hvcsd->lock, flags);
54145 - if (--hvcsd->port.count == 0) {
54146 + if (atomic_dec_and_test(&hvcsd->port.count)) {
54147
54148 vio_disable_interrupts(hvcsd->vdev);
54149
54150 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
54151
54152 free_irq(irq, hvcsd);
54153 return;
54154 - } else if (hvcsd->port.count < 0) {
54155 + } else if (atomic_read(&hvcsd->port.count) < 0) {
54156 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
54157 " is missmanaged.\n",
54158 - hvcsd->vdev->unit_address, hvcsd->port.count);
54159 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
54160 }
54161
54162 spin_unlock_irqrestore(&hvcsd->lock, flags);
54163 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
54164
54165 spin_lock_irqsave(&hvcsd->lock, flags);
54166 /* Preserve this so that we know how many kref refs to put */
54167 - temp_open_count = hvcsd->port.count;
54168 + temp_open_count = atomic_read(&hvcsd->port.count);
54169
54170 /*
54171 * Don't kref put inside the spinlock because the destruction
54172 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
54173 tty->driver_data = NULL;
54174 hvcsd->port.tty = NULL;
54175
54176 - hvcsd->port.count = 0;
54177 + atomic_set(&hvcsd->port.count, 0);
54178
54179 /* This will drop any buffered data on the floor which is OK in a hangup
54180 * scenario. */
54181 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
54182 * the middle of a write operation? This is a crummy place to do this
54183 * but we want to keep it all in the spinlock.
54184 */
54185 - if (hvcsd->port.count <= 0) {
54186 + if (atomic_read(&hvcsd->port.count) <= 0) {
54187 spin_unlock_irqrestore(&hvcsd->lock, flags);
54188 return -ENODEV;
54189 }
54190 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
54191 {
54192 struct hvcs_struct *hvcsd = tty->driver_data;
54193
54194 - if (!hvcsd || hvcsd->port.count <= 0)
54195 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
54196 return 0;
54197
54198 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
54199 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
54200 index 4190199..06d5bfa 100644
54201 --- a/drivers/tty/hvc/hvsi.c
54202 +++ b/drivers/tty/hvc/hvsi.c
54203 @@ -85,7 +85,7 @@ struct hvsi_struct {
54204 int n_outbuf;
54205 uint32_t vtermno;
54206 uint32_t virq;
54207 - atomic_t seqno; /* HVSI packet sequence number */
54208 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
54209 uint16_t mctrl;
54210 uint8_t state; /* HVSI protocol state */
54211 uint8_t flags;
54212 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
54213
54214 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
54215 packet.hdr.len = sizeof(struct hvsi_query_response);
54216 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
54217 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
54218 packet.verb = VSV_SEND_VERSION_NUMBER;
54219 packet.u.version = HVSI_VERSION;
54220 packet.query_seqno = query_seqno+1;
54221 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
54222
54223 packet.hdr.type = VS_QUERY_PACKET_HEADER;
54224 packet.hdr.len = sizeof(struct hvsi_query);
54225 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
54226 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
54227 packet.verb = verb;
54228
54229 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
54230 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
54231 int wrote;
54232
54233 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
54234 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
54235 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
54236 packet.hdr.len = sizeof(struct hvsi_control);
54237 packet.verb = VSV_SET_MODEM_CTL;
54238 packet.mask = HVSI_TSDTR;
54239 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
54240 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
54241
54242 packet.hdr.type = VS_DATA_PACKET_HEADER;
54243 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
54244 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
54245 packet.hdr.len = count + sizeof(struct hvsi_header);
54246 memcpy(&packet.data, buf, count);
54247
54248 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
54249 struct hvsi_control packet __ALIGNED__;
54250
54251 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
54252 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
54253 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
54254 packet.hdr.len = 6;
54255 packet.verb = VSV_CLOSE_PROTOCOL;
54256
54257 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
54258
54259 tty_port_tty_set(&hp->port, tty);
54260 spin_lock_irqsave(&hp->lock, flags);
54261 - hp->port.count++;
54262 + atomic_inc(&hp->port.count);
54263 atomic_set(&hp->seqno, 0);
54264 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
54265 spin_unlock_irqrestore(&hp->lock, flags);
54266 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
54267
54268 spin_lock_irqsave(&hp->lock, flags);
54269
54270 - if (--hp->port.count == 0) {
54271 + if (atomic_dec_return(&hp->port.count) == 0) {
54272 tty_port_tty_set(&hp->port, NULL);
54273 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
54274
54275 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
54276
54277 spin_lock_irqsave(&hp->lock, flags);
54278 }
54279 - } else if (hp->port.count < 0)
54280 + } else if (atomic_read(&hp->port.count) < 0)
54281 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
54282 - hp - hvsi_ports, hp->port.count);
54283 + hp - hvsi_ports, atomic_read(&hp->port.count));
54284
54285 spin_unlock_irqrestore(&hp->lock, flags);
54286 }
54287 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
54288 tty_port_tty_set(&hp->port, NULL);
54289
54290 spin_lock_irqsave(&hp->lock, flags);
54291 - hp->port.count = 0;
54292 + atomic_set(&hp->port.count, 0);
54293 hp->n_outbuf = 0;
54294 spin_unlock_irqrestore(&hp->lock, flags);
54295 }
54296 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
54297 index 7ae6c29..05c6dba 100644
54298 --- a/drivers/tty/hvc/hvsi_lib.c
54299 +++ b/drivers/tty/hvc/hvsi_lib.c
54300 @@ -8,7 +8,7 @@
54301
54302 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
54303 {
54304 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
54305 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
54306
54307 /* Assumes that always succeeds, works in practice */
54308 return pv->put_chars(pv->termno, (char *)packet, packet->len);
54309 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
54310
54311 /* Reset state */
54312 pv->established = 0;
54313 - atomic_set(&pv->seqno, 0);
54314 + atomic_set_unchecked(&pv->seqno, 0);
54315
54316 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
54317
54318 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
54319 index 17ee3bf..8d2520d 100644
54320 --- a/drivers/tty/ipwireless/tty.c
54321 +++ b/drivers/tty/ipwireless/tty.c
54322 @@ -28,6 +28,7 @@
54323 #include <linux/tty_driver.h>
54324 #include <linux/tty_flip.h>
54325 #include <linux/uaccess.h>
54326 +#include <asm/local.h>
54327
54328 #include "tty.h"
54329 #include "network.h"
54330 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
54331 mutex_unlock(&tty->ipw_tty_mutex);
54332 return -ENODEV;
54333 }
54334 - if (tty->port.count == 0)
54335 + if (atomic_read(&tty->port.count) == 0)
54336 tty->tx_bytes_queued = 0;
54337
54338 - tty->port.count++;
54339 + atomic_inc(&tty->port.count);
54340
54341 tty->port.tty = linux_tty;
54342 linux_tty->driver_data = tty;
54343 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
54344
54345 static void do_ipw_close(struct ipw_tty *tty)
54346 {
54347 - tty->port.count--;
54348 -
54349 - if (tty->port.count == 0) {
54350 + if (atomic_dec_return(&tty->port.count) == 0) {
54351 struct tty_struct *linux_tty = tty->port.tty;
54352
54353 if (linux_tty != NULL) {
54354 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
54355 return;
54356
54357 mutex_lock(&tty->ipw_tty_mutex);
54358 - if (tty->port.count == 0) {
54359 + if (atomic_read(&tty->port.count) == 0) {
54360 mutex_unlock(&tty->ipw_tty_mutex);
54361 return;
54362 }
54363 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
54364
54365 mutex_lock(&tty->ipw_tty_mutex);
54366
54367 - if (!tty->port.count) {
54368 + if (!atomic_read(&tty->port.count)) {
54369 mutex_unlock(&tty->ipw_tty_mutex);
54370 return;
54371 }
54372 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
54373 return -ENODEV;
54374
54375 mutex_lock(&tty->ipw_tty_mutex);
54376 - if (!tty->port.count) {
54377 + if (!atomic_read(&tty->port.count)) {
54378 mutex_unlock(&tty->ipw_tty_mutex);
54379 return -EINVAL;
54380 }
54381 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
54382 if (!tty)
54383 return -ENODEV;
54384
54385 - if (!tty->port.count)
54386 + if (!atomic_read(&tty->port.count))
54387 return -EINVAL;
54388
54389 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
54390 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
54391 if (!tty)
54392 return 0;
54393
54394 - if (!tty->port.count)
54395 + if (!atomic_read(&tty->port.count))
54396 return 0;
54397
54398 return tty->tx_bytes_queued;
54399 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
54400 if (!tty)
54401 return -ENODEV;
54402
54403 - if (!tty->port.count)
54404 + if (!atomic_read(&tty->port.count))
54405 return -EINVAL;
54406
54407 return get_control_lines(tty);
54408 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
54409 if (!tty)
54410 return -ENODEV;
54411
54412 - if (!tty->port.count)
54413 + if (!atomic_read(&tty->port.count))
54414 return -EINVAL;
54415
54416 return set_control_lines(tty, set, clear);
54417 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
54418 if (!tty)
54419 return -ENODEV;
54420
54421 - if (!tty->port.count)
54422 + if (!atomic_read(&tty->port.count))
54423 return -EINVAL;
54424
54425 /* FIXME: Exactly how is the tty object locked here .. */
54426 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
54427 * are gone */
54428 mutex_lock(&ttyj->ipw_tty_mutex);
54429 }
54430 - while (ttyj->port.count)
54431 + while (atomic_read(&ttyj->port.count))
54432 do_ipw_close(ttyj);
54433 ipwireless_disassociate_network_ttys(network,
54434 ttyj->channel_idx);
54435 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
54436 index 1deaca4..c8582d4 100644
54437 --- a/drivers/tty/moxa.c
54438 +++ b/drivers/tty/moxa.c
54439 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
54440 }
54441
54442 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
54443 - ch->port.count++;
54444 + atomic_inc(&ch->port.count);
54445 tty->driver_data = ch;
54446 tty_port_tty_set(&ch->port, tty);
54447 mutex_lock(&ch->port.mutex);
54448 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
54449 index 2ebe47b..3205833 100644
54450 --- a/drivers/tty/n_gsm.c
54451 +++ b/drivers/tty/n_gsm.c
54452 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
54453 spin_lock_init(&dlci->lock);
54454 mutex_init(&dlci->mutex);
54455 dlci->fifo = &dlci->_fifo;
54456 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
54457 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
54458 kfree(dlci);
54459 return NULL;
54460 }
54461 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
54462 struct gsm_dlci *dlci = tty->driver_data;
54463 struct tty_port *port = &dlci->port;
54464
54465 - port->count++;
54466 + atomic_inc(&port->count);
54467 tty_port_tty_set(port, tty);
54468
54469 dlci->modem_rx = 0;
54470 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
54471 index f44f1ba..a8d5915 100644
54472 --- a/drivers/tty/n_tty.c
54473 +++ b/drivers/tty/n_tty.c
54474 @@ -115,7 +115,7 @@ struct n_tty_data {
54475 int minimum_to_wake;
54476
54477 /* consumer-published */
54478 - size_t read_tail;
54479 + size_t read_tail __intentional_overflow(-1);
54480 size_t line_start;
54481
54482 /* protected by output lock */
54483 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
54484 {
54485 *ops = tty_ldisc_N_TTY;
54486 ops->owner = NULL;
54487 - ops->refcount = ops->flags = 0;
54488 + atomic_set(&ops->refcount, 0);
54489 + ops->flags = 0;
54490 }
54491 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
54492 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
54493 index 25c9bc7..24077b7 100644
54494 --- a/drivers/tty/pty.c
54495 +++ b/drivers/tty/pty.c
54496 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
54497 panic("Couldn't register Unix98 pts driver");
54498
54499 /* Now create the /dev/ptmx special device */
54500 + pax_open_kernel();
54501 tty_default_fops(&ptmx_fops);
54502 - ptmx_fops.open = ptmx_open;
54503 + *(void **)&ptmx_fops.open = ptmx_open;
54504 + pax_close_kernel();
54505
54506 cdev_init(&ptmx_cdev, &ptmx_fops);
54507 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
54508 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
54509 index 383c4c7..d408e21 100644
54510 --- a/drivers/tty/rocket.c
54511 +++ b/drivers/tty/rocket.c
54512 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54513 tty->driver_data = info;
54514 tty_port_tty_set(port, tty);
54515
54516 - if (port->count++ == 0) {
54517 + if (atomic_inc_return(&port->count) == 1) {
54518 atomic_inc(&rp_num_ports_open);
54519
54520 #ifdef ROCKET_DEBUG_OPEN
54521 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
54522 #endif
54523 }
54524 #ifdef ROCKET_DEBUG_OPEN
54525 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
54526 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
54527 #endif
54528
54529 /*
54530 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
54531 spin_unlock_irqrestore(&info->port.lock, flags);
54532 return;
54533 }
54534 - if (info->port.count)
54535 + if (atomic_read(&info->port.count))
54536 atomic_dec(&rp_num_ports_open);
54537 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
54538 spin_unlock_irqrestore(&info->port.lock, flags);
54539 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
54540 index 1274499..f541382 100644
54541 --- a/drivers/tty/serial/ioc4_serial.c
54542 +++ b/drivers/tty/serial/ioc4_serial.c
54543 @@ -437,7 +437,7 @@ struct ioc4_soft {
54544 } is_intr_info[MAX_IOC4_INTR_ENTS];
54545
54546 /* Number of entries active in the above array */
54547 - atomic_t is_num_intrs;
54548 + atomic_unchecked_t is_num_intrs;
54549 } is_intr_type[IOC4_NUM_INTR_TYPES];
54550
54551 /* is_ir_lock must be held while
54552 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
54553 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
54554 || (type == IOC4_OTHER_INTR_TYPE)));
54555
54556 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
54557 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
54558 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
54559
54560 /* Save off the lower level interrupt handler */
54561 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
54562
54563 soft = arg;
54564 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
54565 - num_intrs = (int)atomic_read(
54566 + num_intrs = (int)atomic_read_unchecked(
54567 &soft->is_intr_type[intr_type].is_num_intrs);
54568
54569 this_mir = this_ir = pending_intrs(soft, intr_type);
54570 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
54571 index cfadf29..8cf4595 100644
54572 --- a/drivers/tty/serial/kgdb_nmi.c
54573 +++ b/drivers/tty/serial/kgdb_nmi.c
54574 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
54575 * I/O utilities that messages sent to the console will automatically
54576 * be displayed on the dbg_io.
54577 */
54578 - dbg_io_ops->is_console = true;
54579 + pax_open_kernel();
54580 + *(int *)&dbg_io_ops->is_console = true;
54581 + pax_close_kernel();
54582
54583 return 0;
54584 }
54585 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
54586 index a260cde..6b2b5ce 100644
54587 --- a/drivers/tty/serial/kgdboc.c
54588 +++ b/drivers/tty/serial/kgdboc.c
54589 @@ -24,8 +24,9 @@
54590 #define MAX_CONFIG_LEN 40
54591
54592 static struct kgdb_io kgdboc_io_ops;
54593 +static struct kgdb_io kgdboc_io_ops_console;
54594
54595 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
54596 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
54597 static int configured = -1;
54598
54599 static char config[MAX_CONFIG_LEN];
54600 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
54601 kgdboc_unregister_kbd();
54602 if (configured == 1)
54603 kgdb_unregister_io_module(&kgdboc_io_ops);
54604 + else if (configured == 2)
54605 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
54606 }
54607
54608 static int configure_kgdboc(void)
54609 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
54610 int err;
54611 char *cptr = config;
54612 struct console *cons;
54613 + int is_console = 0;
54614
54615 err = kgdboc_option_setup(config);
54616 if (err || !strlen(config) || isspace(config[0]))
54617 goto noconfig;
54618
54619 err = -ENODEV;
54620 - kgdboc_io_ops.is_console = 0;
54621 kgdb_tty_driver = NULL;
54622
54623 kgdboc_use_kms = 0;
54624 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
54625 int idx;
54626 if (cons->device && cons->device(cons, &idx) == p &&
54627 idx == tty_line) {
54628 - kgdboc_io_ops.is_console = 1;
54629 + is_console = 1;
54630 break;
54631 }
54632 cons = cons->next;
54633 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
54634 kgdb_tty_line = tty_line;
54635
54636 do_register:
54637 - err = kgdb_register_io_module(&kgdboc_io_ops);
54638 + if (is_console) {
54639 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
54640 + configured = 2;
54641 + } else {
54642 + err = kgdb_register_io_module(&kgdboc_io_ops);
54643 + configured = 1;
54644 + }
54645 if (err)
54646 goto noconfig;
54647
54648 @@ -205,8 +214,6 @@ do_register:
54649 if (err)
54650 goto nmi_con_failed;
54651
54652 - configured = 1;
54653 -
54654 return 0;
54655
54656 nmi_con_failed:
54657 @@ -223,7 +230,7 @@ noconfig:
54658 static int __init init_kgdboc(void)
54659 {
54660 /* Already configured? */
54661 - if (configured == 1)
54662 + if (configured >= 1)
54663 return 0;
54664
54665 return configure_kgdboc();
54666 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
54667 if (config[len - 1] == '\n')
54668 config[len - 1] = '\0';
54669
54670 - if (configured == 1)
54671 + if (configured >= 1)
54672 cleanup_kgdboc();
54673
54674 /* Go and configure with the new params. */
54675 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
54676 .post_exception = kgdboc_post_exp_handler,
54677 };
54678
54679 +static struct kgdb_io kgdboc_io_ops_console = {
54680 + .name = "kgdboc",
54681 + .read_char = kgdboc_get_char,
54682 + .write_char = kgdboc_put_char,
54683 + .pre_exception = kgdboc_pre_exp_handler,
54684 + .post_exception = kgdboc_post_exp_handler,
54685 + .is_console = 1
54686 +};
54687 +
54688 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
54689 /* This is only available if kgdboc is a built in for early debugging */
54690 static int __init kgdboc_early_init(char *opt)
54691 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
54692 index 72000a6..a190bc4 100644
54693 --- a/drivers/tty/serial/msm_serial.c
54694 +++ b/drivers/tty/serial/msm_serial.c
54695 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
54696 .cons = MSM_CONSOLE,
54697 };
54698
54699 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
54700 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
54701
54702 static const struct of_device_id msm_uartdm_table[] = {
54703 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
54704 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
54705 int irq;
54706
54707 if (pdev->id == -1)
54708 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
54709 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
54710
54711 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
54712 return -ENXIO;
54713 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
54714 index c1d3ebd..f618a93 100644
54715 --- a/drivers/tty/serial/samsung.c
54716 +++ b/drivers/tty/serial/samsung.c
54717 @@ -486,11 +486,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
54718 }
54719 }
54720
54721 +static int s3c64xx_serial_startup(struct uart_port *port);
54722 static int s3c24xx_serial_startup(struct uart_port *port)
54723 {
54724 struct s3c24xx_uart_port *ourport = to_ourport(port);
54725 int ret;
54726
54727 + /* Startup sequence is different for s3c64xx and higher SoC's */
54728 + if (s3c24xx_serial_has_interrupt_mask(port))
54729 + return s3c64xx_serial_startup(port);
54730 +
54731 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
54732 port, (unsigned long long)port->mapbase, port->membase);
54733
54734 @@ -1164,10 +1169,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
54735 /* setup info for port */
54736 port->dev = &platdev->dev;
54737
54738 - /* Startup sequence is different for s3c64xx and higher SoC's */
54739 - if (s3c24xx_serial_has_interrupt_mask(port))
54740 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
54741 -
54742 port->uartclk = 1;
54743
54744 if (cfg->uart_flags & UPF_CONS_FLOW) {
54745 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
54746 index ef2fb36..238d80c 100644
54747 --- a/drivers/tty/serial/serial_core.c
54748 +++ b/drivers/tty/serial/serial_core.c
54749 @@ -1336,7 +1336,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
54750
54751 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
54752
54753 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
54754 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
54755 return;
54756
54757 /*
54758 @@ -1463,7 +1463,7 @@ static void uart_hangup(struct tty_struct *tty)
54759 uart_flush_buffer(tty);
54760 uart_shutdown(tty, state);
54761 spin_lock_irqsave(&port->lock, flags);
54762 - port->count = 0;
54763 + atomic_set(&port->count, 0);
54764 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
54765 spin_unlock_irqrestore(&port->lock, flags);
54766 tty_port_tty_set(port, NULL);
54767 @@ -1561,7 +1561,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54768 goto end;
54769 }
54770
54771 - port->count++;
54772 + atomic_inc(&port->count);
54773 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
54774 retval = -ENXIO;
54775 goto err_dec_count;
54776 @@ -1601,7 +1601,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
54777 end:
54778 return retval;
54779 err_dec_count:
54780 - port->count--;
54781 + atomic_inc(&port->count);
54782 mutex_unlock(&port->mutex);
54783 goto end;
54784 }
54785 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
54786 index d48e040..0f52764 100644
54787 --- a/drivers/tty/synclink.c
54788 +++ b/drivers/tty/synclink.c
54789 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54790
54791 if (debug_level >= DEBUG_LEVEL_INFO)
54792 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
54793 - __FILE__,__LINE__, info->device_name, info->port.count);
54794 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54795
54796 if (tty_port_close_start(&info->port, tty, filp) == 0)
54797 goto cleanup;
54798 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
54799 cleanup:
54800 if (debug_level >= DEBUG_LEVEL_INFO)
54801 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
54802 - tty->driver->name, info->port.count);
54803 + tty->driver->name, atomic_read(&info->port.count));
54804
54805 } /* end of mgsl_close() */
54806
54807 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
54808
54809 mgsl_flush_buffer(tty);
54810 shutdown(info);
54811 -
54812 - info->port.count = 0;
54813 +
54814 + atomic_set(&info->port.count, 0);
54815 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54816 info->port.tty = NULL;
54817
54818 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54819
54820 if (debug_level >= DEBUG_LEVEL_INFO)
54821 printk("%s(%d):block_til_ready before block on %s count=%d\n",
54822 - __FILE__,__LINE__, tty->driver->name, port->count );
54823 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54824
54825 spin_lock_irqsave(&info->irq_spinlock, flags);
54826 if (!tty_hung_up_p(filp)) {
54827 extra_count = true;
54828 - port->count--;
54829 + atomic_dec(&port->count);
54830 }
54831 spin_unlock_irqrestore(&info->irq_spinlock, flags);
54832 port->blocked_open++;
54833 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54834
54835 if (debug_level >= DEBUG_LEVEL_INFO)
54836 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
54837 - __FILE__,__LINE__, tty->driver->name, port->count );
54838 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54839
54840 tty_unlock(tty);
54841 schedule();
54842 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
54843
54844 /* FIXME: Racy on hangup during close wait */
54845 if (extra_count)
54846 - port->count++;
54847 + atomic_inc(&port->count);
54848 port->blocked_open--;
54849
54850 if (debug_level >= DEBUG_LEVEL_INFO)
54851 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
54852 - __FILE__,__LINE__, tty->driver->name, port->count );
54853 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54854
54855 if (!retval)
54856 port->flags |= ASYNC_NORMAL_ACTIVE;
54857 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54858
54859 if (debug_level >= DEBUG_LEVEL_INFO)
54860 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
54861 - __FILE__,__LINE__,tty->driver->name, info->port.count);
54862 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54863
54864 /* If port is closing, signal caller to try again */
54865 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54866 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
54867 spin_unlock_irqrestore(&info->netlock, flags);
54868 goto cleanup;
54869 }
54870 - info->port.count++;
54871 + atomic_inc(&info->port.count);
54872 spin_unlock_irqrestore(&info->netlock, flags);
54873
54874 - if (info->port.count == 1) {
54875 + if (atomic_read(&info->port.count) == 1) {
54876 /* 1st open on this device, init hardware */
54877 retval = startup(info);
54878 if (retval < 0)
54879 @@ -3446,8 +3446,8 @@ cleanup:
54880 if (retval) {
54881 if (tty->count == 1)
54882 info->port.tty = NULL; /* tty layer will release tty struct */
54883 - if(info->port.count)
54884 - info->port.count--;
54885 + if (atomic_read(&info->port.count))
54886 + atomic_dec(&info->port.count);
54887 }
54888
54889 return retval;
54890 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54891 unsigned short new_crctype;
54892
54893 /* return error if TTY interface open */
54894 - if (info->port.count)
54895 + if (atomic_read(&info->port.count))
54896 return -EBUSY;
54897
54898 switch (encoding)
54899 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
54900
54901 /* arbitrate between network and tty opens */
54902 spin_lock_irqsave(&info->netlock, flags);
54903 - if (info->port.count != 0 || info->netcount != 0) {
54904 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54905 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54906 spin_unlock_irqrestore(&info->netlock, flags);
54907 return -EBUSY;
54908 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54909 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54910
54911 /* return error if TTY interface open */
54912 - if (info->port.count)
54913 + if (atomic_read(&info->port.count))
54914 return -EBUSY;
54915
54916 if (cmd != SIOCWANDEV)
54917 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
54918 index c359a91..959fc26 100644
54919 --- a/drivers/tty/synclink_gt.c
54920 +++ b/drivers/tty/synclink_gt.c
54921 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54922 tty->driver_data = info;
54923 info->port.tty = tty;
54924
54925 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54926 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54927
54928 /* If port is closing, signal caller to try again */
54929 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
54930 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54931 mutex_unlock(&info->port.mutex);
54932 goto cleanup;
54933 }
54934 - info->port.count++;
54935 + atomic_inc(&info->port.count);
54936 spin_unlock_irqrestore(&info->netlock, flags);
54937
54938 - if (info->port.count == 1) {
54939 + if (atomic_read(&info->port.count) == 1) {
54940 /* 1st open on this device, init hardware */
54941 retval = startup(info);
54942 if (retval < 0) {
54943 @@ -715,8 +715,8 @@ cleanup:
54944 if (retval) {
54945 if (tty->count == 1)
54946 info->port.tty = NULL; /* tty layer will release tty struct */
54947 - if(info->port.count)
54948 - info->port.count--;
54949 + if(atomic_read(&info->port.count))
54950 + atomic_dec(&info->port.count);
54951 }
54952
54953 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54954 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54955
54956 if (sanity_check(info, tty->name, "close"))
54957 return;
54958 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54959 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54960
54961 if (tty_port_close_start(&info->port, tty, filp) == 0)
54962 goto cleanup;
54963 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54964 tty_port_close_end(&info->port, tty);
54965 info->port.tty = NULL;
54966 cleanup:
54967 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54968 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54969 }
54970
54971 static void hangup(struct tty_struct *tty)
54972 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54973 shutdown(info);
54974
54975 spin_lock_irqsave(&info->port.lock, flags);
54976 - info->port.count = 0;
54977 + atomic_set(&info->port.count, 0);
54978 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54979 info->port.tty = NULL;
54980 spin_unlock_irqrestore(&info->port.lock, flags);
54981 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54982 unsigned short new_crctype;
54983
54984 /* return error if TTY interface open */
54985 - if (info->port.count)
54986 + if (atomic_read(&info->port.count))
54987 return -EBUSY;
54988
54989 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54990 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54991
54992 /* arbitrate between network and tty opens */
54993 spin_lock_irqsave(&info->netlock, flags);
54994 - if (info->port.count != 0 || info->netcount != 0) {
54995 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54996 DBGINFO(("%s hdlc_open busy\n", dev->name));
54997 spin_unlock_irqrestore(&info->netlock, flags);
54998 return -EBUSY;
54999 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
55000 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
55001
55002 /* return error if TTY interface open */
55003 - if (info->port.count)
55004 + if (atomic_read(&info->port.count))
55005 return -EBUSY;
55006
55007 if (cmd != SIOCWANDEV)
55008 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
55009 if (port == NULL)
55010 continue;
55011 spin_lock(&port->lock);
55012 - if ((port->port.count || port->netcount) &&
55013 + if ((atomic_read(&port->port.count) || port->netcount) &&
55014 port->pending_bh && !port->bh_running &&
55015 !port->bh_requested) {
55016 DBGISR(("%s bh queued\n", port->device_name));
55017 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
55018 spin_lock_irqsave(&info->lock, flags);
55019 if (!tty_hung_up_p(filp)) {
55020 extra_count = true;
55021 - port->count--;
55022 + atomic_dec(&port->count);
55023 }
55024 spin_unlock_irqrestore(&info->lock, flags);
55025 port->blocked_open++;
55026 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
55027 remove_wait_queue(&port->open_wait, &wait);
55028
55029 if (extra_count)
55030 - port->count++;
55031 + atomic_inc(&port->count);
55032 port->blocked_open--;
55033
55034 if (!retval)
55035 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
55036 index 53ba853..3c30f6d 100644
55037 --- a/drivers/tty/synclinkmp.c
55038 +++ b/drivers/tty/synclinkmp.c
55039 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
55040
55041 if (debug_level >= DEBUG_LEVEL_INFO)
55042 printk("%s(%d):%s open(), old ref count = %d\n",
55043 - __FILE__,__LINE__,tty->driver->name, info->port.count);
55044 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
55045
55046 /* If port is closing, signal caller to try again */
55047 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
55048 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
55049 spin_unlock_irqrestore(&info->netlock, flags);
55050 goto cleanup;
55051 }
55052 - info->port.count++;
55053 + atomic_inc(&info->port.count);
55054 spin_unlock_irqrestore(&info->netlock, flags);
55055
55056 - if (info->port.count == 1) {
55057 + if (atomic_read(&info->port.count) == 1) {
55058 /* 1st open on this device, init hardware */
55059 retval = startup(info);
55060 if (retval < 0)
55061 @@ -796,8 +796,8 @@ cleanup:
55062 if (retval) {
55063 if (tty->count == 1)
55064 info->port.tty = NULL; /* tty layer will release tty struct */
55065 - if(info->port.count)
55066 - info->port.count--;
55067 + if(atomic_read(&info->port.count))
55068 + atomic_dec(&info->port.count);
55069 }
55070
55071 return retval;
55072 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
55073
55074 if (debug_level >= DEBUG_LEVEL_INFO)
55075 printk("%s(%d):%s close() entry, count=%d\n",
55076 - __FILE__,__LINE__, info->device_name, info->port.count);
55077 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
55078
55079 if (tty_port_close_start(&info->port, tty, filp) == 0)
55080 goto cleanup;
55081 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
55082 cleanup:
55083 if (debug_level >= DEBUG_LEVEL_INFO)
55084 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
55085 - tty->driver->name, info->port.count);
55086 + tty->driver->name, atomic_read(&info->port.count));
55087 }
55088
55089 /* Called by tty_hangup() when a hangup is signaled.
55090 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
55091 shutdown(info);
55092
55093 spin_lock_irqsave(&info->port.lock, flags);
55094 - info->port.count = 0;
55095 + atomic_set(&info->port.count, 0);
55096 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
55097 info->port.tty = NULL;
55098 spin_unlock_irqrestore(&info->port.lock, flags);
55099 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
55100 unsigned short new_crctype;
55101
55102 /* return error if TTY interface open */
55103 - if (info->port.count)
55104 + if (atomic_read(&info->port.count))
55105 return -EBUSY;
55106
55107 switch (encoding)
55108 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
55109
55110 /* arbitrate between network and tty opens */
55111 spin_lock_irqsave(&info->netlock, flags);
55112 - if (info->port.count != 0 || info->netcount != 0) {
55113 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
55114 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
55115 spin_unlock_irqrestore(&info->netlock, flags);
55116 return -EBUSY;
55117 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
55118 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
55119
55120 /* return error if TTY interface open */
55121 - if (info->port.count)
55122 + if (atomic_read(&info->port.count))
55123 return -EBUSY;
55124
55125 if (cmd != SIOCWANDEV)
55126 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
55127 * do not request bottom half processing if the
55128 * device is not open in a normal mode.
55129 */
55130 - if ( port && (port->port.count || port->netcount) &&
55131 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
55132 port->pending_bh && !port->bh_running &&
55133 !port->bh_requested ) {
55134 if ( debug_level >= DEBUG_LEVEL_ISR )
55135 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
55136
55137 if (debug_level >= DEBUG_LEVEL_INFO)
55138 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
55139 - __FILE__,__LINE__, tty->driver->name, port->count );
55140 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
55141
55142 spin_lock_irqsave(&info->lock, flags);
55143 if (!tty_hung_up_p(filp)) {
55144 extra_count = true;
55145 - port->count--;
55146 + atomic_dec(&port->count);
55147 }
55148 spin_unlock_irqrestore(&info->lock, flags);
55149 port->blocked_open++;
55150 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
55151
55152 if (debug_level >= DEBUG_LEVEL_INFO)
55153 printk("%s(%d):%s block_til_ready() count=%d\n",
55154 - __FILE__,__LINE__, tty->driver->name, port->count );
55155 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
55156
55157 tty_unlock(tty);
55158 schedule();
55159 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
55160 remove_wait_queue(&port->open_wait, &wait);
55161
55162 if (extra_count)
55163 - port->count++;
55164 + atomic_inc(&port->count);
55165 port->blocked_open--;
55166
55167 if (debug_level >= DEBUG_LEVEL_INFO)
55168 printk("%s(%d):%s block_til_ready() after, count=%d\n",
55169 - __FILE__,__LINE__, tty->driver->name, port->count );
55170 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
55171
55172 if (!retval)
55173 port->flags |= ASYNC_NORMAL_ACTIVE;
55174 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
55175 index 454b658..57b1430 100644
55176 --- a/drivers/tty/sysrq.c
55177 +++ b/drivers/tty/sysrq.c
55178 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
55179 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
55180 size_t count, loff_t *ppos)
55181 {
55182 - if (count) {
55183 + if (count && capable(CAP_SYS_ADMIN)) {
55184 char c;
55185
55186 if (get_user(c, buf))
55187 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
55188 index 3411071..86f2cf2 100644
55189 --- a/drivers/tty/tty_io.c
55190 +++ b/drivers/tty/tty_io.c
55191 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
55192
55193 void tty_default_fops(struct file_operations *fops)
55194 {
55195 - *fops = tty_fops;
55196 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
55197 }
55198
55199 /*
55200 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
55201 index 2d822aa..a566234 100644
55202 --- a/drivers/tty/tty_ldisc.c
55203 +++ b/drivers/tty/tty_ldisc.c
55204 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
55205 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
55206 tty_ldiscs[disc] = new_ldisc;
55207 new_ldisc->num = disc;
55208 - new_ldisc->refcount = 0;
55209 + atomic_set(&new_ldisc->refcount, 0);
55210 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
55211
55212 return ret;
55213 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
55214 return -EINVAL;
55215
55216 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
55217 - if (tty_ldiscs[disc]->refcount)
55218 + if (atomic_read(&tty_ldiscs[disc]->refcount))
55219 ret = -EBUSY;
55220 else
55221 tty_ldiscs[disc] = NULL;
55222 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
55223 if (ldops) {
55224 ret = ERR_PTR(-EAGAIN);
55225 if (try_module_get(ldops->owner)) {
55226 - ldops->refcount++;
55227 + atomic_inc(&ldops->refcount);
55228 ret = ldops;
55229 }
55230 }
55231 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
55232 unsigned long flags;
55233
55234 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
55235 - ldops->refcount--;
55236 + atomic_dec(&ldops->refcount);
55237 module_put(ldops->owner);
55238 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
55239 }
55240 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
55241 index 3f746c8..2f2fcaa 100644
55242 --- a/drivers/tty/tty_port.c
55243 +++ b/drivers/tty/tty_port.c
55244 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
55245 unsigned long flags;
55246
55247 spin_lock_irqsave(&port->lock, flags);
55248 - port->count = 0;
55249 + atomic_set(&port->count, 0);
55250 port->flags &= ~ASYNC_NORMAL_ACTIVE;
55251 tty = port->tty;
55252 if (tty)
55253 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
55254 /* The port lock protects the port counts */
55255 spin_lock_irqsave(&port->lock, flags);
55256 if (!tty_hung_up_p(filp))
55257 - port->count--;
55258 + atomic_dec(&port->count);
55259 port->blocked_open++;
55260 spin_unlock_irqrestore(&port->lock, flags);
55261
55262 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
55263 we must not mess that up further */
55264 spin_lock_irqsave(&port->lock, flags);
55265 if (!tty_hung_up_p(filp))
55266 - port->count++;
55267 + atomic_inc(&port->count);
55268 port->blocked_open--;
55269 if (retval == 0)
55270 port->flags |= ASYNC_NORMAL_ACTIVE;
55271 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
55272 return 0;
55273 }
55274
55275 - if (tty->count == 1 && port->count != 1) {
55276 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
55277 printk(KERN_WARNING
55278 "tty_port_close_start: tty->count = 1 port count = %d.\n",
55279 - port->count);
55280 - port->count = 1;
55281 + atomic_read(&port->count));
55282 + atomic_set(&port->count, 1);
55283 }
55284 - if (--port->count < 0) {
55285 + if (atomic_dec_return(&port->count) < 0) {
55286 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
55287 - port->count);
55288 - port->count = 0;
55289 + atomic_read(&port->count));
55290 + atomic_set(&port->count, 0);
55291 }
55292
55293 - if (port->count) {
55294 + if (atomic_read(&port->count)) {
55295 spin_unlock_irqrestore(&port->lock, flags);
55296 return 0;
55297 }
55298 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
55299 {
55300 spin_lock_irq(&port->lock);
55301 if (!tty_hung_up_p(filp))
55302 - ++port->count;
55303 + atomic_inc(&port->count);
55304 spin_unlock_irq(&port->lock);
55305 tty_port_tty_set(port, tty);
55306
55307 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
55308 index d0e3a44..5f8b754 100644
55309 --- a/drivers/tty/vt/keyboard.c
55310 +++ b/drivers/tty/vt/keyboard.c
55311 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
55312 kbd->kbdmode == VC_OFF) &&
55313 value != KVAL(K_SAK))
55314 return; /* SAK is allowed even in raw mode */
55315 +
55316 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55317 + {
55318 + void *func = fn_handler[value];
55319 + if (func == fn_show_state || func == fn_show_ptregs ||
55320 + func == fn_show_mem)
55321 + return;
55322 + }
55323 +#endif
55324 +
55325 fn_handler[value](vc);
55326 }
55327
55328 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
55329 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
55330 return -EFAULT;
55331
55332 - if (!capable(CAP_SYS_TTY_CONFIG))
55333 - perm = 0;
55334 -
55335 switch (cmd) {
55336 case KDGKBENT:
55337 /* Ensure another thread doesn't free it under us */
55338 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
55339 spin_unlock_irqrestore(&kbd_event_lock, flags);
55340 return put_user(val, &user_kbe->kb_value);
55341 case KDSKBENT:
55342 + if (!capable(CAP_SYS_TTY_CONFIG))
55343 + perm = 0;
55344 +
55345 if (!perm)
55346 return -EPERM;
55347 if (!i && v == K_NOSUCHMAP) {
55348 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
55349 int i, j, k;
55350 int ret;
55351
55352 - if (!capable(CAP_SYS_TTY_CONFIG))
55353 - perm = 0;
55354 -
55355 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
55356 if (!kbs) {
55357 ret = -ENOMEM;
55358 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
55359 kfree(kbs);
55360 return ((p && *p) ? -EOVERFLOW : 0);
55361 case KDSKBSENT:
55362 + if (!capable(CAP_SYS_TTY_CONFIG))
55363 + perm = 0;
55364 +
55365 if (!perm) {
55366 ret = -EPERM;
55367 goto reterr;
55368 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
55369 index a673e5b..36e5d32 100644
55370 --- a/drivers/uio/uio.c
55371 +++ b/drivers/uio/uio.c
55372 @@ -25,6 +25,7 @@
55373 #include <linux/kobject.h>
55374 #include <linux/cdev.h>
55375 #include <linux/uio_driver.h>
55376 +#include <asm/local.h>
55377
55378 #define UIO_MAX_DEVICES (1U << MINORBITS)
55379
55380 @@ -32,7 +33,7 @@ struct uio_device {
55381 struct module *owner;
55382 struct device *dev;
55383 int minor;
55384 - atomic_t event;
55385 + atomic_unchecked_t event;
55386 struct fasync_struct *async_queue;
55387 wait_queue_head_t wait;
55388 struct uio_info *info;
55389 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
55390 struct device_attribute *attr, char *buf)
55391 {
55392 struct uio_device *idev = dev_get_drvdata(dev);
55393 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
55394 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
55395 }
55396 static DEVICE_ATTR_RO(event);
55397
55398 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
55399 {
55400 struct uio_device *idev = info->uio_dev;
55401
55402 - atomic_inc(&idev->event);
55403 + atomic_inc_unchecked(&idev->event);
55404 wake_up_interruptible(&idev->wait);
55405 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
55406 }
55407 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
55408 }
55409
55410 listener->dev = idev;
55411 - listener->event_count = atomic_read(&idev->event);
55412 + listener->event_count = atomic_read_unchecked(&idev->event);
55413 filep->private_data = listener;
55414
55415 if (idev->info->open) {
55416 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
55417 return -EIO;
55418
55419 poll_wait(filep, &idev->wait, wait);
55420 - if (listener->event_count != atomic_read(&idev->event))
55421 + if (listener->event_count != atomic_read_unchecked(&idev->event))
55422 return POLLIN | POLLRDNORM;
55423 return 0;
55424 }
55425 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
55426 do {
55427 set_current_state(TASK_INTERRUPTIBLE);
55428
55429 - event_count = atomic_read(&idev->event);
55430 + event_count = atomic_read_unchecked(&idev->event);
55431 if (event_count != listener->event_count) {
55432 if (copy_to_user(buf, &event_count, count))
55433 retval = -EFAULT;
55434 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
55435 static int uio_find_mem_index(struct vm_area_struct *vma)
55436 {
55437 struct uio_device *idev = vma->vm_private_data;
55438 + unsigned long size;
55439
55440 if (vma->vm_pgoff < MAX_UIO_MAPS) {
55441 - if (idev->info->mem[vma->vm_pgoff].size == 0)
55442 + size = idev->info->mem[vma->vm_pgoff].size;
55443 + if (size == 0)
55444 + return -1;
55445 + if (vma->vm_end - vma->vm_start > size)
55446 return -1;
55447 return (int)vma->vm_pgoff;
55448 }
55449 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
55450 idev->owner = owner;
55451 idev->info = info;
55452 init_waitqueue_head(&idev->wait);
55453 - atomic_set(&idev->event, 0);
55454 + atomic_set_unchecked(&idev->event, 0);
55455
55456 ret = uio_get_minor(idev);
55457 if (ret)
55458 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
55459 index 813d4d3..a71934f 100644
55460 --- a/drivers/usb/atm/cxacru.c
55461 +++ b/drivers/usb/atm/cxacru.c
55462 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
55463 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
55464 if (ret < 2)
55465 return -EINVAL;
55466 - if (index < 0 || index > 0x7f)
55467 + if (index > 0x7f)
55468 return -EINVAL;
55469 pos += tmp;
55470
55471 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
55472 index dada014..1d0d517 100644
55473 --- a/drivers/usb/atm/usbatm.c
55474 +++ b/drivers/usb/atm/usbatm.c
55475 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55476 if (printk_ratelimit())
55477 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
55478 __func__, vpi, vci);
55479 - atomic_inc(&vcc->stats->rx_err);
55480 + atomic_inc_unchecked(&vcc->stats->rx_err);
55481 return;
55482 }
55483
55484 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55485 if (length > ATM_MAX_AAL5_PDU) {
55486 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
55487 __func__, length, vcc);
55488 - atomic_inc(&vcc->stats->rx_err);
55489 + atomic_inc_unchecked(&vcc->stats->rx_err);
55490 goto out;
55491 }
55492
55493 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55494 if (sarb->len < pdu_length) {
55495 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
55496 __func__, pdu_length, sarb->len, vcc);
55497 - atomic_inc(&vcc->stats->rx_err);
55498 + atomic_inc_unchecked(&vcc->stats->rx_err);
55499 goto out;
55500 }
55501
55502 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
55503 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
55504 __func__, vcc);
55505 - atomic_inc(&vcc->stats->rx_err);
55506 + atomic_inc_unchecked(&vcc->stats->rx_err);
55507 goto out;
55508 }
55509
55510 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55511 if (printk_ratelimit())
55512 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
55513 __func__, length);
55514 - atomic_inc(&vcc->stats->rx_drop);
55515 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55516 goto out;
55517 }
55518
55519 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
55520
55521 vcc->push(vcc, skb);
55522
55523 - atomic_inc(&vcc->stats->rx);
55524 + atomic_inc_unchecked(&vcc->stats->rx);
55525 out:
55526 skb_trim(sarb, 0);
55527 }
55528 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
55529 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
55530
55531 usbatm_pop(vcc, skb);
55532 - atomic_inc(&vcc->stats->tx);
55533 + atomic_inc_unchecked(&vcc->stats->tx);
55534
55535 skb = skb_dequeue(&instance->sndqueue);
55536 }
55537 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
55538 if (!left--)
55539 return sprintf(page,
55540 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
55541 - atomic_read(&atm_dev->stats.aal5.tx),
55542 - atomic_read(&atm_dev->stats.aal5.tx_err),
55543 - atomic_read(&atm_dev->stats.aal5.rx),
55544 - atomic_read(&atm_dev->stats.aal5.rx_err),
55545 - atomic_read(&atm_dev->stats.aal5.rx_drop));
55546 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
55547 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
55548 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
55549 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
55550 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
55551
55552 if (!left--) {
55553 if (instance->disconnected)
55554 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
55555 index 2a3bbdf..91d72cf 100644
55556 --- a/drivers/usb/core/devices.c
55557 +++ b/drivers/usb/core/devices.c
55558 @@ -126,7 +126,7 @@ static const char format_endpt[] =
55559 * time it gets called.
55560 */
55561 static struct device_connect_event {
55562 - atomic_t count;
55563 + atomic_unchecked_t count;
55564 wait_queue_head_t wait;
55565 } device_event = {
55566 .count = ATOMIC_INIT(1),
55567 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
55568
55569 void usbfs_conn_disc_event(void)
55570 {
55571 - atomic_add(2, &device_event.count);
55572 + atomic_add_unchecked(2, &device_event.count);
55573 wake_up(&device_event.wait);
55574 }
55575
55576 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
55577
55578 poll_wait(file, &device_event.wait, wait);
55579
55580 - event_count = atomic_read(&device_event.count);
55581 + event_count = atomic_read_unchecked(&device_event.count);
55582 if (file->f_version != event_count) {
55583 file->f_version = event_count;
55584 return POLLIN | POLLRDNORM;
55585 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
55586 index 0b59731..46ee7d1 100644
55587 --- a/drivers/usb/core/devio.c
55588 +++ b/drivers/usb/core/devio.c
55589 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55590 struct usb_dev_state *ps = file->private_data;
55591 struct usb_device *dev = ps->dev;
55592 ssize_t ret = 0;
55593 - unsigned len;
55594 + size_t len;
55595 loff_t pos;
55596 int i;
55597
55598 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
55599 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
55600 struct usb_config_descriptor *config =
55601 (struct usb_config_descriptor *)dev->rawdescriptors[i];
55602 - unsigned int length = le16_to_cpu(config->wTotalLength);
55603 + size_t length = le16_to_cpu(config->wTotalLength);
55604
55605 if (*ppos < pos + length) {
55606
55607 /* The descriptor may claim to be longer than it
55608 * really is. Here is the actual allocated length. */
55609 - unsigned alloclen =
55610 + size_t alloclen =
55611 le16_to_cpu(dev->config[i].desc.wTotalLength);
55612
55613 - len = length - (*ppos - pos);
55614 + len = length + pos - *ppos;
55615 if (len > nbytes)
55616 len = nbytes;
55617
55618 /* Simply don't write (skip over) unallocated parts */
55619 if (alloclen > (*ppos - pos)) {
55620 - alloclen -= (*ppos - pos);
55621 + alloclen = alloclen + pos - *ppos;
55622 if (copy_to_user(buf,
55623 dev->rawdescriptors[i] + (*ppos - pos),
55624 min(len, alloclen))) {
55625 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
55626 index bec31e2..b8091cd 100644
55627 --- a/drivers/usb/core/hcd.c
55628 +++ b/drivers/usb/core/hcd.c
55629 @@ -1554,7 +1554,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55630 */
55631 usb_get_urb(urb);
55632 atomic_inc(&urb->use_count);
55633 - atomic_inc(&urb->dev->urbnum);
55634 + atomic_inc_unchecked(&urb->dev->urbnum);
55635 usbmon_urb_submit(&hcd->self, urb);
55636
55637 /* NOTE requirements on root-hub callers (usbfs and the hub
55638 @@ -1581,7 +1581,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
55639 urb->hcpriv = NULL;
55640 INIT_LIST_HEAD(&urb->urb_list);
55641 atomic_dec(&urb->use_count);
55642 - atomic_dec(&urb->dev->urbnum);
55643 + atomic_dec_unchecked(&urb->dev->urbnum);
55644 if (atomic_read(&urb->reject))
55645 wake_up(&usb_kill_urb_queue);
55646 usb_put_urb(urb);
55647 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
55648 index 27f2171..e3dfc22 100644
55649 --- a/drivers/usb/core/hub.c
55650 +++ b/drivers/usb/core/hub.c
55651 @@ -27,6 +27,7 @@
55652 #include <linux/freezer.h>
55653 #include <linux/random.h>
55654 #include <linux/pm_qos.h>
55655 +#include <linux/grsecurity.h>
55656
55657 #include <asm/uaccess.h>
55658 #include <asm/byteorder.h>
55659 @@ -4644,6 +4645,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
55660 goto done;
55661 return;
55662 }
55663 +
55664 + if (gr_handle_new_usb())
55665 + goto done;
55666 +
55667 if (hub_is_superspeed(hub->hdev))
55668 unit_load = 150;
55669 else
55670 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
55671 index 0c8a7fc..c45b40a 100644
55672 --- a/drivers/usb/core/message.c
55673 +++ b/drivers/usb/core/message.c
55674 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
55675 * Return: If successful, the number of bytes transferred. Otherwise, a negative
55676 * error number.
55677 */
55678 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55679 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
55680 __u8 requesttype, __u16 value, __u16 index, void *data,
55681 __u16 size, int timeout)
55682 {
55683 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
55684 * If successful, 0. Otherwise a negative error number. The number of actual
55685 * bytes transferred will be stored in the @actual_length parameter.
55686 */
55687 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55688 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
55689 void *data, int len, int *actual_length, int timeout)
55690 {
55691 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
55692 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
55693 * bytes transferred will be stored in the @actual_length parameter.
55694 *
55695 */
55696 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55697 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
55698 void *data, int len, int *actual_length, int timeout)
55699 {
55700 struct urb *urb;
55701 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
55702 index 1236c60..d47a51c 100644
55703 --- a/drivers/usb/core/sysfs.c
55704 +++ b/drivers/usb/core/sysfs.c
55705 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
55706 struct usb_device *udev;
55707
55708 udev = to_usb_device(dev);
55709 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
55710 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
55711 }
55712 static DEVICE_ATTR_RO(urbnum);
55713
55714 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
55715 index 4d11449..f4ccabf 100644
55716 --- a/drivers/usb/core/usb.c
55717 +++ b/drivers/usb/core/usb.c
55718 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
55719 set_dev_node(&dev->dev, dev_to_node(bus->controller));
55720 dev->state = USB_STATE_ATTACHED;
55721 dev->lpm_disable_count = 1;
55722 - atomic_set(&dev->urbnum, 0);
55723 + atomic_set_unchecked(&dev->urbnum, 0);
55724
55725 INIT_LIST_HEAD(&dev->ep0.urb_list);
55726 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
55727 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
55728 index dab7927..6f53afc 100644
55729 --- a/drivers/usb/dwc3/gadget.c
55730 +++ b/drivers/usb/dwc3/gadget.c
55731 @@ -615,8 +615,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
55732 if (!usb_endpoint_xfer_isoc(desc))
55733 return 0;
55734
55735 - memset(&trb_link, 0, sizeof(trb_link));
55736 -
55737 /* Link TRB for ISOC. The HWO bit is never reset */
55738 trb_st_hw = &dep->trb_pool[0];
55739
55740 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
55741 index 8cfc319..4868255 100644
55742 --- a/drivers/usb/early/ehci-dbgp.c
55743 +++ b/drivers/usb/early/ehci-dbgp.c
55744 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
55745
55746 #ifdef CONFIG_KGDB
55747 static struct kgdb_io kgdbdbgp_io_ops;
55748 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
55749 +static struct kgdb_io kgdbdbgp_io_ops_console;
55750 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
55751 #else
55752 #define dbgp_kgdb_mode (0)
55753 #endif
55754 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
55755 .write_char = kgdbdbgp_write_char,
55756 };
55757
55758 +static struct kgdb_io kgdbdbgp_io_ops_console = {
55759 + .name = "kgdbdbgp",
55760 + .read_char = kgdbdbgp_read_char,
55761 + .write_char = kgdbdbgp_write_char,
55762 + .is_console = 1
55763 +};
55764 +
55765 static int kgdbdbgp_wait_time;
55766
55767 static int __init kgdbdbgp_parse_config(char *str)
55768 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
55769 ptr++;
55770 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
55771 }
55772 - kgdb_register_io_module(&kgdbdbgp_io_ops);
55773 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
55774 + if (early_dbgp_console.index != -1)
55775 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
55776 + else
55777 + kgdb_register_io_module(&kgdbdbgp_io_ops);
55778
55779 return 0;
55780 }
55781 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
55782 index 2b4c82d..06a8ee6 100644
55783 --- a/drivers/usb/gadget/f_uac1.c
55784 +++ b/drivers/usb/gadget/f_uac1.c
55785 @@ -13,6 +13,7 @@
55786 #include <linux/kernel.h>
55787 #include <linux/device.h>
55788 #include <linux/atomic.h>
55789 +#include <linux/module.h>
55790
55791 #include "u_uac1.h"
55792
55793 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
55794 index ad0aca8..8ff84865 100644
55795 --- a/drivers/usb/gadget/u_serial.c
55796 +++ b/drivers/usb/gadget/u_serial.c
55797 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55798 spin_lock_irq(&port->port_lock);
55799
55800 /* already open? Great. */
55801 - if (port->port.count) {
55802 + if (atomic_read(&port->port.count)) {
55803 status = 0;
55804 - port->port.count++;
55805 + atomic_inc(&port->port.count);
55806
55807 /* currently opening/closing? wait ... */
55808 } else if (port->openclose) {
55809 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
55810 tty->driver_data = port;
55811 port->port.tty = tty;
55812
55813 - port->port.count = 1;
55814 + atomic_set(&port->port.count, 1);
55815 port->openclose = false;
55816
55817 /* if connected, start the I/O stream */
55818 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55819
55820 spin_lock_irq(&port->port_lock);
55821
55822 - if (port->port.count != 1) {
55823 - if (port->port.count == 0)
55824 + if (atomic_read(&port->port.count) != 1) {
55825 + if (atomic_read(&port->port.count) == 0)
55826 WARN_ON(1);
55827 else
55828 - --port->port.count;
55829 + atomic_dec(&port->port.count);
55830 goto exit;
55831 }
55832
55833 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
55834 * and sleep if necessary
55835 */
55836 port->openclose = true;
55837 - port->port.count = 0;
55838 + atomic_set(&port->port.count, 0);
55839
55840 gser = port->port_usb;
55841 if (gser && gser->disconnect)
55842 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
55843 int cond;
55844
55845 spin_lock_irq(&port->port_lock);
55846 - cond = (port->port.count == 0) && !port->openclose;
55847 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
55848 spin_unlock_irq(&port->port_lock);
55849 return cond;
55850 }
55851 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
55852 /* if it's already open, start I/O ... and notify the serial
55853 * protocol about open/close status (connect/disconnect).
55854 */
55855 - if (port->port.count) {
55856 + if (atomic_read(&port->port.count)) {
55857 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
55858 gs_start_io(port);
55859 if (gser->connect)
55860 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
55861
55862 port->port_usb = NULL;
55863 gser->ioport = NULL;
55864 - if (port->port.count > 0 || port->openclose) {
55865 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
55866 wake_up_interruptible(&port->drain_wait);
55867 if (port->port.tty)
55868 tty_hangup(port->port.tty);
55869 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
55870
55871 /* finally, free any unused/unusable I/O buffers */
55872 spin_lock_irqsave(&port->port_lock, flags);
55873 - if (port->port.count == 0 && !port->openclose)
55874 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
55875 gs_buf_free(&port->port_write_buf);
55876 gs_free_requests(gser->out, &port->read_pool, NULL);
55877 gs_free_requests(gser->out, &port->read_queue, NULL);
55878 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
55879 index 7a55fea..cc0ed4f 100644
55880 --- a/drivers/usb/gadget/u_uac1.c
55881 +++ b/drivers/usb/gadget/u_uac1.c
55882 @@ -16,6 +16,7 @@
55883 #include <linux/ctype.h>
55884 #include <linux/random.h>
55885 #include <linux/syscalls.h>
55886 +#include <linux/module.h>
55887
55888 #include "u_uac1.h"
55889
55890 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
55891 index 6130b75..3b60008 100644
55892 --- a/drivers/usb/host/ehci-hub.c
55893 +++ b/drivers/usb/host/ehci-hub.c
55894 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
55895 urb->transfer_flags = URB_DIR_IN;
55896 usb_get_urb(urb);
55897 atomic_inc(&urb->use_count);
55898 - atomic_inc(&urb->dev->urbnum);
55899 + atomic_inc_unchecked(&urb->dev->urbnum);
55900 urb->setup_dma = dma_map_single(
55901 hcd->self.controller,
55902 urb->setup_packet,
55903 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
55904 urb->status = -EINPROGRESS;
55905 usb_get_urb(urb);
55906 atomic_inc(&urb->use_count);
55907 - atomic_inc(&urb->dev->urbnum);
55908 + atomic_inc_unchecked(&urb->dev->urbnum);
55909 retval = submit_single_step_set_feature(hcd, urb, 0);
55910 if (!retval && !wait_for_completion_timeout(&done,
55911 msecs_to_jiffies(2000))) {
55912 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
55913 index d0d8fad..668ef7b 100644
55914 --- a/drivers/usb/host/hwa-hc.c
55915 +++ b/drivers/usb/host/hwa-hc.c
55916 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55917 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
55918 struct wahc *wa = &hwahc->wa;
55919 struct device *dev = &wa->usb_iface->dev;
55920 - u8 mas_le[UWB_NUM_MAS/8];
55921 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
55922 +
55923 + if (mas_le == NULL)
55924 + return -ENOMEM;
55925
55926 /* Set the stream index */
55927 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
55928 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55929 WUSB_REQ_SET_WUSB_MAS,
55930 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
55931 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
55932 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
55933 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55934 if (result < 0)
55935 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55936 out:
55937 + kfree(mas_le);
55938 +
55939 return result;
55940 }
55941
55942 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55943 index b3d245e..99549ed 100644
55944 --- a/drivers/usb/misc/appledisplay.c
55945 +++ b/drivers/usb/misc/appledisplay.c
55946 @@ -84,7 +84,7 @@ struct appledisplay {
55947 struct mutex sysfslock; /* concurrent read and write */
55948 };
55949
55950 -static atomic_t count_displays = ATOMIC_INIT(0);
55951 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55952 static struct workqueue_struct *wq;
55953
55954 static void appledisplay_complete(struct urb *urb)
55955 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55956
55957 /* Register backlight device */
55958 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55959 - atomic_inc_return(&count_displays) - 1);
55960 + atomic_inc_return_unchecked(&count_displays) - 1);
55961 memset(&props, 0, sizeof(struct backlight_properties));
55962 props.type = BACKLIGHT_RAW;
55963 props.max_brightness = 0xff;
55964 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55965 index 8d7fc48..01c4986 100644
55966 --- a/drivers/usb/serial/console.c
55967 +++ b/drivers/usb/serial/console.c
55968 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55969
55970 info->port = port;
55971
55972 - ++port->port.count;
55973 + atomic_inc(&port->port.count);
55974 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55975 if (serial->type->set_termios) {
55976 /*
55977 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55978 }
55979 /* Now that any required fake tty operations are completed restore
55980 * the tty port count */
55981 - --port->port.count;
55982 + atomic_dec(&port->port.count);
55983 /* The console is special in terms of closing the device so
55984 * indicate this port is now acting as a system console. */
55985 port->port.console = 1;
55986 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55987 free_tty:
55988 kfree(tty);
55989 reset_open_count:
55990 - port->port.count = 0;
55991 + atomic_set(&port->port.count, 0);
55992 usb_autopm_put_interface(serial->interface);
55993 error_get_interface:
55994 usb_serial_put(serial);
55995 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55996 static void usb_console_write(struct console *co,
55997 const char *buf, unsigned count)
55998 {
55999 - static struct usbcons_info *info = &usbcons_info;
56000 + struct usbcons_info *info = &usbcons_info;
56001 struct usb_serial_port *port = info->port;
56002 struct usb_serial *serial;
56003 int retval = -ENODEV;
56004 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
56005 index 307e339..6aa97cb 100644
56006 --- a/drivers/usb/storage/usb.h
56007 +++ b/drivers/usb/storage/usb.h
56008 @@ -63,7 +63,7 @@ struct us_unusual_dev {
56009 __u8 useProtocol;
56010 __u8 useTransport;
56011 int (*initFunction)(struct us_data *);
56012 -};
56013 +} __do_const;
56014
56015
56016 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
56017 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
56018 index f2a8d29..7bc3fe7 100644
56019 --- a/drivers/usb/wusbcore/wa-hc.h
56020 +++ b/drivers/usb/wusbcore/wa-hc.h
56021 @@ -240,7 +240,7 @@ struct wahc {
56022 spinlock_t xfer_list_lock;
56023 struct work_struct xfer_enqueue_work;
56024 struct work_struct xfer_error_work;
56025 - atomic_t xfer_id_count;
56026 + atomic_unchecked_t xfer_id_count;
56027
56028 kernel_ulong_t quirks;
56029 };
56030 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
56031 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
56032 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
56033 wa->dto_in_use = 0;
56034 - atomic_set(&wa->xfer_id_count, 1);
56035 + atomic_set_unchecked(&wa->xfer_id_count, 1);
56036 /* init the buf in URBs */
56037 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
56038 usb_init_urb(&(wa->buf_in_urbs[index]));
56039 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
56040 index 3e2e4ed..060c9b8 100644
56041 --- a/drivers/usb/wusbcore/wa-xfer.c
56042 +++ b/drivers/usb/wusbcore/wa-xfer.c
56043 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
56044 */
56045 static void wa_xfer_id_init(struct wa_xfer *xfer)
56046 {
56047 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
56048 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
56049 }
56050
56051 /* Return the xfer's ID. */
56052 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
56053 index f018d8d..ccab63f 100644
56054 --- a/drivers/vfio/vfio.c
56055 +++ b/drivers/vfio/vfio.c
56056 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
56057 return 0;
56058
56059 /* TODO Prevent device auto probing */
56060 - WARN("Device %s added to live group %d!\n", dev_name(dev),
56061 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
56062 iommu_group_id(group->iommu_group));
56063
56064 return 0;
56065 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
56066 index 5174eba..451e6bc 100644
56067 --- a/drivers/vhost/vringh.c
56068 +++ b/drivers/vhost/vringh.c
56069 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
56070 /* Userspace access helpers: in this case, addresses are really userspace. */
56071 static inline int getu16_user(u16 *val, const u16 *p)
56072 {
56073 - return get_user(*val, (__force u16 __user *)p);
56074 + return get_user(*val, (u16 __force_user *)p);
56075 }
56076
56077 static inline int putu16_user(u16 *p, u16 val)
56078 {
56079 - return put_user(val, (__force u16 __user *)p);
56080 + return put_user(val, (u16 __force_user *)p);
56081 }
56082
56083 static inline int copydesc_user(void *dst, const void *src, size_t len)
56084 {
56085 - return copy_from_user(dst, (__force void __user *)src, len) ?
56086 + return copy_from_user(dst, (void __force_user *)src, len) ?
56087 -EFAULT : 0;
56088 }
56089
56090 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
56091 const struct vring_used_elem *src,
56092 unsigned int num)
56093 {
56094 - return copy_to_user((__force void __user *)dst, src,
56095 + return copy_to_user((void __force_user *)dst, src,
56096 sizeof(*dst) * num) ? -EFAULT : 0;
56097 }
56098
56099 static inline int xfer_from_user(void *src, void *dst, size_t len)
56100 {
56101 - return copy_from_user(dst, (__force void __user *)src, len) ?
56102 + return copy_from_user(dst, (void __force_user *)src, len) ?
56103 -EFAULT : 0;
56104 }
56105
56106 static inline int xfer_to_user(void *dst, void *src, size_t len)
56107 {
56108 - return copy_to_user((__force void __user *)dst, src, len) ?
56109 + return copy_to_user((void __force_user *)dst, src, len) ?
56110 -EFAULT : 0;
56111 }
56112
56113 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
56114 vrh->last_used_idx = 0;
56115 vrh->vring.num = num;
56116 /* vring expects kernel addresses, but only used via accessors. */
56117 - vrh->vring.desc = (__force struct vring_desc *)desc;
56118 - vrh->vring.avail = (__force struct vring_avail *)avail;
56119 - vrh->vring.used = (__force struct vring_used *)used;
56120 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
56121 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
56122 + vrh->vring.used = (__force_kernel struct vring_used *)used;
56123 return 0;
56124 }
56125 EXPORT_SYMBOL(vringh_init_user);
56126 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
56127
56128 static inline int putu16_kern(u16 *p, u16 val)
56129 {
56130 - ACCESS_ONCE(*p) = val;
56131 + ACCESS_ONCE_RW(*p) = val;
56132 return 0;
56133 }
56134
56135 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
56136 index 84a110a..96312c3 100644
56137 --- a/drivers/video/backlight/kb3886_bl.c
56138 +++ b/drivers/video/backlight/kb3886_bl.c
56139 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
56140 static unsigned long kb3886bl_flags;
56141 #define KB3886BL_SUSPENDED 0x01
56142
56143 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
56144 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
56145 {
56146 .ident = "Sahara Touch-iT",
56147 .matches = {
56148 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
56149 index 1b0b233..6f34c2c 100644
56150 --- a/drivers/video/fbdev/arcfb.c
56151 +++ b/drivers/video/fbdev/arcfb.c
56152 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
56153 return -ENOSPC;
56154
56155 err = 0;
56156 - if ((count + p) > fbmemlength) {
56157 + if (count > (fbmemlength - p)) {
56158 count = fbmemlength - p;
56159 err = -ENOSPC;
56160 }
56161 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
56162 index 52108be..c7c110d 100644
56163 --- a/drivers/video/fbdev/aty/aty128fb.c
56164 +++ b/drivers/video/fbdev/aty/aty128fb.c
56165 @@ -149,7 +149,7 @@ enum {
56166 };
56167
56168 /* Must match above enum */
56169 -static char * const r128_family[] = {
56170 +static const char * const r128_family[] = {
56171 "AGP",
56172 "PCI",
56173 "PRO AGP",
56174 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
56175 index c3d0074..0b9077e 100644
56176 --- a/drivers/video/fbdev/aty/atyfb_base.c
56177 +++ b/drivers/video/fbdev/aty/atyfb_base.c
56178 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
56179 par->accel_flags = var->accel_flags; /* hack */
56180
56181 if (var->accel_flags) {
56182 - info->fbops->fb_sync = atyfb_sync;
56183 + pax_open_kernel();
56184 + *(void **)&info->fbops->fb_sync = atyfb_sync;
56185 + pax_close_kernel();
56186 info->flags &= ~FBINFO_HWACCEL_DISABLED;
56187 } else {
56188 - info->fbops->fb_sync = NULL;
56189 + pax_open_kernel();
56190 + *(void **)&info->fbops->fb_sync = NULL;
56191 + pax_close_kernel();
56192 info->flags |= FBINFO_HWACCEL_DISABLED;
56193 }
56194
56195 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
56196 index 2fa0317..4983f2a 100644
56197 --- a/drivers/video/fbdev/aty/mach64_cursor.c
56198 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
56199 @@ -8,6 +8,7 @@
56200 #include "../core/fb_draw.h"
56201
56202 #include <asm/io.h>
56203 +#include <asm/pgtable.h>
56204
56205 #ifdef __sparc__
56206 #include <asm/fbio.h>
56207 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
56208 info->sprite.buf_align = 16; /* and 64 lines tall. */
56209 info->sprite.flags = FB_PIXMAP_IO;
56210
56211 - info->fbops->fb_cursor = atyfb_cursor;
56212 + pax_open_kernel();
56213 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
56214 + pax_close_kernel();
56215
56216 return 0;
56217 }
56218 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
56219 index 900aa4e..6d49418 100644
56220 --- a/drivers/video/fbdev/core/fb_defio.c
56221 +++ b/drivers/video/fbdev/core/fb_defio.c
56222 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
56223
56224 BUG_ON(!fbdefio);
56225 mutex_init(&fbdefio->lock);
56226 - info->fbops->fb_mmap = fb_deferred_io_mmap;
56227 + pax_open_kernel();
56228 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
56229 + pax_close_kernel();
56230 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
56231 INIT_LIST_HEAD(&fbdefio->pagelist);
56232 if (fbdefio->delay == 0) /* set a default of 1 s */
56233 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
56234 page->mapping = NULL;
56235 }
56236
56237 - info->fbops->fb_mmap = NULL;
56238 + *(void **)&info->fbops->fb_mmap = NULL;
56239 mutex_destroy(&fbdefio->lock);
56240 }
56241 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
56242 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
56243 index b5e85f6..290f8c7 100644
56244 --- a/drivers/video/fbdev/core/fbmem.c
56245 +++ b/drivers/video/fbdev/core/fbmem.c
56246 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
56247 __u32 data;
56248 int err;
56249
56250 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
56251 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
56252
56253 data = (__u32) (unsigned long) fix->smem_start;
56254 err |= put_user(data, &fix32->smem_start);
56255 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
56256 index e23392e..8a77540 100644
56257 --- a/drivers/video/fbdev/hyperv_fb.c
56258 +++ b/drivers/video/fbdev/hyperv_fb.c
56259 @@ -235,7 +235,7 @@ static uint screen_fb_size;
56260 static inline int synthvid_send(struct hv_device *hdev,
56261 struct synthvid_msg *msg)
56262 {
56263 - static atomic64_t request_id = ATOMIC64_INIT(0);
56264 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
56265 int ret;
56266
56267 msg->pipe_hdr.type = PIPE_MSG_DATA;
56268 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
56269
56270 ret = vmbus_sendpacket(hdev->channel, msg,
56271 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
56272 - atomic64_inc_return(&request_id),
56273 + atomic64_inc_return_unchecked(&request_id),
56274 VM_PKT_DATA_INBAND, 0);
56275
56276 if (ret)
56277 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
56278 index 7672d2e..b56437f 100644
56279 --- a/drivers/video/fbdev/i810/i810_accel.c
56280 +++ b/drivers/video/fbdev/i810/i810_accel.c
56281 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
56282 }
56283 }
56284 printk("ringbuffer lockup!!!\n");
56285 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
56286 i810_report_error(mmio);
56287 par->dev_flags |= LOCKUP;
56288 info->pixmap.scan_align = 1;
56289 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
56290 index a01147f..5d896f8 100644
56291 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
56292 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
56293 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
56294
56295 #ifdef CONFIG_FB_MATROX_MYSTIQUE
56296 struct matrox_switch matrox_mystique = {
56297 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
56298 + .preinit = MGA1064_preinit,
56299 + .reset = MGA1064_reset,
56300 + .init = MGA1064_init,
56301 + .restore = MGA1064_restore,
56302 };
56303 EXPORT_SYMBOL(matrox_mystique);
56304 #endif
56305
56306 #ifdef CONFIG_FB_MATROX_G
56307 struct matrox_switch matrox_G100 = {
56308 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
56309 + .preinit = MGAG100_preinit,
56310 + .reset = MGAG100_reset,
56311 + .init = MGAG100_init,
56312 + .restore = MGAG100_restore,
56313 };
56314 EXPORT_SYMBOL(matrox_G100);
56315 #endif
56316 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
56317 index 195ad7c..09743fc 100644
56318 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
56319 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
56320 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
56321 }
56322
56323 struct matrox_switch matrox_millennium = {
56324 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
56325 + .preinit = Ti3026_preinit,
56326 + .reset = Ti3026_reset,
56327 + .init = Ti3026_init,
56328 + .restore = Ti3026_restore
56329 };
56330 EXPORT_SYMBOL(matrox_millennium);
56331 #endif
56332 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
56333 index fe92eed..106e085 100644
56334 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
56335 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
56336 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
56337 struct mb862xxfb_par *par = info->par;
56338
56339 if (info->var.bits_per_pixel == 32) {
56340 - info->fbops->fb_fillrect = cfb_fillrect;
56341 - info->fbops->fb_copyarea = cfb_copyarea;
56342 - info->fbops->fb_imageblit = cfb_imageblit;
56343 + pax_open_kernel();
56344 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
56345 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
56346 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
56347 + pax_close_kernel();
56348 } else {
56349 outreg(disp, GC_L0EM, 3);
56350 - info->fbops->fb_fillrect = mb86290fb_fillrect;
56351 - info->fbops->fb_copyarea = mb86290fb_copyarea;
56352 - info->fbops->fb_imageblit = mb86290fb_imageblit;
56353 + pax_open_kernel();
56354 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
56355 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
56356 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
56357 + pax_close_kernel();
56358 }
56359 outreg(draw, GDC_REG_DRAW_BASE, 0);
56360 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
56361 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
56362 index def0412..fed6529 100644
56363 --- a/drivers/video/fbdev/nvidia/nvidia.c
56364 +++ b/drivers/video/fbdev/nvidia/nvidia.c
56365 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
56366 info->fix.line_length = (info->var.xres_virtual *
56367 info->var.bits_per_pixel) >> 3;
56368 if (info->var.accel_flags) {
56369 - info->fbops->fb_imageblit = nvidiafb_imageblit;
56370 - info->fbops->fb_fillrect = nvidiafb_fillrect;
56371 - info->fbops->fb_copyarea = nvidiafb_copyarea;
56372 - info->fbops->fb_sync = nvidiafb_sync;
56373 + pax_open_kernel();
56374 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
56375 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
56376 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
56377 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
56378 + pax_close_kernel();
56379 info->pixmap.scan_align = 4;
56380 info->flags &= ~FBINFO_HWACCEL_DISABLED;
56381 info->flags |= FBINFO_READS_FAST;
56382 NVResetGraphics(info);
56383 } else {
56384 - info->fbops->fb_imageblit = cfb_imageblit;
56385 - info->fbops->fb_fillrect = cfb_fillrect;
56386 - info->fbops->fb_copyarea = cfb_copyarea;
56387 - info->fbops->fb_sync = NULL;
56388 + pax_open_kernel();
56389 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
56390 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
56391 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
56392 + *(void **)&info->fbops->fb_sync = NULL;
56393 + pax_close_kernel();
56394 info->pixmap.scan_align = 1;
56395 info->flags |= FBINFO_HWACCEL_DISABLED;
56396 info->flags &= ~FBINFO_READS_FAST;
56397 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
56398 info->pixmap.size = 8 * 1024;
56399 info->pixmap.flags = FB_PIXMAP_SYSTEM;
56400
56401 - if (!hwcur)
56402 - info->fbops->fb_cursor = NULL;
56403 + if (!hwcur) {
56404 + pax_open_kernel();
56405 + *(void **)&info->fbops->fb_cursor = NULL;
56406 + pax_close_kernel();
56407 + }
56408
56409 info->var.accel_flags = (!noaccel);
56410
56411 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
56412 index 2412a0d..294215b 100644
56413 --- a/drivers/video/fbdev/omap2/dss/display.c
56414 +++ b/drivers/video/fbdev/omap2/dss/display.c
56415 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
56416 if (dssdev->name == NULL)
56417 dssdev->name = dssdev->alias;
56418
56419 + pax_open_kernel();
56420 if (drv && drv->get_resolution == NULL)
56421 - drv->get_resolution = omapdss_default_get_resolution;
56422 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
56423 if (drv && drv->get_recommended_bpp == NULL)
56424 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56425 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56426 if (drv && drv->get_timings == NULL)
56427 - drv->get_timings = omapdss_default_get_timings;
56428 + *(void **)&drv->get_timings = omapdss_default_get_timings;
56429 + pax_close_kernel();
56430
56431 mutex_lock(&panel_list_mutex);
56432 list_add_tail(&dssdev->panel_list, &panel_list);
56433 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
56434 index 83433cb..71e9b98 100644
56435 --- a/drivers/video/fbdev/s1d13xxxfb.c
56436 +++ b/drivers/video/fbdev/s1d13xxxfb.c
56437 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
56438
56439 switch(prod_id) {
56440 case S1D13506_PROD_ID: /* activate acceleration */
56441 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56442 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56443 + pax_open_kernel();
56444 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56445 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56446 + pax_close_kernel();
56447 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
56448 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
56449 break;
56450 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56451 index 2bcc84a..29dd1ea 100644
56452 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
56453 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
56454 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
56455 }
56456
56457 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
56458 - lcdc_sys_write_index,
56459 - lcdc_sys_write_data,
56460 - lcdc_sys_read_data,
56461 + .write_index = lcdc_sys_write_index,
56462 + .write_data = lcdc_sys_write_data,
56463 + .read_data = lcdc_sys_read_data,
56464 };
56465
56466 static int sh_mobile_lcdc_sginit(struct fb_info *info,
56467 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
56468 index d513ed6..90b0de9 100644
56469 --- a/drivers/video/fbdev/smscufx.c
56470 +++ b/drivers/video/fbdev/smscufx.c
56471 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
56472 fb_deferred_io_cleanup(info);
56473 kfree(info->fbdefio);
56474 info->fbdefio = NULL;
56475 - info->fbops->fb_mmap = ufx_ops_mmap;
56476 + pax_open_kernel();
56477 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
56478 + pax_close_kernel();
56479 }
56480
56481 pr_debug("released /dev/fb%d user=%d count=%d",
56482 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
56483 index 77b890e..458e666 100644
56484 --- a/drivers/video/fbdev/udlfb.c
56485 +++ b/drivers/video/fbdev/udlfb.c
56486 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
56487 dlfb_urb_completion(urb);
56488
56489 error:
56490 - atomic_add(bytes_sent, &dev->bytes_sent);
56491 - atomic_add(bytes_identical, &dev->bytes_identical);
56492 - atomic_add(width*height*2, &dev->bytes_rendered);
56493 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56494 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56495 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56496 end_cycles = get_cycles();
56497 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56498 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56499 >> 10)), /* Kcycles */
56500 &dev->cpu_kcycles_used);
56501
56502 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56503 dlfb_urb_completion(urb);
56504
56505 error:
56506 - atomic_add(bytes_sent, &dev->bytes_sent);
56507 - atomic_add(bytes_identical, &dev->bytes_identical);
56508 - atomic_add(bytes_rendered, &dev->bytes_rendered);
56509 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56510 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56511 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56512 end_cycles = get_cycles();
56513 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56514 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56515 >> 10)), /* Kcycles */
56516 &dev->cpu_kcycles_used);
56517 }
56518 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56519 fb_deferred_io_cleanup(info);
56520 kfree(info->fbdefio);
56521 info->fbdefio = NULL;
56522 - info->fbops->fb_mmap = dlfb_ops_mmap;
56523 + pax_open_kernel();
56524 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56525 + pax_close_kernel();
56526 }
56527
56528 pr_warn("released /dev/fb%d user=%d count=%d\n",
56529 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56530 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56531 struct dlfb_data *dev = fb_info->par;
56532 return snprintf(buf, PAGE_SIZE, "%u\n",
56533 - atomic_read(&dev->bytes_rendered));
56534 + atomic_read_unchecked(&dev->bytes_rendered));
56535 }
56536
56537 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56538 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56539 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56540 struct dlfb_data *dev = fb_info->par;
56541 return snprintf(buf, PAGE_SIZE, "%u\n",
56542 - atomic_read(&dev->bytes_identical));
56543 + atomic_read_unchecked(&dev->bytes_identical));
56544 }
56545
56546 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56547 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56548 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56549 struct dlfb_data *dev = fb_info->par;
56550 return snprintf(buf, PAGE_SIZE, "%u\n",
56551 - atomic_read(&dev->bytes_sent));
56552 + atomic_read_unchecked(&dev->bytes_sent));
56553 }
56554
56555 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56556 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56557 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56558 struct dlfb_data *dev = fb_info->par;
56559 return snprintf(buf, PAGE_SIZE, "%u\n",
56560 - atomic_read(&dev->cpu_kcycles_used));
56561 + atomic_read_unchecked(&dev->cpu_kcycles_used));
56562 }
56563
56564 static ssize_t edid_show(
56565 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56566 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56567 struct dlfb_data *dev = fb_info->par;
56568
56569 - atomic_set(&dev->bytes_rendered, 0);
56570 - atomic_set(&dev->bytes_identical, 0);
56571 - atomic_set(&dev->bytes_sent, 0);
56572 - atomic_set(&dev->cpu_kcycles_used, 0);
56573 + atomic_set_unchecked(&dev->bytes_rendered, 0);
56574 + atomic_set_unchecked(&dev->bytes_identical, 0);
56575 + atomic_set_unchecked(&dev->bytes_sent, 0);
56576 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56577
56578 return count;
56579 }
56580 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
56581 index 509d452..7c9d2de 100644
56582 --- a/drivers/video/fbdev/uvesafb.c
56583 +++ b/drivers/video/fbdev/uvesafb.c
56584 @@ -19,6 +19,7 @@
56585 #include <linux/io.h>
56586 #include <linux/mutex.h>
56587 #include <linux/slab.h>
56588 +#include <linux/moduleloader.h>
56589 #include <video/edid.h>
56590 #include <video/uvesafb.h>
56591 #ifdef CONFIG_X86
56592 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56593 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56594 par->pmi_setpal = par->ypan = 0;
56595 } else {
56596 +
56597 +#ifdef CONFIG_PAX_KERNEXEC
56598 +#ifdef CONFIG_MODULES
56599 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56600 +#endif
56601 + if (!par->pmi_code) {
56602 + par->pmi_setpal = par->ypan = 0;
56603 + return 0;
56604 + }
56605 +#endif
56606 +
56607 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56608 + task->t.regs.edi);
56609 +
56610 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56611 + pax_open_kernel();
56612 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56613 + pax_close_kernel();
56614 +
56615 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56616 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56617 +#else
56618 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56619 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56620 +#endif
56621 +
56622 printk(KERN_INFO "uvesafb: protected mode interface info at "
56623 "%04x:%04x\n",
56624 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56625 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56626 par->ypan = ypan;
56627
56628 if (par->pmi_setpal || par->ypan) {
56629 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56630 if (__supported_pte_mask & _PAGE_NX) {
56631 par->pmi_setpal = par->ypan = 0;
56632 printk(KERN_WARNING "uvesafb: NX protection is active, "
56633 "better not use the PMI.\n");
56634 - } else {
56635 + } else
56636 +#endif
56637 uvesafb_vbe_getpmi(task, par);
56638 - }
56639 }
56640 #else
56641 /* The protected mode interface is not available on non-x86. */
56642 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56643 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56644
56645 /* Disable blanking if the user requested so. */
56646 - if (!blank)
56647 - info->fbops->fb_blank = NULL;
56648 + if (!blank) {
56649 + pax_open_kernel();
56650 + *(void **)&info->fbops->fb_blank = NULL;
56651 + pax_close_kernel();
56652 + }
56653
56654 /*
56655 * Find out how much IO memory is required for the mode with
56656 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56657 info->flags = FBINFO_FLAG_DEFAULT |
56658 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56659
56660 - if (!par->ypan)
56661 - info->fbops->fb_pan_display = NULL;
56662 + if (!par->ypan) {
56663 + pax_open_kernel();
56664 + *(void **)&info->fbops->fb_pan_display = NULL;
56665 + pax_close_kernel();
56666 + }
56667 }
56668
56669 static void uvesafb_init_mtrr(struct fb_info *info)
56670 @@ -1787,6 +1817,11 @@ out_mode:
56671 out:
56672 kfree(par->vbe_modes);
56673
56674 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56675 + if (par->pmi_code)
56676 + module_free_exec(NULL, par->pmi_code);
56677 +#endif
56678 +
56679 framebuffer_release(info);
56680 return err;
56681 }
56682 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
56683 kfree(par->vbe_state_orig);
56684 kfree(par->vbe_state_saved);
56685
56686 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56687 + if (par->pmi_code)
56688 + module_free_exec(NULL, par->pmi_code);
56689 +#endif
56690 +
56691 framebuffer_release(info);
56692 }
56693 return 0;
56694 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
56695 index 6170e7f..dd63031 100644
56696 --- a/drivers/video/fbdev/vesafb.c
56697 +++ b/drivers/video/fbdev/vesafb.c
56698 @@ -9,6 +9,7 @@
56699 */
56700
56701 #include <linux/module.h>
56702 +#include <linux/moduleloader.h>
56703 #include <linux/kernel.h>
56704 #include <linux/errno.h>
56705 #include <linux/string.h>
56706 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56707 static int vram_total; /* Set total amount of memory */
56708 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56709 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56710 -static void (*pmi_start)(void) __read_mostly;
56711 -static void (*pmi_pal) (void) __read_mostly;
56712 +static void (*pmi_start)(void) __read_only;
56713 +static void (*pmi_pal) (void) __read_only;
56714 static int depth __read_mostly;
56715 static int vga_compat __read_mostly;
56716 /* --------------------------------------------------------------------- */
56717 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
56718 unsigned int size_remap;
56719 unsigned int size_total;
56720 char *option = NULL;
56721 + void *pmi_code = NULL;
56722
56723 /* ignore error return of fb_get_options */
56724 fb_get_options("vesafb", &option);
56725 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
56726 size_remap = size_total;
56727 vesafb_fix.smem_len = size_remap;
56728
56729 -#ifndef __i386__
56730 - screen_info.vesapm_seg = 0;
56731 -#endif
56732 -
56733 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56734 printk(KERN_WARNING
56735 "vesafb: cannot reserve video memory at 0x%lx\n",
56736 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56737 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56738 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56739
56740 +#ifdef __i386__
56741 +
56742 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56743 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
56744 + if (!pmi_code)
56745 +#elif !defined(CONFIG_PAX_KERNEXEC)
56746 + if (0)
56747 +#endif
56748 +
56749 +#endif
56750 + screen_info.vesapm_seg = 0;
56751 +
56752 if (screen_info.vesapm_seg) {
56753 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56754 - screen_info.vesapm_seg,screen_info.vesapm_off);
56755 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56756 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56757 }
56758
56759 if (screen_info.vesapm_seg < 0xc000)
56760 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56761
56762 if (ypan || pmi_setpal) {
56763 unsigned short *pmi_base;
56764 +
56765 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56766 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56767 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56768 +
56769 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56770 + pax_open_kernel();
56771 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56772 +#else
56773 + pmi_code = pmi_base;
56774 +#endif
56775 +
56776 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56777 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56778 +
56779 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56780 + pmi_start = ktva_ktla(pmi_start);
56781 + pmi_pal = ktva_ktla(pmi_pal);
56782 + pax_close_kernel();
56783 +#endif
56784 +
56785 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56786 if (pmi_base[3]) {
56787 printk(KERN_INFO "vesafb: pmi: ports = ");
56788 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56789 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56790 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56791
56792 - if (!ypan)
56793 - info->fbops->fb_pan_display = NULL;
56794 + if (!ypan) {
56795 + pax_open_kernel();
56796 + *(void **)&info->fbops->fb_pan_display = NULL;
56797 + pax_close_kernel();
56798 + }
56799
56800 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56801 err = -ENOMEM;
56802 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56803 fb_info(info, "%s frame buffer device\n", info->fix.id);
56804 return 0;
56805 err:
56806 +
56807 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56808 + module_free_exec(NULL, pmi_code);
56809 +#endif
56810 +
56811 if (info->screen_base)
56812 iounmap(info->screen_base);
56813 framebuffer_release(info);
56814 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
56815 index 88714ae..16c2e11 100644
56816 --- a/drivers/video/fbdev/via/via_clock.h
56817 +++ b/drivers/video/fbdev/via/via_clock.h
56818 @@ -56,7 +56,7 @@ struct via_clock {
56819
56820 void (*set_engine_pll_state)(u8 state);
56821 void (*set_engine_pll)(struct via_pll_config config);
56822 -};
56823 +} __no_const;
56824
56825
56826 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56827 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
56828 index 3c14e43..2630570 100644
56829 --- a/drivers/video/logo/logo_linux_clut224.ppm
56830 +++ b/drivers/video/logo/logo_linux_clut224.ppm
56831 @@ -2,1603 +2,1123 @@ P3
56832 # Standard 224-color Linux logo
56833 80 80
56834 255
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 0 0 0 0 0 0 0 0 0 0 0 0
56837 - 0 0 0 0 0 0 0 0 0 0 0 0
56838 - 0 0 0 0 0 0 0 0 0 0 0 0
56839 - 0 0 0 0 0 0 0 0 0 0 0 0
56840 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 6 6 6 10 10 10 10 10 10
56845 - 10 10 10 6 6 6 6 6 6 6 6 6
56846 - 0 0 0 0 0 0 0 0 0 0 0 0
56847 - 0 0 0 0 0 0 0 0 0 0 0 0
56848 - 0 0 0 0 0 0 0 0 0 0 0 0
56849 - 0 0 0 0 0 0 0 0 0 0 0 0
56850 - 0 0 0 0 0 0 0 0 0 0 0 0
56851 - 0 0 0 0 0 0 0 0 0 0 0 0
56852 - 0 0 0 0 0 0 0 0 0 0 0 0
56853 - 0 0 0 0 0 0 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 0 0 0
56855 - 0 0 0 0 0 0 0 0 0 0 0 0
56856 - 0 0 0 0 0 0 0 0 0 0 0 0
56857 - 0 0 0 0 0 0 0 0 0 0 0 0
56858 - 0 0 0 0 0 0 0 0 0 0 0 0
56859 - 0 0 0 0 0 0 0 0 0 0 0 0
56860 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
56864 - 22 22 22 26 26 26 30 30 30 34 34 34
56865 - 30 30 30 30 30 30 26 26 26 18 18 18
56866 - 14 14 14 10 10 10 6 6 6 0 0 0
56867 - 0 0 0 0 0 0 0 0 0 0 0 0
56868 - 0 0 0 0 0 0 0 0 0 0 0 0
56869 - 0 0 0 0 0 0 0 0 0 0 0 0
56870 - 0 0 0 0 0 0 0 0 0 0 0 0
56871 - 0 0 0 0 0 0 0 0 0 0 0 0
56872 - 0 0 0 0 0 0 0 0 0 0 0 0
56873 - 0 0 0 0 0 0 0 0 0 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 0 0 0
56875 - 0 0 0 0 0 0 0 0 0 0 0 0
56876 - 0 0 0 0 0 1 0 0 1 0 0 0
56877 - 0 0 0 0 0 0 0 0 0 0 0 0
56878 - 0 0 0 0 0 0 0 0 0 0 0 0
56879 - 0 0 0 0 0 0 0 0 0 0 0 0
56880 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 26 26 26 42 42 42
56884 - 54 54 54 66 66 66 78 78 78 78 78 78
56885 - 78 78 78 74 74 74 66 66 66 54 54 54
56886 - 42 42 42 26 26 26 18 18 18 10 10 10
56887 - 6 6 6 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 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 1 0 0 0 0 0 0 0 0 0
56897 - 0 0 0 0 0 0 0 0 0 0 0 0
56898 - 0 0 0 0 0 0 0 0 0 0 0 0
56899 - 0 0 0 0 0 0 0 0 0 0 0 0
56900 - 0 0 0 0 0 0 0 0 0 0 0 0
56901 - 0 0 0 0 0 0 0 0 0 0 0 0
56902 - 0 0 0 0 0 0 0 0 0 10 10 10
56903 - 22 22 22 42 42 42 66 66 66 86 86 86
56904 - 66 66 66 38 38 38 38 38 38 22 22 22
56905 - 26 26 26 34 34 34 54 54 54 66 66 66
56906 - 86 86 86 70 70 70 46 46 46 26 26 26
56907 - 14 14 14 6 6 6 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 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 0 0 0
56915 - 0 0 0 0 0 0 0 0 0 0 0 0
56916 - 0 0 1 0 0 1 0 0 1 0 0 0
56917 - 0 0 0 0 0 0 0 0 0 0 0 0
56918 - 0 0 0 0 0 0 0 0 0 0 0 0
56919 - 0 0 0 0 0 0 0 0 0 0 0 0
56920 - 0 0 0 0 0 0 0 0 0 0 0 0
56921 - 0 0 0 0 0 0 0 0 0 0 0 0
56922 - 0 0 0 0 0 0 10 10 10 26 26 26
56923 - 50 50 50 82 82 82 58 58 58 6 6 6
56924 - 2 2 6 2 2 6 2 2 6 2 2 6
56925 - 2 2 6 2 2 6 2 2 6 2 2 6
56926 - 6 6 6 54 54 54 86 86 86 66 66 66
56927 - 38 38 38 18 18 18 6 6 6 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 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 0 0 0
56935 - 0 0 0 0 0 0 0 0 0 0 0 0
56936 - 0 0 0 0 0 0 0 0 0 0 0 0
56937 - 0 0 0 0 0 0 0 0 0 0 0 0
56938 - 0 0 0 0 0 0 0 0 0 0 0 0
56939 - 0 0 0 0 0 0 0 0 0 0 0 0
56940 - 0 0 0 0 0 0 0 0 0 0 0 0
56941 - 0 0 0 0 0 0 0 0 0 0 0 0
56942 - 0 0 0 6 6 6 22 22 22 50 50 50
56943 - 78 78 78 34 34 34 2 2 6 2 2 6
56944 - 2 2 6 2 2 6 2 2 6 2 2 6
56945 - 2 2 6 2 2 6 2 2 6 2 2 6
56946 - 2 2 6 2 2 6 6 6 6 70 70 70
56947 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 0 0 0
56955 - 0 0 0 0 0 0 0 0 0 0 0 0
56956 - 0 0 1 0 0 1 0 0 1 0 0 0
56957 - 0 0 0 0 0 0 0 0 0 0 0 0
56958 - 0 0 0 0 0 0 0 0 0 0 0 0
56959 - 0 0 0 0 0 0 0 0 0 0 0 0
56960 - 0 0 0 0 0 0 0 0 0 0 0 0
56961 - 0 0 0 0 0 0 0 0 0 0 0 0
56962 - 6 6 6 18 18 18 42 42 42 82 82 82
56963 - 26 26 26 2 2 6 2 2 6 2 2 6
56964 - 2 2 6 2 2 6 2 2 6 2 2 6
56965 - 2 2 6 2 2 6 2 2 6 14 14 14
56966 - 46 46 46 34 34 34 6 6 6 2 2 6
56967 - 42 42 42 78 78 78 42 42 42 18 18 18
56968 - 6 6 6 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 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 0 0 0
56975 - 0 0 0 0 0 0 0 0 0 0 0 0
56976 - 0 0 1 0 0 0 0 0 1 0 0 0
56977 - 0 0 0 0 0 0 0 0 0 0 0 0
56978 - 0 0 0 0 0 0 0 0 0 0 0 0
56979 - 0 0 0 0 0 0 0 0 0 0 0 0
56980 - 0 0 0 0 0 0 0 0 0 0 0 0
56981 - 0 0 0 0 0 0 0 0 0 0 0 0
56982 - 10 10 10 30 30 30 66 66 66 58 58 58
56983 - 2 2 6 2 2 6 2 2 6 2 2 6
56984 - 2 2 6 2 2 6 2 2 6 2 2 6
56985 - 2 2 6 2 2 6 2 2 6 26 26 26
56986 - 86 86 86 101 101 101 46 46 46 10 10 10
56987 - 2 2 6 58 58 58 70 70 70 34 34 34
56988 - 10 10 10 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 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 0 0 0
56995 - 0 0 0 0 0 0 0 0 0 0 0 0
56996 - 0 0 1 0 0 1 0 0 1 0 0 0
56997 - 0 0 0 0 0 0 0 0 0 0 0 0
56998 - 0 0 0 0 0 0 0 0 0 0 0 0
56999 - 0 0 0 0 0 0 0 0 0 0 0 0
57000 - 0 0 0 0 0 0 0 0 0 0 0 0
57001 - 0 0 0 0 0 0 0 0 0 0 0 0
57002 - 14 14 14 42 42 42 86 86 86 10 10 10
57003 - 2 2 6 2 2 6 2 2 6 2 2 6
57004 - 2 2 6 2 2 6 2 2 6 2 2 6
57005 - 2 2 6 2 2 6 2 2 6 30 30 30
57006 - 94 94 94 94 94 94 58 58 58 26 26 26
57007 - 2 2 6 6 6 6 78 78 78 54 54 54
57008 - 22 22 22 6 6 6 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 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 0 0 0
57015 - 0 0 0 0 0 0 0 0 0 0 0 0
57016 - 0 0 0 0 0 0 0 0 0 0 0 0
57017 - 0 0 0 0 0 0 0 0 0 0 0 0
57018 - 0 0 0 0 0 0 0 0 0 0 0 0
57019 - 0 0 0 0 0 0 0 0 0 0 0 0
57020 - 0 0 0 0 0 0 0 0 0 0 0 0
57021 - 0 0 0 0 0 0 0 0 0 6 6 6
57022 - 22 22 22 62 62 62 62 62 62 2 2 6
57023 - 2 2 6 2 2 6 2 2 6 2 2 6
57024 - 2 2 6 2 2 6 2 2 6 2 2 6
57025 - 2 2 6 2 2 6 2 2 6 26 26 26
57026 - 54 54 54 38 38 38 18 18 18 10 10 10
57027 - 2 2 6 2 2 6 34 34 34 82 82 82
57028 - 38 38 38 14 14 14 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 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 0 0 0 0 0 0
57035 - 0 0 0 0 0 0 0 0 0 0 0 0
57036 - 0 0 0 0 0 1 0 0 1 0 0 0
57037 - 0 0 0 0 0 0 0 0 0 0 0 0
57038 - 0 0 0 0 0 0 0 0 0 0 0 0
57039 - 0 0 0 0 0 0 0 0 0 0 0 0
57040 - 0 0 0 0 0 0 0 0 0 0 0 0
57041 - 0 0 0 0 0 0 0 0 0 6 6 6
57042 - 30 30 30 78 78 78 30 30 30 2 2 6
57043 - 2 2 6 2 2 6 2 2 6 2 2 6
57044 - 2 2 6 2 2 6 2 2 6 2 2 6
57045 - 2 2 6 2 2 6 2 2 6 10 10 10
57046 - 10 10 10 2 2 6 2 2 6 2 2 6
57047 - 2 2 6 2 2 6 2 2 6 78 78 78
57048 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 0 0 0 0 0 0
57055 - 0 0 0 0 0 0 0 0 0 0 0 0
57056 - 0 0 1 0 0 0 0 0 0 0 0 0
57057 - 0 0 0 0 0 0 0 0 0 0 0 0
57058 - 0 0 0 0 0 0 0 0 0 0 0 0
57059 - 0 0 0 0 0 0 0 0 0 0 0 0
57060 - 0 0 0 0 0 0 0 0 0 0 0 0
57061 - 0 0 0 0 0 0 0 0 0 10 10 10
57062 - 38 38 38 86 86 86 14 14 14 2 2 6
57063 - 2 2 6 2 2 6 2 2 6 2 2 6
57064 - 2 2 6 2 2 6 2 2 6 2 2 6
57065 - 2 2 6 2 2 6 2 2 6 2 2 6
57066 - 2 2 6 2 2 6 2 2 6 2 2 6
57067 - 2 2 6 2 2 6 2 2 6 54 54 54
57068 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 0 0 0 0 0 0 0 0 0
57075 - 0 0 0 0 0 0 0 0 0 0 0 0
57076 - 0 0 0 0 0 1 0 0 1 0 0 0
57077 - 0 0 0 0 0 0 0 0 0 0 0 0
57078 - 0 0 0 0 0 0 0 0 0 0 0 0
57079 - 0 0 0 0 0 0 0 0 0 0 0 0
57080 - 0 0 0 0 0 0 0 0 0 0 0 0
57081 - 0 0 0 0 0 0 0 0 0 14 14 14
57082 - 42 42 42 82 82 82 2 2 6 2 2 6
57083 - 2 2 6 6 6 6 10 10 10 2 2 6
57084 - 2 2 6 2 2 6 2 2 6 2 2 6
57085 - 2 2 6 2 2 6 2 2 6 6 6 6
57086 - 14 14 14 10 10 10 2 2 6 2 2 6
57087 - 2 2 6 2 2 6 2 2 6 18 18 18
57088 - 82 82 82 34 34 34 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 0 0 0 0 0 0 0 0 0 0 0 0
57095 - 0 0 0 0 0 0 0 0 0 0 0 0
57096 - 0 0 1 0 0 0 0 0 0 0 0 0
57097 - 0 0 0 0 0 0 0 0 0 0 0 0
57098 - 0 0 0 0 0 0 0 0 0 0 0 0
57099 - 0 0 0 0 0 0 0 0 0 0 0 0
57100 - 0 0 0 0 0 0 0 0 0 0 0 0
57101 - 0 0 0 0 0 0 0 0 0 14 14 14
57102 - 46 46 46 86 86 86 2 2 6 2 2 6
57103 - 6 6 6 6 6 6 22 22 22 34 34 34
57104 - 6 6 6 2 2 6 2 2 6 2 2 6
57105 - 2 2 6 2 2 6 18 18 18 34 34 34
57106 - 10 10 10 50 50 50 22 22 22 2 2 6
57107 - 2 2 6 2 2 6 2 2 6 10 10 10
57108 - 86 86 86 42 42 42 14 14 14 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 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 0 0 0
57114 - 0 0 0 0 0 0 0 0 0 0 0 0
57115 - 0 0 0 0 0 0 0 0 0 0 0 0
57116 - 0 0 1 0 0 1 0 0 1 0 0 0
57117 - 0 0 0 0 0 0 0 0 0 0 0 0
57118 - 0 0 0 0 0 0 0 0 0 0 0 0
57119 - 0 0 0 0 0 0 0 0 0 0 0 0
57120 - 0 0 0 0 0 0 0 0 0 0 0 0
57121 - 0 0 0 0 0 0 0 0 0 14 14 14
57122 - 46 46 46 86 86 86 2 2 6 2 2 6
57123 - 38 38 38 116 116 116 94 94 94 22 22 22
57124 - 22 22 22 2 2 6 2 2 6 2 2 6
57125 - 14 14 14 86 86 86 138 138 138 162 162 162
57126 -154 154 154 38 38 38 26 26 26 6 6 6
57127 - 2 2 6 2 2 6 2 2 6 2 2 6
57128 - 86 86 86 46 46 46 14 14 14 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 0 0 0
57133 - 0 0 0 0 0 0 0 0 0 0 0 0
57134 - 0 0 0 0 0 0 0 0 0 0 0 0
57135 - 0 0 0 0 0 0 0 0 0 0 0 0
57136 - 0 0 0 0 0 0 0 0 0 0 0 0
57137 - 0 0 0 0 0 0 0 0 0 0 0 0
57138 - 0 0 0 0 0 0 0 0 0 0 0 0
57139 - 0 0 0 0 0 0 0 0 0 0 0 0
57140 - 0 0 0 0 0 0 0 0 0 0 0 0
57141 - 0 0 0 0 0 0 0 0 0 14 14 14
57142 - 46 46 46 86 86 86 2 2 6 14 14 14
57143 -134 134 134 198 198 198 195 195 195 116 116 116
57144 - 10 10 10 2 2 6 2 2 6 6 6 6
57145 -101 98 89 187 187 187 210 210 210 218 218 218
57146 -214 214 214 134 134 134 14 14 14 6 6 6
57147 - 2 2 6 2 2 6 2 2 6 2 2 6
57148 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0
57153 - 0 0 0 0 0 0 0 0 0 0 0 0
57154 - 0 0 0 0 0 0 0 0 0 0 0 0
57155 - 0 0 0 0 0 0 0 0 1 0 0 0
57156 - 0 0 1 0 0 1 0 0 1 0 0 0
57157 - 0 0 0 0 0 0 0 0 0 0 0 0
57158 - 0 0 0 0 0 0 0 0 0 0 0 0
57159 - 0 0 0 0 0 0 0 0 0 0 0 0
57160 - 0 0 0 0 0 0 0 0 0 0 0 0
57161 - 0 0 0 0 0 0 0 0 0 14 14 14
57162 - 46 46 46 86 86 86 2 2 6 54 54 54
57163 -218 218 218 195 195 195 226 226 226 246 246 246
57164 - 58 58 58 2 2 6 2 2 6 30 30 30
57165 -210 210 210 253 253 253 174 174 174 123 123 123
57166 -221 221 221 234 234 234 74 74 74 2 2 6
57167 - 2 2 6 2 2 6 2 2 6 2 2 6
57168 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
57173 - 0 0 0 0 0 0 0 0 0 0 0 0
57174 - 0 0 0 0 0 0 0 0 0 0 0 0
57175 - 0 0 0 0 0 0 0 0 0 0 0 0
57176 - 0 0 0 0 0 0 0 0 0 0 0 0
57177 - 0 0 0 0 0 0 0 0 0 0 0 0
57178 - 0 0 0 0 0 0 0 0 0 0 0 0
57179 - 0 0 0 0 0 0 0 0 0 0 0 0
57180 - 0 0 0 0 0 0 0 0 0 0 0 0
57181 - 0 0 0 0 0 0 0 0 0 14 14 14
57182 - 46 46 46 82 82 82 2 2 6 106 106 106
57183 -170 170 170 26 26 26 86 86 86 226 226 226
57184 -123 123 123 10 10 10 14 14 14 46 46 46
57185 -231 231 231 190 190 190 6 6 6 70 70 70
57186 - 90 90 90 238 238 238 158 158 158 2 2 6
57187 - 2 2 6 2 2 6 2 2 6 2 2 6
57188 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
57193 - 0 0 0 0 0 0 0 0 0 0 0 0
57194 - 0 0 0 0 0 0 0 0 0 0 0 0
57195 - 0 0 0 0 0 0 0 0 1 0 0 0
57196 - 0 0 1 0 0 1 0 0 1 0 0 0
57197 - 0 0 0 0 0 0 0 0 0 0 0 0
57198 - 0 0 0 0 0 0 0 0 0 0 0 0
57199 - 0 0 0 0 0 0 0 0 0 0 0 0
57200 - 0 0 0 0 0 0 0 0 0 0 0 0
57201 - 0 0 0 0 0 0 0 0 0 14 14 14
57202 - 42 42 42 86 86 86 6 6 6 116 116 116
57203 -106 106 106 6 6 6 70 70 70 149 149 149
57204 -128 128 128 18 18 18 38 38 38 54 54 54
57205 -221 221 221 106 106 106 2 2 6 14 14 14
57206 - 46 46 46 190 190 190 198 198 198 2 2 6
57207 - 2 2 6 2 2 6 2 2 6 2 2 6
57208 - 74 74 74 62 62 62 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
57213 - 0 0 0 0 0 0 0 0 0 0 0 0
57214 - 0 0 0 0 0 0 0 0 0 0 0 0
57215 - 0 0 0 0 0 0 0 0 1 0 0 0
57216 - 0 0 1 0 0 0 0 0 1 0 0 0
57217 - 0 0 0 0 0 0 0 0 0 0 0 0
57218 - 0 0 0 0 0 0 0 0 0 0 0 0
57219 - 0 0 0 0 0 0 0 0 0 0 0 0
57220 - 0 0 0 0 0 0 0 0 0 0 0 0
57221 - 0 0 0 0 0 0 0 0 0 14 14 14
57222 - 42 42 42 94 94 94 14 14 14 101 101 101
57223 -128 128 128 2 2 6 18 18 18 116 116 116
57224 -118 98 46 121 92 8 121 92 8 98 78 10
57225 -162 162 162 106 106 106 2 2 6 2 2 6
57226 - 2 2 6 195 195 195 195 195 195 6 6 6
57227 - 2 2 6 2 2 6 2 2 6 2 2 6
57228 - 74 74 74 62 62 62 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
57233 - 0 0 0 0 0 0 0 0 0 0 0 0
57234 - 0 0 0 0 0 0 0 0 0 0 0 0
57235 - 0 0 0 0 0 0 0 0 1 0 0 1
57236 - 0 0 1 0 0 0 0 0 1 0 0 0
57237 - 0 0 0 0 0 0 0 0 0 0 0 0
57238 - 0 0 0 0 0 0 0 0 0 0 0 0
57239 - 0 0 0 0 0 0 0 0 0 0 0 0
57240 - 0 0 0 0 0 0 0 0 0 0 0 0
57241 - 0 0 0 0 0 0 0 0 0 10 10 10
57242 - 38 38 38 90 90 90 14 14 14 58 58 58
57243 -210 210 210 26 26 26 54 38 6 154 114 10
57244 -226 170 11 236 186 11 225 175 15 184 144 12
57245 -215 174 15 175 146 61 37 26 9 2 2 6
57246 - 70 70 70 246 246 246 138 138 138 2 2 6
57247 - 2 2 6 2 2 6 2 2 6 2 2 6
57248 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
57252 - 0 0 0 0 0 0 0 0 0 0 0 0
57253 - 0 0 0 0 0 0 0 0 0 0 0 0
57254 - 0 0 0 0 0 0 0 0 0 0 0 0
57255 - 0 0 0 0 0 0 0 0 0 0 0 0
57256 - 0 0 0 0 0 0 0 0 0 0 0 0
57257 - 0 0 0 0 0 0 0 0 0 0 0 0
57258 - 0 0 0 0 0 0 0 0 0 0 0 0
57259 - 0 0 0 0 0 0 0 0 0 0 0 0
57260 - 0 0 0 0 0 0 0 0 0 0 0 0
57261 - 0 0 0 0 0 0 0 0 0 10 10 10
57262 - 38 38 38 86 86 86 14 14 14 10 10 10
57263 -195 195 195 188 164 115 192 133 9 225 175 15
57264 -239 182 13 234 190 10 232 195 16 232 200 30
57265 -245 207 45 241 208 19 232 195 16 184 144 12
57266 -218 194 134 211 206 186 42 42 42 2 2 6
57267 - 2 2 6 2 2 6 2 2 6 2 2 6
57268 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
57272 - 0 0 0 0 0 0 0 0 0 0 0 0
57273 - 0 0 0 0 0 0 0 0 0 0 0 0
57274 - 0 0 0 0 0 0 0 0 0 0 0 0
57275 - 0 0 0 0 0 0 0 0 0 0 0 0
57276 - 0 0 0 0 0 0 0 0 0 0 0 0
57277 - 0 0 0 0 0 0 0 0 0 0 0 0
57278 - 0 0 0 0 0 0 0 0 0 0 0 0
57279 - 0 0 0 0 0 0 0 0 0 0 0 0
57280 - 0 0 0 0 0 0 0 0 0 0 0 0
57281 - 0 0 0 0 0 0 0 0 0 10 10 10
57282 - 34 34 34 86 86 86 14 14 14 2 2 6
57283 -121 87 25 192 133 9 219 162 10 239 182 13
57284 -236 186 11 232 195 16 241 208 19 244 214 54
57285 -246 218 60 246 218 38 246 215 20 241 208 19
57286 -241 208 19 226 184 13 121 87 25 2 2 6
57287 - 2 2 6 2 2 6 2 2 6 2 2 6
57288 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
57292 - 0 0 0 0 0 0 0 0 0 0 0 0
57293 - 0 0 0 0 0 0 0 0 0 0 0 0
57294 - 0 0 0 0 0 0 0 0 0 0 0 0
57295 - 0 0 0 0 0 0 0 0 0 0 0 0
57296 - 0 0 0 0 0 0 0 0 0 0 0 0
57297 - 0 0 0 0 0 0 0 0 0 0 0 0
57298 - 0 0 0 0 0 0 0 0 0 0 0 0
57299 - 0 0 0 0 0 0 0 0 0 0 0 0
57300 - 0 0 0 0 0 0 0 0 0 0 0 0
57301 - 0 0 0 0 0 0 0 0 0 10 10 10
57302 - 34 34 34 82 82 82 30 30 30 61 42 6
57303 -180 123 7 206 145 10 230 174 11 239 182 13
57304 -234 190 10 238 202 15 241 208 19 246 218 74
57305 -246 218 38 246 215 20 246 215 20 246 215 20
57306 -226 184 13 215 174 15 184 144 12 6 6 6
57307 - 2 2 6 2 2 6 2 2 6 2 2 6
57308 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0
57312 - 0 0 0 0 0 0 0 0 0 0 0 0
57313 - 0 0 0 0 0 0 0 0 0 0 0 0
57314 - 0 0 0 0 0 0 0 0 0 0 0 0
57315 - 0 0 0 0 0 0 0 0 0 0 0 0
57316 - 0 0 0 0 0 0 0 0 0 0 0 0
57317 - 0 0 0 0 0 0 0 0 0 0 0 0
57318 - 0 0 0 0 0 0 0 0 0 0 0 0
57319 - 0 0 0 0 0 0 0 0 0 0 0 0
57320 - 0 0 0 0 0 0 0 0 0 0 0 0
57321 - 0 0 0 0 0 0 0 0 0 10 10 10
57322 - 30 30 30 78 78 78 50 50 50 104 69 6
57323 -192 133 9 216 158 10 236 178 12 236 186 11
57324 -232 195 16 241 208 19 244 214 54 245 215 43
57325 -246 215 20 246 215 20 241 208 19 198 155 10
57326 -200 144 11 216 158 10 156 118 10 2 2 6
57327 - 2 2 6 2 2 6 2 2 6 2 2 6
57328 - 6 6 6 90 90 90 54 54 54 18 18 18
57329 - 6 6 6 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 0 0 0 0 0 0
57332 - 0 0 0 0 0 0 0 0 0 0 0 0
57333 - 0 0 0 0 0 0 0 0 0 0 0 0
57334 - 0 0 0 0 0 0 0 0 0 0 0 0
57335 - 0 0 0 0 0 0 0 0 0 0 0 0
57336 - 0 0 0 0 0 0 0 0 0 0 0 0
57337 - 0 0 0 0 0 0 0 0 0 0 0 0
57338 - 0 0 0 0 0 0 0 0 0 0 0 0
57339 - 0 0 0 0 0 0 0 0 0 0 0 0
57340 - 0 0 0 0 0 0 0 0 0 0 0 0
57341 - 0 0 0 0 0 0 0 0 0 10 10 10
57342 - 30 30 30 78 78 78 46 46 46 22 22 22
57343 -137 92 6 210 162 10 239 182 13 238 190 10
57344 -238 202 15 241 208 19 246 215 20 246 215 20
57345 -241 208 19 203 166 17 185 133 11 210 150 10
57346 -216 158 10 210 150 10 102 78 10 2 2 6
57347 - 6 6 6 54 54 54 14 14 14 2 2 6
57348 - 2 2 6 62 62 62 74 74 74 30 30 30
57349 - 10 10 10 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 0 0 0 0 0 0 0 0 0
57352 - 0 0 0 0 0 0 0 0 0 0 0 0
57353 - 0 0 0 0 0 0 0 0 0 0 0 0
57354 - 0 0 0 0 0 0 0 0 0 0 0 0
57355 - 0 0 0 0 0 0 0 0 0 0 0 0
57356 - 0 0 0 0 0 0 0 0 0 0 0 0
57357 - 0 0 0 0 0 0 0 0 0 0 0 0
57358 - 0 0 0 0 0 0 0 0 0 0 0 0
57359 - 0 0 0 0 0 0 0 0 0 0 0 0
57360 - 0 0 0 0 0 0 0 0 0 0 0 0
57361 - 0 0 0 0 0 0 0 0 0 10 10 10
57362 - 34 34 34 78 78 78 50 50 50 6 6 6
57363 - 94 70 30 139 102 15 190 146 13 226 184 13
57364 -232 200 30 232 195 16 215 174 15 190 146 13
57365 -168 122 10 192 133 9 210 150 10 213 154 11
57366 -202 150 34 182 157 106 101 98 89 2 2 6
57367 - 2 2 6 78 78 78 116 116 116 58 58 58
57368 - 2 2 6 22 22 22 90 90 90 46 46 46
57369 - 18 18 18 6 6 6 0 0 0 0 0 0
57370 - 0 0 0 0 0 0 0 0 0 0 0 0
57371 - 0 0 0 0 0 0 0 0 0 0 0 0
57372 - 0 0 0 0 0 0 0 0 0 0 0 0
57373 - 0 0 0 0 0 0 0 0 0 0 0 0
57374 - 0 0 0 0 0 0 0 0 0 0 0 0
57375 - 0 0 0 0 0 0 0 0 0 0 0 0
57376 - 0 0 0 0 0 0 0 0 0 0 0 0
57377 - 0 0 0 0 0 0 0 0 0 0 0 0
57378 - 0 0 0 0 0 0 0 0 0 0 0 0
57379 - 0 0 0 0 0 0 0 0 0 0 0 0
57380 - 0 0 0 0 0 0 0 0 0 0 0 0
57381 - 0 0 0 0 0 0 0 0 0 10 10 10
57382 - 38 38 38 86 86 86 50 50 50 6 6 6
57383 -128 128 128 174 154 114 156 107 11 168 122 10
57384 -198 155 10 184 144 12 197 138 11 200 144 11
57385 -206 145 10 206 145 10 197 138 11 188 164 115
57386 -195 195 195 198 198 198 174 174 174 14 14 14
57387 - 2 2 6 22 22 22 116 116 116 116 116 116
57388 - 22 22 22 2 2 6 74 74 74 70 70 70
57389 - 30 30 30 10 10 10 0 0 0 0 0 0
57390 - 0 0 0 0 0 0 0 0 0 0 0 0
57391 - 0 0 0 0 0 0 0 0 0 0 0 0
57392 - 0 0 0 0 0 0 0 0 0 0 0 0
57393 - 0 0 0 0 0 0 0 0 0 0 0 0
57394 - 0 0 0 0 0 0 0 0 0 0 0 0
57395 - 0 0 0 0 0 0 0 0 0 0 0 0
57396 - 0 0 0 0 0 0 0 0 0 0 0 0
57397 - 0 0 0 0 0 0 0 0 0 0 0 0
57398 - 0 0 0 0 0 0 0 0 0 0 0 0
57399 - 0 0 0 0 0 0 0 0 0 0 0 0
57400 - 0 0 0 0 0 0 0 0 0 0 0 0
57401 - 0 0 0 0 0 0 6 6 6 18 18 18
57402 - 50 50 50 101 101 101 26 26 26 10 10 10
57403 -138 138 138 190 190 190 174 154 114 156 107 11
57404 -197 138 11 200 144 11 197 138 11 192 133 9
57405 -180 123 7 190 142 34 190 178 144 187 187 187
57406 -202 202 202 221 221 221 214 214 214 66 66 66
57407 - 2 2 6 2 2 6 50 50 50 62 62 62
57408 - 6 6 6 2 2 6 10 10 10 90 90 90
57409 - 50 50 50 18 18 18 6 6 6 0 0 0
57410 - 0 0 0 0 0 0 0 0 0 0 0 0
57411 - 0 0 0 0 0 0 0 0 0 0 0 0
57412 - 0 0 0 0 0 0 0 0 0 0 0 0
57413 - 0 0 0 0 0 0 0 0 0 0 0 0
57414 - 0 0 0 0 0 0 0 0 0 0 0 0
57415 - 0 0 0 0 0 0 0 0 0 0 0 0
57416 - 0 0 0 0 0 0 0 0 0 0 0 0
57417 - 0 0 0 0 0 0 0 0 0 0 0 0
57418 - 0 0 0 0 0 0 0 0 0 0 0 0
57419 - 0 0 0 0 0 0 0 0 0 0 0 0
57420 - 0 0 0 0 0 0 0 0 0 0 0 0
57421 - 0 0 0 0 0 0 10 10 10 34 34 34
57422 - 74 74 74 74 74 74 2 2 6 6 6 6
57423 -144 144 144 198 198 198 190 190 190 178 166 146
57424 -154 121 60 156 107 11 156 107 11 168 124 44
57425 -174 154 114 187 187 187 190 190 190 210 210 210
57426 -246 246 246 253 253 253 253 253 253 182 182 182
57427 - 6 6 6 2 2 6 2 2 6 2 2 6
57428 - 2 2 6 2 2 6 2 2 6 62 62 62
57429 - 74 74 74 34 34 34 14 14 14 0 0 0
57430 - 0 0 0 0 0 0 0 0 0 0 0 0
57431 - 0 0 0 0 0 0 0 0 0 0 0 0
57432 - 0 0 0 0 0 0 0 0 0 0 0 0
57433 - 0 0 0 0 0 0 0 0 0 0 0 0
57434 - 0 0 0 0 0 0 0 0 0 0 0 0
57435 - 0 0 0 0 0 0 0 0 0 0 0 0
57436 - 0 0 0 0 0 0 0 0 0 0 0 0
57437 - 0 0 0 0 0 0 0 0 0 0 0 0
57438 - 0 0 0 0 0 0 0 0 0 0 0 0
57439 - 0 0 0 0 0 0 0 0 0 0 0 0
57440 - 0 0 0 0 0 0 0 0 0 0 0 0
57441 - 0 0 0 10 10 10 22 22 22 54 54 54
57442 - 94 94 94 18 18 18 2 2 6 46 46 46
57443 -234 234 234 221 221 221 190 190 190 190 190 190
57444 -190 190 190 187 187 187 187 187 187 190 190 190
57445 -190 190 190 195 195 195 214 214 214 242 242 242
57446 -253 253 253 253 253 253 253 253 253 253 253 253
57447 - 82 82 82 2 2 6 2 2 6 2 2 6
57448 - 2 2 6 2 2 6 2 2 6 14 14 14
57449 - 86 86 86 54 54 54 22 22 22 6 6 6
57450 - 0 0 0 0 0 0 0 0 0 0 0 0
57451 - 0 0 0 0 0 0 0 0 0 0 0 0
57452 - 0 0 0 0 0 0 0 0 0 0 0 0
57453 - 0 0 0 0 0 0 0 0 0 0 0 0
57454 - 0 0 0 0 0 0 0 0 0 0 0 0
57455 - 0 0 0 0 0 0 0 0 0 0 0 0
57456 - 0 0 0 0 0 0 0 0 0 0 0 0
57457 - 0 0 0 0 0 0 0 0 0 0 0 0
57458 - 0 0 0 0 0 0 0 0 0 0 0 0
57459 - 0 0 0 0 0 0 0 0 0 0 0 0
57460 - 0 0 0 0 0 0 0 0 0 0 0 0
57461 - 6 6 6 18 18 18 46 46 46 90 90 90
57462 - 46 46 46 18 18 18 6 6 6 182 182 182
57463 -253 253 253 246 246 246 206 206 206 190 190 190
57464 -190 190 190 190 190 190 190 190 190 190 190 190
57465 -206 206 206 231 231 231 250 250 250 253 253 253
57466 -253 253 253 253 253 253 253 253 253 253 253 253
57467 -202 202 202 14 14 14 2 2 6 2 2 6
57468 - 2 2 6 2 2 6 2 2 6 2 2 6
57469 - 42 42 42 86 86 86 42 42 42 18 18 18
57470 - 6 6 6 0 0 0 0 0 0 0 0 0
57471 - 0 0 0 0 0 0 0 0 0 0 0 0
57472 - 0 0 0 0 0 0 0 0 0 0 0 0
57473 - 0 0 0 0 0 0 0 0 0 0 0 0
57474 - 0 0 0 0 0 0 0 0 0 0 0 0
57475 - 0 0 0 0 0 0 0 0 0 0 0 0
57476 - 0 0 0 0 0 0 0 0 0 0 0 0
57477 - 0 0 0 0 0 0 0 0 0 0 0 0
57478 - 0 0 0 0 0 0 0 0 0 0 0 0
57479 - 0 0 0 0 0 0 0 0 0 0 0 0
57480 - 0 0 0 0 0 0 0 0 0 6 6 6
57481 - 14 14 14 38 38 38 74 74 74 66 66 66
57482 - 2 2 6 6 6 6 90 90 90 250 250 250
57483 -253 253 253 253 253 253 238 238 238 198 198 198
57484 -190 190 190 190 190 190 195 195 195 221 221 221
57485 -246 246 246 253 253 253 253 253 253 253 253 253
57486 -253 253 253 253 253 253 253 253 253 253 253 253
57487 -253 253 253 82 82 82 2 2 6 2 2 6
57488 - 2 2 6 2 2 6 2 2 6 2 2 6
57489 - 2 2 6 78 78 78 70 70 70 34 34 34
57490 - 14 14 14 6 6 6 0 0 0 0 0 0
57491 - 0 0 0 0 0 0 0 0 0 0 0 0
57492 - 0 0 0 0 0 0 0 0 0 0 0 0
57493 - 0 0 0 0 0 0 0 0 0 0 0 0
57494 - 0 0 0 0 0 0 0 0 0 0 0 0
57495 - 0 0 0 0 0 0 0 0 0 0 0 0
57496 - 0 0 0 0 0 0 0 0 0 0 0 0
57497 - 0 0 0 0 0 0 0 0 0 0 0 0
57498 - 0 0 0 0 0 0 0 0 0 0 0 0
57499 - 0 0 0 0 0 0 0 0 0 0 0 0
57500 - 0 0 0 0 0 0 0 0 0 14 14 14
57501 - 34 34 34 66 66 66 78 78 78 6 6 6
57502 - 2 2 6 18 18 18 218 218 218 253 253 253
57503 -253 253 253 253 253 253 253 253 253 246 246 246
57504 -226 226 226 231 231 231 246 246 246 253 253 253
57505 -253 253 253 253 253 253 253 253 253 253 253 253
57506 -253 253 253 253 253 253 253 253 253 253 253 253
57507 -253 253 253 178 178 178 2 2 6 2 2 6
57508 - 2 2 6 2 2 6 2 2 6 2 2 6
57509 - 2 2 6 18 18 18 90 90 90 62 62 62
57510 - 30 30 30 10 10 10 0 0 0 0 0 0
57511 - 0 0 0 0 0 0 0 0 0 0 0 0
57512 - 0 0 0 0 0 0 0 0 0 0 0 0
57513 - 0 0 0 0 0 0 0 0 0 0 0 0
57514 - 0 0 0 0 0 0 0 0 0 0 0 0
57515 - 0 0 0 0 0 0 0 0 0 0 0 0
57516 - 0 0 0 0 0 0 0 0 0 0 0 0
57517 - 0 0 0 0 0 0 0 0 0 0 0 0
57518 - 0 0 0 0 0 0 0 0 0 0 0 0
57519 - 0 0 0 0 0 0 0 0 0 0 0 0
57520 - 0 0 0 0 0 0 10 10 10 26 26 26
57521 - 58 58 58 90 90 90 18 18 18 2 2 6
57522 - 2 2 6 110 110 110 253 253 253 253 253 253
57523 -253 253 253 253 253 253 253 253 253 253 253 253
57524 -250 250 250 253 253 253 253 253 253 253 253 253
57525 -253 253 253 253 253 253 253 253 253 253 253 253
57526 -253 253 253 253 253 253 253 253 253 253 253 253
57527 -253 253 253 231 231 231 18 18 18 2 2 6
57528 - 2 2 6 2 2 6 2 2 6 2 2 6
57529 - 2 2 6 2 2 6 18 18 18 94 94 94
57530 - 54 54 54 26 26 26 10 10 10 0 0 0
57531 - 0 0 0 0 0 0 0 0 0 0 0 0
57532 - 0 0 0 0 0 0 0 0 0 0 0 0
57533 - 0 0 0 0 0 0 0 0 0 0 0 0
57534 - 0 0 0 0 0 0 0 0 0 0 0 0
57535 - 0 0 0 0 0 0 0 0 0 0 0 0
57536 - 0 0 0 0 0 0 0 0 0 0 0 0
57537 - 0 0 0 0 0 0 0 0 0 0 0 0
57538 - 0 0 0 0 0 0 0 0 0 0 0 0
57539 - 0 0 0 0 0 0 0 0 0 0 0 0
57540 - 0 0 0 6 6 6 22 22 22 50 50 50
57541 - 90 90 90 26 26 26 2 2 6 2 2 6
57542 - 14 14 14 195 195 195 250 250 250 253 253 253
57543 -253 253 253 253 253 253 253 253 253 253 253 253
57544 -253 253 253 253 253 253 253 253 253 253 253 253
57545 -253 253 253 253 253 253 253 253 253 253 253 253
57546 -253 253 253 253 253 253 253 253 253 253 253 253
57547 -250 250 250 242 242 242 54 54 54 2 2 6
57548 - 2 2 6 2 2 6 2 2 6 2 2 6
57549 - 2 2 6 2 2 6 2 2 6 38 38 38
57550 - 86 86 86 50 50 50 22 22 22 6 6 6
57551 - 0 0 0 0 0 0 0 0 0 0 0 0
57552 - 0 0 0 0 0 0 0 0 0 0 0 0
57553 - 0 0 0 0 0 0 0 0 0 0 0 0
57554 - 0 0 0 0 0 0 0 0 0 0 0 0
57555 - 0 0 0 0 0 0 0 0 0 0 0 0
57556 - 0 0 0 0 0 0 0 0 0 0 0 0
57557 - 0 0 0 0 0 0 0 0 0 0 0 0
57558 - 0 0 0 0 0 0 0 0 0 0 0 0
57559 - 0 0 0 0 0 0 0 0 0 0 0 0
57560 - 6 6 6 14 14 14 38 38 38 82 82 82
57561 - 34 34 34 2 2 6 2 2 6 2 2 6
57562 - 42 42 42 195 195 195 246 246 246 253 253 253
57563 -253 253 253 253 253 253 253 253 253 250 250 250
57564 -242 242 242 242 242 242 250 250 250 253 253 253
57565 -253 253 253 253 253 253 253 253 253 253 253 253
57566 -253 253 253 250 250 250 246 246 246 238 238 238
57567 -226 226 226 231 231 231 101 101 101 6 6 6
57568 - 2 2 6 2 2 6 2 2 6 2 2 6
57569 - 2 2 6 2 2 6 2 2 6 2 2 6
57570 - 38 38 38 82 82 82 42 42 42 14 14 14
57571 - 6 6 6 0 0 0 0 0 0 0 0 0
57572 - 0 0 0 0 0 0 0 0 0 0 0 0
57573 - 0 0 0 0 0 0 0 0 0 0 0 0
57574 - 0 0 0 0 0 0 0 0 0 0 0 0
57575 - 0 0 0 0 0 0 0 0 0 0 0 0
57576 - 0 0 0 0 0 0 0 0 0 0 0 0
57577 - 0 0 0 0 0 0 0 0 0 0 0 0
57578 - 0 0 0 0 0 0 0 0 0 0 0 0
57579 - 0 0 0 0 0 0 0 0 0 0 0 0
57580 - 10 10 10 26 26 26 62 62 62 66 66 66
57581 - 2 2 6 2 2 6 2 2 6 6 6 6
57582 - 70 70 70 170 170 170 206 206 206 234 234 234
57583 -246 246 246 250 250 250 250 250 250 238 238 238
57584 -226 226 226 231 231 231 238 238 238 250 250 250
57585 -250 250 250 250 250 250 246 246 246 231 231 231
57586 -214 214 214 206 206 206 202 202 202 202 202 202
57587 -198 198 198 202 202 202 182 182 182 18 18 18
57588 - 2 2 6 2 2 6 2 2 6 2 2 6
57589 - 2 2 6 2 2 6 2 2 6 2 2 6
57590 - 2 2 6 62 62 62 66 66 66 30 30 30
57591 - 10 10 10 0 0 0 0 0 0 0 0 0
57592 - 0 0 0 0 0 0 0 0 0 0 0 0
57593 - 0 0 0 0 0 0 0 0 0 0 0 0
57594 - 0 0 0 0 0 0 0 0 0 0 0 0
57595 - 0 0 0 0 0 0 0 0 0 0 0 0
57596 - 0 0 0 0 0 0 0 0 0 0 0 0
57597 - 0 0 0 0 0 0 0 0 0 0 0 0
57598 - 0 0 0 0 0 0 0 0 0 0 0 0
57599 - 0 0 0 0 0 0 0 0 0 0 0 0
57600 - 14 14 14 42 42 42 82 82 82 18 18 18
57601 - 2 2 6 2 2 6 2 2 6 10 10 10
57602 - 94 94 94 182 182 182 218 218 218 242 242 242
57603 -250 250 250 253 253 253 253 253 253 250 250 250
57604 -234 234 234 253 253 253 253 253 253 253 253 253
57605 -253 253 253 253 253 253 253 253 253 246 246 246
57606 -238 238 238 226 226 226 210 210 210 202 202 202
57607 -195 195 195 195 195 195 210 210 210 158 158 158
57608 - 6 6 6 14 14 14 50 50 50 14 14 14
57609 - 2 2 6 2 2 6 2 2 6 2 2 6
57610 - 2 2 6 6 6 6 86 86 86 46 46 46
57611 - 18 18 18 6 6 6 0 0 0 0 0 0
57612 - 0 0 0 0 0 0 0 0 0 0 0 0
57613 - 0 0 0 0 0 0 0 0 0 0 0 0
57614 - 0 0 0 0 0 0 0 0 0 0 0 0
57615 - 0 0 0 0 0 0 0 0 0 0 0 0
57616 - 0 0 0 0 0 0 0 0 0 0 0 0
57617 - 0 0 0 0 0 0 0 0 0 0 0 0
57618 - 0 0 0 0 0 0 0 0 0 0 0 0
57619 - 0 0 0 0 0 0 0 0 0 6 6 6
57620 - 22 22 22 54 54 54 70 70 70 2 2 6
57621 - 2 2 6 10 10 10 2 2 6 22 22 22
57622 -166 166 166 231 231 231 250 250 250 253 253 253
57623 -253 253 253 253 253 253 253 253 253 250 250 250
57624 -242 242 242 253 253 253 253 253 253 253 253 253
57625 -253 253 253 253 253 253 253 253 253 253 253 253
57626 -253 253 253 253 253 253 253 253 253 246 246 246
57627 -231 231 231 206 206 206 198 198 198 226 226 226
57628 - 94 94 94 2 2 6 6 6 6 38 38 38
57629 - 30 30 30 2 2 6 2 2 6 2 2 6
57630 - 2 2 6 2 2 6 62 62 62 66 66 66
57631 - 26 26 26 10 10 10 0 0 0 0 0 0
57632 - 0 0 0 0 0 0 0 0 0 0 0 0
57633 - 0 0 0 0 0 0 0 0 0 0 0 0
57634 - 0 0 0 0 0 0 0 0 0 0 0 0
57635 - 0 0 0 0 0 0 0 0 0 0 0 0
57636 - 0 0 0 0 0 0 0 0 0 0 0 0
57637 - 0 0 0 0 0 0 0 0 0 0 0 0
57638 - 0 0 0 0 0 0 0 0 0 0 0 0
57639 - 0 0 0 0 0 0 0 0 0 10 10 10
57640 - 30 30 30 74 74 74 50 50 50 2 2 6
57641 - 26 26 26 26 26 26 2 2 6 106 106 106
57642 -238 238 238 253 253 253 253 253 253 253 253 253
57643 -253 253 253 253 253 253 253 253 253 253 253 253
57644 -253 253 253 253 253 253 253 253 253 253 253 253
57645 -253 253 253 253 253 253 253 253 253 253 253 253
57646 -253 253 253 253 253 253 253 253 253 253 253 253
57647 -253 253 253 246 246 246 218 218 218 202 202 202
57648 -210 210 210 14 14 14 2 2 6 2 2 6
57649 - 30 30 30 22 22 22 2 2 6 2 2 6
57650 - 2 2 6 2 2 6 18 18 18 86 86 86
57651 - 42 42 42 14 14 14 0 0 0 0 0 0
57652 - 0 0 0 0 0 0 0 0 0 0 0 0
57653 - 0 0 0 0 0 0 0 0 0 0 0 0
57654 - 0 0 0 0 0 0 0 0 0 0 0 0
57655 - 0 0 0 0 0 0 0 0 0 0 0 0
57656 - 0 0 0 0 0 0 0 0 0 0 0 0
57657 - 0 0 0 0 0 0 0 0 0 0 0 0
57658 - 0 0 0 0 0 0 0 0 0 0 0 0
57659 - 0 0 0 0 0 0 0 0 0 14 14 14
57660 - 42 42 42 90 90 90 22 22 22 2 2 6
57661 - 42 42 42 2 2 6 18 18 18 218 218 218
57662 -253 253 253 253 253 253 253 253 253 253 253 253
57663 -253 253 253 253 253 253 253 253 253 253 253 253
57664 -253 253 253 253 253 253 253 253 253 253 253 253
57665 -253 253 253 253 253 253 253 253 253 253 253 253
57666 -253 253 253 253 253 253 253 253 253 253 253 253
57667 -253 253 253 253 253 253 250 250 250 221 221 221
57668 -218 218 218 101 101 101 2 2 6 14 14 14
57669 - 18 18 18 38 38 38 10 10 10 2 2 6
57670 - 2 2 6 2 2 6 2 2 6 78 78 78
57671 - 58 58 58 22 22 22 6 6 6 0 0 0
57672 - 0 0 0 0 0 0 0 0 0 0 0 0
57673 - 0 0 0 0 0 0 0 0 0 0 0 0
57674 - 0 0 0 0 0 0 0 0 0 0 0 0
57675 - 0 0 0 0 0 0 0 0 0 0 0 0
57676 - 0 0 0 0 0 0 0 0 0 0 0 0
57677 - 0 0 0 0 0 0 0 0 0 0 0 0
57678 - 0 0 0 0 0 0 0 0 0 0 0 0
57679 - 0 0 0 0 0 0 6 6 6 18 18 18
57680 - 54 54 54 82 82 82 2 2 6 26 26 26
57681 - 22 22 22 2 2 6 123 123 123 253 253 253
57682 -253 253 253 253 253 253 253 253 253 253 253 253
57683 -253 253 253 253 253 253 253 253 253 253 253 253
57684 -253 253 253 253 253 253 253 253 253 253 253 253
57685 -253 253 253 253 253 253 253 253 253 253 253 253
57686 -253 253 253 253 253 253 253 253 253 253 253 253
57687 -253 253 253 253 253 253 253 253 253 250 250 250
57688 -238 238 238 198 198 198 6 6 6 38 38 38
57689 - 58 58 58 26 26 26 38 38 38 2 2 6
57690 - 2 2 6 2 2 6 2 2 6 46 46 46
57691 - 78 78 78 30 30 30 10 10 10 0 0 0
57692 - 0 0 0 0 0 0 0 0 0 0 0 0
57693 - 0 0 0 0 0 0 0 0 0 0 0 0
57694 - 0 0 0 0 0 0 0 0 0 0 0 0
57695 - 0 0 0 0 0 0 0 0 0 0 0 0
57696 - 0 0 0 0 0 0 0 0 0 0 0 0
57697 - 0 0 0 0 0 0 0 0 0 0 0 0
57698 - 0 0 0 0 0 0 0 0 0 0 0 0
57699 - 0 0 0 0 0 0 10 10 10 30 30 30
57700 - 74 74 74 58 58 58 2 2 6 42 42 42
57701 - 2 2 6 22 22 22 231 231 231 253 253 253
57702 -253 253 253 253 253 253 253 253 253 253 253 253
57703 -253 253 253 253 253 253 253 253 253 250 250 250
57704 -253 253 253 253 253 253 253 253 253 253 253 253
57705 -253 253 253 253 253 253 253 253 253 253 253 253
57706 -253 253 253 253 253 253 253 253 253 253 253 253
57707 -253 253 253 253 253 253 253 253 253 253 253 253
57708 -253 253 253 246 246 246 46 46 46 38 38 38
57709 - 42 42 42 14 14 14 38 38 38 14 14 14
57710 - 2 2 6 2 2 6 2 2 6 6 6 6
57711 - 86 86 86 46 46 46 14 14 14 0 0 0
57712 - 0 0 0 0 0 0 0 0 0 0 0 0
57713 - 0 0 0 0 0 0 0 0 0 0 0 0
57714 - 0 0 0 0 0 0 0 0 0 0 0 0
57715 - 0 0 0 0 0 0 0 0 0 0 0 0
57716 - 0 0 0 0 0 0 0 0 0 0 0 0
57717 - 0 0 0 0 0 0 0 0 0 0 0 0
57718 - 0 0 0 0 0 0 0 0 0 0 0 0
57719 - 0 0 0 6 6 6 14 14 14 42 42 42
57720 - 90 90 90 18 18 18 18 18 18 26 26 26
57721 - 2 2 6 116 116 116 253 253 253 253 253 253
57722 -253 253 253 253 253 253 253 253 253 253 253 253
57723 -253 253 253 253 253 253 250 250 250 238 238 238
57724 -253 253 253 253 253 253 253 253 253 253 253 253
57725 -253 253 253 253 253 253 253 253 253 253 253 253
57726 -253 253 253 253 253 253 253 253 253 253 253 253
57727 -253 253 253 253 253 253 253 253 253 253 253 253
57728 -253 253 253 253 253 253 94 94 94 6 6 6
57729 - 2 2 6 2 2 6 10 10 10 34 34 34
57730 - 2 2 6 2 2 6 2 2 6 2 2 6
57731 - 74 74 74 58 58 58 22 22 22 6 6 6
57732 - 0 0 0 0 0 0 0 0 0 0 0 0
57733 - 0 0 0 0 0 0 0 0 0 0 0 0
57734 - 0 0 0 0 0 0 0 0 0 0 0 0
57735 - 0 0 0 0 0 0 0 0 0 0 0 0
57736 - 0 0 0 0 0 0 0 0 0 0 0 0
57737 - 0 0 0 0 0 0 0 0 0 0 0 0
57738 - 0 0 0 0 0 0 0 0 0 0 0 0
57739 - 0 0 0 10 10 10 26 26 26 66 66 66
57740 - 82 82 82 2 2 6 38 38 38 6 6 6
57741 - 14 14 14 210 210 210 253 253 253 253 253 253
57742 -253 253 253 253 253 253 253 253 253 253 253 253
57743 -253 253 253 253 253 253 246 246 246 242 242 242
57744 -253 253 253 253 253 253 253 253 253 253 253 253
57745 -253 253 253 253 253 253 253 253 253 253 253 253
57746 -253 253 253 253 253 253 253 253 253 253 253 253
57747 -253 253 253 253 253 253 253 253 253 253 253 253
57748 -253 253 253 253 253 253 144 144 144 2 2 6
57749 - 2 2 6 2 2 6 2 2 6 46 46 46
57750 - 2 2 6 2 2 6 2 2 6 2 2 6
57751 - 42 42 42 74 74 74 30 30 30 10 10 10
57752 - 0 0 0 0 0 0 0 0 0 0 0 0
57753 - 0 0 0 0 0 0 0 0 0 0 0 0
57754 - 0 0 0 0 0 0 0 0 0 0 0 0
57755 - 0 0 0 0 0 0 0 0 0 0 0 0
57756 - 0 0 0 0 0 0 0 0 0 0 0 0
57757 - 0 0 0 0 0 0 0 0 0 0 0 0
57758 - 0 0 0 0 0 0 0 0 0 0 0 0
57759 - 6 6 6 14 14 14 42 42 42 90 90 90
57760 - 26 26 26 6 6 6 42 42 42 2 2 6
57761 - 74 74 74 250 250 250 253 253 253 253 253 253
57762 -253 253 253 253 253 253 253 253 253 253 253 253
57763 -253 253 253 253 253 253 242 242 242 242 242 242
57764 -253 253 253 253 253 253 253 253 253 253 253 253
57765 -253 253 253 253 253 253 253 253 253 253 253 253
57766 -253 253 253 253 253 253 253 253 253 253 253 253
57767 -253 253 253 253 253 253 253 253 253 253 253 253
57768 -253 253 253 253 253 253 182 182 182 2 2 6
57769 - 2 2 6 2 2 6 2 2 6 46 46 46
57770 - 2 2 6 2 2 6 2 2 6 2 2 6
57771 - 10 10 10 86 86 86 38 38 38 10 10 10
57772 - 0 0 0 0 0 0 0 0 0 0 0 0
57773 - 0 0 0 0 0 0 0 0 0 0 0 0
57774 - 0 0 0 0 0 0 0 0 0 0 0 0
57775 - 0 0 0 0 0 0 0 0 0 0 0 0
57776 - 0 0 0 0 0 0 0 0 0 0 0 0
57777 - 0 0 0 0 0 0 0 0 0 0 0 0
57778 - 0 0 0 0 0 0 0 0 0 0 0 0
57779 - 10 10 10 26 26 26 66 66 66 82 82 82
57780 - 2 2 6 22 22 22 18 18 18 2 2 6
57781 -149 149 149 253 253 253 253 253 253 253 253 253
57782 -253 253 253 253 253 253 253 253 253 253 253 253
57783 -253 253 253 253 253 253 234 234 234 242 242 242
57784 -253 253 253 253 253 253 253 253 253 253 253 253
57785 -253 253 253 253 253 253 253 253 253 253 253 253
57786 -253 253 253 253 253 253 253 253 253 253 253 253
57787 -253 253 253 253 253 253 253 253 253 253 253 253
57788 -253 253 253 253 253 253 206 206 206 2 2 6
57789 - 2 2 6 2 2 6 2 2 6 38 38 38
57790 - 2 2 6 2 2 6 2 2 6 2 2 6
57791 - 6 6 6 86 86 86 46 46 46 14 14 14
57792 - 0 0 0 0 0 0 0 0 0 0 0 0
57793 - 0 0 0 0 0 0 0 0 0 0 0 0
57794 - 0 0 0 0 0 0 0 0 0 0 0 0
57795 - 0 0 0 0 0 0 0 0 0 0 0 0
57796 - 0 0 0 0 0 0 0 0 0 0 0 0
57797 - 0 0 0 0 0 0 0 0 0 0 0 0
57798 - 0 0 0 0 0 0 0 0 0 6 6 6
57799 - 18 18 18 46 46 46 86 86 86 18 18 18
57800 - 2 2 6 34 34 34 10 10 10 6 6 6
57801 -210 210 210 253 253 253 253 253 253 253 253 253
57802 -253 253 253 253 253 253 253 253 253 253 253 253
57803 -253 253 253 253 253 253 234 234 234 242 242 242
57804 -253 253 253 253 253 253 253 253 253 253 253 253
57805 -253 253 253 253 253 253 253 253 253 253 253 253
57806 -253 253 253 253 253 253 253 253 253 253 253 253
57807 -253 253 253 253 253 253 253 253 253 253 253 253
57808 -253 253 253 253 253 253 221 221 221 6 6 6
57809 - 2 2 6 2 2 6 6 6 6 30 30 30
57810 - 2 2 6 2 2 6 2 2 6 2 2 6
57811 - 2 2 6 82 82 82 54 54 54 18 18 18
57812 - 6 6 6 0 0 0 0 0 0 0 0 0
57813 - 0 0 0 0 0 0 0 0 0 0 0 0
57814 - 0 0 0 0 0 0 0 0 0 0 0 0
57815 - 0 0 0 0 0 0 0 0 0 0 0 0
57816 - 0 0 0 0 0 0 0 0 0 0 0 0
57817 - 0 0 0 0 0 0 0 0 0 0 0 0
57818 - 0 0 0 0 0 0 0 0 0 10 10 10
57819 - 26 26 26 66 66 66 62 62 62 2 2 6
57820 - 2 2 6 38 38 38 10 10 10 26 26 26
57821 -238 238 238 253 253 253 253 253 253 253 253 253
57822 -253 253 253 253 253 253 253 253 253 253 253 253
57823 -253 253 253 253 253 253 231 231 231 238 238 238
57824 -253 253 253 253 253 253 253 253 253 253 253 253
57825 -253 253 253 253 253 253 253 253 253 253 253 253
57826 -253 253 253 253 253 253 253 253 253 253 253 253
57827 -253 253 253 253 253 253 253 253 253 253 253 253
57828 -253 253 253 253 253 253 231 231 231 6 6 6
57829 - 2 2 6 2 2 6 10 10 10 30 30 30
57830 - 2 2 6 2 2 6 2 2 6 2 2 6
57831 - 2 2 6 66 66 66 58 58 58 22 22 22
57832 - 6 6 6 0 0 0 0 0 0 0 0 0
57833 - 0 0 0 0 0 0 0 0 0 0 0 0
57834 - 0 0 0 0 0 0 0 0 0 0 0 0
57835 - 0 0 0 0 0 0 0 0 0 0 0 0
57836 - 0 0 0 0 0 0 0 0 0 0 0 0
57837 - 0 0 0 0 0 0 0 0 0 0 0 0
57838 - 0 0 0 0 0 0 0 0 0 10 10 10
57839 - 38 38 38 78 78 78 6 6 6 2 2 6
57840 - 2 2 6 46 46 46 14 14 14 42 42 42
57841 -246 246 246 253 253 253 253 253 253 253 253 253
57842 -253 253 253 253 253 253 253 253 253 253 253 253
57843 -253 253 253 253 253 253 231 231 231 242 242 242
57844 -253 253 253 253 253 253 253 253 253 253 253 253
57845 -253 253 253 253 253 253 253 253 253 253 253 253
57846 -253 253 253 253 253 253 253 253 253 253 253 253
57847 -253 253 253 253 253 253 253 253 253 253 253 253
57848 -253 253 253 253 253 253 234 234 234 10 10 10
57849 - 2 2 6 2 2 6 22 22 22 14 14 14
57850 - 2 2 6 2 2 6 2 2 6 2 2 6
57851 - 2 2 6 66 66 66 62 62 62 22 22 22
57852 - 6 6 6 0 0 0 0 0 0 0 0 0
57853 - 0 0 0 0 0 0 0 0 0 0 0 0
57854 - 0 0 0 0 0 0 0 0 0 0 0 0
57855 - 0 0 0 0 0 0 0 0 0 0 0 0
57856 - 0 0 0 0 0 0 0 0 0 0 0 0
57857 - 0 0 0 0 0 0 0 0 0 0 0 0
57858 - 0 0 0 0 0 0 6 6 6 18 18 18
57859 - 50 50 50 74 74 74 2 2 6 2 2 6
57860 - 14 14 14 70 70 70 34 34 34 62 62 62
57861 -250 250 250 253 253 253 253 253 253 253 253 253
57862 -253 253 253 253 253 253 253 253 253 253 253 253
57863 -253 253 253 253 253 253 231 231 231 246 246 246
57864 -253 253 253 253 253 253 253 253 253 253 253 253
57865 -253 253 253 253 253 253 253 253 253 253 253 253
57866 -253 253 253 253 253 253 253 253 253 253 253 253
57867 -253 253 253 253 253 253 253 253 253 253 253 253
57868 -253 253 253 253 253 253 234 234 234 14 14 14
57869 - 2 2 6 2 2 6 30 30 30 2 2 6
57870 - 2 2 6 2 2 6 2 2 6 2 2 6
57871 - 2 2 6 66 66 66 62 62 62 22 22 22
57872 - 6 6 6 0 0 0 0 0 0 0 0 0
57873 - 0 0 0 0 0 0 0 0 0 0 0 0
57874 - 0 0 0 0 0 0 0 0 0 0 0 0
57875 - 0 0 0 0 0 0 0 0 0 0 0 0
57876 - 0 0 0 0 0 0 0 0 0 0 0 0
57877 - 0 0 0 0 0 0 0 0 0 0 0 0
57878 - 0 0 0 0 0 0 6 6 6 18 18 18
57879 - 54 54 54 62 62 62 2 2 6 2 2 6
57880 - 2 2 6 30 30 30 46 46 46 70 70 70
57881 -250 250 250 253 253 253 253 253 253 253 253 253
57882 -253 253 253 253 253 253 253 253 253 253 253 253
57883 -253 253 253 253 253 253 231 231 231 246 246 246
57884 -253 253 253 253 253 253 253 253 253 253 253 253
57885 -253 253 253 253 253 253 253 253 253 253 253 253
57886 -253 253 253 253 253 253 253 253 253 253 253 253
57887 -253 253 253 253 253 253 253 253 253 253 253 253
57888 -253 253 253 253 253 253 226 226 226 10 10 10
57889 - 2 2 6 6 6 6 30 30 30 2 2 6
57890 - 2 2 6 2 2 6 2 2 6 2 2 6
57891 - 2 2 6 66 66 66 58 58 58 22 22 22
57892 - 6 6 6 0 0 0 0 0 0 0 0 0
57893 - 0 0 0 0 0 0 0 0 0 0 0 0
57894 - 0 0 0 0 0 0 0 0 0 0 0 0
57895 - 0 0 0 0 0 0 0 0 0 0 0 0
57896 - 0 0 0 0 0 0 0 0 0 0 0 0
57897 - 0 0 0 0 0 0 0 0 0 0 0 0
57898 - 0 0 0 0 0 0 6 6 6 22 22 22
57899 - 58 58 58 62 62 62 2 2 6 2 2 6
57900 - 2 2 6 2 2 6 30 30 30 78 78 78
57901 -250 250 250 253 253 253 253 253 253 253 253 253
57902 -253 253 253 253 253 253 253 253 253 253 253 253
57903 -253 253 253 253 253 253 231 231 231 246 246 246
57904 -253 253 253 253 253 253 253 253 253 253 253 253
57905 -253 253 253 253 253 253 253 253 253 253 253 253
57906 -253 253 253 253 253 253 253 253 253 253 253 253
57907 -253 253 253 253 253 253 253 253 253 253 253 253
57908 -253 253 253 253 253 253 206 206 206 2 2 6
57909 - 22 22 22 34 34 34 18 14 6 22 22 22
57910 - 26 26 26 18 18 18 6 6 6 2 2 6
57911 - 2 2 6 82 82 82 54 54 54 18 18 18
57912 - 6 6 6 0 0 0 0 0 0 0 0 0
57913 - 0 0 0 0 0 0 0 0 0 0 0 0
57914 - 0 0 0 0 0 0 0 0 0 0 0 0
57915 - 0 0 0 0 0 0 0 0 0 0 0 0
57916 - 0 0 0 0 0 0 0 0 0 0 0 0
57917 - 0 0 0 0 0 0 0 0 0 0 0 0
57918 - 0 0 0 0 0 0 6 6 6 26 26 26
57919 - 62 62 62 106 106 106 74 54 14 185 133 11
57920 -210 162 10 121 92 8 6 6 6 62 62 62
57921 -238 238 238 253 253 253 253 253 253 253 253 253
57922 -253 253 253 253 253 253 253 253 253 253 253 253
57923 -253 253 253 253 253 253 231 231 231 246 246 246
57924 -253 253 253 253 253 253 253 253 253 253 253 253
57925 -253 253 253 253 253 253 253 253 253 253 253 253
57926 -253 253 253 253 253 253 253 253 253 253 253 253
57927 -253 253 253 253 253 253 253 253 253 253 253 253
57928 -253 253 253 253 253 253 158 158 158 18 18 18
57929 - 14 14 14 2 2 6 2 2 6 2 2 6
57930 - 6 6 6 18 18 18 66 66 66 38 38 38
57931 - 6 6 6 94 94 94 50 50 50 18 18 18
57932 - 6 6 6 0 0 0 0 0 0 0 0 0
57933 - 0 0 0 0 0 0 0 0 0 0 0 0
57934 - 0 0 0 0 0 0 0 0 0 0 0 0
57935 - 0 0 0 0 0 0 0 0 0 0 0 0
57936 - 0 0 0 0 0 0 0 0 0 0 0 0
57937 - 0 0 0 0 0 0 0 0 0 6 6 6
57938 - 10 10 10 10 10 10 18 18 18 38 38 38
57939 - 78 78 78 142 134 106 216 158 10 242 186 14
57940 -246 190 14 246 190 14 156 118 10 10 10 10
57941 - 90 90 90 238 238 238 253 253 253 253 253 253
57942 -253 253 253 253 253 253 253 253 253 253 253 253
57943 -253 253 253 253 253 253 231 231 231 250 250 250
57944 -253 253 253 253 253 253 253 253 253 253 253 253
57945 -253 253 253 253 253 253 253 253 253 253 253 253
57946 -253 253 253 253 253 253 253 253 253 253 253 253
57947 -253 253 253 253 253 253 253 253 253 246 230 190
57948 -238 204 91 238 204 91 181 142 44 37 26 9
57949 - 2 2 6 2 2 6 2 2 6 2 2 6
57950 - 2 2 6 2 2 6 38 38 38 46 46 46
57951 - 26 26 26 106 106 106 54 54 54 18 18 18
57952 - 6 6 6 0 0 0 0 0 0 0 0 0
57953 - 0 0 0 0 0 0 0 0 0 0 0 0
57954 - 0 0 0 0 0 0 0 0 0 0 0 0
57955 - 0 0 0 0 0 0 0 0 0 0 0 0
57956 - 0 0 0 0 0 0 0 0 0 0 0 0
57957 - 0 0 0 6 6 6 14 14 14 22 22 22
57958 - 30 30 30 38 38 38 50 50 50 70 70 70
57959 -106 106 106 190 142 34 226 170 11 242 186 14
57960 -246 190 14 246 190 14 246 190 14 154 114 10
57961 - 6 6 6 74 74 74 226 226 226 253 253 253
57962 -253 253 253 253 253 253 253 253 253 253 253 253
57963 -253 253 253 253 253 253 231 231 231 250 250 250
57964 -253 253 253 253 253 253 253 253 253 253 253 253
57965 -253 253 253 253 253 253 253 253 253 253 253 253
57966 -253 253 253 253 253 253 253 253 253 253 253 253
57967 -253 253 253 253 253 253 253 253 253 228 184 62
57968 -241 196 14 241 208 19 232 195 16 38 30 10
57969 - 2 2 6 2 2 6 2 2 6 2 2 6
57970 - 2 2 6 6 6 6 30 30 30 26 26 26
57971 -203 166 17 154 142 90 66 66 66 26 26 26
57972 - 6 6 6 0 0 0 0 0 0 0 0 0
57973 - 0 0 0 0 0 0 0 0 0 0 0 0
57974 - 0 0 0 0 0 0 0 0 0 0 0 0
57975 - 0 0 0 0 0 0 0 0 0 0 0 0
57976 - 0 0 0 0 0 0 0 0 0 0 0 0
57977 - 6 6 6 18 18 18 38 38 38 58 58 58
57978 - 78 78 78 86 86 86 101 101 101 123 123 123
57979 -175 146 61 210 150 10 234 174 13 246 186 14
57980 -246 190 14 246 190 14 246 190 14 238 190 10
57981 -102 78 10 2 2 6 46 46 46 198 198 198
57982 -253 253 253 253 253 253 253 253 253 253 253 253
57983 -253 253 253 253 253 253 234 234 234 242 242 242
57984 -253 253 253 253 253 253 253 253 253 253 253 253
57985 -253 253 253 253 253 253 253 253 253 253 253 253
57986 -253 253 253 253 253 253 253 253 253 253 253 253
57987 -253 253 253 253 253 253 253 253 253 224 178 62
57988 -242 186 14 241 196 14 210 166 10 22 18 6
57989 - 2 2 6 2 2 6 2 2 6 2 2 6
57990 - 2 2 6 2 2 6 6 6 6 121 92 8
57991 -238 202 15 232 195 16 82 82 82 34 34 34
57992 - 10 10 10 0 0 0 0 0 0 0 0 0
57993 - 0 0 0 0 0 0 0 0 0 0 0 0
57994 - 0 0 0 0 0 0 0 0 0 0 0 0
57995 - 0 0 0 0 0 0 0 0 0 0 0 0
57996 - 0 0 0 0 0 0 0 0 0 0 0 0
57997 - 14 14 14 38 38 38 70 70 70 154 122 46
57998 -190 142 34 200 144 11 197 138 11 197 138 11
57999 -213 154 11 226 170 11 242 186 14 246 190 14
58000 -246 190 14 246 190 14 246 190 14 246 190 14
58001 -225 175 15 46 32 6 2 2 6 22 22 22
58002 -158 158 158 250 250 250 253 253 253 253 253 253
58003 -253 253 253 253 253 253 253 253 253 253 253 253
58004 -253 253 253 253 253 253 253 253 253 253 253 253
58005 -253 253 253 253 253 253 253 253 253 253 253 253
58006 -253 253 253 253 253 253 253 253 253 253 253 253
58007 -253 253 253 250 250 250 242 242 242 224 178 62
58008 -239 182 13 236 186 11 213 154 11 46 32 6
58009 - 2 2 6 2 2 6 2 2 6 2 2 6
58010 - 2 2 6 2 2 6 61 42 6 225 175 15
58011 -238 190 10 236 186 11 112 100 78 42 42 42
58012 - 14 14 14 0 0 0 0 0 0 0 0 0
58013 - 0 0 0 0 0 0 0 0 0 0 0 0
58014 - 0 0 0 0 0 0 0 0 0 0 0 0
58015 - 0 0 0 0 0 0 0 0 0 0 0 0
58016 - 0 0 0 0 0 0 0 0 0 6 6 6
58017 - 22 22 22 54 54 54 154 122 46 213 154 11
58018 -226 170 11 230 174 11 226 170 11 226 170 11
58019 -236 178 12 242 186 14 246 190 14 246 190 14
58020 -246 190 14 246 190 14 246 190 14 246 190 14
58021 -241 196 14 184 144 12 10 10 10 2 2 6
58022 - 6 6 6 116 116 116 242 242 242 253 253 253
58023 -253 253 253 253 253 253 253 253 253 253 253 253
58024 -253 253 253 253 253 253 253 253 253 253 253 253
58025 -253 253 253 253 253 253 253 253 253 253 253 253
58026 -253 253 253 253 253 253 253 253 253 253 253 253
58027 -253 253 253 231 231 231 198 198 198 214 170 54
58028 -236 178 12 236 178 12 210 150 10 137 92 6
58029 - 18 14 6 2 2 6 2 2 6 2 2 6
58030 - 6 6 6 70 47 6 200 144 11 236 178 12
58031 -239 182 13 239 182 13 124 112 88 58 58 58
58032 - 22 22 22 6 6 6 0 0 0 0 0 0
58033 - 0 0 0 0 0 0 0 0 0 0 0 0
58034 - 0 0 0 0 0 0 0 0 0 0 0 0
58035 - 0 0 0 0 0 0 0 0 0 0 0 0
58036 - 0 0 0 0 0 0 0 0 0 10 10 10
58037 - 30 30 30 70 70 70 180 133 36 226 170 11
58038 -239 182 13 242 186 14 242 186 14 246 186 14
58039 -246 190 14 246 190 14 246 190 14 246 190 14
58040 -246 190 14 246 190 14 246 190 14 246 190 14
58041 -246 190 14 232 195 16 98 70 6 2 2 6
58042 - 2 2 6 2 2 6 66 66 66 221 221 221
58043 -253 253 253 253 253 253 253 253 253 253 253 253
58044 -253 253 253 253 253 253 253 253 253 253 253 253
58045 -253 253 253 253 253 253 253 253 253 253 253 253
58046 -253 253 253 253 253 253 253 253 253 253 253 253
58047 -253 253 253 206 206 206 198 198 198 214 166 58
58048 -230 174 11 230 174 11 216 158 10 192 133 9
58049 -163 110 8 116 81 8 102 78 10 116 81 8
58050 -167 114 7 197 138 11 226 170 11 239 182 13
58051 -242 186 14 242 186 14 162 146 94 78 78 78
58052 - 34 34 34 14 14 14 6 6 6 0 0 0
58053 - 0 0 0 0 0 0 0 0 0 0 0 0
58054 - 0 0 0 0 0 0 0 0 0 0 0 0
58055 - 0 0 0 0 0 0 0 0 0 0 0 0
58056 - 0 0 0 0 0 0 0 0 0 6 6 6
58057 - 30 30 30 78 78 78 190 142 34 226 170 11
58058 -239 182 13 246 190 14 246 190 14 246 190 14
58059 -246 190 14 246 190 14 246 190 14 246 190 14
58060 -246 190 14 246 190 14 246 190 14 246 190 14
58061 -246 190 14 241 196 14 203 166 17 22 18 6
58062 - 2 2 6 2 2 6 2 2 6 38 38 38
58063 -218 218 218 253 253 253 253 253 253 253 253 253
58064 -253 253 253 253 253 253 253 253 253 253 253 253
58065 -253 253 253 253 253 253 253 253 253 253 253 253
58066 -253 253 253 253 253 253 253 253 253 253 253 253
58067 -250 250 250 206 206 206 198 198 198 202 162 69
58068 -226 170 11 236 178 12 224 166 10 210 150 10
58069 -200 144 11 197 138 11 192 133 9 197 138 11
58070 -210 150 10 226 170 11 242 186 14 246 190 14
58071 -246 190 14 246 186 14 225 175 15 124 112 88
58072 - 62 62 62 30 30 30 14 14 14 6 6 6
58073 - 0 0 0 0 0 0 0 0 0 0 0 0
58074 - 0 0 0 0 0 0 0 0 0 0 0 0
58075 - 0 0 0 0 0 0 0 0 0 0 0 0
58076 - 0 0 0 0 0 0 0 0 0 10 10 10
58077 - 30 30 30 78 78 78 174 135 50 224 166 10
58078 -239 182 13 246 190 14 246 190 14 246 190 14
58079 -246 190 14 246 190 14 246 190 14 246 190 14
58080 -246 190 14 246 190 14 246 190 14 246 190 14
58081 -246 190 14 246 190 14 241 196 14 139 102 15
58082 - 2 2 6 2 2 6 2 2 6 2 2 6
58083 - 78 78 78 250 250 250 253 253 253 253 253 253
58084 -253 253 253 253 253 253 253 253 253 253 253 253
58085 -253 253 253 253 253 253 253 253 253 253 253 253
58086 -253 253 253 253 253 253 253 253 253 253 253 253
58087 -250 250 250 214 214 214 198 198 198 190 150 46
58088 -219 162 10 236 178 12 234 174 13 224 166 10
58089 -216 158 10 213 154 11 213 154 11 216 158 10
58090 -226 170 11 239 182 13 246 190 14 246 190 14
58091 -246 190 14 246 190 14 242 186 14 206 162 42
58092 -101 101 101 58 58 58 30 30 30 14 14 14
58093 - 6 6 6 0 0 0 0 0 0 0 0 0
58094 - 0 0 0 0 0 0 0 0 0 0 0 0
58095 - 0 0 0 0 0 0 0 0 0 0 0 0
58096 - 0 0 0 0 0 0 0 0 0 10 10 10
58097 - 30 30 30 74 74 74 174 135 50 216 158 10
58098 -236 178 12 246 190 14 246 190 14 246 190 14
58099 -246 190 14 246 190 14 246 190 14 246 190 14
58100 -246 190 14 246 190 14 246 190 14 246 190 14
58101 -246 190 14 246 190 14 241 196 14 226 184 13
58102 - 61 42 6 2 2 6 2 2 6 2 2 6
58103 - 22 22 22 238 238 238 253 253 253 253 253 253
58104 -253 253 253 253 253 253 253 253 253 253 253 253
58105 -253 253 253 253 253 253 253 253 253 253 253 253
58106 -253 253 253 253 253 253 253 253 253 253 253 253
58107 -253 253 253 226 226 226 187 187 187 180 133 36
58108 -216 158 10 236 178 12 239 182 13 236 178 12
58109 -230 174 11 226 170 11 226 170 11 230 174 11
58110 -236 178 12 242 186 14 246 190 14 246 190 14
58111 -246 190 14 246 190 14 246 186 14 239 182 13
58112 -206 162 42 106 106 106 66 66 66 34 34 34
58113 - 14 14 14 6 6 6 0 0 0 0 0 0
58114 - 0 0 0 0 0 0 0 0 0 0 0 0
58115 - 0 0 0 0 0 0 0 0 0 0 0 0
58116 - 0 0 0 0 0 0 0 0 0 6 6 6
58117 - 26 26 26 70 70 70 163 133 67 213 154 11
58118 -236 178 12 246 190 14 246 190 14 246 190 14
58119 -246 190 14 246 190 14 246 190 14 246 190 14
58120 -246 190 14 246 190 14 246 190 14 246 190 14
58121 -246 190 14 246 190 14 246 190 14 241 196 14
58122 -190 146 13 18 14 6 2 2 6 2 2 6
58123 - 46 46 46 246 246 246 253 253 253 253 253 253
58124 -253 253 253 253 253 253 253 253 253 253 253 253
58125 -253 253 253 253 253 253 253 253 253 253 253 253
58126 -253 253 253 253 253 253 253 253 253 253 253 253
58127 -253 253 253 221 221 221 86 86 86 156 107 11
58128 -216 158 10 236 178 12 242 186 14 246 186 14
58129 -242 186 14 239 182 13 239 182 13 242 186 14
58130 -242 186 14 246 186 14 246 190 14 246 190 14
58131 -246 190 14 246 190 14 246 190 14 246 190 14
58132 -242 186 14 225 175 15 142 122 72 66 66 66
58133 - 30 30 30 10 10 10 0 0 0 0 0 0
58134 - 0 0 0 0 0 0 0 0 0 0 0 0
58135 - 0 0 0 0 0 0 0 0 0 0 0 0
58136 - 0 0 0 0 0 0 0 0 0 6 6 6
58137 - 26 26 26 70 70 70 163 133 67 210 150 10
58138 -236 178 12 246 190 14 246 190 14 246 190 14
58139 -246 190 14 246 190 14 246 190 14 246 190 14
58140 -246 190 14 246 190 14 246 190 14 246 190 14
58141 -246 190 14 246 190 14 246 190 14 246 190 14
58142 -232 195 16 121 92 8 34 34 34 106 106 106
58143 -221 221 221 253 253 253 253 253 253 253 253 253
58144 -253 253 253 253 253 253 253 253 253 253 253 253
58145 -253 253 253 253 253 253 253 253 253 253 253 253
58146 -253 253 253 253 253 253 253 253 253 253 253 253
58147 -242 242 242 82 82 82 18 14 6 163 110 8
58148 -216 158 10 236 178 12 242 186 14 246 190 14
58149 -246 190 14 246 190 14 246 190 14 246 190 14
58150 -246 190 14 246 190 14 246 190 14 246 190 14
58151 -246 190 14 246 190 14 246 190 14 246 190 14
58152 -246 190 14 246 190 14 242 186 14 163 133 67
58153 - 46 46 46 18 18 18 6 6 6 0 0 0
58154 - 0 0 0 0 0 0 0 0 0 0 0 0
58155 - 0 0 0 0 0 0 0 0 0 0 0 0
58156 - 0 0 0 0 0 0 0 0 0 10 10 10
58157 - 30 30 30 78 78 78 163 133 67 210 150 10
58158 -236 178 12 246 186 14 246 190 14 246 190 14
58159 -246 190 14 246 190 14 246 190 14 246 190 14
58160 -246 190 14 246 190 14 246 190 14 246 190 14
58161 -246 190 14 246 190 14 246 190 14 246 190 14
58162 -241 196 14 215 174 15 190 178 144 253 253 253
58163 -253 253 253 253 253 253 253 253 253 253 253 253
58164 -253 253 253 253 253 253 253 253 253 253 253 253
58165 -253 253 253 253 253 253 253 253 253 253 253 253
58166 -253 253 253 253 253 253 253 253 253 218 218 218
58167 - 58 58 58 2 2 6 22 18 6 167 114 7
58168 -216 158 10 236 178 12 246 186 14 246 190 14
58169 -246 190 14 246 190 14 246 190 14 246 190 14
58170 -246 190 14 246 190 14 246 190 14 246 190 14
58171 -246 190 14 246 190 14 246 190 14 246 190 14
58172 -246 190 14 246 186 14 242 186 14 190 150 46
58173 - 54 54 54 22 22 22 6 6 6 0 0 0
58174 - 0 0 0 0 0 0 0 0 0 0 0 0
58175 - 0 0 0 0 0 0 0 0 0 0 0 0
58176 - 0 0 0 0 0 0 0 0 0 14 14 14
58177 - 38 38 38 86 86 86 180 133 36 213 154 11
58178 -236 178 12 246 186 14 246 190 14 246 190 14
58179 -246 190 14 246 190 14 246 190 14 246 190 14
58180 -246 190 14 246 190 14 246 190 14 246 190 14
58181 -246 190 14 246 190 14 246 190 14 246 190 14
58182 -246 190 14 232 195 16 190 146 13 214 214 214
58183 -253 253 253 253 253 253 253 253 253 253 253 253
58184 -253 253 253 253 253 253 253 253 253 253 253 253
58185 -253 253 253 253 253 253 253 253 253 253 253 253
58186 -253 253 253 250 250 250 170 170 170 26 26 26
58187 - 2 2 6 2 2 6 37 26 9 163 110 8
58188 -219 162 10 239 182 13 246 186 14 246 190 14
58189 -246 190 14 246 190 14 246 190 14 246 190 14
58190 -246 190 14 246 190 14 246 190 14 246 190 14
58191 -246 190 14 246 190 14 246 190 14 246 190 14
58192 -246 186 14 236 178 12 224 166 10 142 122 72
58193 - 46 46 46 18 18 18 6 6 6 0 0 0
58194 - 0 0 0 0 0 0 0 0 0 0 0 0
58195 - 0 0 0 0 0 0 0 0 0 0 0 0
58196 - 0 0 0 0 0 0 6 6 6 18 18 18
58197 - 50 50 50 109 106 95 192 133 9 224 166 10
58198 -242 186 14 246 190 14 246 190 14 246 190 14
58199 -246 190 14 246 190 14 246 190 14 246 190 14
58200 -246 190 14 246 190 14 246 190 14 246 190 14
58201 -246 190 14 246 190 14 246 190 14 246 190 14
58202 -242 186 14 226 184 13 210 162 10 142 110 46
58203 -226 226 226 253 253 253 253 253 253 253 253 253
58204 -253 253 253 253 253 253 253 253 253 253 253 253
58205 -253 253 253 253 253 253 253 253 253 253 253 253
58206 -198 198 198 66 66 66 2 2 6 2 2 6
58207 - 2 2 6 2 2 6 50 34 6 156 107 11
58208 -219 162 10 239 182 13 246 186 14 246 190 14
58209 -246 190 14 246 190 14 246 190 14 246 190 14
58210 -246 190 14 246 190 14 246 190 14 246 190 14
58211 -246 190 14 246 190 14 246 190 14 242 186 14
58212 -234 174 13 213 154 11 154 122 46 66 66 66
58213 - 30 30 30 10 10 10 0 0 0 0 0 0
58214 - 0 0 0 0 0 0 0 0 0 0 0 0
58215 - 0 0 0 0 0 0 0 0 0 0 0 0
58216 - 0 0 0 0 0 0 6 6 6 22 22 22
58217 - 58 58 58 154 121 60 206 145 10 234 174 13
58218 -242 186 14 246 186 14 246 190 14 246 190 14
58219 -246 190 14 246 190 14 246 190 14 246 190 14
58220 -246 190 14 246 190 14 246 190 14 246 190 14
58221 -246 190 14 246 190 14 246 190 14 246 190 14
58222 -246 186 14 236 178 12 210 162 10 163 110 8
58223 - 61 42 6 138 138 138 218 218 218 250 250 250
58224 -253 253 253 253 253 253 253 253 253 250 250 250
58225 -242 242 242 210 210 210 144 144 144 66 66 66
58226 - 6 6 6 2 2 6 2 2 6 2 2 6
58227 - 2 2 6 2 2 6 61 42 6 163 110 8
58228 -216 158 10 236 178 12 246 190 14 246 190 14
58229 -246 190 14 246 190 14 246 190 14 246 190 14
58230 -246 190 14 246 190 14 246 190 14 246 190 14
58231 -246 190 14 239 182 13 230 174 11 216 158 10
58232 -190 142 34 124 112 88 70 70 70 38 38 38
58233 - 18 18 18 6 6 6 0 0 0 0 0 0
58234 - 0 0 0 0 0 0 0 0 0 0 0 0
58235 - 0 0 0 0 0 0 0 0 0 0 0 0
58236 - 0 0 0 0 0 0 6 6 6 22 22 22
58237 - 62 62 62 168 124 44 206 145 10 224 166 10
58238 -236 178 12 239 182 13 242 186 14 242 186 14
58239 -246 186 14 246 190 14 246 190 14 246 190 14
58240 -246 190 14 246 190 14 246 190 14 246 190 14
58241 -246 190 14 246 190 14 246 190 14 246 190 14
58242 -246 190 14 236 178 12 216 158 10 175 118 6
58243 - 80 54 7 2 2 6 6 6 6 30 30 30
58244 - 54 54 54 62 62 62 50 50 50 38 38 38
58245 - 14 14 14 2 2 6 2 2 6 2 2 6
58246 - 2 2 6 2 2 6 2 2 6 2 2 6
58247 - 2 2 6 6 6 6 80 54 7 167 114 7
58248 -213 154 11 236 178 12 246 190 14 246 190 14
58249 -246 190 14 246 190 14 246 190 14 246 190 14
58250 -246 190 14 242 186 14 239 182 13 239 182 13
58251 -230 174 11 210 150 10 174 135 50 124 112 88
58252 - 82 82 82 54 54 54 34 34 34 18 18 18
58253 - 6 6 6 0 0 0 0 0 0 0 0 0
58254 - 0 0 0 0 0 0 0 0 0 0 0 0
58255 - 0 0 0 0 0 0 0 0 0 0 0 0
58256 - 0 0 0 0 0 0 6 6 6 18 18 18
58257 - 50 50 50 158 118 36 192 133 9 200 144 11
58258 -216 158 10 219 162 10 224 166 10 226 170 11
58259 -230 174 11 236 178 12 239 182 13 239 182 13
58260 -242 186 14 246 186 14 246 190 14 246 190 14
58261 -246 190 14 246 190 14 246 190 14 246 190 14
58262 -246 186 14 230 174 11 210 150 10 163 110 8
58263 -104 69 6 10 10 10 2 2 6 2 2 6
58264 - 2 2 6 2 2 6 2 2 6 2 2 6
58265 - 2 2 6 2 2 6 2 2 6 2 2 6
58266 - 2 2 6 2 2 6 2 2 6 2 2 6
58267 - 2 2 6 6 6 6 91 60 6 167 114 7
58268 -206 145 10 230 174 11 242 186 14 246 190 14
58269 -246 190 14 246 190 14 246 186 14 242 186 14
58270 -239 182 13 230 174 11 224 166 10 213 154 11
58271 -180 133 36 124 112 88 86 86 86 58 58 58
58272 - 38 38 38 22 22 22 10 10 10 6 6 6
58273 - 0 0 0 0 0 0 0 0 0 0 0 0
58274 - 0 0 0 0 0 0 0 0 0 0 0 0
58275 - 0 0 0 0 0 0 0 0 0 0 0 0
58276 - 0 0 0 0 0 0 0 0 0 14 14 14
58277 - 34 34 34 70 70 70 138 110 50 158 118 36
58278 -167 114 7 180 123 7 192 133 9 197 138 11
58279 -200 144 11 206 145 10 213 154 11 219 162 10
58280 -224 166 10 230 174 11 239 182 13 242 186 14
58281 -246 186 14 246 186 14 246 186 14 246 186 14
58282 -239 182 13 216 158 10 185 133 11 152 99 6
58283 -104 69 6 18 14 6 2 2 6 2 2 6
58284 - 2 2 6 2 2 6 2 2 6 2 2 6
58285 - 2 2 6 2 2 6 2 2 6 2 2 6
58286 - 2 2 6 2 2 6 2 2 6 2 2 6
58287 - 2 2 6 6 6 6 80 54 7 152 99 6
58288 -192 133 9 219 162 10 236 178 12 239 182 13
58289 -246 186 14 242 186 14 239 182 13 236 178 12
58290 -224 166 10 206 145 10 192 133 9 154 121 60
58291 - 94 94 94 62 62 62 42 42 42 22 22 22
58292 - 14 14 14 6 6 6 0 0 0 0 0 0
58293 - 0 0 0 0 0 0 0 0 0 0 0 0
58294 - 0 0 0 0 0 0 0 0 0 0 0 0
58295 - 0 0 0 0 0 0 0 0 0 0 0 0
58296 - 0 0 0 0 0 0 0 0 0 6 6 6
58297 - 18 18 18 34 34 34 58 58 58 78 78 78
58298 -101 98 89 124 112 88 142 110 46 156 107 11
58299 -163 110 8 167 114 7 175 118 6 180 123 7
58300 -185 133 11 197 138 11 210 150 10 219 162 10
58301 -226 170 11 236 178 12 236 178 12 234 174 13
58302 -219 162 10 197 138 11 163 110 8 130 83 6
58303 - 91 60 6 10 10 10 2 2 6 2 2 6
58304 - 18 18 18 38 38 38 38 38 38 38 38 38
58305 - 38 38 38 38 38 38 38 38 38 38 38 38
58306 - 38 38 38 38 38 38 26 26 26 2 2 6
58307 - 2 2 6 6 6 6 70 47 6 137 92 6
58308 -175 118 6 200 144 11 219 162 10 230 174 11
58309 -234 174 13 230 174 11 219 162 10 210 150 10
58310 -192 133 9 163 110 8 124 112 88 82 82 82
58311 - 50 50 50 30 30 30 14 14 14 6 6 6
58312 - 0 0 0 0 0 0 0 0 0 0 0 0
58313 - 0 0 0 0 0 0 0 0 0 0 0 0
58314 - 0 0 0 0 0 0 0 0 0 0 0 0
58315 - 0 0 0 0 0 0 0 0 0 0 0 0
58316 - 0 0 0 0 0 0 0 0 0 0 0 0
58317 - 6 6 6 14 14 14 22 22 22 34 34 34
58318 - 42 42 42 58 58 58 74 74 74 86 86 86
58319 -101 98 89 122 102 70 130 98 46 121 87 25
58320 -137 92 6 152 99 6 163 110 8 180 123 7
58321 -185 133 11 197 138 11 206 145 10 200 144 11
58322 -180 123 7 156 107 11 130 83 6 104 69 6
58323 - 50 34 6 54 54 54 110 110 110 101 98 89
58324 - 86 86 86 82 82 82 78 78 78 78 78 78
58325 - 78 78 78 78 78 78 78 78 78 78 78 78
58326 - 78 78 78 82 82 82 86 86 86 94 94 94
58327 -106 106 106 101 101 101 86 66 34 124 80 6
58328 -156 107 11 180 123 7 192 133 9 200 144 11
58329 -206 145 10 200 144 11 192 133 9 175 118 6
58330 -139 102 15 109 106 95 70 70 70 42 42 42
58331 - 22 22 22 10 10 10 0 0 0 0 0 0
58332 - 0 0 0 0 0 0 0 0 0 0 0 0
58333 - 0 0 0 0 0 0 0 0 0 0 0 0
58334 - 0 0 0 0 0 0 0 0 0 0 0 0
58335 - 0 0 0 0 0 0 0 0 0 0 0 0
58336 - 0 0 0 0 0 0 0 0 0 0 0 0
58337 - 0 0 0 0 0 0 6 6 6 10 10 10
58338 - 14 14 14 22 22 22 30 30 30 38 38 38
58339 - 50 50 50 62 62 62 74 74 74 90 90 90
58340 -101 98 89 112 100 78 121 87 25 124 80 6
58341 -137 92 6 152 99 6 152 99 6 152 99 6
58342 -138 86 6 124 80 6 98 70 6 86 66 30
58343 -101 98 89 82 82 82 58 58 58 46 46 46
58344 - 38 38 38 34 34 34 34 34 34 34 34 34
58345 - 34 34 34 34 34 34 34 34 34 34 34 34
58346 - 34 34 34 34 34 34 38 38 38 42 42 42
58347 - 54 54 54 82 82 82 94 86 76 91 60 6
58348 -134 86 6 156 107 11 167 114 7 175 118 6
58349 -175 118 6 167 114 7 152 99 6 121 87 25
58350 -101 98 89 62 62 62 34 34 34 18 18 18
58351 - 6 6 6 0 0 0 0 0 0 0 0 0
58352 - 0 0 0 0 0 0 0 0 0 0 0 0
58353 - 0 0 0 0 0 0 0 0 0 0 0 0
58354 - 0 0 0 0 0 0 0 0 0 0 0 0
58355 - 0 0 0 0 0 0 0 0 0 0 0 0
58356 - 0 0 0 0 0 0 0 0 0 0 0 0
58357 - 0 0 0 0 0 0 0 0 0 0 0 0
58358 - 0 0 0 6 6 6 6 6 6 10 10 10
58359 - 18 18 18 22 22 22 30 30 30 42 42 42
58360 - 50 50 50 66 66 66 86 86 86 101 98 89
58361 -106 86 58 98 70 6 104 69 6 104 69 6
58362 -104 69 6 91 60 6 82 62 34 90 90 90
58363 - 62 62 62 38 38 38 22 22 22 14 14 14
58364 - 10 10 10 10 10 10 10 10 10 10 10 10
58365 - 10 10 10 10 10 10 6 6 6 10 10 10
58366 - 10 10 10 10 10 10 10 10 10 14 14 14
58367 - 22 22 22 42 42 42 70 70 70 89 81 66
58368 - 80 54 7 104 69 6 124 80 6 137 92 6
58369 -134 86 6 116 81 8 100 82 52 86 86 86
58370 - 58 58 58 30 30 30 14 14 14 6 6 6
58371 - 0 0 0 0 0 0 0 0 0 0 0 0
58372 - 0 0 0 0 0 0 0 0 0 0 0 0
58373 - 0 0 0 0 0 0 0 0 0 0 0 0
58374 - 0 0 0 0 0 0 0 0 0 0 0 0
58375 - 0 0 0 0 0 0 0 0 0 0 0 0
58376 - 0 0 0 0 0 0 0 0 0 0 0 0
58377 - 0 0 0 0 0 0 0 0 0 0 0 0
58378 - 0 0 0 0 0 0 0 0 0 0 0 0
58379 - 0 0 0 6 6 6 10 10 10 14 14 14
58380 - 18 18 18 26 26 26 38 38 38 54 54 54
58381 - 70 70 70 86 86 86 94 86 76 89 81 66
58382 - 89 81 66 86 86 86 74 74 74 50 50 50
58383 - 30 30 30 14 14 14 6 6 6 0 0 0
58384 - 0 0 0 0 0 0 0 0 0 0 0 0
58385 - 0 0 0 0 0 0 0 0 0 0 0 0
58386 - 0 0 0 0 0 0 0 0 0 0 0 0
58387 - 6 6 6 18 18 18 34 34 34 58 58 58
58388 - 82 82 82 89 81 66 89 81 66 89 81 66
58389 - 94 86 66 94 86 76 74 74 74 50 50 50
58390 - 26 26 26 14 14 14 6 6 6 0 0 0
58391 - 0 0 0 0 0 0 0 0 0 0 0 0
58392 - 0 0 0 0 0 0 0 0 0 0 0 0
58393 - 0 0 0 0 0 0 0 0 0 0 0 0
58394 - 0 0 0 0 0 0 0 0 0 0 0 0
58395 - 0 0 0 0 0 0 0 0 0 0 0 0
58396 - 0 0 0 0 0 0 0 0 0 0 0 0
58397 - 0 0 0 0 0 0 0 0 0 0 0 0
58398 - 0 0 0 0 0 0 0 0 0 0 0 0
58399 - 0 0 0 0 0 0 0 0 0 0 0 0
58400 - 6 6 6 6 6 6 14 14 14 18 18 18
58401 - 30 30 30 38 38 38 46 46 46 54 54 54
58402 - 50 50 50 42 42 42 30 30 30 18 18 18
58403 - 10 10 10 0 0 0 0 0 0 0 0 0
58404 - 0 0 0 0 0 0 0 0 0 0 0 0
58405 - 0 0 0 0 0 0 0 0 0 0 0 0
58406 - 0 0 0 0 0 0 0 0 0 0 0 0
58407 - 0 0 0 6 6 6 14 14 14 26 26 26
58408 - 38 38 38 50 50 50 58 58 58 58 58 58
58409 - 54 54 54 42 42 42 30 30 30 18 18 18
58410 - 10 10 10 0 0 0 0 0 0 0 0 0
58411 - 0 0 0 0 0 0 0 0 0 0 0 0
58412 - 0 0 0 0 0 0 0 0 0 0 0 0
58413 - 0 0 0 0 0 0 0 0 0 0 0 0
58414 - 0 0 0 0 0 0 0 0 0 0 0 0
58415 - 0 0 0 0 0 0 0 0 0 0 0 0
58416 - 0 0 0 0 0 0 0 0 0 0 0 0
58417 - 0 0 0 0 0 0 0 0 0 0 0 0
58418 - 0 0 0 0 0 0 0 0 0 0 0 0
58419 - 0 0 0 0 0 0 0 0 0 0 0 0
58420 - 0 0 0 0 0 0 0 0 0 6 6 6
58421 - 6 6 6 10 10 10 14 14 14 18 18 18
58422 - 18 18 18 14 14 14 10 10 10 6 6 6
58423 - 0 0 0 0 0 0 0 0 0 0 0 0
58424 - 0 0 0 0 0 0 0 0 0 0 0 0
58425 - 0 0 0 0 0 0 0 0 0 0 0 0
58426 - 0 0 0 0 0 0 0 0 0 0 0 0
58427 - 0 0 0 0 0 0 0 0 0 6 6 6
58428 - 14 14 14 18 18 18 22 22 22 22 22 22
58429 - 18 18 18 14 14 14 10 10 10 6 6 6
58430 - 0 0 0 0 0 0 0 0 0 0 0 0
58431 - 0 0 0 0 0 0 0 0 0 0 0 0
58432 - 0 0 0 0 0 0 0 0 0 0 0 0
58433 - 0 0 0 0 0 0 0 0 0 0 0 0
58434 - 0 0 0 0 0 0 0 0 0 0 0 0
58435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58448 +4 4 4 4 4 4
58449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58462 +4 4 4 4 4 4
58463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58476 +4 4 4 4 4 4
58477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58484 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58490 +4 4 4 4 4 4
58491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58498 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58504 +4 4 4 4 4 4
58505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
58515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58518 +4 4 4 4 4 4
58519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58523 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
58524 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
58525 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 1 1 1 0 0 0
58529 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58530 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
58531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58532 +4 4 4 4 4 4
58533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58537 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
58538 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
58539 +5 5 5 4 4 4 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
58543 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
58544 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
58545 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58546 +4 4 4 4 4 4
58547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58551 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
58552 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
58553 +0 0 0 3 3 3 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
58557 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
58558 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
58559 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
58560 +4 4 4 4 4 4
58561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58564 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
58565 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
58566 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
58567 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
58570 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
58571 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
58572 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
58573 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
58574 +4 4 4 4 4 4
58575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58578 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
58579 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
58580 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
58581 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
58582 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58583 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
58584 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
58585 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
58586 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
58587 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
58588 +4 4 4 4 4 4
58589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58592 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
58593 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
58594 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
58595 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
58596 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58597 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
58598 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
58599 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
58600 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
58601 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
58602 +4 4 4 4 4 4
58603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58605 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
58606 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
58607 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
58608 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
58609 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
58610 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
58611 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
58612 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
58613 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
58614 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
58615 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
58616 +4 4 4 4 4 4
58617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58619 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
58620 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
58621 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
58622 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
58623 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
58624 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
58625 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
58626 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
58627 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
58628 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
58629 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
58630 +4 4 4 4 4 4
58631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58633 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
58634 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
58635 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
58636 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
58637 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
58638 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
58639 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
58640 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
58641 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
58642 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
58643 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
58644 +4 4 4 4 4 4
58645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58647 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
58648 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
58649 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
58650 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
58651 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
58652 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
58653 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
58654 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
58655 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
58656 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
58657 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
58658 +4 4 4 4 4 4
58659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58660 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
58661 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
58662 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
58663 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
58664 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
58665 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
58666 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
58667 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
58668 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
58669 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
58670 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
58671 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
58672 +4 4 4 4 4 4
58673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58674 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
58675 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
58676 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
58677 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58678 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
58679 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
58680 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
58681 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
58682 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
58683 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
58684 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
58685 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
58686 +0 0 0 4 4 4
58687 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
58688 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
58689 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
58690 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
58691 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
58692 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
58693 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
58694 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
58695 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
58696 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
58697 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
58698 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
58699 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
58700 +2 0 0 0 0 0
58701 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
58702 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
58703 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
58704 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
58705 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
58706 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
58707 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
58708 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
58709 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
58710 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
58711 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
58712 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
58713 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
58714 +37 38 37 0 0 0
58715 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58716 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
58717 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
58718 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
58719 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
58720 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
58721 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
58722 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
58723 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
58724 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
58725 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
58726 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
58727 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
58728 +85 115 134 4 0 0
58729 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
58730 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
58731 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
58732 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
58733 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
58734 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
58735 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
58736 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
58737 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
58738 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
58739 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
58740 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
58741 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
58742 +60 73 81 4 0 0
58743 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
58744 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
58745 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
58746 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
58747 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
58748 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
58749 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
58750 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
58751 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
58752 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
58753 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
58754 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
58755 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
58756 +16 19 21 4 0 0
58757 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
58758 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
58759 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
58760 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
58761 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
58762 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
58763 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
58764 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
58765 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
58766 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
58767 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
58768 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
58769 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
58770 +4 0 0 4 3 3
58771 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
58772 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
58773 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
58774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
58775 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
58776 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
58777 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
58778 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
58779 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
58780 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
58781 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
58782 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
58783 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
58784 +3 2 2 4 4 4
58785 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
58786 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
58787 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
58788 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
58789 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
58790 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
58791 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
58792 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
58793 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
58794 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
58795 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
58796 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
58797 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
58798 +4 4 4 4 4 4
58799 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
58800 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
58801 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
58802 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
58803 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
58804 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
58805 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
58806 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
58807 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
58808 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
58809 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
58810 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
58811 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
58812 +4 4 4 4 4 4
58813 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
58814 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
58815 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
58816 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
58817 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
58818 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58819 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
58820 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
58821 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
58822 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
58823 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
58824 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
58825 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
58826 +5 5 5 5 5 5
58827 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
58828 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
58829 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
58830 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
58831 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
58832 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58833 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
58834 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
58835 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
58836 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
58837 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
58838 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
58839 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58840 +5 5 5 4 4 4
58841 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
58842 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
58843 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
58844 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
58845 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58846 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
58847 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
58848 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
58849 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
58850 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
58851 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
58852 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58854 +4 4 4 4 4 4
58855 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
58856 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
58857 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
58858 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
58859 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
58860 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58861 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58862 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
58863 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
58864 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
58865 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
58866 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
58867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58868 +4 4 4 4 4 4
58869 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
58870 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
58871 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
58872 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
58873 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58874 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
58875 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
58876 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58877 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58878 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58879 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58882 +4 4 4 4 4 4
58883 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58884 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58885 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58886 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58887 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58888 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58889 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58890 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58891 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58892 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58893 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58896 +4 4 4 4 4 4
58897 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58898 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58899 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58900 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58901 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58902 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58903 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58904 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58905 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58906 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58907 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58910 +4 4 4 4 4 4
58911 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58912 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58913 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58914 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58915 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58916 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58917 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58918 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58919 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58920 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58921 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
58922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58924 +4 4 4 4 4 4
58925 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58926 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58927 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58928 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58929 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58930 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58931 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58932 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58933 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58934 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58935 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
58936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58938 +4 4 4 4 4 4
58939 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58940 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58941 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58942 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58943 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58944 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58945 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58946 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58947 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58948 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58949 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58952 +4 4 4 4 4 4
58953 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58954 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58955 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58956 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58957 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58958 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58959 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58960 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58961 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58962 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58963 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58966 +4 4 4 4 4 4
58967 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58968 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58969 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58970 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58971 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58972 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58973 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58974 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58975 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58976 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58977 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58980 +4 4 4 4 4 4
58981 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58982 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58983 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58984 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58985 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58986 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58987 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58988 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58989 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58990 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58991 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58994 +4 4 4 4 4 4
58995 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58996 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58997 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58998 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58999 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
59000 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
59001 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
59002 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
59003 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
59004 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59005 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59008 +4 4 4 4 4 4
59009 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
59010 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
59011 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
59012 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
59013 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
59014 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
59015 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
59016 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
59017 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
59018 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59019 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59022 +4 4 4 4 4 4
59023 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
59024 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
59025 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
59026 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
59027 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
59028 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
59029 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
59030 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
59031 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
59032 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59033 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59036 +4 4 4 4 4 4
59037 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
59038 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
59039 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
59040 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
59041 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
59042 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
59043 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
59044 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
59045 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
59046 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59047 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59050 +4 4 4 4 4 4
59051 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
59052 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
59053 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
59054 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
59055 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
59056 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
59057 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
59058 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
59059 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
59060 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59061 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59064 +4 4 4 4 4 4
59065 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
59066 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
59067 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
59068 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
59069 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
59070 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
59071 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
59072 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
59073 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
59074 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59075 +0 0 0 3 3 3 5 5 5 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 4 4 4
59079 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
59080 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
59081 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
59082 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
59083 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
59084 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
59085 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
59086 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
59087 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
59088 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59089 +0 0 0 3 3 3 5 5 5 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
59093 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
59094 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
59095 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
59096 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
59097 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
59098 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
59099 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
59100 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
59101 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
59102 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59103 +0 0 0 3 3 3 5 5 5 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
59107 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
59108 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
59109 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
59110 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
59111 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
59112 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
59113 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
59114 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
59115 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
59116 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59117 +0 0 0 3 3 3 5 5 5 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
59121 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
59122 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
59123 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
59124 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
59125 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
59126 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
59127 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
59128 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
59129 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
59130 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59131 +0 0 0 3 3 3 5 5 5 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
59135 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
59136 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
59137 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
59138 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
59139 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
59140 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
59141 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
59142 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
59143 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
59144 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59145 +0 0 0 3 3 3 5 5 5 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
59149 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
59150 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
59151 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
59152 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
59153 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
59154 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
59155 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
59156 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
59157 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
59158 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59159 +0 0 0 3 3 3 5 5 5 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
59163 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
59164 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
59165 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
59166 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
59167 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
59168 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
59169 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
59170 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
59171 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
59172 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59173 +0 0 0 3 3 3 5 5 5 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
59177 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
59178 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
59179 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
59180 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
59181 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
59182 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
59183 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
59184 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
59185 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
59186 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
59187 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59190 +4 4 4 4 4 4
59191 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
59192 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
59193 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
59194 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
59195 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
59196 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
59197 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
59198 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
59199 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
59200 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
59201 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59204 +4 4 4 4 4 4
59205 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
59206 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
59207 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
59208 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
59209 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
59210 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
59211 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
59212 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
59213 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
59214 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
59215 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59218 +4 4 4 4 4 4
59219 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
59220 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
59221 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
59222 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
59223 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
59224 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
59225 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59226 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
59227 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
59228 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
59229 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59232 +4 4 4 4 4 4
59233 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
59234 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
59235 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
59236 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
59237 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
59238 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
59239 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
59240 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
59241 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
59242 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
59243 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59246 +4 4 4 4 4 4
59247 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
59248 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
59249 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
59250 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
59251 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
59252 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
59253 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
59254 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
59255 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
59256 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
59257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59260 +4 4 4 4 4 4
59261 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
59262 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
59263 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
59264 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
59265 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
59266 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
59267 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
59268 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
59269 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
59270 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
59271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59274 +4 4 4 4 4 4
59275 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
59276 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
59277 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
59278 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
59279 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
59280 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
59281 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
59282 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
59283 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
59284 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
59285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59288 +4 4 4 4 4 4
59289 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
59290 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
59291 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
59292 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
59293 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
59294 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
59295 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
59296 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
59297 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
59298 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59302 +4 4 4 4 4 4
59303 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
59304 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
59305 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
59306 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
59307 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
59308 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
59309 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
59310 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
59311 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
59312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59316 +4 4 4 4 4 4
59317 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
59318 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
59319 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
59320 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
59321 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
59322 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
59323 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
59324 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
59325 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
59326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59330 +4 4 4 4 4 4
59331 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
59332 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
59333 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
59334 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
59335 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
59336 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
59337 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
59338 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
59339 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59344 +4 4 4 4 4 4
59345 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
59346 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
59347 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
59348 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
59349 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
59350 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
59351 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
59352 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
59353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59358 +4 4 4 4 4 4
59359 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
59360 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
59361 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
59362 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
59363 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
59364 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
59365 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
59366 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
59367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59372 +4 4 4 4 4 4
59373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59374 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
59375 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59376 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
59377 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
59378 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
59379 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
59380 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
59381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59386 +4 4 4 4 4 4
59387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59388 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
59389 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
59390 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
59391 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
59392 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
59393 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
59394 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
59395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59400 +4 4 4 4 4 4
59401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59402 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
59403 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
59404 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59405 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
59406 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
59407 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
59408 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59414 +4 4 4 4 4 4
59415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59417 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59418 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
59419 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
59420 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
59421 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
59422 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
59423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59428 +4 4 4 4 4 4
59429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59432 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59433 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
59434 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
59435 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
59436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59442 +4 4 4 4 4 4
59443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59446 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
59447 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
59448 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
59449 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
59450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59456 +4 4 4 4 4 4
59457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59460 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
59461 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
59462 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
59463 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
59464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59470 +4 4 4 4 4 4
59471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59474 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
59475 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
59476 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
59477 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
59478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59484 +4 4 4 4 4 4
59485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
59489 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
59490 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
59491 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
59492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59498 +4 4 4 4 4 4
59499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59503 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
59504 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
59505 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
59506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59512 +4 4 4 4 4 4
59513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59517 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
59518 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
59519 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59526 +4 4 4 4 4 4
59527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59531 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
59532 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
59533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59540 +4 4 4 4 4 4
59541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59545 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
59546 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
59547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
59554 +4 4 4 4 4 4
59555 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
59556 index fef20db..d28b1ab 100644
59557 --- a/drivers/xen/xenfs/xenstored.c
59558 +++ b/drivers/xen/xenfs/xenstored.c
59559 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
59560 static int xsd_kva_open(struct inode *inode, struct file *file)
59561 {
59562 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
59563 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59564 + NULL);
59565 +#else
59566 xen_store_interface);
59567 +#endif
59568 +
59569 if (!file->private_data)
59570 return -ENOMEM;
59571 return 0;
59572 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
59573 index cc1cfae..41158ad 100644
59574 --- a/fs/9p/vfs_addr.c
59575 +++ b/fs/9p/vfs_addr.c
59576 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
59577
59578 retval = v9fs_file_write_internal(inode,
59579 v9inode->writeback_fid,
59580 - (__force const char __user *)buffer,
59581 + (const char __force_user *)buffer,
59582 len, &offset, 0);
59583 if (retval > 0)
59584 retval = 0;
59585 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
59586 index 7fa4f7a..a7ebf8c 100644
59587 --- a/fs/9p/vfs_inode.c
59588 +++ b/fs/9p/vfs_inode.c
59589 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59590 void
59591 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
59592 {
59593 - char *s = nd_get_link(nd);
59594 + const char *s = nd_get_link(nd);
59595
59596 p9_debug(P9_DEBUG_VFS, " %s %s\n",
59597 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
59598 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
59599 index 370b24c..ff0be7b 100644
59600 --- a/fs/Kconfig.binfmt
59601 +++ b/fs/Kconfig.binfmt
59602 @@ -103,7 +103,7 @@ config HAVE_AOUT
59603
59604 config BINFMT_AOUT
59605 tristate "Kernel support for a.out and ECOFF binaries"
59606 - depends on HAVE_AOUT
59607 + depends on HAVE_AOUT && BROKEN
59608 ---help---
59609 A.out (Assembler.OUTput) is a set of formats for libraries and
59610 executables used in the earliest versions of UNIX. Linux used
59611 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
59612 index 2946712..f737435 100644
59613 --- a/fs/afs/inode.c
59614 +++ b/fs/afs/inode.c
59615 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59616 struct afs_vnode *vnode;
59617 struct super_block *sb;
59618 struct inode *inode;
59619 - static atomic_t afs_autocell_ino;
59620 + static atomic_unchecked_t afs_autocell_ino;
59621
59622 _enter("{%x:%u},%*.*s,",
59623 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
59624 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
59625 data.fid.unique = 0;
59626 data.fid.vnode = 0;
59627
59628 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
59629 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
59630 afs_iget5_autocell_test, afs_iget5_set,
59631 &data);
59632 if (!inode) {
59633 diff --git a/fs/aio.c b/fs/aio.c
59634 index 1c9c5f0..c935d6e 100644
59635 --- a/fs/aio.c
59636 +++ b/fs/aio.c
59637 @@ -141,6 +141,7 @@ struct kioctx {
59638
59639 struct {
59640 unsigned tail;
59641 + unsigned completed_events;
59642 spinlock_t completion_lock;
59643 } ____cacheline_aligned_in_smp;
59644
59645 @@ -380,7 +381,7 @@ static int aio_setup_ring(struct kioctx *ctx)
59646 size += sizeof(struct io_event) * nr_events;
59647
59648 nr_pages = PFN_UP(size);
59649 - if (nr_pages < 0)
59650 + if (nr_pages <= 0)
59651 return -EINVAL;
59652
59653 file = aio_private_file(ctx, nr_pages);
59654 @@ -880,6 +881,68 @@ out:
59655 return ret;
59656 }
59657
59658 +/* refill_reqs_available
59659 + * Updates the reqs_available reference counts used for tracking the
59660 + * number of free slots in the completion ring. This can be called
59661 + * from aio_complete() (to optimistically update reqs_available) or
59662 + * from aio_get_req() (the we're out of events case). It must be
59663 + * called holding ctx->completion_lock.
59664 + */
59665 +static void refill_reqs_available(struct kioctx *ctx, unsigned head,
59666 + unsigned tail)
59667 +{
59668 + unsigned events_in_ring, completed;
59669 +
59670 + /* Clamp head since userland can write to it. */
59671 + head %= ctx->nr_events;
59672 + if (head <= tail)
59673 + events_in_ring = tail - head;
59674 + else
59675 + events_in_ring = ctx->nr_events - (head - tail);
59676 +
59677 + completed = ctx->completed_events;
59678 + if (events_in_ring < completed)
59679 + completed -= events_in_ring;
59680 + else
59681 + completed = 0;
59682 +
59683 + if (!completed)
59684 + return;
59685 +
59686 + ctx->completed_events -= completed;
59687 + put_reqs_available(ctx, completed);
59688 +}
59689 +
59690 +/* user_refill_reqs_available
59691 + * Called to refill reqs_available when aio_get_req() encounters an
59692 + * out of space in the completion ring.
59693 + */
59694 +static void user_refill_reqs_available(struct kioctx *ctx)
59695 +{
59696 + spin_lock_irq(&ctx->completion_lock);
59697 + if (ctx->completed_events) {
59698 + struct aio_ring *ring;
59699 + unsigned head;
59700 +
59701 + /* Access of ring->head may race with aio_read_events_ring()
59702 + * here, but that's okay since whether we read the old version
59703 + * or the new version, and either will be valid. The important
59704 + * part is that head cannot pass tail since we prevent
59705 + * aio_complete() from updating tail by holding
59706 + * ctx->completion_lock. Even if head is invalid, the check
59707 + * against ctx->completed_events below will make sure we do the
59708 + * safe/right thing.
59709 + */
59710 + ring = kmap_atomic(ctx->ring_pages[0]);
59711 + head = ring->head;
59712 + kunmap_atomic(ring);
59713 +
59714 + refill_reqs_available(ctx, head, ctx->tail);
59715 + }
59716 +
59717 + spin_unlock_irq(&ctx->completion_lock);
59718 +}
59719 +
59720 /* aio_get_req
59721 * Allocate a slot for an aio request.
59722 * Returns NULL if no requests are free.
59723 @@ -888,8 +951,11 @@ static inline struct kiocb *aio_get_req(struct kioctx *ctx)
59724 {
59725 struct kiocb *req;
59726
59727 - if (!get_reqs_available(ctx))
59728 - return NULL;
59729 + if (!get_reqs_available(ctx)) {
59730 + user_refill_reqs_available(ctx);
59731 + if (!get_reqs_available(ctx))
59732 + return NULL;
59733 + }
59734
59735 req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL|__GFP_ZERO);
59736 if (unlikely(!req))
59737 @@ -948,8 +1014,8 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59738 struct kioctx *ctx = iocb->ki_ctx;
59739 struct aio_ring *ring;
59740 struct io_event *ev_page, *event;
59741 + unsigned tail, pos, head;
59742 unsigned long flags;
59743 - unsigned tail, pos;
59744
59745 /*
59746 * Special case handling for sync iocbs:
59747 @@ -1010,10 +1076,14 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59748 ctx->tail = tail;
59749
59750 ring = kmap_atomic(ctx->ring_pages[0]);
59751 + head = ring->head;
59752 ring->tail = tail;
59753 kunmap_atomic(ring);
59754 flush_dcache_page(ctx->ring_pages[0]);
59755
59756 + ctx->completed_events++;
59757 + if (ctx->completed_events > 1)
59758 + refill_reqs_available(ctx, head, tail);
59759 spin_unlock_irqrestore(&ctx->completion_lock, flags);
59760
59761 pr_debug("added to ring %p at [%u]\n", iocb, tail);
59762 @@ -1028,7 +1098,6 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
59763
59764 /* everything turned out well, dispose of the aiocb. */
59765 kiocb_free(iocb);
59766 - put_reqs_available(ctx, 1);
59767
59768 /*
59769 * We have to order our ring_info tail store above and test
59770 @@ -1065,6 +1134,12 @@ static long aio_read_events_ring(struct kioctx *ctx,
59771 tail = ring->tail;
59772 kunmap_atomic(ring);
59773
59774 + /*
59775 + * Ensure that once we've read the current tail pointer, that
59776 + * we also see the events that were stored up to the tail.
59777 + */
59778 + smp_rmb();
59779 +
59780 pr_debug("h%u t%u m%u\n", head, tail, ctx->nr_events);
59781
59782 if (head == tail)
59783 diff --git a/fs/attr.c b/fs/attr.c
59784 index 6530ced..4a827e2 100644
59785 --- a/fs/attr.c
59786 +++ b/fs/attr.c
59787 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
59788 unsigned long limit;
59789
59790 limit = rlimit(RLIMIT_FSIZE);
59791 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
59792 if (limit != RLIM_INFINITY && offset > limit)
59793 goto out_sig;
59794 if (offset > inode->i_sb->s_maxbytes)
59795 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
59796 index 116fd38..c04182da 100644
59797 --- a/fs/autofs4/waitq.c
59798 +++ b/fs/autofs4/waitq.c
59799 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
59800 {
59801 unsigned long sigpipe, flags;
59802 mm_segment_t fs;
59803 - const char *data = (const char *)addr;
59804 + const char __user *data = (const char __force_user *)addr;
59805 ssize_t wr = 0;
59806
59807 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
59808 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
59809 return 1;
59810 }
59811
59812 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59813 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
59814 +#endif
59815 +
59816 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59817 enum autofs_notify notify)
59818 {
59819 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
59820
59821 /* If this is a direct mount request create a dummy name */
59822 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
59823 +#ifdef CONFIG_GRKERNSEC_HIDESYM
59824 + /* this name does get written to userland via autofs4_write() */
59825 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
59826 +#else
59827 qstr.len = sprintf(name, "%p", dentry);
59828 +#endif
59829 else {
59830 qstr.len = autofs4_getpath(sbi, dentry, &name);
59831 if (!qstr.len) {
59832 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
59833 index 2722387..56059b5 100644
59834 --- a/fs/befs/endian.h
59835 +++ b/fs/befs/endian.h
59836 @@ -11,7 +11,7 @@
59837
59838 #include <asm/byteorder.h>
59839
59840 -static inline u64
59841 +static inline u64 __intentional_overflow(-1)
59842 fs64_to_cpu(const struct super_block *sb, fs64 n)
59843 {
59844 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59845 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
59846 return (__force fs64)cpu_to_be64(n);
59847 }
59848
59849 -static inline u32
59850 +static inline u32 __intentional_overflow(-1)
59851 fs32_to_cpu(const struct super_block *sb, fs32 n)
59852 {
59853 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59854 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
59855 return (__force fs32)cpu_to_be32(n);
59856 }
59857
59858 -static inline u16
59859 +static inline u16 __intentional_overflow(-1)
59860 fs16_to_cpu(const struct super_block *sb, fs16 n)
59861 {
59862 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
59863 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
59864 index ca0ba15..0fa3257 100644
59865 --- a/fs/binfmt_aout.c
59866 +++ b/fs/binfmt_aout.c
59867 @@ -16,6 +16,7 @@
59868 #include <linux/string.h>
59869 #include <linux/fs.h>
59870 #include <linux/file.h>
59871 +#include <linux/security.h>
59872 #include <linux/stat.h>
59873 #include <linux/fcntl.h>
59874 #include <linux/ptrace.h>
59875 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
59876 #endif
59877 # define START_STACK(u) ((void __user *)u.start_stack)
59878
59879 + memset(&dump, 0, sizeof(dump));
59880 +
59881 fs = get_fs();
59882 set_fs(KERNEL_DS);
59883 has_dumped = 1;
59884 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
59885
59886 /* If the size of the dump file exceeds the rlimit, then see what would happen
59887 if we wrote the stack, but not the data area. */
59888 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
59889 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
59890 dump.u_dsize = 0;
59891
59892 /* Make sure we have enough room to write the stack and data areas. */
59893 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
59894 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
59895 dump.u_ssize = 0;
59896
59897 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
59898 rlim = rlimit(RLIMIT_DATA);
59899 if (rlim >= RLIM_INFINITY)
59900 rlim = ~0;
59901 +
59902 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
59903 if (ex.a_data + ex.a_bss > rlim)
59904 return -ENOMEM;
59905
59906 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
59907
59908 install_exec_creds(bprm);
59909
59910 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59911 + current->mm->pax_flags = 0UL;
59912 +#endif
59913 +
59914 +#ifdef CONFIG_PAX_PAGEEXEC
59915 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
59916 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
59917 +
59918 +#ifdef CONFIG_PAX_EMUTRAMP
59919 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
59920 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
59921 +#endif
59922 +
59923 +#ifdef CONFIG_PAX_MPROTECT
59924 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
59925 + current->mm->pax_flags |= MF_PAX_MPROTECT;
59926 +#endif
59927 +
59928 + }
59929 +#endif
59930 +
59931 if (N_MAGIC(ex) == OMAGIC) {
59932 unsigned long text_addr, map_size;
59933 loff_t pos;
59934 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
59935 }
59936
59937 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
59938 - PROT_READ | PROT_WRITE | PROT_EXEC,
59939 + PROT_READ | PROT_WRITE,
59940 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
59941 fd_offset + ex.a_text);
59942 if (error != N_DATADDR(ex)) {
59943 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
59944 index 3892c1a..4e27c04 100644
59945 --- a/fs/binfmt_elf.c
59946 +++ b/fs/binfmt_elf.c
59947 @@ -34,6 +34,7 @@
59948 #include <linux/utsname.h>
59949 #include <linux/coredump.h>
59950 #include <linux/sched.h>
59951 +#include <linux/xattr.h>
59952 #include <asm/uaccess.h>
59953 #include <asm/param.h>
59954 #include <asm/page.h>
59955 @@ -47,7 +48,7 @@
59956
59957 static int load_elf_binary(struct linux_binprm *bprm);
59958 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
59959 - int, int, unsigned long);
59960 + int, int, unsigned long) __intentional_overflow(-1);
59961
59962 #ifdef CONFIG_USELIB
59963 static int load_elf_library(struct file *);
59964 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
59965 #define elf_core_dump NULL
59966 #endif
59967
59968 +#ifdef CONFIG_PAX_MPROTECT
59969 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
59970 +#endif
59971 +
59972 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59973 +static void elf_handle_mmap(struct file *file);
59974 +#endif
59975 +
59976 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
59977 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
59978 #else
59979 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
59980 .load_binary = load_elf_binary,
59981 .load_shlib = load_elf_library,
59982 .core_dump = elf_core_dump,
59983 +
59984 +#ifdef CONFIG_PAX_MPROTECT
59985 + .handle_mprotect= elf_handle_mprotect,
59986 +#endif
59987 +
59988 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59989 + .handle_mmap = elf_handle_mmap,
59990 +#endif
59991 +
59992 .min_coredump = ELF_EXEC_PAGESIZE,
59993 };
59994
59995 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
59996
59997 static int set_brk(unsigned long start, unsigned long end)
59998 {
59999 + unsigned long e = end;
60000 +
60001 start = ELF_PAGEALIGN(start);
60002 end = ELF_PAGEALIGN(end);
60003 if (end > start) {
60004 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
60005 if (BAD_ADDR(addr))
60006 return addr;
60007 }
60008 - current->mm->start_brk = current->mm->brk = end;
60009 + current->mm->start_brk = current->mm->brk = e;
60010 return 0;
60011 }
60012
60013 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
60014 elf_addr_t __user *u_rand_bytes;
60015 const char *k_platform = ELF_PLATFORM;
60016 const char *k_base_platform = ELF_BASE_PLATFORM;
60017 - unsigned char k_rand_bytes[16];
60018 + u32 k_rand_bytes[4];
60019 int items;
60020 elf_addr_t *elf_info;
60021 int ei_index = 0;
60022 const struct cred *cred = current_cred();
60023 struct vm_area_struct *vma;
60024 + unsigned long saved_auxv[AT_VECTOR_SIZE];
60025
60026 /*
60027 * In some cases (e.g. Hyper-Threading), we want to avoid L1
60028 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
60029 * Generate 16 random bytes for userspace PRNG seeding.
60030 */
60031 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
60032 - u_rand_bytes = (elf_addr_t __user *)
60033 - STACK_ALLOC(p, sizeof(k_rand_bytes));
60034 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
60035 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
60036 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
60037 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
60038 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
60039 + u_rand_bytes = (elf_addr_t __user *) p;
60040 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
60041 return -EFAULT;
60042
60043 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
60044 return -EFAULT;
60045 current->mm->env_end = p;
60046
60047 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
60048 +
60049 /* Put the elf_info on the stack in the right place. */
60050 sp = (elf_addr_t __user *)envp + 1;
60051 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
60052 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
60053 return -EFAULT;
60054 return 0;
60055 }
60056 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
60057 an ELF header */
60058
60059 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
60060 - struct file *interpreter, unsigned long *interp_map_addr,
60061 - unsigned long no_base)
60062 + struct file *interpreter, unsigned long no_base)
60063 {
60064 struct elf_phdr *elf_phdata;
60065 struct elf_phdr *eppnt;
60066 - unsigned long load_addr = 0;
60067 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
60068 int load_addr_set = 0;
60069 unsigned long last_bss = 0, elf_bss = 0;
60070 - unsigned long error = ~0UL;
60071 + unsigned long error = -EINVAL;
60072 unsigned long total_size;
60073 int retval, i, size;
60074
60075 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
60076 goto out_close;
60077 }
60078
60079 +#ifdef CONFIG_PAX_SEGMEXEC
60080 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
60081 + pax_task_size = SEGMEXEC_TASK_SIZE;
60082 +#endif
60083 +
60084 eppnt = elf_phdata;
60085 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
60086 if (eppnt->p_type == PT_LOAD) {
60087 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
60088 map_addr = elf_map(interpreter, load_addr + vaddr,
60089 eppnt, elf_prot, elf_type, total_size);
60090 total_size = 0;
60091 - if (!*interp_map_addr)
60092 - *interp_map_addr = map_addr;
60093 error = map_addr;
60094 if (BAD_ADDR(map_addr))
60095 goto out_close;
60096 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
60097 k = load_addr + eppnt->p_vaddr;
60098 if (BAD_ADDR(k) ||
60099 eppnt->p_filesz > eppnt->p_memsz ||
60100 - eppnt->p_memsz > TASK_SIZE ||
60101 - TASK_SIZE - eppnt->p_memsz < k) {
60102 + eppnt->p_memsz > pax_task_size ||
60103 + pax_task_size - eppnt->p_memsz < k) {
60104 error = -ENOMEM;
60105 goto out_close;
60106 }
60107 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
60108 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
60109
60110 /* Map the last of the bss segment */
60111 - error = vm_brk(elf_bss, last_bss - elf_bss);
60112 - if (BAD_ADDR(error))
60113 - goto out_close;
60114 + if (last_bss > elf_bss) {
60115 + error = vm_brk(elf_bss, last_bss - elf_bss);
60116 + if (BAD_ADDR(error))
60117 + goto out_close;
60118 + }
60119 }
60120
60121 error = load_addr;
60122 @@ -543,6 +574,336 @@ out:
60123 return error;
60124 }
60125
60126 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
60127 +#ifdef CONFIG_PAX_SOFTMODE
60128 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
60129 +{
60130 + unsigned long pax_flags = 0UL;
60131 +
60132 +#ifdef CONFIG_PAX_PAGEEXEC
60133 + if (elf_phdata->p_flags & PF_PAGEEXEC)
60134 + pax_flags |= MF_PAX_PAGEEXEC;
60135 +#endif
60136 +
60137 +#ifdef CONFIG_PAX_SEGMEXEC
60138 + if (elf_phdata->p_flags & PF_SEGMEXEC)
60139 + pax_flags |= MF_PAX_SEGMEXEC;
60140 +#endif
60141 +
60142 +#ifdef CONFIG_PAX_EMUTRAMP
60143 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
60144 + pax_flags |= MF_PAX_EMUTRAMP;
60145 +#endif
60146 +
60147 +#ifdef CONFIG_PAX_MPROTECT
60148 + if (elf_phdata->p_flags & PF_MPROTECT)
60149 + pax_flags |= MF_PAX_MPROTECT;
60150 +#endif
60151 +
60152 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
60153 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
60154 + pax_flags |= MF_PAX_RANDMMAP;
60155 +#endif
60156 +
60157 + return pax_flags;
60158 +}
60159 +#endif
60160 +
60161 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
60162 +{
60163 + unsigned long pax_flags = 0UL;
60164 +
60165 +#ifdef CONFIG_PAX_PAGEEXEC
60166 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
60167 + pax_flags |= MF_PAX_PAGEEXEC;
60168 +#endif
60169 +
60170 +#ifdef CONFIG_PAX_SEGMEXEC
60171 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
60172 + pax_flags |= MF_PAX_SEGMEXEC;
60173 +#endif
60174 +
60175 +#ifdef CONFIG_PAX_EMUTRAMP
60176 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
60177 + pax_flags |= MF_PAX_EMUTRAMP;
60178 +#endif
60179 +
60180 +#ifdef CONFIG_PAX_MPROTECT
60181 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
60182 + pax_flags |= MF_PAX_MPROTECT;
60183 +#endif
60184 +
60185 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
60186 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
60187 + pax_flags |= MF_PAX_RANDMMAP;
60188 +#endif
60189 +
60190 + return pax_flags;
60191 +}
60192 +#endif
60193 +
60194 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60195 +#ifdef CONFIG_PAX_SOFTMODE
60196 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
60197 +{
60198 + unsigned long pax_flags = 0UL;
60199 +
60200 +#ifdef CONFIG_PAX_PAGEEXEC
60201 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
60202 + pax_flags |= MF_PAX_PAGEEXEC;
60203 +#endif
60204 +
60205 +#ifdef CONFIG_PAX_SEGMEXEC
60206 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
60207 + pax_flags |= MF_PAX_SEGMEXEC;
60208 +#endif
60209 +
60210 +#ifdef CONFIG_PAX_EMUTRAMP
60211 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
60212 + pax_flags |= MF_PAX_EMUTRAMP;
60213 +#endif
60214 +
60215 +#ifdef CONFIG_PAX_MPROTECT
60216 + if (pax_flags_softmode & MF_PAX_MPROTECT)
60217 + pax_flags |= MF_PAX_MPROTECT;
60218 +#endif
60219 +
60220 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
60221 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
60222 + pax_flags |= MF_PAX_RANDMMAP;
60223 +#endif
60224 +
60225 + return pax_flags;
60226 +}
60227 +#endif
60228 +
60229 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
60230 +{
60231 + unsigned long pax_flags = 0UL;
60232 +
60233 +#ifdef CONFIG_PAX_PAGEEXEC
60234 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
60235 + pax_flags |= MF_PAX_PAGEEXEC;
60236 +#endif
60237 +
60238 +#ifdef CONFIG_PAX_SEGMEXEC
60239 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
60240 + pax_flags |= MF_PAX_SEGMEXEC;
60241 +#endif
60242 +
60243 +#ifdef CONFIG_PAX_EMUTRAMP
60244 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
60245 + pax_flags |= MF_PAX_EMUTRAMP;
60246 +#endif
60247 +
60248 +#ifdef CONFIG_PAX_MPROTECT
60249 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
60250 + pax_flags |= MF_PAX_MPROTECT;
60251 +#endif
60252 +
60253 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
60254 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
60255 + pax_flags |= MF_PAX_RANDMMAP;
60256 +#endif
60257 +
60258 + return pax_flags;
60259 +}
60260 +#endif
60261 +
60262 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60263 +static unsigned long pax_parse_defaults(void)
60264 +{
60265 + unsigned long pax_flags = 0UL;
60266 +
60267 +#ifdef CONFIG_PAX_SOFTMODE
60268 + if (pax_softmode)
60269 + return pax_flags;
60270 +#endif
60271 +
60272 +#ifdef CONFIG_PAX_PAGEEXEC
60273 + pax_flags |= MF_PAX_PAGEEXEC;
60274 +#endif
60275 +
60276 +#ifdef CONFIG_PAX_SEGMEXEC
60277 + pax_flags |= MF_PAX_SEGMEXEC;
60278 +#endif
60279 +
60280 +#ifdef CONFIG_PAX_MPROTECT
60281 + pax_flags |= MF_PAX_MPROTECT;
60282 +#endif
60283 +
60284 +#ifdef CONFIG_PAX_RANDMMAP
60285 + if (randomize_va_space)
60286 + pax_flags |= MF_PAX_RANDMMAP;
60287 +#endif
60288 +
60289 + return pax_flags;
60290 +}
60291 +
60292 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
60293 +{
60294 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
60295 +
60296 +#ifdef CONFIG_PAX_EI_PAX
60297 +
60298 +#ifdef CONFIG_PAX_SOFTMODE
60299 + if (pax_softmode)
60300 + return pax_flags;
60301 +#endif
60302 +
60303 + pax_flags = 0UL;
60304 +
60305 +#ifdef CONFIG_PAX_PAGEEXEC
60306 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
60307 + pax_flags |= MF_PAX_PAGEEXEC;
60308 +#endif
60309 +
60310 +#ifdef CONFIG_PAX_SEGMEXEC
60311 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
60312 + pax_flags |= MF_PAX_SEGMEXEC;
60313 +#endif
60314 +
60315 +#ifdef CONFIG_PAX_EMUTRAMP
60316 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
60317 + pax_flags |= MF_PAX_EMUTRAMP;
60318 +#endif
60319 +
60320 +#ifdef CONFIG_PAX_MPROTECT
60321 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
60322 + pax_flags |= MF_PAX_MPROTECT;
60323 +#endif
60324 +
60325 +#ifdef CONFIG_PAX_ASLR
60326 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
60327 + pax_flags |= MF_PAX_RANDMMAP;
60328 +#endif
60329 +
60330 +#endif
60331 +
60332 + return pax_flags;
60333 +
60334 +}
60335 +
60336 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
60337 +{
60338 +
60339 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
60340 + unsigned long i;
60341 +
60342 + for (i = 0UL; i < elf_ex->e_phnum; i++)
60343 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
60344 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
60345 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
60346 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
60347 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
60348 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
60349 + return PAX_PARSE_FLAGS_FALLBACK;
60350 +
60351 +#ifdef CONFIG_PAX_SOFTMODE
60352 + if (pax_softmode)
60353 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
60354 + else
60355 +#endif
60356 +
60357 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
60358 + break;
60359 + }
60360 +#endif
60361 +
60362 + return PAX_PARSE_FLAGS_FALLBACK;
60363 +}
60364 +
60365 +static unsigned long pax_parse_xattr_pax(struct file * const file)
60366 +{
60367 +
60368 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60369 + ssize_t xattr_size, i;
60370 + unsigned char xattr_value[sizeof("pemrs") - 1];
60371 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
60372 +
60373 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
60374 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
60375 + return PAX_PARSE_FLAGS_FALLBACK;
60376 +
60377 + for (i = 0; i < xattr_size; i++)
60378 + switch (xattr_value[i]) {
60379 + default:
60380 + return PAX_PARSE_FLAGS_FALLBACK;
60381 +
60382 +#define parse_flag(option1, option2, flag) \
60383 + case option1: \
60384 + if (pax_flags_hardmode & MF_PAX_##flag) \
60385 + return PAX_PARSE_FLAGS_FALLBACK;\
60386 + pax_flags_hardmode |= MF_PAX_##flag; \
60387 + break; \
60388 + case option2: \
60389 + if (pax_flags_softmode & MF_PAX_##flag) \
60390 + return PAX_PARSE_FLAGS_FALLBACK;\
60391 + pax_flags_softmode |= MF_PAX_##flag; \
60392 + break;
60393 +
60394 + parse_flag('p', 'P', PAGEEXEC);
60395 + parse_flag('e', 'E', EMUTRAMP);
60396 + parse_flag('m', 'M', MPROTECT);
60397 + parse_flag('r', 'R', RANDMMAP);
60398 + parse_flag('s', 'S', SEGMEXEC);
60399 +
60400 +#undef parse_flag
60401 + }
60402 +
60403 + if (pax_flags_hardmode & pax_flags_softmode)
60404 + return PAX_PARSE_FLAGS_FALLBACK;
60405 +
60406 +#ifdef CONFIG_PAX_SOFTMODE
60407 + if (pax_softmode)
60408 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
60409 + else
60410 +#endif
60411 +
60412 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
60413 +#else
60414 + return PAX_PARSE_FLAGS_FALLBACK;
60415 +#endif
60416 +
60417 +}
60418 +
60419 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
60420 +{
60421 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
60422 +
60423 + pax_flags = pax_parse_defaults();
60424 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
60425 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
60426 + xattr_pax_flags = pax_parse_xattr_pax(file);
60427 +
60428 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
60429 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
60430 + pt_pax_flags != xattr_pax_flags)
60431 + return -EINVAL;
60432 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60433 + pax_flags = xattr_pax_flags;
60434 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60435 + pax_flags = pt_pax_flags;
60436 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
60437 + pax_flags = ei_pax_flags;
60438 +
60439 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
60440 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60441 + if ((__supported_pte_mask & _PAGE_NX))
60442 + pax_flags &= ~MF_PAX_SEGMEXEC;
60443 + else
60444 + pax_flags &= ~MF_PAX_PAGEEXEC;
60445 + }
60446 +#endif
60447 +
60448 + if (0 > pax_check_flags(&pax_flags))
60449 + return -EINVAL;
60450 +
60451 + current->mm->pax_flags = pax_flags;
60452 + return 0;
60453 +}
60454 +#endif
60455 +
60456 /*
60457 * These are the functions used to load ELF style executables and shared
60458 * libraries. There is no binary dependent code anywhere else.
60459 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
60460 {
60461 unsigned int random_variable = 0;
60462
60463 +#ifdef CONFIG_PAX_RANDUSTACK
60464 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
60465 + return stack_top - current->mm->delta_stack;
60466 +#endif
60467 +
60468 if ((current->flags & PF_RANDOMIZE) &&
60469 !(current->personality & ADDR_NO_RANDOMIZE)) {
60470 random_variable = get_random_int() & STACK_RND_MASK;
60471 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
60472 unsigned long load_addr = 0, load_bias = 0;
60473 int load_addr_set = 0;
60474 char * elf_interpreter = NULL;
60475 - unsigned long error;
60476 + unsigned long error = 0;
60477 struct elf_phdr *elf_ppnt, *elf_phdata;
60478 unsigned long elf_bss, elf_brk;
60479 int retval, i;
60480 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
60481 struct elfhdr elf_ex;
60482 struct elfhdr interp_elf_ex;
60483 } *loc;
60484 + unsigned long pax_task_size;
60485
60486 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
60487 if (!loc) {
60488 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
60489 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
60490 may depend on the personality. */
60491 SET_PERSONALITY(loc->elf_ex);
60492 +
60493 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60494 + current->mm->pax_flags = 0UL;
60495 +#endif
60496 +
60497 +#ifdef CONFIG_PAX_DLRESOLVE
60498 + current->mm->call_dl_resolve = 0UL;
60499 +#endif
60500 +
60501 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60502 + current->mm->call_syscall = 0UL;
60503 +#endif
60504 +
60505 +#ifdef CONFIG_PAX_ASLR
60506 + current->mm->delta_mmap = 0UL;
60507 + current->mm->delta_stack = 0UL;
60508 +#endif
60509 +
60510 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60511 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
60512 + send_sig(SIGKILL, current, 0);
60513 + goto out_free_dentry;
60514 + }
60515 +#endif
60516 +
60517 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60518 + pax_set_initial_flags(bprm);
60519 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60520 + if (pax_set_initial_flags_func)
60521 + (pax_set_initial_flags_func)(bprm);
60522 +#endif
60523 +
60524 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60525 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
60526 + current->mm->context.user_cs_limit = PAGE_SIZE;
60527 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
60528 + }
60529 +#endif
60530 +
60531 +#ifdef CONFIG_PAX_SEGMEXEC
60532 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
60533 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
60534 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
60535 + pax_task_size = SEGMEXEC_TASK_SIZE;
60536 + current->mm->def_flags |= VM_NOHUGEPAGE;
60537 + } else
60538 +#endif
60539 +
60540 + pax_task_size = TASK_SIZE;
60541 +
60542 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
60543 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60544 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
60545 + put_cpu();
60546 + }
60547 +#endif
60548 +
60549 +#ifdef CONFIG_PAX_ASLR
60550 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60551 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
60552 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
60553 + }
60554 +#endif
60555 +
60556 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60557 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60558 + executable_stack = EXSTACK_DISABLE_X;
60559 + current->personality &= ~READ_IMPLIES_EXEC;
60560 + } else
60561 +#endif
60562 +
60563 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
60564 current->personality |= READ_IMPLIES_EXEC;
60565
60566 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
60567 #else
60568 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
60569 #endif
60570 +
60571 +#ifdef CONFIG_PAX_RANDMMAP
60572 + /* PaX: randomize base address at the default exe base if requested */
60573 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
60574 +#ifdef CONFIG_SPARC64
60575 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
60576 +#else
60577 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
60578 +#endif
60579 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
60580 + elf_flags |= MAP_FIXED;
60581 + }
60582 +#endif
60583 +
60584 }
60585
60586 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
60587 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
60588 * allowed task size. Note that p_filesz must always be
60589 * <= p_memsz so it is only necessary to check p_memsz.
60590 */
60591 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60592 - elf_ppnt->p_memsz > TASK_SIZE ||
60593 - TASK_SIZE - elf_ppnt->p_memsz < k) {
60594 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
60595 + elf_ppnt->p_memsz > pax_task_size ||
60596 + pax_task_size - elf_ppnt->p_memsz < k) {
60597 /* set_brk can never work. Avoid overflows. */
60598 send_sig(SIGKILL, current, 0);
60599 retval = -EINVAL;
60600 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
60601 goto out_free_dentry;
60602 }
60603 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
60604 - send_sig(SIGSEGV, current, 0);
60605 - retval = -EFAULT; /* Nobody gets to see this, but.. */
60606 - goto out_free_dentry;
60607 + /*
60608 + * This bss-zeroing can fail if the ELF
60609 + * file specifies odd protections. So
60610 + * we don't check the return value
60611 + */
60612 }
60613
60614 +#ifdef CONFIG_PAX_RANDMMAP
60615 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
60616 + unsigned long start, size, flags;
60617 + vm_flags_t vm_flags;
60618 +
60619 + start = ELF_PAGEALIGN(elf_brk);
60620 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
60621 + flags = MAP_FIXED | MAP_PRIVATE;
60622 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
60623 +
60624 + down_write(&current->mm->mmap_sem);
60625 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
60626 + retval = -ENOMEM;
60627 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
60628 +// if (current->personality & ADDR_NO_RANDOMIZE)
60629 +// vm_flags |= VM_READ | VM_MAYREAD;
60630 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
60631 + retval = IS_ERR_VALUE(start) ? start : 0;
60632 + }
60633 + up_write(&current->mm->mmap_sem);
60634 + if (retval == 0)
60635 + retval = set_brk(start + size, start + size + PAGE_SIZE);
60636 + if (retval < 0) {
60637 + send_sig(SIGKILL, current, 0);
60638 + goto out_free_dentry;
60639 + }
60640 + }
60641 +#endif
60642 +
60643 if (elf_interpreter) {
60644 - unsigned long interp_map_addr = 0;
60645 -
60646 elf_entry = load_elf_interp(&loc->interp_elf_ex,
60647 interpreter,
60648 - &interp_map_addr,
60649 load_bias);
60650 if (!IS_ERR((void *)elf_entry)) {
60651 /*
60652 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
60653 * Decide what to dump of a segment, part, all or none.
60654 */
60655 static unsigned long vma_dump_size(struct vm_area_struct *vma,
60656 - unsigned long mm_flags)
60657 + unsigned long mm_flags, long signr)
60658 {
60659 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
60660
60661 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
60662 if (vma->vm_file == NULL)
60663 return 0;
60664
60665 - if (FILTER(MAPPED_PRIVATE))
60666 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
60667 goto whole;
60668
60669 /*
60670 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
60671 {
60672 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
60673 int i = 0;
60674 - do
60675 + do {
60676 i += 2;
60677 - while (auxv[i - 2] != AT_NULL);
60678 + } while (auxv[i - 2] != AT_NULL);
60679 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
60680 }
60681
60682 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
60683 {
60684 mm_segment_t old_fs = get_fs();
60685 set_fs(KERNEL_DS);
60686 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
60687 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
60688 set_fs(old_fs);
60689 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
60690 }
60691 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
60692 }
60693
60694 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
60695 - unsigned long mm_flags)
60696 + struct coredump_params *cprm)
60697 {
60698 struct vm_area_struct *vma;
60699 size_t size = 0;
60700
60701 for (vma = first_vma(current, gate_vma); vma != NULL;
60702 vma = next_vma(vma, gate_vma))
60703 - size += vma_dump_size(vma, mm_flags);
60704 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60705 return size;
60706 }
60707
60708 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60709
60710 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
60711
60712 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
60713 + offset += elf_core_vma_data_size(gate_vma, cprm);
60714 offset += elf_core_extra_data_size();
60715 e_shoff = offset;
60716
60717 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60718 phdr.p_offset = offset;
60719 phdr.p_vaddr = vma->vm_start;
60720 phdr.p_paddr = 0;
60721 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
60722 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60723 phdr.p_memsz = vma->vm_end - vma->vm_start;
60724 offset += phdr.p_filesz;
60725 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
60726 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
60727 unsigned long addr;
60728 unsigned long end;
60729
60730 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
60731 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
60732
60733 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
60734 struct page *page;
60735 @@ -2210,6 +2690,167 @@ out:
60736
60737 #endif /* CONFIG_ELF_CORE */
60738
60739 +#ifdef CONFIG_PAX_MPROTECT
60740 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
60741 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
60742 + * we'll remove VM_MAYWRITE for good on RELRO segments.
60743 + *
60744 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
60745 + * basis because we want to allow the common case and not the special ones.
60746 + */
60747 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
60748 +{
60749 + struct elfhdr elf_h;
60750 + struct elf_phdr elf_p;
60751 + unsigned long i;
60752 + unsigned long oldflags;
60753 + bool is_textrel_rw, is_textrel_rx, is_relro;
60754 +
60755 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
60756 + return;
60757 +
60758 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
60759 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
60760 +
60761 +#ifdef CONFIG_PAX_ELFRELOCS
60762 + /* possible TEXTREL */
60763 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
60764 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
60765 +#else
60766 + is_textrel_rw = false;
60767 + is_textrel_rx = false;
60768 +#endif
60769 +
60770 + /* possible RELRO */
60771 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
60772 +
60773 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
60774 + return;
60775 +
60776 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60777 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60778 +
60779 +#ifdef CONFIG_PAX_ETEXECRELOCS
60780 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60781 +#else
60782 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
60783 +#endif
60784 +
60785 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
60786 + !elf_check_arch(&elf_h) ||
60787 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60788 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60789 + return;
60790 +
60791 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60792 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60793 + return;
60794 + switch (elf_p.p_type) {
60795 + case PT_DYNAMIC:
60796 + if (!is_textrel_rw && !is_textrel_rx)
60797 + continue;
60798 + i = 0UL;
60799 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
60800 + elf_dyn dyn;
60801 +
60802 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
60803 + break;
60804 + if (dyn.d_tag == DT_NULL)
60805 + break;
60806 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
60807 + gr_log_textrel(vma);
60808 + if (is_textrel_rw)
60809 + vma->vm_flags |= VM_MAYWRITE;
60810 + else
60811 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
60812 + vma->vm_flags &= ~VM_MAYWRITE;
60813 + break;
60814 + }
60815 + i++;
60816 + }
60817 + is_textrel_rw = false;
60818 + is_textrel_rx = false;
60819 + continue;
60820 +
60821 + case PT_GNU_RELRO:
60822 + if (!is_relro)
60823 + continue;
60824 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
60825 + vma->vm_flags &= ~VM_MAYWRITE;
60826 + is_relro = false;
60827 + continue;
60828 +
60829 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
60830 + case PT_PAX_FLAGS: {
60831 + const char *msg_mprotect = "", *msg_emutramp = "";
60832 + char *buffer_lib, *buffer_exe;
60833 +
60834 + if (elf_p.p_flags & PF_NOMPROTECT)
60835 + msg_mprotect = "MPROTECT disabled";
60836 +
60837 +#ifdef CONFIG_PAX_EMUTRAMP
60838 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
60839 + msg_emutramp = "EMUTRAMP enabled";
60840 +#endif
60841 +
60842 + if (!msg_mprotect[0] && !msg_emutramp[0])
60843 + continue;
60844 +
60845 + if (!printk_ratelimit())
60846 + continue;
60847 +
60848 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
60849 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
60850 + if (buffer_lib && buffer_exe) {
60851 + char *path_lib, *path_exe;
60852 +
60853 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
60854 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
60855 +
60856 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
60857 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
60858 +
60859 + }
60860 + free_page((unsigned long)buffer_exe);
60861 + free_page((unsigned long)buffer_lib);
60862 + continue;
60863 + }
60864 +#endif
60865 +
60866 + }
60867 + }
60868 +}
60869 +#endif
60870 +
60871 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60872 +
60873 +extern int grsec_enable_log_rwxmaps;
60874 +
60875 +static void elf_handle_mmap(struct file *file)
60876 +{
60877 + struct elfhdr elf_h;
60878 + struct elf_phdr elf_p;
60879 + unsigned long i;
60880 +
60881 + if (!grsec_enable_log_rwxmaps)
60882 + return;
60883 +
60884 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
60885 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
60886 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
60887 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
60888 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
60889 + return;
60890 +
60891 + for (i = 0UL; i < elf_h.e_phnum; i++) {
60892 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
60893 + return;
60894 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
60895 + gr_log_ptgnustack(file);
60896 + }
60897 +}
60898 +#endif
60899 +
60900 static int __init init_elf_binfmt(void)
60901 {
60902 register_binfmt(&elf_format);
60903 diff --git a/fs/block_dev.c b/fs/block_dev.c
60904 index 6d72746..536d1db 100644
60905 --- a/fs/block_dev.c
60906 +++ b/fs/block_dev.c
60907 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
60908 else if (bdev->bd_contains == bdev)
60909 return true; /* is a whole device which isn't held */
60910
60911 - else if (whole->bd_holder == bd_may_claim)
60912 + else if (whole->bd_holder == (void *)bd_may_claim)
60913 return true; /* is a partition of a device that is being partitioned */
60914 else if (whole->bd_holder != NULL)
60915 return false; /* is a partition of a held device */
60916 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
60917 index aeab453..48dbafc 100644
60918 --- a/fs/btrfs/ctree.c
60919 +++ b/fs/btrfs/ctree.c
60920 @@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
60921 free_extent_buffer(buf);
60922 add_root_to_dirty_list(root);
60923 } else {
60924 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
60925 - parent_start = parent->start;
60926 - else
60927 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
60928 + if (parent)
60929 + parent_start = parent->start;
60930 + else
60931 + parent_start = 0;
60932 + } else
60933 parent_start = 0;
60934
60935 WARN_ON(trans->transid != btrfs_header_generation(parent));
60936 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
60937 index a2e90f8..5135e5f 100644
60938 --- a/fs/btrfs/delayed-inode.c
60939 +++ b/fs/btrfs/delayed-inode.c
60940 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
60941
60942 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
60943 {
60944 - int seq = atomic_inc_return(&delayed_root->items_seq);
60945 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
60946 if ((atomic_dec_return(&delayed_root->items) <
60947 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
60948 waitqueue_active(&delayed_root->wait))
60949 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
60950
60951 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
60952 {
60953 - int val = atomic_read(&delayed_root->items_seq);
60954 + int val = atomic_read_unchecked(&delayed_root->items_seq);
60955
60956 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
60957 return 1;
60958 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
60959 int seq;
60960 int ret;
60961
60962 - seq = atomic_read(&delayed_root->items_seq);
60963 + seq = atomic_read_unchecked(&delayed_root->items_seq);
60964
60965 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
60966 if (ret)
60967 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
60968 index f70119f..ab5894d 100644
60969 --- a/fs/btrfs/delayed-inode.h
60970 +++ b/fs/btrfs/delayed-inode.h
60971 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
60972 */
60973 struct list_head prepare_list;
60974 atomic_t items; /* for delayed items */
60975 - atomic_t items_seq; /* for delayed items */
60976 + atomic_unchecked_t items_seq; /* for delayed items */
60977 int nodes; /* for delayed nodes */
60978 wait_queue_head_t wait;
60979 };
60980 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
60981 struct btrfs_delayed_root *delayed_root)
60982 {
60983 atomic_set(&delayed_root->items, 0);
60984 - atomic_set(&delayed_root->items_seq, 0);
60985 + atomic_set_unchecked(&delayed_root->items_seq, 0);
60986 delayed_root->nodes = 0;
60987 spin_lock_init(&delayed_root->lock);
60988 init_waitqueue_head(&delayed_root->wait);
60989 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
60990 index 47aceb4..7d28b1c 100644
60991 --- a/fs/btrfs/ioctl.c
60992 +++ b/fs/btrfs/ioctl.c
60993 @@ -3965,9 +3965,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60994 for (i = 0; i < num_types; i++) {
60995 struct btrfs_space_info *tmp;
60996
60997 + /* Don't copy in more than we allocated */
60998 if (!slot_count)
60999 break;
61000
61001 + slot_count--;
61002 +
61003 info = NULL;
61004 rcu_read_lock();
61005 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
61006 @@ -3989,10 +3992,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
61007 memcpy(dest, &space, sizeof(space));
61008 dest++;
61009 space_args.total_spaces++;
61010 - slot_count--;
61011 }
61012 - if (!slot_count)
61013 - break;
61014 }
61015 up_read(&info->groups_sem);
61016 }
61017 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
61018 index 8e16bca..6eabd9e 100644
61019 --- a/fs/btrfs/super.c
61020 +++ b/fs/btrfs/super.c
61021 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
61022 function, line, errstr);
61023 return;
61024 }
61025 - ACCESS_ONCE(trans->transaction->aborted) = errno;
61026 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
61027 /* Wake up anybody who may be waiting on this transaction */
61028 wake_up(&root->fs_info->transaction_wait);
61029 wake_up(&root->fs_info->transaction_blocked_wait);
61030 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
61031 index 7869936..7e153dc 100644
61032 --- a/fs/btrfs/sysfs.c
61033 +++ b/fs/btrfs/sysfs.c
61034 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
61035 for (set = 0; set < FEAT_MAX; set++) {
61036 int i;
61037 struct attribute *attrs[2];
61038 - struct attribute_group agroup = {
61039 + attribute_group_no_const agroup = {
61040 .name = "features",
61041 .attrs = attrs,
61042 };
61043 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
61044 index 7f5b41b..e589c13 100644
61045 --- a/fs/btrfs/tree-log.h
61046 +++ b/fs/btrfs/tree-log.h
61047 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
61048 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
61049 struct btrfs_trans_handle *trans)
61050 {
61051 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
61052 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
61053 }
61054
61055 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
61056 diff --git a/fs/buffer.c b/fs/buffer.c
61057 index eba6e4f..af1182c 100644
61058 --- a/fs/buffer.c
61059 +++ b/fs/buffer.c
61060 @@ -3429,7 +3429,7 @@ void __init buffer_init(void)
61061 bh_cachep = kmem_cache_create("buffer_head",
61062 sizeof(struct buffer_head), 0,
61063 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
61064 - SLAB_MEM_SPREAD),
61065 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
61066 NULL);
61067
61068 /*
61069 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
61070 index d749731..dd333a6 100644
61071 --- a/fs/cachefiles/bind.c
61072 +++ b/fs/cachefiles/bind.c
61073 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
61074 args);
61075
61076 /* start by checking things over */
61077 - ASSERT(cache->fstop_percent >= 0 &&
61078 - cache->fstop_percent < cache->fcull_percent &&
61079 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
61080 cache->fcull_percent < cache->frun_percent &&
61081 cache->frun_percent < 100);
61082
61083 - ASSERT(cache->bstop_percent >= 0 &&
61084 - cache->bstop_percent < cache->bcull_percent &&
61085 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
61086 cache->bcull_percent < cache->brun_percent &&
61087 cache->brun_percent < 100);
61088
61089 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
61090 index b078d30..db23012 100644
61091 --- a/fs/cachefiles/daemon.c
61092 +++ b/fs/cachefiles/daemon.c
61093 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
61094 if (n > buflen)
61095 return -EMSGSIZE;
61096
61097 - if (copy_to_user(_buffer, buffer, n) != 0)
61098 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
61099 return -EFAULT;
61100
61101 return n;
61102 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
61103 if (test_bit(CACHEFILES_DEAD, &cache->flags))
61104 return -EIO;
61105
61106 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
61107 + if (datalen > PAGE_SIZE - 1)
61108 return -EOPNOTSUPP;
61109
61110 /* drag the command string into the kernel so we can parse it */
61111 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
61112 if (args[0] != '%' || args[1] != '\0')
61113 return -EINVAL;
61114
61115 - if (fstop < 0 || fstop >= cache->fcull_percent)
61116 + if (fstop >= cache->fcull_percent)
61117 return cachefiles_daemon_range_error(cache, args);
61118
61119 cache->fstop_percent = fstop;
61120 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
61121 if (args[0] != '%' || args[1] != '\0')
61122 return -EINVAL;
61123
61124 - if (bstop < 0 || bstop >= cache->bcull_percent)
61125 + if (bstop >= cache->bcull_percent)
61126 return cachefiles_daemon_range_error(cache, args);
61127
61128 cache->bstop_percent = bstop;
61129 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
61130 index 3d50998..0550d67 100644
61131 --- a/fs/cachefiles/internal.h
61132 +++ b/fs/cachefiles/internal.h
61133 @@ -66,7 +66,7 @@ struct cachefiles_cache {
61134 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
61135 struct rb_root active_nodes; /* active nodes (can't be culled) */
61136 rwlock_t active_lock; /* lock for active_nodes */
61137 - atomic_t gravecounter; /* graveyard uniquifier */
61138 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
61139 unsigned frun_percent; /* when to stop culling (% files) */
61140 unsigned fcull_percent; /* when to start culling (% files) */
61141 unsigned fstop_percent; /* when to stop allocating (% files) */
61142 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
61143 * proc.c
61144 */
61145 #ifdef CONFIG_CACHEFILES_HISTOGRAM
61146 -extern atomic_t cachefiles_lookup_histogram[HZ];
61147 -extern atomic_t cachefiles_mkdir_histogram[HZ];
61148 -extern atomic_t cachefiles_create_histogram[HZ];
61149 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
61150 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
61151 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
61152
61153 extern int __init cachefiles_proc_init(void);
61154 extern void cachefiles_proc_cleanup(void);
61155 static inline
61156 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
61157 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
61158 {
61159 unsigned long jif = jiffies - start_jif;
61160 if (jif >= HZ)
61161 jif = HZ - 1;
61162 - atomic_inc(&histogram[jif]);
61163 + atomic_inc_unchecked(&histogram[jif]);
61164 }
61165
61166 #else
61167 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
61168 index 5bf2b41..85b93f9 100644
61169 --- a/fs/cachefiles/namei.c
61170 +++ b/fs/cachefiles/namei.c
61171 @@ -312,7 +312,7 @@ try_again:
61172 /* first step is to make up a grave dentry in the graveyard */
61173 sprintf(nbuffer, "%08x%08x",
61174 (uint32_t) get_seconds(),
61175 - (uint32_t) atomic_inc_return(&cache->gravecounter));
61176 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
61177
61178 /* do the multiway lock magic */
61179 trap = lock_rename(cache->graveyard, dir);
61180 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
61181 index eccd339..4c1d995 100644
61182 --- a/fs/cachefiles/proc.c
61183 +++ b/fs/cachefiles/proc.c
61184 @@ -14,9 +14,9 @@
61185 #include <linux/seq_file.h>
61186 #include "internal.h"
61187
61188 -atomic_t cachefiles_lookup_histogram[HZ];
61189 -atomic_t cachefiles_mkdir_histogram[HZ];
61190 -atomic_t cachefiles_create_histogram[HZ];
61191 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
61192 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
61193 +atomic_unchecked_t cachefiles_create_histogram[HZ];
61194
61195 /*
61196 * display the latency histogram
61197 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
61198 return 0;
61199 default:
61200 index = (unsigned long) v - 3;
61201 - x = atomic_read(&cachefiles_lookup_histogram[index]);
61202 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
61203 - z = atomic_read(&cachefiles_create_histogram[index]);
61204 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
61205 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
61206 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
61207 if (x == 0 && y == 0 && z == 0)
61208 return 0;
61209
61210 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
61211 index 4b1fb5c..0d2a699 100644
61212 --- a/fs/cachefiles/rdwr.c
61213 +++ b/fs/cachefiles/rdwr.c
61214 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
61215 old_fs = get_fs();
61216 set_fs(KERNEL_DS);
61217 ret = file->f_op->write(
61218 - file, (const void __user *) data, len, &pos);
61219 + file, (const void __force_user *) data, len, &pos);
61220 set_fs(old_fs);
61221 kunmap(page);
61222 file_end_write(file);
61223 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
61224 index c29d6ae..719b9bb 100644
61225 --- a/fs/ceph/dir.c
61226 +++ b/fs/ceph/dir.c
61227 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
61228 struct dentry *dentry, *last;
61229 struct ceph_dentry_info *di;
61230 int err = 0;
61231 + char d_name[DNAME_INLINE_LEN];
61232 + const unsigned char *name;
61233
61234 /* claim ref on last dentry we returned */
61235 last = fi->dentry;
61236 @@ -192,7 +194,12 @@ more:
61237
61238 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
61239 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
61240 - if (!dir_emit(ctx, dentry->d_name.name,
61241 + name = dentry->d_name.name;
61242 + if (name == dentry->d_iname) {
61243 + memcpy(d_name, name, dentry->d_name.len);
61244 + name = d_name;
61245 + }
61246 + if (!dir_emit(ctx, name,
61247 dentry->d_name.len,
61248 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
61249 dentry->d_inode->i_mode >> 12)) {
61250 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
61251 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
61252 struct ceph_mds_client *mdsc = fsc->mdsc;
61253 unsigned frag = fpos_frag(ctx->pos);
61254 - int off = fpos_off(ctx->pos);
61255 + unsigned int off = fpos_off(ctx->pos);
61256 int err;
61257 u32 ftype;
61258 struct ceph_mds_reply_info_parsed *rinfo;
61259 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
61260 index 06150fd..192061b 100644
61261 --- a/fs/ceph/super.c
61262 +++ b/fs/ceph/super.c
61263 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
61264 /*
61265 * construct our own bdi so we can control readahead, etc.
61266 */
61267 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
61268 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
61269
61270 static int ceph_register_bdi(struct super_block *sb,
61271 struct ceph_fs_client *fsc)
61272 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
61273 default_backing_dev_info.ra_pages;
61274
61275 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
61276 - atomic_long_inc_return(&bdi_seq));
61277 + atomic_long_inc_return_unchecked(&bdi_seq));
61278 if (!err)
61279 sb->s_bdi = &fsc->backing_dev_info;
61280 return err;
61281 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
61282 index f3ac415..3d2420c 100644
61283 --- a/fs/cifs/cifs_debug.c
61284 +++ b/fs/cifs/cifs_debug.c
61285 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
61286
61287 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
61288 #ifdef CONFIG_CIFS_STATS2
61289 - atomic_set(&totBufAllocCount, 0);
61290 - atomic_set(&totSmBufAllocCount, 0);
61291 + atomic_set_unchecked(&totBufAllocCount, 0);
61292 + atomic_set_unchecked(&totSmBufAllocCount, 0);
61293 #endif /* CONFIG_CIFS_STATS2 */
61294 spin_lock(&cifs_tcp_ses_lock);
61295 list_for_each(tmp1, &cifs_tcp_ses_list) {
61296 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
61297 tcon = list_entry(tmp3,
61298 struct cifs_tcon,
61299 tcon_list);
61300 - atomic_set(&tcon->num_smbs_sent, 0);
61301 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
61302 if (server->ops->clear_stats)
61303 server->ops->clear_stats(tcon);
61304 }
61305 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
61306 smBufAllocCount.counter, cifs_min_small);
61307 #ifdef CONFIG_CIFS_STATS2
61308 seq_printf(m, "Total Large %d Small %d Allocations\n",
61309 - atomic_read(&totBufAllocCount),
61310 - atomic_read(&totSmBufAllocCount));
61311 + atomic_read_unchecked(&totBufAllocCount),
61312 + atomic_read_unchecked(&totSmBufAllocCount));
61313 #endif /* CONFIG_CIFS_STATS2 */
61314
61315 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
61316 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
61317 if (tcon->need_reconnect)
61318 seq_puts(m, "\tDISCONNECTED ");
61319 seq_printf(m, "\nSMBs: %d",
61320 - atomic_read(&tcon->num_smbs_sent));
61321 + atomic_read_unchecked(&tcon->num_smbs_sent));
61322 if (server->ops->print_stats)
61323 server->ops->print_stats(m, tcon);
61324 }
61325 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
61326 index 8883980..c8ade72 100644
61327 --- a/fs/cifs/cifsfs.c
61328 +++ b/fs/cifs/cifsfs.c
61329 @@ -1072,7 +1072,7 @@ cifs_init_request_bufs(void)
61330 */
61331 cifs_req_cachep = kmem_cache_create("cifs_request",
61332 CIFSMaxBufSize + max_hdr_size, 0,
61333 - SLAB_HWCACHE_ALIGN, NULL);
61334 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
61335 if (cifs_req_cachep == NULL)
61336 return -ENOMEM;
61337
61338 @@ -1099,7 +1099,7 @@ cifs_init_request_bufs(void)
61339 efficient to alloc 1 per page off the slab compared to 17K (5page)
61340 alloc of large cifs buffers even when page debugging is on */
61341 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
61342 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
61343 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
61344 NULL);
61345 if (cifs_sm_req_cachep == NULL) {
61346 mempool_destroy(cifs_req_poolp);
61347 @@ -1184,8 +1184,8 @@ init_cifs(void)
61348 atomic_set(&bufAllocCount, 0);
61349 atomic_set(&smBufAllocCount, 0);
61350 #ifdef CONFIG_CIFS_STATS2
61351 - atomic_set(&totBufAllocCount, 0);
61352 - atomic_set(&totSmBufAllocCount, 0);
61353 + atomic_set_unchecked(&totBufAllocCount, 0);
61354 + atomic_set_unchecked(&totSmBufAllocCount, 0);
61355 #endif /* CONFIG_CIFS_STATS2 */
61356
61357 atomic_set(&midCount, 0);
61358 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
61359 index de6aed8..a0a76fd 100644
61360 --- a/fs/cifs/cifsglob.h
61361 +++ b/fs/cifs/cifsglob.h
61362 @@ -807,35 +807,35 @@ struct cifs_tcon {
61363 __u16 Flags; /* optional support bits */
61364 enum statusEnum tidStatus;
61365 #ifdef CONFIG_CIFS_STATS
61366 - atomic_t num_smbs_sent;
61367 + atomic_unchecked_t num_smbs_sent;
61368 union {
61369 struct {
61370 - atomic_t num_writes;
61371 - atomic_t num_reads;
61372 - atomic_t num_flushes;
61373 - atomic_t num_oplock_brks;
61374 - atomic_t num_opens;
61375 - atomic_t num_closes;
61376 - atomic_t num_deletes;
61377 - atomic_t num_mkdirs;
61378 - atomic_t num_posixopens;
61379 - atomic_t num_posixmkdirs;
61380 - atomic_t num_rmdirs;
61381 - atomic_t num_renames;
61382 - atomic_t num_t2renames;
61383 - atomic_t num_ffirst;
61384 - atomic_t num_fnext;
61385 - atomic_t num_fclose;
61386 - atomic_t num_hardlinks;
61387 - atomic_t num_symlinks;
61388 - atomic_t num_locks;
61389 - atomic_t num_acl_get;
61390 - atomic_t num_acl_set;
61391 + atomic_unchecked_t num_writes;
61392 + atomic_unchecked_t num_reads;
61393 + atomic_unchecked_t num_flushes;
61394 + atomic_unchecked_t num_oplock_brks;
61395 + atomic_unchecked_t num_opens;
61396 + atomic_unchecked_t num_closes;
61397 + atomic_unchecked_t num_deletes;
61398 + atomic_unchecked_t num_mkdirs;
61399 + atomic_unchecked_t num_posixopens;
61400 + atomic_unchecked_t num_posixmkdirs;
61401 + atomic_unchecked_t num_rmdirs;
61402 + atomic_unchecked_t num_renames;
61403 + atomic_unchecked_t num_t2renames;
61404 + atomic_unchecked_t num_ffirst;
61405 + atomic_unchecked_t num_fnext;
61406 + atomic_unchecked_t num_fclose;
61407 + atomic_unchecked_t num_hardlinks;
61408 + atomic_unchecked_t num_symlinks;
61409 + atomic_unchecked_t num_locks;
61410 + atomic_unchecked_t num_acl_get;
61411 + atomic_unchecked_t num_acl_set;
61412 } cifs_stats;
61413 #ifdef CONFIG_CIFS_SMB2
61414 struct {
61415 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
61416 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
61417 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
61418 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
61419 } smb2_stats;
61420 #endif /* CONFIG_CIFS_SMB2 */
61421 } stats;
61422 @@ -1172,7 +1172,7 @@ convert_delimiter(char *path, char delim)
61423 }
61424
61425 #ifdef CONFIG_CIFS_STATS
61426 -#define cifs_stats_inc atomic_inc
61427 +#define cifs_stats_inc atomic_inc_unchecked
61428
61429 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
61430 unsigned int bytes)
61431 @@ -1538,8 +1538,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
61432 /* Various Debug counters */
61433 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
61434 #ifdef CONFIG_CIFS_STATS2
61435 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
61436 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
61437 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
61438 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
61439 #endif
61440 GLOBAL_EXTERN atomic_t smBufAllocCount;
61441 GLOBAL_EXTERN atomic_t midCount;
61442 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
61443 index e90a1e9..908699d 100644
61444 --- a/fs/cifs/file.c
61445 +++ b/fs/cifs/file.c
61446 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
61447 index = mapping->writeback_index; /* Start from prev offset */
61448 end = -1;
61449 } else {
61450 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
61451 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
61452 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
61453 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
61454 range_whole = true;
61455 + index = 0;
61456 + end = ULONG_MAX;
61457 + } else {
61458 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
61459 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
61460 + }
61461 scanned = true;
61462 }
61463 retry:
61464 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
61465 index 3b0c62e..f7d090c 100644
61466 --- a/fs/cifs/misc.c
61467 +++ b/fs/cifs/misc.c
61468 @@ -170,7 +170,7 @@ cifs_buf_get(void)
61469 memset(ret_buf, 0, buf_size + 3);
61470 atomic_inc(&bufAllocCount);
61471 #ifdef CONFIG_CIFS_STATS2
61472 - atomic_inc(&totBufAllocCount);
61473 + atomic_inc_unchecked(&totBufAllocCount);
61474 #endif /* CONFIG_CIFS_STATS2 */
61475 }
61476
61477 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
61478 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
61479 atomic_inc(&smBufAllocCount);
61480 #ifdef CONFIG_CIFS_STATS2
61481 - atomic_inc(&totSmBufAllocCount);
61482 + atomic_inc_unchecked(&totSmBufAllocCount);
61483 #endif /* CONFIG_CIFS_STATS2 */
61484
61485 }
61486 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
61487 index d1fdfa8..94558f8 100644
61488 --- a/fs/cifs/smb1ops.c
61489 +++ b/fs/cifs/smb1ops.c
61490 @@ -626,27 +626,27 @@ static void
61491 cifs_clear_stats(struct cifs_tcon *tcon)
61492 {
61493 #ifdef CONFIG_CIFS_STATS
61494 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
61495 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
61496 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
61497 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61498 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
61499 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
61500 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61501 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
61502 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
61503 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
61504 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
61505 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
61506 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
61507 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
61508 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
61509 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
61510 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
61511 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
61512 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
61513 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
61514 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
61515 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
61516 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
61517 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
61518 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
61519 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
61520 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
61521 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
61522 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
61523 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
61524 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
61525 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
61526 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
61527 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
61528 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
61529 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
61530 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
61531 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
61532 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
61533 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
61534 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
61535 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
61536 #endif
61537 }
61538
61539 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61540 {
61541 #ifdef CONFIG_CIFS_STATS
61542 seq_printf(m, " Oplocks breaks: %d",
61543 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
61544 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
61545 seq_printf(m, "\nReads: %d Bytes: %llu",
61546 - atomic_read(&tcon->stats.cifs_stats.num_reads),
61547 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
61548 (long long)(tcon->bytes_read));
61549 seq_printf(m, "\nWrites: %d Bytes: %llu",
61550 - atomic_read(&tcon->stats.cifs_stats.num_writes),
61551 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
61552 (long long)(tcon->bytes_written));
61553 seq_printf(m, "\nFlushes: %d",
61554 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
61555 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
61556 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
61557 - atomic_read(&tcon->stats.cifs_stats.num_locks),
61558 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
61559 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
61560 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
61561 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
61562 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
61563 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
61564 - atomic_read(&tcon->stats.cifs_stats.num_opens),
61565 - atomic_read(&tcon->stats.cifs_stats.num_closes),
61566 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
61567 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
61568 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
61569 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
61570 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
61571 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
61572 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
61573 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
61574 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
61575 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
61576 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
61577 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
61578 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
61579 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
61580 seq_printf(m, "\nRenames: %d T2 Renames %d",
61581 - atomic_read(&tcon->stats.cifs_stats.num_renames),
61582 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
61583 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
61584 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
61585 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
61586 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
61587 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
61588 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
61589 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
61590 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
61591 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
61592 #endif
61593 }
61594
61595 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
61596 index 787844b..8e7bc7d 100644
61597 --- a/fs/cifs/smb2ops.c
61598 +++ b/fs/cifs/smb2ops.c
61599 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
61600 #ifdef CONFIG_CIFS_STATS
61601 int i;
61602 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
61603 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61604 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61605 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
61606 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
61607 }
61608 #endif
61609 }
61610 @@ -405,65 +405,65 @@ static void
61611 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
61612 {
61613 #ifdef CONFIG_CIFS_STATS
61614 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61615 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61616 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
61617 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
61618 seq_printf(m, "\nNegotiates: %d sent %d failed",
61619 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
61620 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
61621 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
61622 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
61623 seq_printf(m, "\nSessionSetups: %d sent %d failed",
61624 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
61625 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
61626 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
61627 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
61628 seq_printf(m, "\nLogoffs: %d sent %d failed",
61629 - atomic_read(&sent[SMB2_LOGOFF_HE]),
61630 - atomic_read(&failed[SMB2_LOGOFF_HE]));
61631 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
61632 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
61633 seq_printf(m, "\nTreeConnects: %d sent %d failed",
61634 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
61635 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
61636 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
61637 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
61638 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
61639 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
61640 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
61641 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
61642 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
61643 seq_printf(m, "\nCreates: %d sent %d failed",
61644 - atomic_read(&sent[SMB2_CREATE_HE]),
61645 - atomic_read(&failed[SMB2_CREATE_HE]));
61646 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
61647 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
61648 seq_printf(m, "\nCloses: %d sent %d failed",
61649 - atomic_read(&sent[SMB2_CLOSE_HE]),
61650 - atomic_read(&failed[SMB2_CLOSE_HE]));
61651 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
61652 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
61653 seq_printf(m, "\nFlushes: %d sent %d failed",
61654 - atomic_read(&sent[SMB2_FLUSH_HE]),
61655 - atomic_read(&failed[SMB2_FLUSH_HE]));
61656 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
61657 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
61658 seq_printf(m, "\nReads: %d sent %d failed",
61659 - atomic_read(&sent[SMB2_READ_HE]),
61660 - atomic_read(&failed[SMB2_READ_HE]));
61661 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
61662 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
61663 seq_printf(m, "\nWrites: %d sent %d failed",
61664 - atomic_read(&sent[SMB2_WRITE_HE]),
61665 - atomic_read(&failed[SMB2_WRITE_HE]));
61666 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
61667 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
61668 seq_printf(m, "\nLocks: %d sent %d failed",
61669 - atomic_read(&sent[SMB2_LOCK_HE]),
61670 - atomic_read(&failed[SMB2_LOCK_HE]));
61671 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
61672 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
61673 seq_printf(m, "\nIOCTLs: %d sent %d failed",
61674 - atomic_read(&sent[SMB2_IOCTL_HE]),
61675 - atomic_read(&failed[SMB2_IOCTL_HE]));
61676 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
61677 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
61678 seq_printf(m, "\nCancels: %d sent %d failed",
61679 - atomic_read(&sent[SMB2_CANCEL_HE]),
61680 - atomic_read(&failed[SMB2_CANCEL_HE]));
61681 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
61682 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
61683 seq_printf(m, "\nEchos: %d sent %d failed",
61684 - atomic_read(&sent[SMB2_ECHO_HE]),
61685 - atomic_read(&failed[SMB2_ECHO_HE]));
61686 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
61687 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
61688 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
61689 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
61690 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
61691 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
61692 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
61693 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
61694 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
61695 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
61696 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
61697 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
61698 seq_printf(m, "\nQueryInfos: %d sent %d failed",
61699 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
61700 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
61701 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
61702 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
61703 seq_printf(m, "\nSetInfos: %d sent %d failed",
61704 - atomic_read(&sent[SMB2_SET_INFO_HE]),
61705 - atomic_read(&failed[SMB2_SET_INFO_HE]));
61706 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
61707 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
61708 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
61709 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
61710 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
61711 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
61712 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
61713 #endif
61714 }
61715
61716 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
61717 index b0b260d..c8927e1 100644
61718 --- a/fs/cifs/smb2pdu.c
61719 +++ b/fs/cifs/smb2pdu.c
61720 @@ -2105,8 +2105,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
61721 default:
61722 cifs_dbg(VFS, "info level %u isn't supported\n",
61723 srch_inf->info_level);
61724 - rc = -EINVAL;
61725 - goto qdir_exit;
61726 + return -EINVAL;
61727 }
61728
61729 req->FileIndex = cpu_to_le32(index);
61730 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
61731 index 1da168c..8bc7ff6 100644
61732 --- a/fs/coda/cache.c
61733 +++ b/fs/coda/cache.c
61734 @@ -24,7 +24,7 @@
61735 #include "coda_linux.h"
61736 #include "coda_cache.h"
61737
61738 -static atomic_t permission_epoch = ATOMIC_INIT(0);
61739 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
61740
61741 /* replace or extend an acl cache hit */
61742 void coda_cache_enter(struct inode *inode, int mask)
61743 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
61744 struct coda_inode_info *cii = ITOC(inode);
61745
61746 spin_lock(&cii->c_lock);
61747 - cii->c_cached_epoch = atomic_read(&permission_epoch);
61748 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
61749 if (!uid_eq(cii->c_uid, current_fsuid())) {
61750 cii->c_uid = current_fsuid();
61751 cii->c_cached_perm = mask;
61752 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
61753 {
61754 struct coda_inode_info *cii = ITOC(inode);
61755 spin_lock(&cii->c_lock);
61756 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
61757 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
61758 spin_unlock(&cii->c_lock);
61759 }
61760
61761 /* remove all acl caches */
61762 void coda_cache_clear_all(struct super_block *sb)
61763 {
61764 - atomic_inc(&permission_epoch);
61765 + atomic_inc_unchecked(&permission_epoch);
61766 }
61767
61768
61769 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
61770 spin_lock(&cii->c_lock);
61771 hit = (mask & cii->c_cached_perm) == mask &&
61772 uid_eq(cii->c_uid, current_fsuid()) &&
61773 - cii->c_cached_epoch == atomic_read(&permission_epoch);
61774 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
61775 spin_unlock(&cii->c_lock);
61776
61777 return hit;
61778 diff --git a/fs/compat.c b/fs/compat.c
61779 index 66d3d3c..9c10175 100644
61780 --- a/fs/compat.c
61781 +++ b/fs/compat.c
61782 @@ -54,7 +54,7 @@
61783 #include <asm/ioctls.h>
61784 #include "internal.h"
61785
61786 -int compat_log = 1;
61787 +int compat_log = 0;
61788
61789 int compat_printk(const char *fmt, ...)
61790 {
61791 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
61792
61793 set_fs(KERNEL_DS);
61794 /* The __user pointer cast is valid because of the set_fs() */
61795 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
61796 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
61797 set_fs(oldfs);
61798 /* truncating is ok because it's a user address */
61799 if (!ret)
61800 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
61801 goto out;
61802
61803 ret = -EINVAL;
61804 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
61805 + if (nr_segs > UIO_MAXIOV)
61806 goto out;
61807 if (nr_segs > fast_segs) {
61808 ret = -ENOMEM;
61809 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
61810 struct compat_readdir_callback {
61811 struct dir_context ctx;
61812 struct compat_old_linux_dirent __user *dirent;
61813 + struct file * file;
61814 int result;
61815 };
61816
61817 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
61818 buf->result = -EOVERFLOW;
61819 return -EOVERFLOW;
61820 }
61821 +
61822 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61823 + return 0;
61824 +
61825 buf->result++;
61826 dirent = buf->dirent;
61827 if (!access_ok(VERIFY_WRITE, dirent,
61828 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61829 if (!f.file)
61830 return -EBADF;
61831
61832 + buf.file = f.file;
61833 error = iterate_dir(f.file, &buf.ctx);
61834 if (buf.result)
61835 error = buf.result;
61836 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
61837 struct dir_context ctx;
61838 struct compat_linux_dirent __user *current_dir;
61839 struct compat_linux_dirent __user *previous;
61840 + struct file * file;
61841 int count;
61842 int error;
61843 };
61844 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
61845 buf->error = -EOVERFLOW;
61846 return -EOVERFLOW;
61847 }
61848 +
61849 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61850 + return 0;
61851 +
61852 dirent = buf->previous;
61853 if (dirent) {
61854 if (__put_user(offset, &dirent->d_off))
61855 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
61856 if (!f.file)
61857 return -EBADF;
61858
61859 + buf.file = f.file;
61860 error = iterate_dir(f.file, &buf.ctx);
61861 if (error >= 0)
61862 error = buf.error;
61863 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
61864 struct dir_context ctx;
61865 struct linux_dirent64 __user *current_dir;
61866 struct linux_dirent64 __user *previous;
61867 + struct file * file;
61868 int count;
61869 int error;
61870 };
61871 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
61872 buf->error = -EINVAL; /* only used if we fail.. */
61873 if (reclen > buf->count)
61874 return -EINVAL;
61875 +
61876 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61877 + return 0;
61878 +
61879 dirent = buf->previous;
61880
61881 if (dirent) {
61882 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61883 if (!f.file)
61884 return -EBADF;
61885
61886 + buf.file = f.file;
61887 error = iterate_dir(f.file, &buf.ctx);
61888 if (error >= 0)
61889 error = buf.error;
61890 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
61891 index 4d24d17..4f8c09e 100644
61892 --- a/fs/compat_binfmt_elf.c
61893 +++ b/fs/compat_binfmt_elf.c
61894 @@ -30,11 +30,13 @@
61895 #undef elf_phdr
61896 #undef elf_shdr
61897 #undef elf_note
61898 +#undef elf_dyn
61899 #undef elf_addr_t
61900 #define elfhdr elf32_hdr
61901 #define elf_phdr elf32_phdr
61902 #define elf_shdr elf32_shdr
61903 #define elf_note elf32_note
61904 +#define elf_dyn Elf32_Dyn
61905 #define elf_addr_t Elf32_Addr
61906
61907 /*
61908 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
61909 index e822890..fed89d9 100644
61910 --- a/fs/compat_ioctl.c
61911 +++ b/fs/compat_ioctl.c
61912 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
61913 return -EFAULT;
61914 if (__get_user(udata, &ss32->iomem_base))
61915 return -EFAULT;
61916 - ss.iomem_base = compat_ptr(udata);
61917 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
61918 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
61919 __get_user(ss.port_high, &ss32->port_high))
61920 return -EFAULT;
61921 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
61922 for (i = 0; i < nmsgs; i++) {
61923 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
61924 return -EFAULT;
61925 - if (get_user(datap, &umsgs[i].buf) ||
61926 - put_user(compat_ptr(datap), &tmsgs[i].buf))
61927 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
61928 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
61929 return -EFAULT;
61930 }
61931 return sys_ioctl(fd, cmd, (unsigned long)tdata);
61932 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
61933 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
61934 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
61935 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
61936 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
61937 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
61938 return -EFAULT;
61939
61940 return ioctl_preallocate(file, p);
61941 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
61942 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
61943 {
61944 unsigned int a, b;
61945 - a = *(unsigned int *)p;
61946 - b = *(unsigned int *)q;
61947 + a = *(const unsigned int *)p;
61948 + b = *(const unsigned int *)q;
61949 if (a > b)
61950 return 1;
61951 if (a < b)
61952 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
61953 index 668dcab..daebcd6 100644
61954 --- a/fs/configfs/dir.c
61955 +++ b/fs/configfs/dir.c
61956 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61957 }
61958 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
61959 struct configfs_dirent *next;
61960 - const char *name;
61961 + const unsigned char * name;
61962 + char d_name[sizeof(next->s_dentry->d_iname)];
61963 int len;
61964 struct inode *inode = NULL;
61965
61966 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61967 continue;
61968
61969 name = configfs_get_name(next);
61970 - len = strlen(name);
61971 + if (next->s_dentry && name == next->s_dentry->d_iname) {
61972 + len = next->s_dentry->d_name.len;
61973 + memcpy(d_name, name, len);
61974 + name = d_name;
61975 + } else
61976 + len = strlen(name);
61977
61978 /*
61979 * We'll have a dentry and an inode for
61980 diff --git a/fs/coredump.c b/fs/coredump.c
61981 index a93f7e6..d58bcbe 100644
61982 --- a/fs/coredump.c
61983 +++ b/fs/coredump.c
61984 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
61985 struct pipe_inode_info *pipe = file->private_data;
61986
61987 pipe_lock(pipe);
61988 - pipe->readers++;
61989 - pipe->writers--;
61990 + atomic_inc(&pipe->readers);
61991 + atomic_dec(&pipe->writers);
61992 wake_up_interruptible_sync(&pipe->wait);
61993 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61994 pipe_unlock(pipe);
61995 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
61996 * We actually want wait_event_freezable() but then we need
61997 * to clear TIF_SIGPENDING and improve dump_interrupted().
61998 */
61999 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
62000 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
62001
62002 pipe_lock(pipe);
62003 - pipe->readers--;
62004 - pipe->writers++;
62005 + atomic_dec(&pipe->readers);
62006 + atomic_inc(&pipe->writers);
62007 pipe_unlock(pipe);
62008 }
62009
62010 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
62011 struct files_struct *displaced;
62012 bool need_nonrelative = false;
62013 bool core_dumped = false;
62014 - static atomic_t core_dump_count = ATOMIC_INIT(0);
62015 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
62016 + long signr = siginfo->si_signo;
62017 + int dumpable;
62018 struct coredump_params cprm = {
62019 .siginfo = siginfo,
62020 .regs = signal_pt_regs(),
62021 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
62022 .mm_flags = mm->flags,
62023 };
62024
62025 - audit_core_dumps(siginfo->si_signo);
62026 + audit_core_dumps(signr);
62027 +
62028 + dumpable = __get_dumpable(cprm.mm_flags);
62029 +
62030 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
62031 + gr_handle_brute_attach(dumpable);
62032
62033 binfmt = mm->binfmt;
62034 if (!binfmt || !binfmt->core_dump)
62035 goto fail;
62036 - if (!__get_dumpable(cprm.mm_flags))
62037 + if (!dumpable)
62038 goto fail;
62039
62040 cred = prepare_creds();
62041 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
62042 need_nonrelative = true;
62043 }
62044
62045 - retval = coredump_wait(siginfo->si_signo, &core_state);
62046 + retval = coredump_wait(signr, &core_state);
62047 if (retval < 0)
62048 goto fail_creds;
62049
62050 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
62051 }
62052 cprm.limit = RLIM_INFINITY;
62053
62054 - dump_count = atomic_inc_return(&core_dump_count);
62055 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
62056 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
62057 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
62058 task_tgid_vnr(current), current->comm);
62059 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
62060 } else {
62061 struct inode *inode;
62062
62063 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
62064 +
62065 if (cprm.limit < binfmt->min_coredump)
62066 goto fail_unlock;
62067
62068 @@ -673,7 +682,7 @@ close_fail:
62069 filp_close(cprm.file, NULL);
62070 fail_dropcount:
62071 if (ispipe)
62072 - atomic_dec(&core_dump_count);
62073 + atomic_dec_unchecked(&core_dump_count);
62074 fail_unlock:
62075 kfree(cn.corename);
62076 coredump_finish(mm, core_dumped);
62077 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
62078 struct file *file = cprm->file;
62079 loff_t pos = file->f_pos;
62080 ssize_t n;
62081 +
62082 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
62083 if (cprm->written + nr > cprm->limit)
62084 return 0;
62085 while (nr) {
62086 diff --git a/fs/dcache.c b/fs/dcache.c
62087 index 06f6585..c9c5b6c 100644
62088 --- a/fs/dcache.c
62089 +++ b/fs/dcache.c
62090 @@ -106,8 +106,7 @@ static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
62091 unsigned int hash)
62092 {
62093 hash += (unsigned long) parent / L1_CACHE_BYTES;
62094 - hash = hash + (hash >> d_hash_shift);
62095 - return dentry_hashtable + (hash & d_hash_mask);
62096 + return dentry_hashtable + hash_32(hash, d_hash_shift);
62097 }
62098
62099 /* Statistics gathering. */
62100 @@ -479,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
62101 * dentry_iput drops the locks, at which point nobody (except
62102 * transient RCU lookups) can reach this dentry.
62103 */
62104 - BUG_ON((int)dentry->d_lockref.count > 0);
62105 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
62106 this_cpu_dec(nr_dentry);
62107 if (dentry->d_op && dentry->d_op->d_release)
62108 dentry->d_op->d_release(dentry);
62109 @@ -532,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
62110 struct dentry *parent = dentry->d_parent;
62111 if (IS_ROOT(dentry))
62112 return NULL;
62113 - if (unlikely((int)dentry->d_lockref.count < 0))
62114 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
62115 return NULL;
62116 if (likely(spin_trylock(&parent->d_lock)))
62117 return parent;
62118 @@ -609,7 +608,7 @@ repeat:
62119 dentry->d_flags |= DCACHE_REFERENCED;
62120 dentry_lru_add(dentry);
62121
62122 - dentry->d_lockref.count--;
62123 + __lockref_dec(&dentry->d_lockref);
62124 spin_unlock(&dentry->d_lock);
62125 return;
62126
62127 @@ -664,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
62128 * We also need to leave mountpoints alone,
62129 * directory or not.
62130 */
62131 - if (dentry->d_lockref.count > 1 && dentry->d_inode) {
62132 + if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
62133 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
62134 spin_unlock(&dentry->d_lock);
62135 return -EBUSY;
62136 @@ -680,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
62137 /* This must be called with d_lock held */
62138 static inline void __dget_dlock(struct dentry *dentry)
62139 {
62140 - dentry->d_lockref.count++;
62141 + __lockref_inc(&dentry->d_lockref);
62142 }
62143
62144 static inline void __dget(struct dentry *dentry)
62145 @@ -721,8 +720,8 @@ repeat:
62146 goto repeat;
62147 }
62148 rcu_read_unlock();
62149 - BUG_ON(!ret->d_lockref.count);
62150 - ret->d_lockref.count++;
62151 + BUG_ON(!__lockref_read(&ret->d_lockref));
62152 + __lockref_inc(&ret->d_lockref);
62153 spin_unlock(&ret->d_lock);
62154 return ret;
62155 }
62156 @@ -805,7 +804,7 @@ restart:
62157 spin_lock(&inode->i_lock);
62158 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
62159 spin_lock(&dentry->d_lock);
62160 - if (!dentry->d_lockref.count) {
62161 + if (!__lockref_read(&dentry->d_lockref)) {
62162 /*
62163 * inform the fs via d_prune that this dentry
62164 * is about to be unhashed and destroyed.
62165 @@ -848,7 +847,7 @@ static void shrink_dentry_list(struct list_head *list)
62166 * We found an inuse dentry which was not removed from
62167 * the LRU because of laziness during lookup. Do not free it.
62168 */
62169 - if ((int)dentry->d_lockref.count > 0) {
62170 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
62171 spin_unlock(&dentry->d_lock);
62172 if (parent)
62173 spin_unlock(&parent->d_lock);
62174 @@ -886,8 +885,8 @@ static void shrink_dentry_list(struct list_head *list)
62175 dentry = parent;
62176 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
62177 parent = lock_parent(dentry);
62178 - if (dentry->d_lockref.count != 1) {
62179 - dentry->d_lockref.count--;
62180 + if (__lockref_read(&dentry->d_lockref) != 1) {
62181 + __lockref_inc(&dentry->d_lockref);
62182 spin_unlock(&dentry->d_lock);
62183 if (parent)
62184 spin_unlock(&parent->d_lock);
62185 @@ -927,7 +926,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
62186 * counts, just remove them from the LRU. Otherwise give them
62187 * another pass through the LRU.
62188 */
62189 - if (dentry->d_lockref.count) {
62190 + if (__lockref_read(&dentry->d_lockref) > 0) {
62191 d_lru_isolate(dentry);
62192 spin_unlock(&dentry->d_lock);
62193 return LRU_REMOVED;
62194 @@ -1262,7 +1261,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
62195 } else {
62196 if (dentry->d_flags & DCACHE_LRU_LIST)
62197 d_lru_del(dentry);
62198 - if (!dentry->d_lockref.count) {
62199 + if (!__lockref_read(&dentry->d_lockref)) {
62200 d_shrink_add(dentry, &data->dispose);
62201 data->found++;
62202 }
62203 @@ -1310,7 +1309,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
62204 return D_WALK_CONTINUE;
62205
62206 /* root with refcount 1 is fine */
62207 - if (dentry == _data && dentry->d_lockref.count == 1)
62208 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
62209 return D_WALK_CONTINUE;
62210
62211 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
62212 @@ -1319,7 +1318,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
62213 dentry->d_inode ?
62214 dentry->d_inode->i_ino : 0UL,
62215 dentry,
62216 - dentry->d_lockref.count,
62217 + __lockref_read(&dentry->d_lockref),
62218 dentry->d_sb->s_type->name,
62219 dentry->d_sb->s_id);
62220 WARN_ON(1);
62221 @@ -1445,7 +1444,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
62222 */
62223 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
62224 if (name->len > DNAME_INLINE_LEN-1) {
62225 - dname = kmalloc(name->len + 1, GFP_KERNEL);
62226 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
62227 if (!dname) {
62228 kmem_cache_free(dentry_cache, dentry);
62229 return NULL;
62230 @@ -1463,7 +1462,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
62231 smp_wmb();
62232 dentry->d_name.name = dname;
62233
62234 - dentry->d_lockref.count = 1;
62235 + __lockref_set(&dentry->d_lockref, 1);
62236 dentry->d_flags = 0;
62237 spin_lock_init(&dentry->d_lock);
62238 seqcount_init(&dentry->d_seq);
62239 @@ -2226,7 +2225,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
62240 goto next;
62241 }
62242
62243 - dentry->d_lockref.count++;
62244 + __lockref_inc(&dentry->d_lockref);
62245 found = dentry;
62246 spin_unlock(&dentry->d_lock);
62247 break;
62248 @@ -2325,7 +2324,7 @@ again:
62249 spin_lock(&dentry->d_lock);
62250 inode = dentry->d_inode;
62251 isdir = S_ISDIR(inode->i_mode);
62252 - if (dentry->d_lockref.count == 1) {
62253 + if (__lockref_read(&dentry->d_lockref) == 1) {
62254 if (!spin_trylock(&inode->i_lock)) {
62255 spin_unlock(&dentry->d_lock);
62256 cpu_relax();
62257 @@ -2402,7 +2401,7 @@ void dentry_update_name_case(struct dentry *dentry, struct qstr *name)
62258 }
62259 EXPORT_SYMBOL(dentry_update_name_case);
62260
62261 -static void switch_names(struct dentry *dentry, struct dentry *target)
62262 +static void switch_names(struct dentry *dentry, struct dentry *target, bool exchange)
62263 {
62264 if (dname_external(target)) {
62265 if (dname_external(dentry)) {
62266 @@ -2430,7 +2429,7 @@ static void switch_names(struct dentry *dentry, struct dentry *target)
62267 target->d_name.len + 1);
62268 target->d_name.name = dentry->d_name.name;
62269 dentry->d_name.name = dentry->d_iname;
62270 - } else {
62271 + } else if (exchange) {
62272 /*
62273 * Both are internal.
62274 */
62275 @@ -2440,6 +2439,14 @@ static void switch_names(struct dentry *dentry, struct dentry *target)
62276 swap(((long *) &dentry->d_iname)[i],
62277 ((long *) &target->d_iname)[i]);
62278 }
62279 + } else {
62280 + /*
62281 + * Both are internal. Just copy target to dentry
62282 + */
62283 + memcpy(dentry->d_iname, target->d_name.name,
62284 + target->d_name.len + 1);
62285 + dentry->d_name.len = target->d_name.len;
62286 + return;
62287 }
62288 }
62289 swap(dentry->d_name.len, target->d_name.len);
62290 @@ -2540,7 +2547,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
62291 list_del(&target->d_u.d_child);
62292
62293 /* Switch the names.. */
62294 - switch_names(dentry, target);
62295 + switch_names(dentry, target, exchange);
62296 swap(dentry->d_name.hash, target->d_name.hash);
62297
62298 /* ... and switch the parents */
62299 @@ -2679,7 +2686,7 @@ static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon)
62300
62301 dparent = dentry->d_parent;
62302
62303 - switch_names(dentry, anon);
62304 + switch_names(dentry, anon, false);
62305 swap(dentry->d_name.hash, anon->d_name.hash);
62306
62307 dentry->d_parent = dentry;
62308 @@ -3297,7 +3304,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
62309
62310 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
62311 dentry->d_flags |= DCACHE_GENOCIDE;
62312 - dentry->d_lockref.count--;
62313 + __lockref_dec(&dentry->d_lockref);
62314 }
62315 }
62316 return D_WALK_CONTINUE;
62317 @@ -3413,7 +3420,8 @@ void __init vfs_caches_init(unsigned long mempages)
62318 mempages -= reserve;
62319
62320 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
62321 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
62322 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
62323 + SLAB_NO_SANITIZE, NULL);
62324
62325 dcache_init();
62326 inode_init();
62327 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
62328 index 16a46b6..41696fd 100644
62329 --- a/fs/debugfs/inode.c
62330 +++ b/fs/debugfs/inode.c
62331 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
62332 */
62333 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
62334 {
62335 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
62336 + return __create_file(name, S_IFDIR | S_IRWXU,
62337 +#else
62338 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
62339 +#endif
62340 parent, NULL, NULL);
62341 }
62342 EXPORT_SYMBOL_GPL(debugfs_create_dir);
62343 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
62344 index d4a9431..77f9b2e 100644
62345 --- a/fs/ecryptfs/inode.c
62346 +++ b/fs/ecryptfs/inode.c
62347 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
62348 old_fs = get_fs();
62349 set_fs(get_ds());
62350 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
62351 - (char __user *)lower_buf,
62352 + (char __force_user *)lower_buf,
62353 PATH_MAX);
62354 set_fs(old_fs);
62355 if (rc < 0)
62356 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
62357 index e4141f2..d8263e8 100644
62358 --- a/fs/ecryptfs/miscdev.c
62359 +++ b/fs/ecryptfs/miscdev.c
62360 @@ -304,7 +304,7 @@ check_list:
62361 goto out_unlock_msg_ctx;
62362 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
62363 if (msg_ctx->msg) {
62364 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
62365 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
62366 goto out_unlock_msg_ctx;
62367 i += packet_length_size;
62368 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
62369 diff --git a/fs/exec.c b/fs/exec.c
62370 index a3d33fe..49e9bc9 100644
62371 --- a/fs/exec.c
62372 +++ b/fs/exec.c
62373 @@ -56,8 +56,20 @@
62374 #include <linux/pipe_fs_i.h>
62375 #include <linux/oom.h>
62376 #include <linux/compat.h>
62377 +#include <linux/random.h>
62378 +#include <linux/seq_file.h>
62379 +#include <linux/coredump.h>
62380 +#include <linux/mman.h>
62381 +
62382 +#ifdef CONFIG_PAX_REFCOUNT
62383 +#include <linux/kallsyms.h>
62384 +#include <linux/kdebug.h>
62385 +#endif
62386 +
62387 +#include <trace/events/fs.h>
62388
62389 #include <asm/uaccess.h>
62390 +#include <asm/sections.h>
62391 #include <asm/mmu_context.h>
62392 #include <asm/tlb.h>
62393
62394 @@ -66,19 +78,34 @@
62395
62396 #include <trace/events/sched.h>
62397
62398 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62399 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
62400 +{
62401 + 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");
62402 +}
62403 +#endif
62404 +
62405 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
62406 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62407 +EXPORT_SYMBOL(pax_set_initial_flags_func);
62408 +#endif
62409 +
62410 int suid_dumpable = 0;
62411
62412 static LIST_HEAD(formats);
62413 static DEFINE_RWLOCK(binfmt_lock);
62414
62415 +extern int gr_process_kernel_exec_ban(void);
62416 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
62417 +
62418 void __register_binfmt(struct linux_binfmt * fmt, int insert)
62419 {
62420 BUG_ON(!fmt);
62421 if (WARN_ON(!fmt->load_binary))
62422 return;
62423 write_lock(&binfmt_lock);
62424 - insert ? list_add(&fmt->lh, &formats) :
62425 - list_add_tail(&fmt->lh, &formats);
62426 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
62427 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
62428 write_unlock(&binfmt_lock);
62429 }
62430
62431 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
62432 void unregister_binfmt(struct linux_binfmt * fmt)
62433 {
62434 write_lock(&binfmt_lock);
62435 - list_del(&fmt->lh);
62436 + pax_list_del((struct list_head *)&fmt->lh);
62437 write_unlock(&binfmt_lock);
62438 }
62439
62440 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
62441 int write)
62442 {
62443 struct page *page;
62444 - int ret;
62445
62446 -#ifdef CONFIG_STACK_GROWSUP
62447 - if (write) {
62448 - ret = expand_downwards(bprm->vma, pos);
62449 - if (ret < 0)
62450 - return NULL;
62451 - }
62452 -#endif
62453 - ret = get_user_pages(current, bprm->mm, pos,
62454 - 1, write, 1, &page, NULL);
62455 - if (ret <= 0)
62456 + if (0 > expand_downwards(bprm->vma, pos))
62457 + return NULL;
62458 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
62459 return NULL;
62460
62461 if (write) {
62462 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
62463 if (size <= ARG_MAX)
62464 return page;
62465
62466 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62467 + // only allow 512KB for argv+env on suid/sgid binaries
62468 + // to prevent easy ASLR exhaustion
62469 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
62470 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
62471 + (size > (512 * 1024))) {
62472 + put_page(page);
62473 + return NULL;
62474 + }
62475 +#endif
62476 +
62477 /*
62478 * Limit to 1/4-th the stack size for the argv+env strings.
62479 * This ensures that:
62480 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
62481 vma->vm_end = STACK_TOP_MAX;
62482 vma->vm_start = vma->vm_end - PAGE_SIZE;
62483 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
62484 +
62485 +#ifdef CONFIG_PAX_SEGMEXEC
62486 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
62487 +#endif
62488 +
62489 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
62490 INIT_LIST_HEAD(&vma->anon_vma_chain);
62491
62492 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
62493 mm->stack_vm = mm->total_vm = 1;
62494 up_write(&mm->mmap_sem);
62495 bprm->p = vma->vm_end - sizeof(void *);
62496 +
62497 +#ifdef CONFIG_PAX_RANDUSTACK
62498 + if (randomize_va_space)
62499 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
62500 +#endif
62501 +
62502 return 0;
62503 err:
62504 up_write(&mm->mmap_sem);
62505 @@ -399,7 +440,7 @@ struct user_arg_ptr {
62506 } ptr;
62507 };
62508
62509 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
62510 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
62511 {
62512 const char __user *native;
62513
62514 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
62515 compat_uptr_t compat;
62516
62517 if (get_user(compat, argv.ptr.compat + nr))
62518 - return ERR_PTR(-EFAULT);
62519 + return (const char __force_user *)ERR_PTR(-EFAULT);
62520
62521 return compat_ptr(compat);
62522 }
62523 #endif
62524
62525 if (get_user(native, argv.ptr.native + nr))
62526 - return ERR_PTR(-EFAULT);
62527 + return (const char __force_user *)ERR_PTR(-EFAULT);
62528
62529 return native;
62530 }
62531 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
62532 if (!p)
62533 break;
62534
62535 - if (IS_ERR(p))
62536 + if (IS_ERR((const char __force_kernel *)p))
62537 return -EFAULT;
62538
62539 if (i >= max)
62540 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
62541
62542 ret = -EFAULT;
62543 str = get_user_arg_ptr(argv, argc);
62544 - if (IS_ERR(str))
62545 + if (IS_ERR((const char __force_kernel *)str))
62546 goto out;
62547
62548 len = strnlen_user(str, MAX_ARG_STRLEN);
62549 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
62550 int r;
62551 mm_segment_t oldfs = get_fs();
62552 struct user_arg_ptr argv = {
62553 - .ptr.native = (const char __user *const __user *)__argv,
62554 + .ptr.native = (const char __user * const __force_user *)__argv,
62555 };
62556
62557 set_fs(KERNEL_DS);
62558 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
62559 unsigned long new_end = old_end - shift;
62560 struct mmu_gather tlb;
62561
62562 - BUG_ON(new_start > new_end);
62563 + if (new_start >= new_end || new_start < mmap_min_addr)
62564 + return -ENOMEM;
62565
62566 /*
62567 * ensure there are no vmas between where we want to go
62568 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
62569 if (vma != find_vma(mm, new_start))
62570 return -EFAULT;
62571
62572 +#ifdef CONFIG_PAX_SEGMEXEC
62573 + BUG_ON(pax_find_mirror_vma(vma));
62574 +#endif
62575 +
62576 /*
62577 * cover the whole range: [new_start, old_end)
62578 */
62579 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
62580 stack_top = arch_align_stack(stack_top);
62581 stack_top = PAGE_ALIGN(stack_top);
62582
62583 - if (unlikely(stack_top < mmap_min_addr) ||
62584 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
62585 - return -ENOMEM;
62586 -
62587 stack_shift = vma->vm_end - stack_top;
62588
62589 bprm->p -= stack_shift;
62590 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
62591 bprm->exec -= stack_shift;
62592
62593 down_write(&mm->mmap_sem);
62594 +
62595 + /* Move stack pages down in memory. */
62596 + if (stack_shift) {
62597 + ret = shift_arg_pages(vma, stack_shift);
62598 + if (ret)
62599 + goto out_unlock;
62600 + }
62601 +
62602 vm_flags = VM_STACK_FLAGS;
62603
62604 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62605 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
62606 + vm_flags &= ~VM_EXEC;
62607 +
62608 +#ifdef CONFIG_PAX_MPROTECT
62609 + if (mm->pax_flags & MF_PAX_MPROTECT)
62610 + vm_flags &= ~VM_MAYEXEC;
62611 +#endif
62612 +
62613 + }
62614 +#endif
62615 +
62616 /*
62617 * Adjust stack execute permissions; explicitly enable for
62618 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
62619 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
62620 goto out_unlock;
62621 BUG_ON(prev != vma);
62622
62623 - /* Move stack pages down in memory. */
62624 - if (stack_shift) {
62625 - ret = shift_arg_pages(vma, stack_shift);
62626 - if (ret)
62627 - goto out_unlock;
62628 - }
62629 -
62630 /* mprotect_fixup is overkill to remove the temporary stack flags */
62631 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
62632
62633 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
62634 #endif
62635 current->mm->start_stack = bprm->p;
62636 ret = expand_stack(vma, stack_base);
62637 +
62638 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
62639 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
62640 + unsigned long size;
62641 + vm_flags_t vm_flags;
62642 +
62643 + size = STACK_TOP - vma->vm_end;
62644 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
62645 +
62646 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
62647 +
62648 +#ifdef CONFIG_X86
62649 + if (!ret) {
62650 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
62651 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
62652 + }
62653 +#endif
62654 +
62655 + }
62656 +#endif
62657 +
62658 if (ret)
62659 ret = -EFAULT;
62660
62661 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
62662
62663 fsnotify_open(file);
62664
62665 + trace_open_exec(name->name);
62666 +
62667 err = deny_write_access(file);
62668 if (err)
62669 goto exit;
62670 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
62671 old_fs = get_fs();
62672 set_fs(get_ds());
62673 /* The cast to a user pointer is valid due to the set_fs() */
62674 - result = vfs_read(file, (void __user *)addr, count, &pos);
62675 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
62676 set_fs(old_fs);
62677 return result;
62678 }
62679 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
62680 tsk->mm = mm;
62681 tsk->active_mm = mm;
62682 activate_mm(active_mm, mm);
62683 + populate_stack();
62684 tsk->mm->vmacache_seqnum = 0;
62685 vmacache_flush(tsk);
62686 task_unlock(tsk);
62687 @@ -1247,7 +1326,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
62688 }
62689 rcu_read_unlock();
62690
62691 - if (p->fs->users > n_fs)
62692 + if (atomic_read(&p->fs->users) > n_fs)
62693 bprm->unsafe |= LSM_UNSAFE_SHARE;
62694 else
62695 p->fs->in_exec = 1;
62696 @@ -1423,6 +1502,31 @@ static int exec_binprm(struct linux_binprm *bprm)
62697 return ret;
62698 }
62699
62700 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62701 +static DEFINE_PER_CPU(u64, exec_counter);
62702 +static int __init init_exec_counters(void)
62703 +{
62704 + unsigned int cpu;
62705 +
62706 + for_each_possible_cpu(cpu) {
62707 + per_cpu(exec_counter, cpu) = (u64)cpu;
62708 + }
62709 +
62710 + return 0;
62711 +}
62712 +early_initcall(init_exec_counters);
62713 +static inline void increment_exec_counter(void)
62714 +{
62715 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
62716 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
62717 +}
62718 +#else
62719 +static inline void increment_exec_counter(void) {}
62720 +#endif
62721 +
62722 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
62723 + struct user_arg_ptr argv);
62724 +
62725 /*
62726 * sys_execve() executes a new program.
62727 */
62728 @@ -1430,6 +1534,11 @@ static int do_execve_common(struct filename *filename,
62729 struct user_arg_ptr argv,
62730 struct user_arg_ptr envp)
62731 {
62732 +#ifdef CONFIG_GRKERNSEC
62733 + struct file *old_exec_file;
62734 + struct acl_subject_label *old_acl;
62735 + struct rlimit old_rlim[RLIM_NLIMITS];
62736 +#endif
62737 struct linux_binprm *bprm;
62738 struct file *file;
62739 struct files_struct *displaced;
62740 @@ -1438,6 +1547,8 @@ static int do_execve_common(struct filename *filename,
62741 if (IS_ERR(filename))
62742 return PTR_ERR(filename);
62743
62744 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
62745 +
62746 /*
62747 * We move the actual failure in case of RLIMIT_NPROC excess from
62748 * set*uid() to execve() because too many poorly written programs
62749 @@ -1475,11 +1586,21 @@ static int do_execve_common(struct filename *filename,
62750 if (IS_ERR(file))
62751 goto out_unmark;
62752
62753 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
62754 + retval = -EPERM;
62755 + goto out_unmark;
62756 + }
62757 +
62758 sched_exec();
62759
62760 bprm->file = file;
62761 bprm->filename = bprm->interp = filename->name;
62762
62763 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
62764 + retval = -EACCES;
62765 + goto out_unmark;
62766 + }
62767 +
62768 retval = bprm_mm_init(bprm);
62769 if (retval)
62770 goto out_unmark;
62771 @@ -1496,24 +1617,70 @@ static int do_execve_common(struct filename *filename,
62772 if (retval < 0)
62773 goto out;
62774
62775 +#ifdef CONFIG_GRKERNSEC
62776 + old_acl = current->acl;
62777 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
62778 + old_exec_file = current->exec_file;
62779 + get_file(file);
62780 + current->exec_file = file;
62781 +#endif
62782 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62783 + /* limit suid stack to 8MB
62784 + * we saved the old limits above and will restore them if this exec fails
62785 + */
62786 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
62787 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
62788 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
62789 +#endif
62790 +
62791 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
62792 + retval = -EPERM;
62793 + goto out_fail;
62794 + }
62795 +
62796 + if (!gr_tpe_allow(file)) {
62797 + retval = -EACCES;
62798 + goto out_fail;
62799 + }
62800 +
62801 + if (gr_check_crash_exec(file)) {
62802 + retval = -EACCES;
62803 + goto out_fail;
62804 + }
62805 +
62806 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
62807 + bprm->unsafe);
62808 + if (retval < 0)
62809 + goto out_fail;
62810 +
62811 retval = copy_strings_kernel(1, &bprm->filename, bprm);
62812 if (retval < 0)
62813 - goto out;
62814 + goto out_fail;
62815
62816 bprm->exec = bprm->p;
62817 retval = copy_strings(bprm->envc, envp, bprm);
62818 if (retval < 0)
62819 - goto out;
62820 + goto out_fail;
62821
62822 retval = copy_strings(bprm->argc, argv, bprm);
62823 if (retval < 0)
62824 - goto out;
62825 + goto out_fail;
62826 +
62827 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
62828 +
62829 + gr_handle_exec_args(bprm, argv);
62830
62831 retval = exec_binprm(bprm);
62832 if (retval < 0)
62833 - goto out;
62834 + goto out_fail;
62835 +#ifdef CONFIG_GRKERNSEC
62836 + if (old_exec_file)
62837 + fput(old_exec_file);
62838 +#endif
62839
62840 /* execve succeeded */
62841 +
62842 + increment_exec_counter();
62843 current->fs->in_exec = 0;
62844 current->in_execve = 0;
62845 acct_update_integrals(current);
62846 @@ -1524,6 +1691,14 @@ static int do_execve_common(struct filename *filename,
62847 put_files_struct(displaced);
62848 return retval;
62849
62850 +out_fail:
62851 +#ifdef CONFIG_GRKERNSEC
62852 + current->acl = old_acl;
62853 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
62854 + fput(current->exec_file);
62855 + current->exec_file = old_exec_file;
62856 +#endif
62857 +
62858 out:
62859 if (bprm->mm) {
62860 acct_arg_size(bprm, 0);
62861 @@ -1615,3 +1790,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
62862 return compat_do_execve(getname(filename), argv, envp);
62863 }
62864 #endif
62865 +
62866 +int pax_check_flags(unsigned long *flags)
62867 +{
62868 + int retval = 0;
62869 +
62870 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
62871 + if (*flags & MF_PAX_SEGMEXEC)
62872 + {
62873 + *flags &= ~MF_PAX_SEGMEXEC;
62874 + retval = -EINVAL;
62875 + }
62876 +#endif
62877 +
62878 + if ((*flags & MF_PAX_PAGEEXEC)
62879 +
62880 +#ifdef CONFIG_PAX_PAGEEXEC
62881 + && (*flags & MF_PAX_SEGMEXEC)
62882 +#endif
62883 +
62884 + )
62885 + {
62886 + *flags &= ~MF_PAX_PAGEEXEC;
62887 + retval = -EINVAL;
62888 + }
62889 +
62890 + if ((*flags & MF_PAX_MPROTECT)
62891 +
62892 +#ifdef CONFIG_PAX_MPROTECT
62893 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62894 +#endif
62895 +
62896 + )
62897 + {
62898 + *flags &= ~MF_PAX_MPROTECT;
62899 + retval = -EINVAL;
62900 + }
62901 +
62902 + if ((*flags & MF_PAX_EMUTRAMP)
62903 +
62904 +#ifdef CONFIG_PAX_EMUTRAMP
62905 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
62906 +#endif
62907 +
62908 + )
62909 + {
62910 + *flags &= ~MF_PAX_EMUTRAMP;
62911 + retval = -EINVAL;
62912 + }
62913 +
62914 + return retval;
62915 +}
62916 +
62917 +EXPORT_SYMBOL(pax_check_flags);
62918 +
62919 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
62920 +char *pax_get_path(const struct path *path, char *buf, int buflen)
62921 +{
62922 + char *pathname = d_path(path, buf, buflen);
62923 +
62924 + if (IS_ERR(pathname))
62925 + goto toolong;
62926 +
62927 + pathname = mangle_path(buf, pathname, "\t\n\\");
62928 + if (!pathname)
62929 + goto toolong;
62930 +
62931 + *pathname = 0;
62932 + return buf;
62933 +
62934 +toolong:
62935 + return "<path too long>";
62936 +}
62937 +EXPORT_SYMBOL(pax_get_path);
62938 +
62939 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
62940 +{
62941 + struct task_struct *tsk = current;
62942 + struct mm_struct *mm = current->mm;
62943 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
62944 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
62945 + char *path_exec = NULL;
62946 + char *path_fault = NULL;
62947 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
62948 + siginfo_t info = { };
62949 +
62950 + if (buffer_exec && buffer_fault) {
62951 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
62952 +
62953 + down_read(&mm->mmap_sem);
62954 + vma = mm->mmap;
62955 + while (vma && (!vma_exec || !vma_fault)) {
62956 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
62957 + vma_exec = vma;
62958 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
62959 + vma_fault = vma;
62960 + vma = vma->vm_next;
62961 + }
62962 + if (vma_exec)
62963 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
62964 + if (vma_fault) {
62965 + start = vma_fault->vm_start;
62966 + end = vma_fault->vm_end;
62967 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
62968 + if (vma_fault->vm_file)
62969 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
62970 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
62971 + path_fault = "<heap>";
62972 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
62973 + path_fault = "<stack>";
62974 + else
62975 + path_fault = "<anonymous mapping>";
62976 + }
62977 + up_read(&mm->mmap_sem);
62978 + }
62979 + if (tsk->signal->curr_ip)
62980 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
62981 + else
62982 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
62983 + 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),
62984 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
62985 + free_page((unsigned long)buffer_exec);
62986 + free_page((unsigned long)buffer_fault);
62987 + pax_report_insns(regs, pc, sp);
62988 + info.si_signo = SIGKILL;
62989 + info.si_errno = 0;
62990 + info.si_code = SI_KERNEL;
62991 + info.si_pid = 0;
62992 + info.si_uid = 0;
62993 + do_coredump(&info);
62994 +}
62995 +#endif
62996 +
62997 +#ifdef CONFIG_PAX_REFCOUNT
62998 +void pax_report_refcount_overflow(struct pt_regs *regs)
62999 +{
63000 + if (current->signal->curr_ip)
63001 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
63002 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
63003 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
63004 + else
63005 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
63006 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
63007 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
63008 + preempt_disable();
63009 + show_regs(regs);
63010 + preempt_enable();
63011 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
63012 +}
63013 +#endif
63014 +
63015 +#ifdef CONFIG_PAX_USERCOPY
63016 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
63017 +static noinline int check_stack_object(const void *obj, unsigned long len)
63018 +{
63019 + const void * const stack = task_stack_page(current);
63020 + const void * const stackend = stack + THREAD_SIZE;
63021 +
63022 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
63023 + const void *frame = NULL;
63024 + const void *oldframe;
63025 +#endif
63026 +
63027 + if (obj + len < obj)
63028 + return -1;
63029 +
63030 + if (obj + len <= stack || stackend <= obj)
63031 + return 0;
63032 +
63033 + if (obj < stack || stackend < obj + len)
63034 + return -1;
63035 +
63036 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
63037 + oldframe = __builtin_frame_address(1);
63038 + if (oldframe)
63039 + frame = __builtin_frame_address(2);
63040 + /*
63041 + low ----------------------------------------------> high
63042 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
63043 + ^----------------^
63044 + allow copies only within here
63045 + */
63046 + while (stack <= frame && frame < stackend) {
63047 + /* if obj + len extends past the last frame, this
63048 + check won't pass and the next frame will be 0,
63049 + causing us to bail out and correctly report
63050 + the copy as invalid
63051 + */
63052 + if (obj + len <= frame)
63053 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
63054 + oldframe = frame;
63055 + frame = *(const void * const *)frame;
63056 + }
63057 + return -1;
63058 +#else
63059 + return 1;
63060 +#endif
63061 +}
63062 +
63063 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
63064 +{
63065 + if (current->signal->curr_ip)
63066 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
63067 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
63068 + else
63069 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
63070 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
63071 + dump_stack();
63072 + gr_handle_kernel_exploit();
63073 + do_group_exit(SIGKILL);
63074 +}
63075 +#endif
63076 +
63077 +#ifdef CONFIG_PAX_USERCOPY
63078 +
63079 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
63080 +{
63081 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
63082 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
63083 +#ifdef CONFIG_MODULES
63084 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
63085 +#else
63086 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
63087 +#endif
63088 +
63089 +#else
63090 + unsigned long textlow = (unsigned long)_stext;
63091 + unsigned long texthigh = (unsigned long)_etext;
63092 +
63093 +#ifdef CONFIG_X86_64
63094 + /* check against linear mapping as well */
63095 + if (high > (unsigned long)__va(__pa(textlow)) &&
63096 + low < (unsigned long)__va(__pa(texthigh)))
63097 + return true;
63098 +#endif
63099 +
63100 +#endif
63101 +
63102 + if (high <= textlow || low >= texthigh)
63103 + return false;
63104 + else
63105 + return true;
63106 +}
63107 +#endif
63108 +
63109 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
63110 +{
63111 +#ifdef CONFIG_PAX_USERCOPY
63112 + const char *type;
63113 +#endif
63114 +
63115 +#ifndef CONFIG_STACK_GROWSUP
63116 + unsigned long stackstart = (unsigned long)task_stack_page(current);
63117 + unsigned long currentsp = (unsigned long)&stackstart;
63118 + if (unlikely((currentsp < stackstart + 512 ||
63119 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
63120 + BUG();
63121 +#endif
63122 +
63123 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
63124 + if (const_size)
63125 + return;
63126 +#endif
63127 +
63128 +#ifdef CONFIG_PAX_USERCOPY
63129 + if (!n)
63130 + return;
63131 +
63132 + type = check_heap_object(ptr, n);
63133 + if (!type) {
63134 + int ret = check_stack_object(ptr, n);
63135 + if (ret == 1 || ret == 2)
63136 + return;
63137 + if (ret == 0) {
63138 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
63139 + type = "<kernel text>";
63140 + else
63141 + return;
63142 + } else
63143 + type = "<process stack>";
63144 + }
63145 +
63146 + pax_report_usercopy(ptr, n, to_user, type);
63147 +#endif
63148 +
63149 +}
63150 +EXPORT_SYMBOL(__check_object_size);
63151 +
63152 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
63153 +void pax_track_stack(void)
63154 +{
63155 + unsigned long sp = (unsigned long)&sp;
63156 + if (sp < current_thread_info()->lowest_stack &&
63157 + sp > (unsigned long)task_stack_page(current))
63158 + current_thread_info()->lowest_stack = sp;
63159 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
63160 + BUG();
63161 +}
63162 +EXPORT_SYMBOL(pax_track_stack);
63163 +#endif
63164 +
63165 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
63166 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
63167 +{
63168 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
63169 + dump_stack();
63170 + do_group_exit(SIGKILL);
63171 +}
63172 +EXPORT_SYMBOL(report_size_overflow);
63173 +#endif
63174 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
63175 index 9f9992b..8b59411 100644
63176 --- a/fs/ext2/balloc.c
63177 +++ b/fs/ext2/balloc.c
63178 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
63179
63180 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
63181 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
63182 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
63183 + if (free_blocks < root_blocks + 1 &&
63184 !uid_eq(sbi->s_resuid, current_fsuid()) &&
63185 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
63186 - !in_group_p (sbi->s_resgid))) {
63187 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
63188 return 0;
63189 }
63190 return 1;
63191 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
63192 index 9142614..97484fa 100644
63193 --- a/fs/ext2/xattr.c
63194 +++ b/fs/ext2/xattr.c
63195 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
63196 struct buffer_head *bh = NULL;
63197 struct ext2_xattr_entry *entry;
63198 char *end;
63199 - size_t rest = buffer_size;
63200 + size_t rest = buffer_size, total_size = 0;
63201 int error;
63202
63203 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
63204 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
63205 buffer += size;
63206 }
63207 rest -= size;
63208 + total_size += size;
63209 }
63210 }
63211 - error = buffer_size - rest; /* total size */
63212 + error = total_size;
63213
63214 cleanup:
63215 brelse(bh);
63216 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
63217 index 158b5d4..2432610 100644
63218 --- a/fs/ext3/balloc.c
63219 +++ b/fs/ext3/balloc.c
63220 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
63221
63222 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
63223 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
63224 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
63225 + if (free_blocks < root_blocks + 1 &&
63226 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
63227 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
63228 - !in_group_p (sbi->s_resgid))) {
63229 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
63230 return 0;
63231 }
63232 return 1;
63233 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
63234 index c6874be..f8a6ae8 100644
63235 --- a/fs/ext3/xattr.c
63236 +++ b/fs/ext3/xattr.c
63237 @@ -330,7 +330,7 @@ static int
63238 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
63239 char *buffer, size_t buffer_size)
63240 {
63241 - size_t rest = buffer_size;
63242 + size_t rest = buffer_size, total_size = 0;
63243
63244 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
63245 const struct xattr_handler *handler =
63246 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
63247 buffer += size;
63248 }
63249 rest -= size;
63250 + total_size += size;
63251 }
63252 }
63253 - return buffer_size - rest;
63254 + return total_size;
63255 }
63256
63257 static int
63258 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
63259 index fca3820..e1ea241 100644
63260 --- a/fs/ext4/balloc.c
63261 +++ b/fs/ext4/balloc.c
63262 @@ -553,8 +553,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
63263 /* Hm, nope. Are (enough) root reserved clusters available? */
63264 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
63265 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
63266 - capable(CAP_SYS_RESOURCE) ||
63267 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
63268 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
63269 + capable_nolog(CAP_SYS_RESOURCE)) {
63270
63271 if (free_clusters >= (nclusters + dirty_clusters +
63272 resv_clusters))
63273 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
63274 index 1bbe7c3..6f404a5c 100644
63275 --- a/fs/ext4/ext4.h
63276 +++ b/fs/ext4/ext4.h
63277 @@ -1276,19 +1276,19 @@ struct ext4_sb_info {
63278 unsigned long s_mb_last_start;
63279
63280 /* stats for buddy allocator */
63281 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
63282 - atomic_t s_bal_success; /* we found long enough chunks */
63283 - atomic_t s_bal_allocated; /* in blocks */
63284 - atomic_t s_bal_ex_scanned; /* total extents scanned */
63285 - atomic_t s_bal_goals; /* goal hits */
63286 - atomic_t s_bal_breaks; /* too long searches */
63287 - atomic_t s_bal_2orders; /* 2^order hits */
63288 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
63289 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
63290 + atomic_unchecked_t s_bal_allocated; /* in blocks */
63291 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
63292 + atomic_unchecked_t s_bal_goals; /* goal hits */
63293 + atomic_unchecked_t s_bal_breaks; /* too long searches */
63294 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
63295 spinlock_t s_bal_lock;
63296 unsigned long s_mb_buddies_generated;
63297 unsigned long long s_mb_generation_time;
63298 - atomic_t s_mb_lost_chunks;
63299 - atomic_t s_mb_preallocated;
63300 - atomic_t s_mb_discarded;
63301 + atomic_unchecked_t s_mb_lost_chunks;
63302 + atomic_unchecked_t s_mb_preallocated;
63303 + atomic_unchecked_t s_mb_discarded;
63304 atomic_t s_lock_busy;
63305
63306 /* locality groups */
63307 @@ -1826,7 +1826,7 @@ ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
63308 /*
63309 * Special error return code only used by dx_probe() and its callers.
63310 */
63311 -#define ERR_BAD_DX_DIR -75000
63312 +#define ERR_BAD_DX_DIR (-(MAX_ERRNO - 1))
63313
63314 /*
63315 * Timeout and state flag for lazy initialization inode thread.
63316 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
63317 index c3e7418..f62cab3 100644
63318 --- a/fs/ext4/mballoc.c
63319 +++ b/fs/ext4/mballoc.c
63320 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
63321 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
63322
63323 if (EXT4_SB(sb)->s_mb_stats)
63324 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
63325 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
63326
63327 break;
63328 }
63329 @@ -2211,7 +2211,7 @@ repeat:
63330 ac->ac_status = AC_STATUS_CONTINUE;
63331 ac->ac_flags |= EXT4_MB_HINT_FIRST;
63332 cr = 3;
63333 - atomic_inc(&sbi->s_mb_lost_chunks);
63334 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
63335 goto repeat;
63336 }
63337 }
63338 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
63339 if (sbi->s_mb_stats) {
63340 ext4_msg(sb, KERN_INFO,
63341 "mballoc: %u blocks %u reqs (%u success)",
63342 - atomic_read(&sbi->s_bal_allocated),
63343 - atomic_read(&sbi->s_bal_reqs),
63344 - atomic_read(&sbi->s_bal_success));
63345 + atomic_read_unchecked(&sbi->s_bal_allocated),
63346 + atomic_read_unchecked(&sbi->s_bal_reqs),
63347 + atomic_read_unchecked(&sbi->s_bal_success));
63348 ext4_msg(sb, KERN_INFO,
63349 "mballoc: %u extents scanned, %u goal hits, "
63350 "%u 2^N hits, %u breaks, %u lost",
63351 - atomic_read(&sbi->s_bal_ex_scanned),
63352 - atomic_read(&sbi->s_bal_goals),
63353 - atomic_read(&sbi->s_bal_2orders),
63354 - atomic_read(&sbi->s_bal_breaks),
63355 - atomic_read(&sbi->s_mb_lost_chunks));
63356 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
63357 + atomic_read_unchecked(&sbi->s_bal_goals),
63358 + atomic_read_unchecked(&sbi->s_bal_2orders),
63359 + atomic_read_unchecked(&sbi->s_bal_breaks),
63360 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
63361 ext4_msg(sb, KERN_INFO,
63362 "mballoc: %lu generated and it took %Lu",
63363 sbi->s_mb_buddies_generated,
63364 sbi->s_mb_generation_time);
63365 ext4_msg(sb, KERN_INFO,
63366 "mballoc: %u preallocated, %u discarded",
63367 - atomic_read(&sbi->s_mb_preallocated),
63368 - atomic_read(&sbi->s_mb_discarded));
63369 + atomic_read_unchecked(&sbi->s_mb_preallocated),
63370 + atomic_read_unchecked(&sbi->s_mb_discarded));
63371 }
63372
63373 free_percpu(sbi->s_locality_groups);
63374 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
63375 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
63376
63377 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
63378 - atomic_inc(&sbi->s_bal_reqs);
63379 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
63380 + atomic_inc_unchecked(&sbi->s_bal_reqs);
63381 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
63382 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
63383 - atomic_inc(&sbi->s_bal_success);
63384 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
63385 + atomic_inc_unchecked(&sbi->s_bal_success);
63386 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
63387 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
63388 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
63389 - atomic_inc(&sbi->s_bal_goals);
63390 + atomic_inc_unchecked(&sbi->s_bal_goals);
63391 if (ac->ac_found > sbi->s_mb_max_to_scan)
63392 - atomic_inc(&sbi->s_bal_breaks);
63393 + atomic_inc_unchecked(&sbi->s_bal_breaks);
63394 }
63395
63396 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
63397 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
63398 trace_ext4_mb_new_inode_pa(ac, pa);
63399
63400 ext4_mb_use_inode_pa(ac, pa);
63401 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
63402 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
63403
63404 ei = EXT4_I(ac->ac_inode);
63405 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
63406 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
63407 trace_ext4_mb_new_group_pa(ac, pa);
63408
63409 ext4_mb_use_group_pa(ac, pa);
63410 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
63411 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
63412
63413 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
63414 lg = ac->ac_lg;
63415 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
63416 * from the bitmap and continue.
63417 */
63418 }
63419 - atomic_add(free, &sbi->s_mb_discarded);
63420 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
63421
63422 return err;
63423 }
63424 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
63425 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
63426 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
63427 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
63428 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
63429 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
63430 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
63431
63432 return 0;
63433 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
63434 index 32bce84..112d969 100644
63435 --- a/fs/ext4/mmp.c
63436 +++ b/fs/ext4/mmp.c
63437 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
63438 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
63439 const char *function, unsigned int line, const char *msg)
63440 {
63441 - __ext4_warning(sb, function, line, msg);
63442 + __ext4_warning(sb, function, line, "%s", msg);
63443 __ext4_warning(sb, function, line,
63444 "MMP failure info: last update time: %llu, last update "
63445 "node: %s, last update device: %s\n",
63446 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
63447 index 9e6eced..5e127be 100644
63448 --- a/fs/ext4/namei.c
63449 +++ b/fs/ext4/namei.c
63450 @@ -1227,7 +1227,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
63451 buffer */
63452 int num = 0;
63453 ext4_lblk_t nblocks;
63454 - int i, err;
63455 + int i, err = 0;
63456 int namelen;
63457
63458 *res_dir = NULL;
63459 @@ -1264,7 +1264,11 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
63460 * return. Otherwise, fall back to doing a search the
63461 * old fashioned way.
63462 */
63463 - if (bh || (err != ERR_BAD_DX_DIR))
63464 + if (err == -ENOENT)
63465 + return NULL;
63466 + if (err && err != ERR_BAD_DX_DIR)
63467 + return ERR_PTR(err);
63468 + if (bh)
63469 return bh;
63470 dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
63471 "falling back\n"));
63472 @@ -1295,6 +1299,11 @@ restart:
63473 }
63474 num++;
63475 bh = ext4_getblk(NULL, dir, b++, 0, &err);
63476 + if (unlikely(err)) {
63477 + if (ra_max == 0)
63478 + return ERR_PTR(err);
63479 + break;
63480 + }
63481 bh_use[ra_max] = bh;
63482 if (bh)
63483 ll_rw_block(READ | REQ_META | REQ_PRIO,
63484 @@ -1417,6 +1426,8 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
63485 return ERR_PTR(-ENAMETOOLONG);
63486
63487 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
63488 + if (IS_ERR(bh))
63489 + return (struct dentry *) bh;
63490 inode = NULL;
63491 if (bh) {
63492 __u32 ino = le32_to_cpu(de->inode);
63493 @@ -1450,6 +1461,8 @@ struct dentry *ext4_get_parent(struct dentry *child)
63494 struct buffer_head *bh;
63495
63496 bh = ext4_find_entry(child->d_inode, &dotdot, &de, NULL);
63497 + if (IS_ERR(bh))
63498 + return (struct dentry *) bh;
63499 if (!bh)
63500 return ERR_PTR(-ENOENT);
63501 ino = le32_to_cpu(de->inode);
63502 @@ -2727,6 +2740,8 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
63503
63504 retval = -ENOENT;
63505 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
63506 + if (IS_ERR(bh))
63507 + return PTR_ERR(bh);
63508 if (!bh)
63509 goto end_rmdir;
63510
63511 @@ -2794,6 +2809,8 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
63512
63513 retval = -ENOENT;
63514 bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
63515 + if (IS_ERR(bh))
63516 + return PTR_ERR(bh);
63517 if (!bh)
63518 goto end_unlink;
63519
63520 @@ -3121,6 +3138,8 @@ static int ext4_find_delete_entry(handle_t *handle, struct inode *dir,
63521 struct ext4_dir_entry_2 *de;
63522
63523 bh = ext4_find_entry(dir, d_name, &de, NULL);
63524 + if (IS_ERR(bh))
63525 + return PTR_ERR(bh);
63526 if (bh) {
63527 retval = ext4_delete_entry(handle, dir, de, bh);
63528 brelse(bh);
63529 @@ -3205,6 +3224,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
63530 dquot_initialize(new.inode);
63531
63532 old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, &old.de, NULL);
63533 + if (IS_ERR(old.bh))
63534 + return PTR_ERR(old.bh);
63535 /*
63536 * Check for inode number is _not_ due to possible IO errors.
63537 * We might rmdir the source, keep it as pwd of some process
63538 @@ -3217,6 +3238,11 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
63539
63540 new.bh = ext4_find_entry(new.dir, &new.dentry->d_name,
63541 &new.de, &new.inlined);
63542 + if (IS_ERR(new.bh)) {
63543 + retval = PTR_ERR(new.bh);
63544 + new.bh = NULL;
63545 + goto end_rename;
63546 + }
63547 if (new.bh) {
63548 if (!new.inode) {
63549 brelse(new.bh);
63550 @@ -3345,6 +3371,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
63551
63552 old.bh = ext4_find_entry(old.dir, &old.dentry->d_name,
63553 &old.de, &old.inlined);
63554 + if (IS_ERR(old.bh))
63555 + return PTR_ERR(old.bh);
63556 /*
63557 * Check for inode number is _not_ due to possible IO errors.
63558 * We might rmdir the source, keep it as pwd of some process
63559 @@ -3357,6 +3385,11 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
63560
63561 new.bh = ext4_find_entry(new.dir, &new.dentry->d_name,
63562 &new.de, &new.inlined);
63563 + if (IS_ERR(new.bh)) {
63564 + retval = PTR_ERR(new.bh);
63565 + new.bh = NULL;
63566 + goto end_rename;
63567 + }
63568
63569 /* RENAME_EXCHANGE case: old *and* new must both exist */
63570 if (!new.bh || le32_to_cpu(new.de->inode) != new.inode->i_ino)
63571 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
63572 index bb0e80f..1e43b90 100644
63573 --- a/fs/ext4/resize.c
63574 +++ b/fs/ext4/resize.c
63575 @@ -575,6 +575,7 @@ handle_bb:
63576 bh = bclean(handle, sb, block);
63577 if (IS_ERR(bh)) {
63578 err = PTR_ERR(bh);
63579 + bh = NULL;
63580 goto out;
63581 }
63582 overhead = ext4_group_overhead_blocks(sb, group);
63583 @@ -603,6 +604,7 @@ handle_ib:
63584 bh = bclean(handle, sb, block);
63585 if (IS_ERR(bh)) {
63586 err = PTR_ERR(bh);
63587 + bh = NULL;
63588 goto out;
63589 }
63590
63591 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
63592 index beeb5c4..998c28d 100644
63593 --- a/fs/ext4/super.c
63594 +++ b/fs/ext4/super.c
63595 @@ -1276,7 +1276,7 @@ static ext4_fsblk_t get_sb_block(void **data)
63596 }
63597
63598 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
63599 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
63600 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
63601 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
63602
63603 #ifdef CONFIG_QUOTA
63604 @@ -2464,7 +2464,7 @@ struct ext4_attr {
63605 int offset;
63606 int deprecated_val;
63607 } u;
63608 -};
63609 +} __do_const;
63610
63611 static int parse_strtoull(const char *buf,
63612 unsigned long long max, unsigned long long *value)
63613 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
63614 index e738733..9843a6c 100644
63615 --- a/fs/ext4/xattr.c
63616 +++ b/fs/ext4/xattr.c
63617 @@ -386,7 +386,7 @@ static int
63618 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
63619 char *buffer, size_t buffer_size)
63620 {
63621 - size_t rest = buffer_size;
63622 + size_t rest = buffer_size, total_size = 0;
63623
63624 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
63625 const struct xattr_handler *handler =
63626 @@ -403,9 +403,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
63627 buffer += size;
63628 }
63629 rest -= size;
63630 + total_size += size;
63631 }
63632 }
63633 - return buffer_size - rest;
63634 + return total_size;
63635 }
63636
63637 static int
63638 diff --git a/fs/fcntl.c b/fs/fcntl.c
63639 index 72c82f6..a18b263 100644
63640 --- a/fs/fcntl.c
63641 +++ b/fs/fcntl.c
63642 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
63643 if (err)
63644 return err;
63645
63646 + if (gr_handle_chroot_fowner(pid, type))
63647 + return -ENOENT;
63648 + if (gr_check_protected_task_fowner(pid, type))
63649 + return -EACCES;
63650 +
63651 f_modown(filp, pid, type, force);
63652 return 0;
63653 }
63654 diff --git a/fs/fhandle.c b/fs/fhandle.c
63655 index 999ff5c..ac037c9 100644
63656 --- a/fs/fhandle.c
63657 +++ b/fs/fhandle.c
63658 @@ -8,6 +8,7 @@
63659 #include <linux/fs_struct.h>
63660 #include <linux/fsnotify.h>
63661 #include <linux/personality.h>
63662 +#include <linux/grsecurity.h>
63663 #include <asm/uaccess.h>
63664 #include "internal.h"
63665 #include "mount.h"
63666 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
63667 } else
63668 retval = 0;
63669 /* copy the mount id */
63670 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
63671 - sizeof(*mnt_id)) ||
63672 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
63673 copy_to_user(ufh, handle,
63674 sizeof(struct file_handle) + handle_bytes))
63675 retval = -EFAULT;
63676 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
63677 * the directory. Ideally we would like CAP_DAC_SEARCH.
63678 * But we don't have that
63679 */
63680 - if (!capable(CAP_DAC_READ_SEARCH)) {
63681 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
63682 retval = -EPERM;
63683 goto out_err;
63684 }
63685 diff --git a/fs/file.c b/fs/file.c
63686 index 66923fe..2849783 100644
63687 --- a/fs/file.c
63688 +++ b/fs/file.c
63689 @@ -16,6 +16,7 @@
63690 #include <linux/slab.h>
63691 #include <linux/vmalloc.h>
63692 #include <linux/file.h>
63693 +#include <linux/security.h>
63694 #include <linux/fdtable.h>
63695 #include <linux/bitops.h>
63696 #include <linux/interrupt.h>
63697 @@ -139,7 +140,7 @@ out:
63698 * Return <0 error code on error; 1 on successful completion.
63699 * The files->file_lock should be held on entry, and will be held on exit.
63700 */
63701 -static int expand_fdtable(struct files_struct *files, int nr)
63702 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
63703 __releases(files->file_lock)
63704 __acquires(files->file_lock)
63705 {
63706 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
63707 * expanded and execution may have blocked.
63708 * The files->file_lock should be held on entry, and will be held on exit.
63709 */
63710 -static int expand_files(struct files_struct *files, int nr)
63711 +static int expand_files(struct files_struct *files, unsigned int nr)
63712 {
63713 struct fdtable *fdt;
63714
63715 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
63716 if (!file)
63717 return __close_fd(files, fd);
63718
63719 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
63720 if (fd >= rlimit(RLIMIT_NOFILE))
63721 return -EBADF;
63722
63723 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
63724 if (unlikely(oldfd == newfd))
63725 return -EINVAL;
63726
63727 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
63728 if (newfd >= rlimit(RLIMIT_NOFILE))
63729 return -EBADF;
63730
63731 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
63732 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
63733 {
63734 int err;
63735 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
63736 if (from >= rlimit(RLIMIT_NOFILE))
63737 return -EINVAL;
63738 err = alloc_fd(from, flags);
63739 diff --git a/fs/filesystems.c b/fs/filesystems.c
63740 index 5797d45..7d7d79a 100644
63741 --- a/fs/filesystems.c
63742 +++ b/fs/filesystems.c
63743 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
63744 int len = dot ? dot - name : strlen(name);
63745
63746 fs = __get_fs_type(name, len);
63747 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
63748 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
63749 +#else
63750 if (!fs && (request_module("fs-%.*s", len, name) == 0))
63751 +#endif
63752 fs = __get_fs_type(name, len);
63753
63754 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
63755 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
63756 index 7dca743..543d620 100644
63757 --- a/fs/fs_struct.c
63758 +++ b/fs/fs_struct.c
63759 @@ -4,6 +4,7 @@
63760 #include <linux/path.h>
63761 #include <linux/slab.h>
63762 #include <linux/fs_struct.h>
63763 +#include <linux/grsecurity.h>
63764 #include "internal.h"
63765
63766 /*
63767 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
63768 write_seqcount_begin(&fs->seq);
63769 old_root = fs->root;
63770 fs->root = *path;
63771 + gr_set_chroot_entries(current, path);
63772 write_seqcount_end(&fs->seq);
63773 spin_unlock(&fs->lock);
63774 if (old_root.dentry)
63775 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
63776 int hits = 0;
63777 spin_lock(&fs->lock);
63778 write_seqcount_begin(&fs->seq);
63779 + /* this root replacement is only done by pivot_root,
63780 + leave grsec's chroot tagging alone for this task
63781 + so that a pivoted root isn't treated as a chroot
63782 + */
63783 hits += replace_path(&fs->root, old_root, new_root);
63784 hits += replace_path(&fs->pwd, old_root, new_root);
63785 write_seqcount_end(&fs->seq);
63786 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
63787 task_lock(tsk);
63788 spin_lock(&fs->lock);
63789 tsk->fs = NULL;
63790 - kill = !--fs->users;
63791 + gr_clear_chroot_entries(tsk);
63792 + kill = !atomic_dec_return(&fs->users);
63793 spin_unlock(&fs->lock);
63794 task_unlock(tsk);
63795 if (kill)
63796 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63797 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
63798 /* We don't need to lock fs - think why ;-) */
63799 if (fs) {
63800 - fs->users = 1;
63801 + atomic_set(&fs->users, 1);
63802 fs->in_exec = 0;
63803 spin_lock_init(&fs->lock);
63804 seqcount_init(&fs->seq);
63805 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
63806 spin_lock(&old->lock);
63807 fs->root = old->root;
63808 path_get(&fs->root);
63809 + /* instead of calling gr_set_chroot_entries here,
63810 + we call it from every caller of this function
63811 + */
63812 fs->pwd = old->pwd;
63813 path_get(&fs->pwd);
63814 spin_unlock(&old->lock);
63815 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
63816
63817 task_lock(current);
63818 spin_lock(&fs->lock);
63819 - kill = !--fs->users;
63820 + kill = !atomic_dec_return(&fs->users);
63821 current->fs = new_fs;
63822 + gr_set_chroot_entries(current, &new_fs->root);
63823 spin_unlock(&fs->lock);
63824 task_unlock(current);
63825
63826 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
63827
63828 int current_umask(void)
63829 {
63830 - return current->fs->umask;
63831 + return current->fs->umask | gr_acl_umask();
63832 }
63833 EXPORT_SYMBOL(current_umask);
63834
63835 /* to be mentioned only in INIT_TASK */
63836 struct fs_struct init_fs = {
63837 - .users = 1,
63838 + .users = ATOMIC_INIT(1),
63839 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
63840 .seq = SEQCNT_ZERO(init_fs.seq),
63841 .umask = 0022,
63842 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
63843 index aec01be..cf81ff9 100644
63844 --- a/fs/fscache/cookie.c
63845 +++ b/fs/fscache/cookie.c
63846 @@ -19,7 +19,7 @@
63847
63848 struct kmem_cache *fscache_cookie_jar;
63849
63850 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
63851 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
63852
63853 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
63854 static int fscache_alloc_object(struct fscache_cache *cache,
63855 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
63856 parent ? (char *) parent->def->name : "<no-parent>",
63857 def->name, netfs_data, enable);
63858
63859 - fscache_stat(&fscache_n_acquires);
63860 + fscache_stat_unchecked(&fscache_n_acquires);
63861
63862 /* if there's no parent cookie, then we don't create one here either */
63863 if (!parent) {
63864 - fscache_stat(&fscache_n_acquires_null);
63865 + fscache_stat_unchecked(&fscache_n_acquires_null);
63866 _leave(" [no parent]");
63867 return NULL;
63868 }
63869 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63870 /* allocate and initialise a cookie */
63871 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
63872 if (!cookie) {
63873 - fscache_stat(&fscache_n_acquires_oom);
63874 + fscache_stat_unchecked(&fscache_n_acquires_oom);
63875 _leave(" [ENOMEM]");
63876 return NULL;
63877 }
63878 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
63879
63880 switch (cookie->def->type) {
63881 case FSCACHE_COOKIE_TYPE_INDEX:
63882 - fscache_stat(&fscache_n_cookie_index);
63883 + fscache_stat_unchecked(&fscache_n_cookie_index);
63884 break;
63885 case FSCACHE_COOKIE_TYPE_DATAFILE:
63886 - fscache_stat(&fscache_n_cookie_data);
63887 + fscache_stat_unchecked(&fscache_n_cookie_data);
63888 break;
63889 default:
63890 - fscache_stat(&fscache_n_cookie_special);
63891 + fscache_stat_unchecked(&fscache_n_cookie_special);
63892 break;
63893 }
63894
63895 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63896 } else {
63897 atomic_dec(&parent->n_children);
63898 __fscache_cookie_put(cookie);
63899 - fscache_stat(&fscache_n_acquires_nobufs);
63900 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
63901 _leave(" = NULL");
63902 return NULL;
63903 }
63904 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
63905 }
63906 }
63907
63908 - fscache_stat(&fscache_n_acquires_ok);
63909 + fscache_stat_unchecked(&fscache_n_acquires_ok);
63910 _leave(" = %p", cookie);
63911 return cookie;
63912 }
63913 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
63914 cache = fscache_select_cache_for_object(cookie->parent);
63915 if (!cache) {
63916 up_read(&fscache_addremove_sem);
63917 - fscache_stat(&fscache_n_acquires_no_cache);
63918 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
63919 _leave(" = -ENOMEDIUM [no cache]");
63920 return -ENOMEDIUM;
63921 }
63922 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
63923 object = cache->ops->alloc_object(cache, cookie);
63924 fscache_stat_d(&fscache_n_cop_alloc_object);
63925 if (IS_ERR(object)) {
63926 - fscache_stat(&fscache_n_object_no_alloc);
63927 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
63928 ret = PTR_ERR(object);
63929 goto error;
63930 }
63931
63932 - fscache_stat(&fscache_n_object_alloc);
63933 + fscache_stat_unchecked(&fscache_n_object_alloc);
63934
63935 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
63936 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
63937
63938 _debug("ALLOC OBJ%x: %s {%lx}",
63939 object->debug_id, cookie->def->name, object->events);
63940 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
63941
63942 _enter("{%s}", cookie->def->name);
63943
63944 - fscache_stat(&fscache_n_invalidates);
63945 + fscache_stat_unchecked(&fscache_n_invalidates);
63946
63947 /* Only permit invalidation of data files. Invalidating an index will
63948 * require the caller to release all its attachments to the tree rooted
63949 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
63950 {
63951 struct fscache_object *object;
63952
63953 - fscache_stat(&fscache_n_updates);
63954 + fscache_stat_unchecked(&fscache_n_updates);
63955
63956 if (!cookie) {
63957 - fscache_stat(&fscache_n_updates_null);
63958 + fscache_stat_unchecked(&fscache_n_updates_null);
63959 _leave(" [no cookie]");
63960 return;
63961 }
63962 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
63963 */
63964 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
63965 {
63966 - fscache_stat(&fscache_n_relinquishes);
63967 + fscache_stat_unchecked(&fscache_n_relinquishes);
63968 if (retire)
63969 - fscache_stat(&fscache_n_relinquishes_retire);
63970 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
63971
63972 if (!cookie) {
63973 - fscache_stat(&fscache_n_relinquishes_null);
63974 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
63975 _leave(" [no cookie]");
63976 return;
63977 }
63978 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
63979 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
63980 goto inconsistent;
63981
63982 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63983 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63984
63985 __fscache_use_cookie(cookie);
63986 if (fscache_submit_op(object, op) < 0)
63987 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
63988 index bc6c08f..09c0d96 100644
63989 --- a/fs/fscache/internal.h
63990 +++ b/fs/fscache/internal.h
63991 @@ -139,8 +139,8 @@ extern void fscache_operation_gc(struct work_struct *);
63992 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
63993 extern int fscache_wait_for_operation_activation(struct fscache_object *,
63994 struct fscache_operation *,
63995 - atomic_t *,
63996 - atomic_t *,
63997 + atomic_unchecked_t *,
63998 + atomic_unchecked_t *,
63999 void (*)(struct fscache_operation *));
64000 extern void fscache_invalidate_writes(struct fscache_cookie *);
64001
64002 @@ -159,101 +159,101 @@ extern void fscache_proc_cleanup(void);
64003 * stats.c
64004 */
64005 #ifdef CONFIG_FSCACHE_STATS
64006 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
64007 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
64008 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
64009 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
64010
64011 -extern atomic_t fscache_n_op_pend;
64012 -extern atomic_t fscache_n_op_run;
64013 -extern atomic_t fscache_n_op_enqueue;
64014 -extern atomic_t fscache_n_op_deferred_release;
64015 -extern atomic_t fscache_n_op_release;
64016 -extern atomic_t fscache_n_op_gc;
64017 -extern atomic_t fscache_n_op_cancelled;
64018 -extern atomic_t fscache_n_op_rejected;
64019 +extern atomic_unchecked_t fscache_n_op_pend;
64020 +extern atomic_unchecked_t fscache_n_op_run;
64021 +extern atomic_unchecked_t fscache_n_op_enqueue;
64022 +extern atomic_unchecked_t fscache_n_op_deferred_release;
64023 +extern atomic_unchecked_t fscache_n_op_release;
64024 +extern atomic_unchecked_t fscache_n_op_gc;
64025 +extern atomic_unchecked_t fscache_n_op_cancelled;
64026 +extern atomic_unchecked_t fscache_n_op_rejected;
64027
64028 -extern atomic_t fscache_n_attr_changed;
64029 -extern atomic_t fscache_n_attr_changed_ok;
64030 -extern atomic_t fscache_n_attr_changed_nobufs;
64031 -extern atomic_t fscache_n_attr_changed_nomem;
64032 -extern atomic_t fscache_n_attr_changed_calls;
64033 +extern atomic_unchecked_t fscache_n_attr_changed;
64034 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
64035 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
64036 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
64037 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
64038
64039 -extern atomic_t fscache_n_allocs;
64040 -extern atomic_t fscache_n_allocs_ok;
64041 -extern atomic_t fscache_n_allocs_wait;
64042 -extern atomic_t fscache_n_allocs_nobufs;
64043 -extern atomic_t fscache_n_allocs_intr;
64044 -extern atomic_t fscache_n_allocs_object_dead;
64045 -extern atomic_t fscache_n_alloc_ops;
64046 -extern atomic_t fscache_n_alloc_op_waits;
64047 +extern atomic_unchecked_t fscache_n_allocs;
64048 +extern atomic_unchecked_t fscache_n_allocs_ok;
64049 +extern atomic_unchecked_t fscache_n_allocs_wait;
64050 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
64051 +extern atomic_unchecked_t fscache_n_allocs_intr;
64052 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
64053 +extern atomic_unchecked_t fscache_n_alloc_ops;
64054 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
64055
64056 -extern atomic_t fscache_n_retrievals;
64057 -extern atomic_t fscache_n_retrievals_ok;
64058 -extern atomic_t fscache_n_retrievals_wait;
64059 -extern atomic_t fscache_n_retrievals_nodata;
64060 -extern atomic_t fscache_n_retrievals_nobufs;
64061 -extern atomic_t fscache_n_retrievals_intr;
64062 -extern atomic_t fscache_n_retrievals_nomem;
64063 -extern atomic_t fscache_n_retrievals_object_dead;
64064 -extern atomic_t fscache_n_retrieval_ops;
64065 -extern atomic_t fscache_n_retrieval_op_waits;
64066 +extern atomic_unchecked_t fscache_n_retrievals;
64067 +extern atomic_unchecked_t fscache_n_retrievals_ok;
64068 +extern atomic_unchecked_t fscache_n_retrievals_wait;
64069 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
64070 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
64071 +extern atomic_unchecked_t fscache_n_retrievals_intr;
64072 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
64073 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
64074 +extern atomic_unchecked_t fscache_n_retrieval_ops;
64075 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
64076
64077 -extern atomic_t fscache_n_stores;
64078 -extern atomic_t fscache_n_stores_ok;
64079 -extern atomic_t fscache_n_stores_again;
64080 -extern atomic_t fscache_n_stores_nobufs;
64081 -extern atomic_t fscache_n_stores_oom;
64082 -extern atomic_t fscache_n_store_ops;
64083 -extern atomic_t fscache_n_store_calls;
64084 -extern atomic_t fscache_n_store_pages;
64085 -extern atomic_t fscache_n_store_radix_deletes;
64086 -extern atomic_t fscache_n_store_pages_over_limit;
64087 +extern atomic_unchecked_t fscache_n_stores;
64088 +extern atomic_unchecked_t fscache_n_stores_ok;
64089 +extern atomic_unchecked_t fscache_n_stores_again;
64090 +extern atomic_unchecked_t fscache_n_stores_nobufs;
64091 +extern atomic_unchecked_t fscache_n_stores_oom;
64092 +extern atomic_unchecked_t fscache_n_store_ops;
64093 +extern atomic_unchecked_t fscache_n_store_calls;
64094 +extern atomic_unchecked_t fscache_n_store_pages;
64095 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
64096 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
64097
64098 -extern atomic_t fscache_n_store_vmscan_not_storing;
64099 -extern atomic_t fscache_n_store_vmscan_gone;
64100 -extern atomic_t fscache_n_store_vmscan_busy;
64101 -extern atomic_t fscache_n_store_vmscan_cancelled;
64102 -extern atomic_t fscache_n_store_vmscan_wait;
64103 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
64104 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
64105 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
64106 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
64107 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
64108
64109 -extern atomic_t fscache_n_marks;
64110 -extern atomic_t fscache_n_uncaches;
64111 +extern atomic_unchecked_t fscache_n_marks;
64112 +extern atomic_unchecked_t fscache_n_uncaches;
64113
64114 -extern atomic_t fscache_n_acquires;
64115 -extern atomic_t fscache_n_acquires_null;
64116 -extern atomic_t fscache_n_acquires_no_cache;
64117 -extern atomic_t fscache_n_acquires_ok;
64118 -extern atomic_t fscache_n_acquires_nobufs;
64119 -extern atomic_t fscache_n_acquires_oom;
64120 +extern atomic_unchecked_t fscache_n_acquires;
64121 +extern atomic_unchecked_t fscache_n_acquires_null;
64122 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
64123 +extern atomic_unchecked_t fscache_n_acquires_ok;
64124 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
64125 +extern atomic_unchecked_t fscache_n_acquires_oom;
64126
64127 -extern atomic_t fscache_n_invalidates;
64128 -extern atomic_t fscache_n_invalidates_run;
64129 +extern atomic_unchecked_t fscache_n_invalidates;
64130 +extern atomic_unchecked_t fscache_n_invalidates_run;
64131
64132 -extern atomic_t fscache_n_updates;
64133 -extern atomic_t fscache_n_updates_null;
64134 -extern atomic_t fscache_n_updates_run;
64135 +extern atomic_unchecked_t fscache_n_updates;
64136 +extern atomic_unchecked_t fscache_n_updates_null;
64137 +extern atomic_unchecked_t fscache_n_updates_run;
64138
64139 -extern atomic_t fscache_n_relinquishes;
64140 -extern atomic_t fscache_n_relinquishes_null;
64141 -extern atomic_t fscache_n_relinquishes_waitcrt;
64142 -extern atomic_t fscache_n_relinquishes_retire;
64143 +extern atomic_unchecked_t fscache_n_relinquishes;
64144 +extern atomic_unchecked_t fscache_n_relinquishes_null;
64145 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
64146 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
64147
64148 -extern atomic_t fscache_n_cookie_index;
64149 -extern atomic_t fscache_n_cookie_data;
64150 -extern atomic_t fscache_n_cookie_special;
64151 +extern atomic_unchecked_t fscache_n_cookie_index;
64152 +extern atomic_unchecked_t fscache_n_cookie_data;
64153 +extern atomic_unchecked_t fscache_n_cookie_special;
64154
64155 -extern atomic_t fscache_n_object_alloc;
64156 -extern atomic_t fscache_n_object_no_alloc;
64157 -extern atomic_t fscache_n_object_lookups;
64158 -extern atomic_t fscache_n_object_lookups_negative;
64159 -extern atomic_t fscache_n_object_lookups_positive;
64160 -extern atomic_t fscache_n_object_lookups_timed_out;
64161 -extern atomic_t fscache_n_object_created;
64162 -extern atomic_t fscache_n_object_avail;
64163 -extern atomic_t fscache_n_object_dead;
64164 +extern atomic_unchecked_t fscache_n_object_alloc;
64165 +extern atomic_unchecked_t fscache_n_object_no_alloc;
64166 +extern atomic_unchecked_t fscache_n_object_lookups;
64167 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
64168 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
64169 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
64170 +extern atomic_unchecked_t fscache_n_object_created;
64171 +extern atomic_unchecked_t fscache_n_object_avail;
64172 +extern atomic_unchecked_t fscache_n_object_dead;
64173
64174 -extern atomic_t fscache_n_checkaux_none;
64175 -extern atomic_t fscache_n_checkaux_okay;
64176 -extern atomic_t fscache_n_checkaux_update;
64177 -extern atomic_t fscache_n_checkaux_obsolete;
64178 +extern atomic_unchecked_t fscache_n_checkaux_none;
64179 +extern atomic_unchecked_t fscache_n_checkaux_okay;
64180 +extern atomic_unchecked_t fscache_n_checkaux_update;
64181 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
64182
64183 extern atomic_t fscache_n_cop_alloc_object;
64184 extern atomic_t fscache_n_cop_lookup_object;
64185 @@ -278,6 +278,11 @@ static inline void fscache_stat(atomic_t *stat)
64186 atomic_inc(stat);
64187 }
64188
64189 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
64190 +{
64191 + atomic_inc_unchecked(stat);
64192 +}
64193 +
64194 static inline void fscache_stat_d(atomic_t *stat)
64195 {
64196 atomic_dec(stat);
64197 @@ -290,6 +295,7 @@ extern const struct file_operations fscache_stats_fops;
64198
64199 #define __fscache_stat(stat) (NULL)
64200 #define fscache_stat(stat) do {} while (0)
64201 +#define fscache_stat_unchecked(stat) do {} while (0)
64202 #define fscache_stat_d(stat) do {} while (0)
64203 #endif
64204
64205 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
64206 index d3b4539..ed0c659 100644
64207 --- a/fs/fscache/object.c
64208 +++ b/fs/fscache/object.c
64209 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
64210 _debug("LOOKUP \"%s\" in \"%s\"",
64211 cookie->def->name, object->cache->tag->name);
64212
64213 - fscache_stat(&fscache_n_object_lookups);
64214 + fscache_stat_unchecked(&fscache_n_object_lookups);
64215 fscache_stat(&fscache_n_cop_lookup_object);
64216 ret = object->cache->ops->lookup_object(object);
64217 fscache_stat_d(&fscache_n_cop_lookup_object);
64218 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
64219 if (ret == -ETIMEDOUT) {
64220 /* probably stuck behind another object, so move this one to
64221 * the back of the queue */
64222 - fscache_stat(&fscache_n_object_lookups_timed_out);
64223 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
64224 _leave(" [timeout]");
64225 return NO_TRANSIT;
64226 }
64227 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
64228 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
64229
64230 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
64231 - fscache_stat(&fscache_n_object_lookups_negative);
64232 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
64233
64234 /* Allow write requests to begin stacking up and read requests to begin
64235 * returning ENODATA.
64236 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
64237 /* if we were still looking up, then we must have a positive lookup
64238 * result, in which case there may be data available */
64239 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
64240 - fscache_stat(&fscache_n_object_lookups_positive);
64241 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
64242
64243 /* We do (presumably) have data */
64244 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
64245 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
64246 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
64247 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
64248 } else {
64249 - fscache_stat(&fscache_n_object_created);
64250 + fscache_stat_unchecked(&fscache_n_object_created);
64251 }
64252
64253 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
64254 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
64255 fscache_stat_d(&fscache_n_cop_lookup_complete);
64256
64257 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
64258 - fscache_stat(&fscache_n_object_avail);
64259 + fscache_stat_unchecked(&fscache_n_object_avail);
64260
64261 _leave("");
64262 return transit_to(JUMPSTART_DEPS);
64263 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
64264
64265 /* this just shifts the object release to the work processor */
64266 fscache_put_object(object);
64267 - fscache_stat(&fscache_n_object_dead);
64268 + fscache_stat_unchecked(&fscache_n_object_dead);
64269
64270 _leave("");
64271 return transit_to(OBJECT_DEAD);
64272 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
64273 enum fscache_checkaux result;
64274
64275 if (!object->cookie->def->check_aux) {
64276 - fscache_stat(&fscache_n_checkaux_none);
64277 + fscache_stat_unchecked(&fscache_n_checkaux_none);
64278 return FSCACHE_CHECKAUX_OKAY;
64279 }
64280
64281 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
64282 switch (result) {
64283 /* entry okay as is */
64284 case FSCACHE_CHECKAUX_OKAY:
64285 - fscache_stat(&fscache_n_checkaux_okay);
64286 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
64287 break;
64288
64289 /* entry requires update */
64290 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
64291 - fscache_stat(&fscache_n_checkaux_update);
64292 + fscache_stat_unchecked(&fscache_n_checkaux_update);
64293 break;
64294
64295 /* entry requires deletion */
64296 case FSCACHE_CHECKAUX_OBSOLETE:
64297 - fscache_stat(&fscache_n_checkaux_obsolete);
64298 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
64299 break;
64300
64301 default:
64302 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
64303 {
64304 const struct fscache_state *s;
64305
64306 - fscache_stat(&fscache_n_invalidates_run);
64307 + fscache_stat_unchecked(&fscache_n_invalidates_run);
64308 fscache_stat(&fscache_n_cop_invalidate_object);
64309 s = _fscache_invalidate_object(object, event);
64310 fscache_stat_d(&fscache_n_cop_invalidate_object);
64311 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
64312 {
64313 _enter("{OBJ%x},%d", object->debug_id, event);
64314
64315 - fscache_stat(&fscache_n_updates_run);
64316 + fscache_stat_unchecked(&fscache_n_updates_run);
64317 fscache_stat(&fscache_n_cop_update_object);
64318 object->cache->ops->update_object(object);
64319 fscache_stat_d(&fscache_n_cop_update_object);
64320 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
64321 index e7b87a0..a85d47a 100644
64322 --- a/fs/fscache/operation.c
64323 +++ b/fs/fscache/operation.c
64324 @@ -17,7 +17,7 @@
64325 #include <linux/slab.h>
64326 #include "internal.h"
64327
64328 -atomic_t fscache_op_debug_id;
64329 +atomic_unchecked_t fscache_op_debug_id;
64330 EXPORT_SYMBOL(fscache_op_debug_id);
64331
64332 /**
64333 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
64334 ASSERTCMP(atomic_read(&op->usage), >, 0);
64335 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
64336
64337 - fscache_stat(&fscache_n_op_enqueue);
64338 + fscache_stat_unchecked(&fscache_n_op_enqueue);
64339 switch (op->flags & FSCACHE_OP_TYPE) {
64340 case FSCACHE_OP_ASYNC:
64341 _debug("queue async");
64342 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
64343 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
64344 if (op->processor)
64345 fscache_enqueue_operation(op);
64346 - fscache_stat(&fscache_n_op_run);
64347 + fscache_stat_unchecked(&fscache_n_op_run);
64348 }
64349
64350 /*
64351 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
64352 if (object->n_in_progress > 0) {
64353 atomic_inc(&op->usage);
64354 list_add_tail(&op->pend_link, &object->pending_ops);
64355 - fscache_stat(&fscache_n_op_pend);
64356 + fscache_stat_unchecked(&fscache_n_op_pend);
64357 } else if (!list_empty(&object->pending_ops)) {
64358 atomic_inc(&op->usage);
64359 list_add_tail(&op->pend_link, &object->pending_ops);
64360 - fscache_stat(&fscache_n_op_pend);
64361 + fscache_stat_unchecked(&fscache_n_op_pend);
64362 fscache_start_operations(object);
64363 } else {
64364 ASSERTCMP(object->n_in_progress, ==, 0);
64365 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
64366 object->n_exclusive++; /* reads and writes must wait */
64367 atomic_inc(&op->usage);
64368 list_add_tail(&op->pend_link, &object->pending_ops);
64369 - fscache_stat(&fscache_n_op_pend);
64370 + fscache_stat_unchecked(&fscache_n_op_pend);
64371 ret = 0;
64372 } else {
64373 /* If we're in any other state, there must have been an I/O
64374 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
64375 if (object->n_exclusive > 0) {
64376 atomic_inc(&op->usage);
64377 list_add_tail(&op->pend_link, &object->pending_ops);
64378 - fscache_stat(&fscache_n_op_pend);
64379 + fscache_stat_unchecked(&fscache_n_op_pend);
64380 } else if (!list_empty(&object->pending_ops)) {
64381 atomic_inc(&op->usage);
64382 list_add_tail(&op->pend_link, &object->pending_ops);
64383 - fscache_stat(&fscache_n_op_pend);
64384 + fscache_stat_unchecked(&fscache_n_op_pend);
64385 fscache_start_operations(object);
64386 } else {
64387 ASSERTCMP(object->n_exclusive, ==, 0);
64388 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
64389 object->n_ops++;
64390 atomic_inc(&op->usage);
64391 list_add_tail(&op->pend_link, &object->pending_ops);
64392 - fscache_stat(&fscache_n_op_pend);
64393 + fscache_stat_unchecked(&fscache_n_op_pend);
64394 ret = 0;
64395 } else if (fscache_object_is_dying(object)) {
64396 - fscache_stat(&fscache_n_op_rejected);
64397 + fscache_stat_unchecked(&fscache_n_op_rejected);
64398 op->state = FSCACHE_OP_ST_CANCELLED;
64399 ret = -ENOBUFS;
64400 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
64401 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
64402 ret = -EBUSY;
64403 if (op->state == FSCACHE_OP_ST_PENDING) {
64404 ASSERT(!list_empty(&op->pend_link));
64405 - fscache_stat(&fscache_n_op_cancelled);
64406 + fscache_stat_unchecked(&fscache_n_op_cancelled);
64407 list_del_init(&op->pend_link);
64408 if (do_cancel)
64409 do_cancel(op);
64410 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
64411 while (!list_empty(&object->pending_ops)) {
64412 op = list_entry(object->pending_ops.next,
64413 struct fscache_operation, pend_link);
64414 - fscache_stat(&fscache_n_op_cancelled);
64415 + fscache_stat_unchecked(&fscache_n_op_cancelled);
64416 list_del_init(&op->pend_link);
64417
64418 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
64419 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
64420 op->state, ==, FSCACHE_OP_ST_CANCELLED);
64421 op->state = FSCACHE_OP_ST_DEAD;
64422
64423 - fscache_stat(&fscache_n_op_release);
64424 + fscache_stat_unchecked(&fscache_n_op_release);
64425
64426 if (op->release) {
64427 op->release(op);
64428 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
64429 * lock, and defer it otherwise */
64430 if (!spin_trylock(&object->lock)) {
64431 _debug("defer put");
64432 - fscache_stat(&fscache_n_op_deferred_release);
64433 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
64434
64435 cache = object->cache;
64436 spin_lock(&cache->op_gc_list_lock);
64437 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
64438
64439 _debug("GC DEFERRED REL OBJ%x OP%x",
64440 object->debug_id, op->debug_id);
64441 - fscache_stat(&fscache_n_op_gc);
64442 + fscache_stat_unchecked(&fscache_n_op_gc);
64443
64444 ASSERTCMP(atomic_read(&op->usage), ==, 0);
64445 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
64446 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
64447 index ed70714..67f4982 100644
64448 --- a/fs/fscache/page.c
64449 +++ b/fs/fscache/page.c
64450 @@ -61,7 +61,7 @@ try_again:
64451 val = radix_tree_lookup(&cookie->stores, page->index);
64452 if (!val) {
64453 rcu_read_unlock();
64454 - fscache_stat(&fscache_n_store_vmscan_not_storing);
64455 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
64456 __fscache_uncache_page(cookie, page);
64457 return true;
64458 }
64459 @@ -91,11 +91,11 @@ try_again:
64460 spin_unlock(&cookie->stores_lock);
64461
64462 if (xpage) {
64463 - fscache_stat(&fscache_n_store_vmscan_cancelled);
64464 - fscache_stat(&fscache_n_store_radix_deletes);
64465 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
64466 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
64467 ASSERTCMP(xpage, ==, page);
64468 } else {
64469 - fscache_stat(&fscache_n_store_vmscan_gone);
64470 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
64471 }
64472
64473 wake_up_bit(&cookie->flags, 0);
64474 @@ -110,11 +110,11 @@ page_busy:
64475 * sleeping on memory allocation, so we may need to impose a timeout
64476 * too. */
64477 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
64478 - fscache_stat(&fscache_n_store_vmscan_busy);
64479 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
64480 return false;
64481 }
64482
64483 - fscache_stat(&fscache_n_store_vmscan_wait);
64484 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
64485 __fscache_wait_on_page_write(cookie, page);
64486 gfp &= ~__GFP_WAIT;
64487 goto try_again;
64488 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
64489 FSCACHE_COOKIE_STORING_TAG);
64490 if (!radix_tree_tag_get(&cookie->stores, page->index,
64491 FSCACHE_COOKIE_PENDING_TAG)) {
64492 - fscache_stat(&fscache_n_store_radix_deletes);
64493 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
64494 xpage = radix_tree_delete(&cookie->stores, page->index);
64495 }
64496 spin_unlock(&cookie->stores_lock);
64497 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
64498
64499 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
64500
64501 - fscache_stat(&fscache_n_attr_changed_calls);
64502 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
64503
64504 if (fscache_object_is_active(object)) {
64505 fscache_stat(&fscache_n_cop_attr_changed);
64506 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
64507
64508 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64509
64510 - fscache_stat(&fscache_n_attr_changed);
64511 + fscache_stat_unchecked(&fscache_n_attr_changed);
64512
64513 op = kzalloc(sizeof(*op), GFP_KERNEL);
64514 if (!op) {
64515 - fscache_stat(&fscache_n_attr_changed_nomem);
64516 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
64517 _leave(" = -ENOMEM");
64518 return -ENOMEM;
64519 }
64520 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
64521 if (fscache_submit_exclusive_op(object, op) < 0)
64522 goto nobufs;
64523 spin_unlock(&cookie->lock);
64524 - fscache_stat(&fscache_n_attr_changed_ok);
64525 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
64526 fscache_put_operation(op);
64527 _leave(" = 0");
64528 return 0;
64529 @@ -225,7 +225,7 @@ nobufs:
64530 kfree(op);
64531 if (wake_cookie)
64532 __fscache_wake_unused_cookie(cookie);
64533 - fscache_stat(&fscache_n_attr_changed_nobufs);
64534 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
64535 _leave(" = %d", -ENOBUFS);
64536 return -ENOBUFS;
64537 }
64538 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
64539 /* allocate a retrieval operation and attempt to submit it */
64540 op = kzalloc(sizeof(*op), GFP_NOIO);
64541 if (!op) {
64542 - fscache_stat(&fscache_n_retrievals_nomem);
64543 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
64544 return NULL;
64545 }
64546
64547 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
64548 return 0;
64549 }
64550
64551 - fscache_stat(&fscache_n_retrievals_wait);
64552 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
64553
64554 jif = jiffies;
64555 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
64556 fscache_wait_bit_interruptible,
64557 TASK_INTERRUPTIBLE) != 0) {
64558 - fscache_stat(&fscache_n_retrievals_intr);
64559 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
64560 _leave(" = -ERESTARTSYS");
64561 return -ERESTARTSYS;
64562 }
64563 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
64564 */
64565 int fscache_wait_for_operation_activation(struct fscache_object *object,
64566 struct fscache_operation *op,
64567 - atomic_t *stat_op_waits,
64568 - atomic_t *stat_object_dead,
64569 + atomic_unchecked_t *stat_op_waits,
64570 + atomic_unchecked_t *stat_object_dead,
64571 void (*do_cancel)(struct fscache_operation *))
64572 {
64573 int ret;
64574 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
64575
64576 _debug(">>> WT");
64577 if (stat_op_waits)
64578 - fscache_stat(stat_op_waits);
64579 + fscache_stat_unchecked(stat_op_waits);
64580 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
64581 fscache_wait_bit_interruptible,
64582 TASK_INTERRUPTIBLE) != 0) {
64583 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
64584 check_if_dead:
64585 if (op->state == FSCACHE_OP_ST_CANCELLED) {
64586 if (stat_object_dead)
64587 - fscache_stat(stat_object_dead);
64588 + fscache_stat_unchecked(stat_object_dead);
64589 _leave(" = -ENOBUFS [cancelled]");
64590 return -ENOBUFS;
64591 }
64592 @@ -366,7 +366,7 @@ check_if_dead:
64593 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
64594 fscache_cancel_op(op, do_cancel);
64595 if (stat_object_dead)
64596 - fscache_stat(stat_object_dead);
64597 + fscache_stat_unchecked(stat_object_dead);
64598 return -ENOBUFS;
64599 }
64600 return 0;
64601 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
64602
64603 _enter("%p,%p,,,", cookie, page);
64604
64605 - fscache_stat(&fscache_n_retrievals);
64606 + fscache_stat_unchecked(&fscache_n_retrievals);
64607
64608 if (hlist_empty(&cookie->backing_objects))
64609 goto nobufs;
64610 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
64611 goto nobufs_unlock_dec;
64612 spin_unlock(&cookie->lock);
64613
64614 - fscache_stat(&fscache_n_retrieval_ops);
64615 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
64616
64617 /* pin the netfs read context in case we need to do the actual netfs
64618 * read because we've encountered a cache read failure */
64619 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
64620
64621 error:
64622 if (ret == -ENOMEM)
64623 - fscache_stat(&fscache_n_retrievals_nomem);
64624 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
64625 else if (ret == -ERESTARTSYS)
64626 - fscache_stat(&fscache_n_retrievals_intr);
64627 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
64628 else if (ret == -ENODATA)
64629 - fscache_stat(&fscache_n_retrievals_nodata);
64630 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
64631 else if (ret < 0)
64632 - fscache_stat(&fscache_n_retrievals_nobufs);
64633 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64634 else
64635 - fscache_stat(&fscache_n_retrievals_ok);
64636 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
64637
64638 fscache_put_retrieval(op);
64639 _leave(" = %d", ret);
64640 @@ -490,7 +490,7 @@ nobufs_unlock:
64641 __fscache_wake_unused_cookie(cookie);
64642 kfree(op);
64643 nobufs:
64644 - fscache_stat(&fscache_n_retrievals_nobufs);
64645 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64646 _leave(" = -ENOBUFS");
64647 return -ENOBUFS;
64648 }
64649 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
64650
64651 _enter("%p,,%d,,,", cookie, *nr_pages);
64652
64653 - fscache_stat(&fscache_n_retrievals);
64654 + fscache_stat_unchecked(&fscache_n_retrievals);
64655
64656 if (hlist_empty(&cookie->backing_objects))
64657 goto nobufs;
64658 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
64659 goto nobufs_unlock_dec;
64660 spin_unlock(&cookie->lock);
64661
64662 - fscache_stat(&fscache_n_retrieval_ops);
64663 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
64664
64665 /* pin the netfs read context in case we need to do the actual netfs
64666 * read because we've encountered a cache read failure */
64667 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
64668
64669 error:
64670 if (ret == -ENOMEM)
64671 - fscache_stat(&fscache_n_retrievals_nomem);
64672 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
64673 else if (ret == -ERESTARTSYS)
64674 - fscache_stat(&fscache_n_retrievals_intr);
64675 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
64676 else if (ret == -ENODATA)
64677 - fscache_stat(&fscache_n_retrievals_nodata);
64678 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
64679 else if (ret < 0)
64680 - fscache_stat(&fscache_n_retrievals_nobufs);
64681 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64682 else
64683 - fscache_stat(&fscache_n_retrievals_ok);
64684 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
64685
64686 fscache_put_retrieval(op);
64687 _leave(" = %d", ret);
64688 @@ -621,7 +621,7 @@ nobufs_unlock:
64689 if (wake_cookie)
64690 __fscache_wake_unused_cookie(cookie);
64691 nobufs:
64692 - fscache_stat(&fscache_n_retrievals_nobufs);
64693 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
64694 _leave(" = -ENOBUFS");
64695 return -ENOBUFS;
64696 }
64697 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
64698
64699 _enter("%p,%p,,,", cookie, page);
64700
64701 - fscache_stat(&fscache_n_allocs);
64702 + fscache_stat_unchecked(&fscache_n_allocs);
64703
64704 if (hlist_empty(&cookie->backing_objects))
64705 goto nobufs;
64706 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
64707 goto nobufs_unlock_dec;
64708 spin_unlock(&cookie->lock);
64709
64710 - fscache_stat(&fscache_n_alloc_ops);
64711 + fscache_stat_unchecked(&fscache_n_alloc_ops);
64712
64713 ret = fscache_wait_for_operation_activation(
64714 object, &op->op,
64715 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
64716
64717 error:
64718 if (ret == -ERESTARTSYS)
64719 - fscache_stat(&fscache_n_allocs_intr);
64720 + fscache_stat_unchecked(&fscache_n_allocs_intr);
64721 else if (ret < 0)
64722 - fscache_stat(&fscache_n_allocs_nobufs);
64723 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
64724 else
64725 - fscache_stat(&fscache_n_allocs_ok);
64726 + fscache_stat_unchecked(&fscache_n_allocs_ok);
64727
64728 fscache_put_retrieval(op);
64729 _leave(" = %d", ret);
64730 @@ -715,7 +715,7 @@ nobufs_unlock:
64731 if (wake_cookie)
64732 __fscache_wake_unused_cookie(cookie);
64733 nobufs:
64734 - fscache_stat(&fscache_n_allocs_nobufs);
64735 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
64736 _leave(" = -ENOBUFS");
64737 return -ENOBUFS;
64738 }
64739 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64740
64741 spin_lock(&cookie->stores_lock);
64742
64743 - fscache_stat(&fscache_n_store_calls);
64744 + fscache_stat_unchecked(&fscache_n_store_calls);
64745
64746 /* find a page to store */
64747 page = NULL;
64748 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64749 page = results[0];
64750 _debug("gang %d [%lx]", n, page->index);
64751 if (page->index > op->store_limit) {
64752 - fscache_stat(&fscache_n_store_pages_over_limit);
64753 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
64754 goto superseded;
64755 }
64756
64757 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
64758 spin_unlock(&cookie->stores_lock);
64759 spin_unlock(&object->lock);
64760
64761 - fscache_stat(&fscache_n_store_pages);
64762 + fscache_stat_unchecked(&fscache_n_store_pages);
64763 fscache_stat(&fscache_n_cop_write_page);
64764 ret = object->cache->ops->write_page(op, page);
64765 fscache_stat_d(&fscache_n_cop_write_page);
64766 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64767 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64768 ASSERT(PageFsCache(page));
64769
64770 - fscache_stat(&fscache_n_stores);
64771 + fscache_stat_unchecked(&fscache_n_stores);
64772
64773 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
64774 _leave(" = -ENOBUFS [invalidating]");
64775 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64776 spin_unlock(&cookie->stores_lock);
64777 spin_unlock(&object->lock);
64778
64779 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
64780 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64781 op->store_limit = object->store_limit;
64782
64783 __fscache_use_cookie(cookie);
64784 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64785
64786 spin_unlock(&cookie->lock);
64787 radix_tree_preload_end();
64788 - fscache_stat(&fscache_n_store_ops);
64789 - fscache_stat(&fscache_n_stores_ok);
64790 + fscache_stat_unchecked(&fscache_n_store_ops);
64791 + fscache_stat_unchecked(&fscache_n_stores_ok);
64792
64793 /* the work queue now carries its own ref on the object */
64794 fscache_put_operation(&op->op);
64795 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
64796 return 0;
64797
64798 already_queued:
64799 - fscache_stat(&fscache_n_stores_again);
64800 + fscache_stat_unchecked(&fscache_n_stores_again);
64801 already_pending:
64802 spin_unlock(&cookie->stores_lock);
64803 spin_unlock(&object->lock);
64804 spin_unlock(&cookie->lock);
64805 radix_tree_preload_end();
64806 kfree(op);
64807 - fscache_stat(&fscache_n_stores_ok);
64808 + fscache_stat_unchecked(&fscache_n_stores_ok);
64809 _leave(" = 0");
64810 return 0;
64811
64812 @@ -1024,14 +1024,14 @@ nobufs:
64813 kfree(op);
64814 if (wake_cookie)
64815 __fscache_wake_unused_cookie(cookie);
64816 - fscache_stat(&fscache_n_stores_nobufs);
64817 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
64818 _leave(" = -ENOBUFS");
64819 return -ENOBUFS;
64820
64821 nomem_free:
64822 kfree(op);
64823 nomem:
64824 - fscache_stat(&fscache_n_stores_oom);
64825 + fscache_stat_unchecked(&fscache_n_stores_oom);
64826 _leave(" = -ENOMEM");
64827 return -ENOMEM;
64828 }
64829 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
64830 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
64831 ASSERTCMP(page, !=, NULL);
64832
64833 - fscache_stat(&fscache_n_uncaches);
64834 + fscache_stat_unchecked(&fscache_n_uncaches);
64835
64836 /* cache withdrawal may beat us to it */
64837 if (!PageFsCache(page))
64838 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
64839 struct fscache_cookie *cookie = op->op.object->cookie;
64840
64841 #ifdef CONFIG_FSCACHE_STATS
64842 - atomic_inc(&fscache_n_marks);
64843 + atomic_inc_unchecked(&fscache_n_marks);
64844 #endif
64845
64846 _debug("- mark %p{%lx}", page, page->index);
64847 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
64848 index 40d13c7..ddf52b9 100644
64849 --- a/fs/fscache/stats.c
64850 +++ b/fs/fscache/stats.c
64851 @@ -18,99 +18,99 @@
64852 /*
64853 * operation counters
64854 */
64855 -atomic_t fscache_n_op_pend;
64856 -atomic_t fscache_n_op_run;
64857 -atomic_t fscache_n_op_enqueue;
64858 -atomic_t fscache_n_op_requeue;
64859 -atomic_t fscache_n_op_deferred_release;
64860 -atomic_t fscache_n_op_release;
64861 -atomic_t fscache_n_op_gc;
64862 -atomic_t fscache_n_op_cancelled;
64863 -atomic_t fscache_n_op_rejected;
64864 +atomic_unchecked_t fscache_n_op_pend;
64865 +atomic_unchecked_t fscache_n_op_run;
64866 +atomic_unchecked_t fscache_n_op_enqueue;
64867 +atomic_unchecked_t fscache_n_op_requeue;
64868 +atomic_unchecked_t fscache_n_op_deferred_release;
64869 +atomic_unchecked_t fscache_n_op_release;
64870 +atomic_unchecked_t fscache_n_op_gc;
64871 +atomic_unchecked_t fscache_n_op_cancelled;
64872 +atomic_unchecked_t fscache_n_op_rejected;
64873
64874 -atomic_t fscache_n_attr_changed;
64875 -atomic_t fscache_n_attr_changed_ok;
64876 -atomic_t fscache_n_attr_changed_nobufs;
64877 -atomic_t fscache_n_attr_changed_nomem;
64878 -atomic_t fscache_n_attr_changed_calls;
64879 +atomic_unchecked_t fscache_n_attr_changed;
64880 +atomic_unchecked_t fscache_n_attr_changed_ok;
64881 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
64882 +atomic_unchecked_t fscache_n_attr_changed_nomem;
64883 +atomic_unchecked_t fscache_n_attr_changed_calls;
64884
64885 -atomic_t fscache_n_allocs;
64886 -atomic_t fscache_n_allocs_ok;
64887 -atomic_t fscache_n_allocs_wait;
64888 -atomic_t fscache_n_allocs_nobufs;
64889 -atomic_t fscache_n_allocs_intr;
64890 -atomic_t fscache_n_allocs_object_dead;
64891 -atomic_t fscache_n_alloc_ops;
64892 -atomic_t fscache_n_alloc_op_waits;
64893 +atomic_unchecked_t fscache_n_allocs;
64894 +atomic_unchecked_t fscache_n_allocs_ok;
64895 +atomic_unchecked_t fscache_n_allocs_wait;
64896 +atomic_unchecked_t fscache_n_allocs_nobufs;
64897 +atomic_unchecked_t fscache_n_allocs_intr;
64898 +atomic_unchecked_t fscache_n_allocs_object_dead;
64899 +atomic_unchecked_t fscache_n_alloc_ops;
64900 +atomic_unchecked_t fscache_n_alloc_op_waits;
64901
64902 -atomic_t fscache_n_retrievals;
64903 -atomic_t fscache_n_retrievals_ok;
64904 -atomic_t fscache_n_retrievals_wait;
64905 -atomic_t fscache_n_retrievals_nodata;
64906 -atomic_t fscache_n_retrievals_nobufs;
64907 -atomic_t fscache_n_retrievals_intr;
64908 -atomic_t fscache_n_retrievals_nomem;
64909 -atomic_t fscache_n_retrievals_object_dead;
64910 -atomic_t fscache_n_retrieval_ops;
64911 -atomic_t fscache_n_retrieval_op_waits;
64912 +atomic_unchecked_t fscache_n_retrievals;
64913 +atomic_unchecked_t fscache_n_retrievals_ok;
64914 +atomic_unchecked_t fscache_n_retrievals_wait;
64915 +atomic_unchecked_t fscache_n_retrievals_nodata;
64916 +atomic_unchecked_t fscache_n_retrievals_nobufs;
64917 +atomic_unchecked_t fscache_n_retrievals_intr;
64918 +atomic_unchecked_t fscache_n_retrievals_nomem;
64919 +atomic_unchecked_t fscache_n_retrievals_object_dead;
64920 +atomic_unchecked_t fscache_n_retrieval_ops;
64921 +atomic_unchecked_t fscache_n_retrieval_op_waits;
64922
64923 -atomic_t fscache_n_stores;
64924 -atomic_t fscache_n_stores_ok;
64925 -atomic_t fscache_n_stores_again;
64926 -atomic_t fscache_n_stores_nobufs;
64927 -atomic_t fscache_n_stores_oom;
64928 -atomic_t fscache_n_store_ops;
64929 -atomic_t fscache_n_store_calls;
64930 -atomic_t fscache_n_store_pages;
64931 -atomic_t fscache_n_store_radix_deletes;
64932 -atomic_t fscache_n_store_pages_over_limit;
64933 +atomic_unchecked_t fscache_n_stores;
64934 +atomic_unchecked_t fscache_n_stores_ok;
64935 +atomic_unchecked_t fscache_n_stores_again;
64936 +atomic_unchecked_t fscache_n_stores_nobufs;
64937 +atomic_unchecked_t fscache_n_stores_oom;
64938 +atomic_unchecked_t fscache_n_store_ops;
64939 +atomic_unchecked_t fscache_n_store_calls;
64940 +atomic_unchecked_t fscache_n_store_pages;
64941 +atomic_unchecked_t fscache_n_store_radix_deletes;
64942 +atomic_unchecked_t fscache_n_store_pages_over_limit;
64943
64944 -atomic_t fscache_n_store_vmscan_not_storing;
64945 -atomic_t fscache_n_store_vmscan_gone;
64946 -atomic_t fscache_n_store_vmscan_busy;
64947 -atomic_t fscache_n_store_vmscan_cancelled;
64948 -atomic_t fscache_n_store_vmscan_wait;
64949 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
64950 +atomic_unchecked_t fscache_n_store_vmscan_gone;
64951 +atomic_unchecked_t fscache_n_store_vmscan_busy;
64952 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
64953 +atomic_unchecked_t fscache_n_store_vmscan_wait;
64954
64955 -atomic_t fscache_n_marks;
64956 -atomic_t fscache_n_uncaches;
64957 +atomic_unchecked_t fscache_n_marks;
64958 +atomic_unchecked_t fscache_n_uncaches;
64959
64960 -atomic_t fscache_n_acquires;
64961 -atomic_t fscache_n_acquires_null;
64962 -atomic_t fscache_n_acquires_no_cache;
64963 -atomic_t fscache_n_acquires_ok;
64964 -atomic_t fscache_n_acquires_nobufs;
64965 -atomic_t fscache_n_acquires_oom;
64966 +atomic_unchecked_t fscache_n_acquires;
64967 +atomic_unchecked_t fscache_n_acquires_null;
64968 +atomic_unchecked_t fscache_n_acquires_no_cache;
64969 +atomic_unchecked_t fscache_n_acquires_ok;
64970 +atomic_unchecked_t fscache_n_acquires_nobufs;
64971 +atomic_unchecked_t fscache_n_acquires_oom;
64972
64973 -atomic_t fscache_n_invalidates;
64974 -atomic_t fscache_n_invalidates_run;
64975 +atomic_unchecked_t fscache_n_invalidates;
64976 +atomic_unchecked_t fscache_n_invalidates_run;
64977
64978 -atomic_t fscache_n_updates;
64979 -atomic_t fscache_n_updates_null;
64980 -atomic_t fscache_n_updates_run;
64981 +atomic_unchecked_t fscache_n_updates;
64982 +atomic_unchecked_t fscache_n_updates_null;
64983 +atomic_unchecked_t fscache_n_updates_run;
64984
64985 -atomic_t fscache_n_relinquishes;
64986 -atomic_t fscache_n_relinquishes_null;
64987 -atomic_t fscache_n_relinquishes_waitcrt;
64988 -atomic_t fscache_n_relinquishes_retire;
64989 +atomic_unchecked_t fscache_n_relinquishes;
64990 +atomic_unchecked_t fscache_n_relinquishes_null;
64991 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
64992 +atomic_unchecked_t fscache_n_relinquishes_retire;
64993
64994 -atomic_t fscache_n_cookie_index;
64995 -atomic_t fscache_n_cookie_data;
64996 -atomic_t fscache_n_cookie_special;
64997 +atomic_unchecked_t fscache_n_cookie_index;
64998 +atomic_unchecked_t fscache_n_cookie_data;
64999 +atomic_unchecked_t fscache_n_cookie_special;
65000
65001 -atomic_t fscache_n_object_alloc;
65002 -atomic_t fscache_n_object_no_alloc;
65003 -atomic_t fscache_n_object_lookups;
65004 -atomic_t fscache_n_object_lookups_negative;
65005 -atomic_t fscache_n_object_lookups_positive;
65006 -atomic_t fscache_n_object_lookups_timed_out;
65007 -atomic_t fscache_n_object_created;
65008 -atomic_t fscache_n_object_avail;
65009 -atomic_t fscache_n_object_dead;
65010 +atomic_unchecked_t fscache_n_object_alloc;
65011 +atomic_unchecked_t fscache_n_object_no_alloc;
65012 +atomic_unchecked_t fscache_n_object_lookups;
65013 +atomic_unchecked_t fscache_n_object_lookups_negative;
65014 +atomic_unchecked_t fscache_n_object_lookups_positive;
65015 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
65016 +atomic_unchecked_t fscache_n_object_created;
65017 +atomic_unchecked_t fscache_n_object_avail;
65018 +atomic_unchecked_t fscache_n_object_dead;
65019
65020 -atomic_t fscache_n_checkaux_none;
65021 -atomic_t fscache_n_checkaux_okay;
65022 -atomic_t fscache_n_checkaux_update;
65023 -atomic_t fscache_n_checkaux_obsolete;
65024 +atomic_unchecked_t fscache_n_checkaux_none;
65025 +atomic_unchecked_t fscache_n_checkaux_okay;
65026 +atomic_unchecked_t fscache_n_checkaux_update;
65027 +atomic_unchecked_t fscache_n_checkaux_obsolete;
65028
65029 atomic_t fscache_n_cop_alloc_object;
65030 atomic_t fscache_n_cop_lookup_object;
65031 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
65032 seq_puts(m, "FS-Cache statistics\n");
65033
65034 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
65035 - atomic_read(&fscache_n_cookie_index),
65036 - atomic_read(&fscache_n_cookie_data),
65037 - atomic_read(&fscache_n_cookie_special));
65038 + atomic_read_unchecked(&fscache_n_cookie_index),
65039 + atomic_read_unchecked(&fscache_n_cookie_data),
65040 + atomic_read_unchecked(&fscache_n_cookie_special));
65041
65042 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
65043 - atomic_read(&fscache_n_object_alloc),
65044 - atomic_read(&fscache_n_object_no_alloc),
65045 - atomic_read(&fscache_n_object_avail),
65046 - atomic_read(&fscache_n_object_dead));
65047 + atomic_read_unchecked(&fscache_n_object_alloc),
65048 + atomic_read_unchecked(&fscache_n_object_no_alloc),
65049 + atomic_read_unchecked(&fscache_n_object_avail),
65050 + atomic_read_unchecked(&fscache_n_object_dead));
65051 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
65052 - atomic_read(&fscache_n_checkaux_none),
65053 - atomic_read(&fscache_n_checkaux_okay),
65054 - atomic_read(&fscache_n_checkaux_update),
65055 - atomic_read(&fscache_n_checkaux_obsolete));
65056 + atomic_read_unchecked(&fscache_n_checkaux_none),
65057 + atomic_read_unchecked(&fscache_n_checkaux_okay),
65058 + atomic_read_unchecked(&fscache_n_checkaux_update),
65059 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
65060
65061 seq_printf(m, "Pages : mrk=%u unc=%u\n",
65062 - atomic_read(&fscache_n_marks),
65063 - atomic_read(&fscache_n_uncaches));
65064 + atomic_read_unchecked(&fscache_n_marks),
65065 + atomic_read_unchecked(&fscache_n_uncaches));
65066
65067 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
65068 " oom=%u\n",
65069 - atomic_read(&fscache_n_acquires),
65070 - atomic_read(&fscache_n_acquires_null),
65071 - atomic_read(&fscache_n_acquires_no_cache),
65072 - atomic_read(&fscache_n_acquires_ok),
65073 - atomic_read(&fscache_n_acquires_nobufs),
65074 - atomic_read(&fscache_n_acquires_oom));
65075 + atomic_read_unchecked(&fscache_n_acquires),
65076 + atomic_read_unchecked(&fscache_n_acquires_null),
65077 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
65078 + atomic_read_unchecked(&fscache_n_acquires_ok),
65079 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
65080 + atomic_read_unchecked(&fscache_n_acquires_oom));
65081
65082 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
65083 - atomic_read(&fscache_n_object_lookups),
65084 - atomic_read(&fscache_n_object_lookups_negative),
65085 - atomic_read(&fscache_n_object_lookups_positive),
65086 - atomic_read(&fscache_n_object_created),
65087 - atomic_read(&fscache_n_object_lookups_timed_out));
65088 + atomic_read_unchecked(&fscache_n_object_lookups),
65089 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
65090 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
65091 + atomic_read_unchecked(&fscache_n_object_created),
65092 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
65093
65094 seq_printf(m, "Invals : n=%u run=%u\n",
65095 - atomic_read(&fscache_n_invalidates),
65096 - atomic_read(&fscache_n_invalidates_run));
65097 + atomic_read_unchecked(&fscache_n_invalidates),
65098 + atomic_read_unchecked(&fscache_n_invalidates_run));
65099
65100 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
65101 - atomic_read(&fscache_n_updates),
65102 - atomic_read(&fscache_n_updates_null),
65103 - atomic_read(&fscache_n_updates_run));
65104 + atomic_read_unchecked(&fscache_n_updates),
65105 + atomic_read_unchecked(&fscache_n_updates_null),
65106 + atomic_read_unchecked(&fscache_n_updates_run));
65107
65108 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
65109 - atomic_read(&fscache_n_relinquishes),
65110 - atomic_read(&fscache_n_relinquishes_null),
65111 - atomic_read(&fscache_n_relinquishes_waitcrt),
65112 - atomic_read(&fscache_n_relinquishes_retire));
65113 + atomic_read_unchecked(&fscache_n_relinquishes),
65114 + atomic_read_unchecked(&fscache_n_relinquishes_null),
65115 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
65116 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
65117
65118 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
65119 - atomic_read(&fscache_n_attr_changed),
65120 - atomic_read(&fscache_n_attr_changed_ok),
65121 - atomic_read(&fscache_n_attr_changed_nobufs),
65122 - atomic_read(&fscache_n_attr_changed_nomem),
65123 - atomic_read(&fscache_n_attr_changed_calls));
65124 + atomic_read_unchecked(&fscache_n_attr_changed),
65125 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
65126 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
65127 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
65128 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
65129
65130 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
65131 - atomic_read(&fscache_n_allocs),
65132 - atomic_read(&fscache_n_allocs_ok),
65133 - atomic_read(&fscache_n_allocs_wait),
65134 - atomic_read(&fscache_n_allocs_nobufs),
65135 - atomic_read(&fscache_n_allocs_intr));
65136 + atomic_read_unchecked(&fscache_n_allocs),
65137 + atomic_read_unchecked(&fscache_n_allocs_ok),
65138 + atomic_read_unchecked(&fscache_n_allocs_wait),
65139 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
65140 + atomic_read_unchecked(&fscache_n_allocs_intr));
65141 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
65142 - atomic_read(&fscache_n_alloc_ops),
65143 - atomic_read(&fscache_n_alloc_op_waits),
65144 - atomic_read(&fscache_n_allocs_object_dead));
65145 + atomic_read_unchecked(&fscache_n_alloc_ops),
65146 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
65147 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
65148
65149 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
65150 " int=%u oom=%u\n",
65151 - atomic_read(&fscache_n_retrievals),
65152 - atomic_read(&fscache_n_retrievals_ok),
65153 - atomic_read(&fscache_n_retrievals_wait),
65154 - atomic_read(&fscache_n_retrievals_nodata),
65155 - atomic_read(&fscache_n_retrievals_nobufs),
65156 - atomic_read(&fscache_n_retrievals_intr),
65157 - atomic_read(&fscache_n_retrievals_nomem));
65158 + atomic_read_unchecked(&fscache_n_retrievals),
65159 + atomic_read_unchecked(&fscache_n_retrievals_ok),
65160 + atomic_read_unchecked(&fscache_n_retrievals_wait),
65161 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
65162 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
65163 + atomic_read_unchecked(&fscache_n_retrievals_intr),
65164 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
65165 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
65166 - atomic_read(&fscache_n_retrieval_ops),
65167 - atomic_read(&fscache_n_retrieval_op_waits),
65168 - atomic_read(&fscache_n_retrievals_object_dead));
65169 + atomic_read_unchecked(&fscache_n_retrieval_ops),
65170 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
65171 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
65172
65173 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
65174 - atomic_read(&fscache_n_stores),
65175 - atomic_read(&fscache_n_stores_ok),
65176 - atomic_read(&fscache_n_stores_again),
65177 - atomic_read(&fscache_n_stores_nobufs),
65178 - atomic_read(&fscache_n_stores_oom));
65179 + atomic_read_unchecked(&fscache_n_stores),
65180 + atomic_read_unchecked(&fscache_n_stores_ok),
65181 + atomic_read_unchecked(&fscache_n_stores_again),
65182 + atomic_read_unchecked(&fscache_n_stores_nobufs),
65183 + atomic_read_unchecked(&fscache_n_stores_oom));
65184 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
65185 - atomic_read(&fscache_n_store_ops),
65186 - atomic_read(&fscache_n_store_calls),
65187 - atomic_read(&fscache_n_store_pages),
65188 - atomic_read(&fscache_n_store_radix_deletes),
65189 - atomic_read(&fscache_n_store_pages_over_limit));
65190 + atomic_read_unchecked(&fscache_n_store_ops),
65191 + atomic_read_unchecked(&fscache_n_store_calls),
65192 + atomic_read_unchecked(&fscache_n_store_pages),
65193 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
65194 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
65195
65196 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
65197 - atomic_read(&fscache_n_store_vmscan_not_storing),
65198 - atomic_read(&fscache_n_store_vmscan_gone),
65199 - atomic_read(&fscache_n_store_vmscan_busy),
65200 - atomic_read(&fscache_n_store_vmscan_cancelled),
65201 - atomic_read(&fscache_n_store_vmscan_wait));
65202 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
65203 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
65204 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
65205 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
65206 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
65207
65208 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
65209 - atomic_read(&fscache_n_op_pend),
65210 - atomic_read(&fscache_n_op_run),
65211 - atomic_read(&fscache_n_op_enqueue),
65212 - atomic_read(&fscache_n_op_cancelled),
65213 - atomic_read(&fscache_n_op_rejected));
65214 + atomic_read_unchecked(&fscache_n_op_pend),
65215 + atomic_read_unchecked(&fscache_n_op_run),
65216 + atomic_read_unchecked(&fscache_n_op_enqueue),
65217 + atomic_read_unchecked(&fscache_n_op_cancelled),
65218 + atomic_read_unchecked(&fscache_n_op_rejected));
65219 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
65220 - atomic_read(&fscache_n_op_deferred_release),
65221 - atomic_read(&fscache_n_op_release),
65222 - atomic_read(&fscache_n_op_gc));
65223 + atomic_read_unchecked(&fscache_n_op_deferred_release),
65224 + atomic_read_unchecked(&fscache_n_op_release),
65225 + atomic_read_unchecked(&fscache_n_op_gc));
65226
65227 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
65228 atomic_read(&fscache_n_cop_alloc_object),
65229 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
65230 index 966ace8..030a03a 100644
65231 --- a/fs/fuse/cuse.c
65232 +++ b/fs/fuse/cuse.c
65233 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
65234 INIT_LIST_HEAD(&cuse_conntbl[i]);
65235
65236 /* inherit and extend fuse_dev_operations */
65237 - cuse_channel_fops = fuse_dev_operations;
65238 - cuse_channel_fops.owner = THIS_MODULE;
65239 - cuse_channel_fops.open = cuse_channel_open;
65240 - cuse_channel_fops.release = cuse_channel_release;
65241 + pax_open_kernel();
65242 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
65243 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
65244 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
65245 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
65246 + pax_close_kernel();
65247
65248 cuse_class = class_create(THIS_MODULE, "cuse");
65249 if (IS_ERR(cuse_class))
65250 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
65251 index ca88731..8e9c55d 100644
65252 --- a/fs/fuse/dev.c
65253 +++ b/fs/fuse/dev.c
65254 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
65255 ret = 0;
65256 pipe_lock(pipe);
65257
65258 - if (!pipe->readers) {
65259 + if (!atomic_read(&pipe->readers)) {
65260 send_sig(SIGPIPE, current, 0);
65261 if (!ret)
65262 ret = -EPIPE;
65263 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
65264 page_nr++;
65265 ret += buf->len;
65266
65267 - if (pipe->files)
65268 + if (atomic_read(&pipe->files))
65269 do_wakeup = 1;
65270 }
65271
65272 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
65273 index 0c60482..025724f 100644
65274 --- a/fs/fuse/dir.c
65275 +++ b/fs/fuse/dir.c
65276 @@ -1485,7 +1485,7 @@ static char *read_link(struct dentry *dentry)
65277 return link;
65278 }
65279
65280 -static void free_link(char *link)
65281 +static void free_link(const char *link)
65282 {
65283 if (!IS_ERR(link))
65284 free_page((unsigned long) link);
65285 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
65286 index bb529f3..454c253 100644
65287 --- a/fs/hostfs/hostfs_kern.c
65288 +++ b/fs/hostfs/hostfs_kern.c
65289 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
65290
65291 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
65292 {
65293 - char *s = nd_get_link(nd);
65294 + const char *s = nd_get_link(nd);
65295 if (!IS_ERR(s))
65296 __putname(s);
65297 }
65298 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
65299 index 1e2872b..7aea000 100644
65300 --- a/fs/hugetlbfs/inode.c
65301 +++ b/fs/hugetlbfs/inode.c
65302 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
65303 struct mm_struct *mm = current->mm;
65304 struct vm_area_struct *vma;
65305 struct hstate *h = hstate_file(file);
65306 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
65307 struct vm_unmapped_area_info info;
65308
65309 if (len & ~huge_page_mask(h))
65310 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
65311 return addr;
65312 }
65313
65314 +#ifdef CONFIG_PAX_RANDMMAP
65315 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
65316 +#endif
65317 +
65318 if (addr) {
65319 addr = ALIGN(addr, huge_page_size(h));
65320 vma = find_vma(mm, addr);
65321 - if (TASK_SIZE - len >= addr &&
65322 - (!vma || addr + len <= vma->vm_start))
65323 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
65324 return addr;
65325 }
65326
65327 info.flags = 0;
65328 info.length = len;
65329 info.low_limit = TASK_UNMAPPED_BASE;
65330 +
65331 +#ifdef CONFIG_PAX_RANDMMAP
65332 + if (mm->pax_flags & MF_PAX_RANDMMAP)
65333 + info.low_limit += mm->delta_mmap;
65334 +#endif
65335 +
65336 info.high_limit = TASK_SIZE;
65337 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
65338 info.align_offset = 0;
65339 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
65340 };
65341 MODULE_ALIAS_FS("hugetlbfs");
65342
65343 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65344 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65345
65346 static int can_do_hugetlb_shm(void)
65347 {
65348 diff --git a/fs/inode.c b/fs/inode.c
65349 index 6eecb7f..abec305 100644
65350 --- a/fs/inode.c
65351 +++ b/fs/inode.c
65352 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
65353 unsigned int *p = &get_cpu_var(last_ino);
65354 unsigned int res = *p;
65355
65356 +start:
65357 +
65358 #ifdef CONFIG_SMP
65359 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
65360 - static atomic_t shared_last_ino;
65361 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
65362 + static atomic_unchecked_t shared_last_ino;
65363 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
65364
65365 res = next - LAST_INO_BATCH;
65366 }
65367 #endif
65368
65369 - *p = ++res;
65370 + if (unlikely(!++res))
65371 + goto start; /* never zero */
65372 + *p = res;
65373 put_cpu_var(last_ino);
65374 return res;
65375 }
65376 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
65377 index 4a6cf28..d3a29d3 100644
65378 --- a/fs/jffs2/erase.c
65379 +++ b/fs/jffs2/erase.c
65380 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
65381 struct jffs2_unknown_node marker = {
65382 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
65383 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
65384 - .totlen = cpu_to_je32(c->cleanmarker_size)
65385 + .totlen = cpu_to_je32(c->cleanmarker_size),
65386 + .hdr_crc = cpu_to_je32(0)
65387 };
65388
65389 jffs2_prealloc_raw_node_refs(c, jeb, 1);
65390 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
65391 index a6597d6..41b30ec 100644
65392 --- a/fs/jffs2/wbuf.c
65393 +++ b/fs/jffs2/wbuf.c
65394 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
65395 {
65396 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
65397 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
65398 - .totlen = constant_cpu_to_je32(8)
65399 + .totlen = constant_cpu_to_je32(8),
65400 + .hdr_crc = constant_cpu_to_je32(0)
65401 };
65402
65403 /*
65404 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
65405 index adf8cb0..bb935fa 100644
65406 --- a/fs/jfs/super.c
65407 +++ b/fs/jfs/super.c
65408 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
65409
65410 jfs_inode_cachep =
65411 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
65412 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
65413 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
65414 init_once);
65415 if (jfs_inode_cachep == NULL)
65416 return -ENOMEM;
65417 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
65418 index a693f5b..82276a1 100644
65419 --- a/fs/kernfs/dir.c
65420 +++ b/fs/kernfs/dir.c
65421 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
65422 *
65423 * Returns 31 bit hash of ns + name (so it fits in an off_t )
65424 */
65425 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
65426 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
65427 {
65428 unsigned long hash = init_name_hash();
65429 unsigned int len = strlen(name);
65430 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
65431 index d895b4b..0b8af77 100644
65432 --- a/fs/kernfs/file.c
65433 +++ b/fs/kernfs/file.c
65434 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
65435
65436 struct kernfs_open_node {
65437 atomic_t refcnt;
65438 - atomic_t event;
65439 + atomic_unchecked_t event;
65440 wait_queue_head_t poll;
65441 struct list_head files; /* goes through kernfs_open_file.list */
65442 };
65443 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
65444 {
65445 struct kernfs_open_file *of = sf->private;
65446
65447 - of->event = atomic_read(&of->kn->attr.open->event);
65448 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
65449
65450 return of->kn->attr.ops->seq_show(sf, v);
65451 }
65452 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
65453 return ret;
65454 }
65455
65456 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
65457 - void *buf, int len, int write)
65458 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
65459 + void *buf, size_t len, int write)
65460 {
65461 struct file *file = vma->vm_file;
65462 struct kernfs_open_file *of = kernfs_of(file);
65463 - int ret;
65464 + ssize_t ret;
65465
65466 if (!of->vm_ops)
65467 return -EINVAL;
65468 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
65469 return -ENOMEM;
65470
65471 atomic_set(&new_on->refcnt, 0);
65472 - atomic_set(&new_on->event, 1);
65473 + atomic_set_unchecked(&new_on->event, 1);
65474 init_waitqueue_head(&new_on->poll);
65475 INIT_LIST_HEAD(&new_on->files);
65476 goto retry;
65477 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
65478
65479 kernfs_put_active(kn);
65480
65481 - if (of->event != atomic_read(&on->event))
65482 + if (of->event != atomic_read_unchecked(&on->event))
65483 goto trigger;
65484
65485 return DEFAULT_POLLMASK;
65486 @@ -818,7 +818,7 @@ repeat:
65487
65488 on = kn->attr.open;
65489 if (on) {
65490 - atomic_inc(&on->event);
65491 + atomic_inc_unchecked(&on->event);
65492 wake_up_interruptible(&on->poll);
65493 }
65494
65495 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
65496 index 8a19889..4c3069a 100644
65497 --- a/fs/kernfs/symlink.c
65498 +++ b/fs/kernfs/symlink.c
65499 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
65500 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
65501 void *cookie)
65502 {
65503 - char *page = nd_get_link(nd);
65504 + const char *page = nd_get_link(nd);
65505 if (!IS_ERR(page))
65506 free_page((unsigned long)page);
65507 }
65508 diff --git a/fs/libfs.c b/fs/libfs.c
65509 index 88e3e00..979c262 100644
65510 --- a/fs/libfs.c
65511 +++ b/fs/libfs.c
65512 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
65513
65514 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
65515 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
65516 + char d_name[sizeof(next->d_iname)];
65517 + const unsigned char *name;
65518 +
65519 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
65520 if (!simple_positive(next)) {
65521 spin_unlock(&next->d_lock);
65522 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
65523
65524 spin_unlock(&next->d_lock);
65525 spin_unlock(&dentry->d_lock);
65526 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
65527 + name = next->d_name.name;
65528 + if (name == next->d_iname) {
65529 + memcpy(d_name, name, next->d_name.len);
65530 + name = d_name;
65531 + }
65532 + if (!dir_emit(ctx, name, next->d_name.len,
65533 next->d_inode->i_ino, dt_type(next->d_inode)))
65534 return 0;
65535 spin_lock(&dentry->d_lock);
65536 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
65537 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
65538 void *cookie)
65539 {
65540 - char *s = nd_get_link(nd);
65541 + const char *s = nd_get_link(nd);
65542 if (!IS_ERR(s))
65543 kfree(s);
65544 }
65545 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
65546 index acd3947..1f896e2 100644
65547 --- a/fs/lockd/clntproc.c
65548 +++ b/fs/lockd/clntproc.c
65549 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
65550 /*
65551 * Cookie counter for NLM requests
65552 */
65553 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
65554 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
65555
65556 void nlmclnt_next_cookie(struct nlm_cookie *c)
65557 {
65558 - u32 cookie = atomic_inc_return(&nlm_cookie);
65559 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
65560
65561 memcpy(c->data, &cookie, 4);
65562 c->len=4;
65563 diff --git a/fs/locks.c b/fs/locks.c
65564 index 717fbc4..74628c3 100644
65565 --- a/fs/locks.c
65566 +++ b/fs/locks.c
65567 @@ -2327,7 +2327,7 @@ void locks_remove_file(struct file *filp)
65568 locks_remove_posix(filp, (fl_owner_t)filp);
65569
65570 if (filp->f_op->flock) {
65571 - struct file_lock fl = {
65572 + struct file_lock flock = {
65573 .fl_owner = (fl_owner_t)filp,
65574 .fl_pid = current->tgid,
65575 .fl_file = filp,
65576 @@ -2335,9 +2335,9 @@ void locks_remove_file(struct file *filp)
65577 .fl_type = F_UNLCK,
65578 .fl_end = OFFSET_MAX,
65579 };
65580 - filp->f_op->flock(filp, F_SETLKW, &fl);
65581 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
65582 - fl.fl_ops->fl_release_private(&fl);
65583 + filp->f_op->flock(filp, F_SETLKW, &flock);
65584 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
65585 + flock.fl_ops->fl_release_private(&flock);
65586 }
65587
65588 spin_lock(&inode->i_lock);
65589 diff --git a/fs/mount.h b/fs/mount.h
65590 index d55297f..f5b28c5 100644
65591 --- a/fs/mount.h
65592 +++ b/fs/mount.h
65593 @@ -11,7 +11,7 @@ struct mnt_namespace {
65594 u64 seq; /* Sequence number to prevent loops */
65595 wait_queue_head_t poll;
65596 u64 event;
65597 -};
65598 +} __randomize_layout;
65599
65600 struct mnt_pcp {
65601 int mnt_count;
65602 @@ -57,7 +57,7 @@ struct mount {
65603 int mnt_expiry_mark; /* true if marked for expiry */
65604 int mnt_pinned;
65605 struct path mnt_ex_mountpoint;
65606 -};
65607 +} __randomize_layout;
65608
65609 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
65610
65611 diff --git a/fs/namei.c b/fs/namei.c
65612 index 9eb787e..2de9500 100644
65613 --- a/fs/namei.c
65614 +++ b/fs/namei.c
65615 @@ -34,6 +34,7 @@
65616 #include <linux/device_cgroup.h>
65617 #include <linux/fs_struct.h>
65618 #include <linux/posix_acl.h>
65619 +#include <linux/hash.h>
65620 #include <asm/uaccess.h>
65621
65622 #include "internal.h"
65623 @@ -330,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
65624 if (ret != -EACCES)
65625 return ret;
65626
65627 +#ifdef CONFIG_GRKERNSEC
65628 + /* we'll block if we have to log due to a denied capability use */
65629 + if (mask & MAY_NOT_BLOCK)
65630 + return -ECHILD;
65631 +#endif
65632 +
65633 if (S_ISDIR(inode->i_mode)) {
65634 /* DACs are overridable for directories */
65635 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65636 - return 0;
65637 if (!(mask & MAY_WRITE))
65638 - if (capable_wrt_inode_uidgid(inode,
65639 - CAP_DAC_READ_SEARCH))
65640 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65641 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65642 return 0;
65643 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65644 + return 0;
65645 return -EACCES;
65646 }
65647 /*
65648 + * Searching includes executable on directories, else just read.
65649 + */
65650 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65651 + if (mask == MAY_READ)
65652 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
65653 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65654 + return 0;
65655 +
65656 + /*
65657 * Read/write DACs are always overridable.
65658 * Executable DACs are overridable when there is
65659 * at least one exec bit set.
65660 @@ -349,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
65661 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
65662 return 0;
65663
65664 - /*
65665 - * Searching includes executable on directories, else just read.
65666 - */
65667 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
65668 - if (mask == MAY_READ)
65669 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
65670 - return 0;
65671 -
65672 return -EACCES;
65673 }
65674 EXPORT_SYMBOL(generic_permission);
65675 @@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65676 {
65677 struct dentry *dentry = link->dentry;
65678 int error;
65679 - char *s;
65680 + const char *s;
65681
65682 BUG_ON(nd->flags & LOOKUP_RCU);
65683
65684 @@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
65685 if (error)
65686 goto out_put_nd_path;
65687
65688 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
65689 + dentry->d_inode, dentry, nd->path.mnt)) {
65690 + error = -EACCES;
65691 + goto out_put_nd_path;
65692 + }
65693 +
65694 nd->last_type = LAST_BIND;
65695 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
65696 error = PTR_ERR(*p);
65697 @@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
65698 if (res)
65699 break;
65700 res = walk_component(nd, path, LOOKUP_FOLLOW);
65701 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
65702 + res = -EACCES;
65703 put_link(nd, &link, cookie);
65704 } while (res > 0);
65705
65706 @@ -1629,8 +1645,7 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
65707
65708 static inline unsigned int fold_hash(unsigned long hash)
65709 {
65710 - hash += hash >> (8*sizeof(int));
65711 - return hash;
65712 + return hash_64(hash, 32);
65713 }
65714
65715 #else /* 32-bit case */
65716 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
65717 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
65718 {
65719 unsigned long a, b, adata, bdata, mask, hash, len;
65720 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65721 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
65722
65723 hash = a = 0;
65724 len = -sizeof(unsigned long);
65725 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
65726 if (err)
65727 break;
65728 err = lookup_last(nd, &path);
65729 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
65730 + err = -EACCES;
65731 put_link(nd, &link, cookie);
65732 }
65733 }
65734 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
65735 if (!err)
65736 err = complete_walk(nd);
65737
65738 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
65739 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65740 + path_put(&nd->path);
65741 + err = -ENOENT;
65742 + }
65743 + }
65744 +
65745 if (!err && nd->flags & LOOKUP_DIRECTORY) {
65746 if (!d_can_lookup(nd->path.dentry)) {
65747 path_put(&nd->path);
65748 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
65749 retval = path_lookupat(dfd, name->name,
65750 flags | LOOKUP_REVAL, nd);
65751
65752 - if (likely(!retval))
65753 + if (likely(!retval)) {
65754 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
65755 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
65756 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
65757 + path_put(&nd->path);
65758 + return -ENOENT;
65759 + }
65760 + }
65761 + }
65762 return retval;
65763 }
65764
65765 @@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
65766 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
65767 return -EPERM;
65768
65769 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
65770 + return -EPERM;
65771 + if (gr_handle_rawio(inode))
65772 + return -EPERM;
65773 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
65774 + return -EACCES;
65775 +
65776 return 0;
65777 }
65778
65779 @@ -2801,7 +2839,7 @@ looked_up:
65780 * cleared otherwise prior to returning.
65781 */
65782 static int lookup_open(struct nameidata *nd, struct path *path,
65783 - struct file *file,
65784 + struct path *link, struct file *file,
65785 const struct open_flags *op,
65786 bool got_write, int *opened)
65787 {
65788 @@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65789 /* Negative dentry, just create the file */
65790 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
65791 umode_t mode = op->mode;
65792 +
65793 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
65794 + error = -EACCES;
65795 + goto out_dput;
65796 + }
65797 +
65798 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
65799 + error = -EACCES;
65800 + goto out_dput;
65801 + }
65802 +
65803 if (!IS_POSIXACL(dir->d_inode))
65804 mode &= ~current_umask();
65805 /*
65806 @@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
65807 nd->flags & LOOKUP_EXCL);
65808 if (error)
65809 goto out_dput;
65810 + else
65811 + gr_handle_create(dentry, nd->path.mnt);
65812 }
65813 out_no_open:
65814 path->dentry = dentry;
65815 @@ -2871,7 +2922,7 @@ out_dput:
65816 /*
65817 * Handle the last step of open()
65818 */
65819 -static int do_last(struct nameidata *nd, struct path *path,
65820 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
65821 struct file *file, const struct open_flags *op,
65822 int *opened, struct filename *name)
65823 {
65824 @@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
65825 if (error)
65826 return error;
65827
65828 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
65829 + error = -ENOENT;
65830 + goto out;
65831 + }
65832 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65833 + error = -EACCES;
65834 + goto out;
65835 + }
65836 +
65837 audit_inode(name, dir, LOOKUP_PARENT);
65838 error = -EISDIR;
65839 /* trailing slashes? */
65840 @@ -2940,7 +3000,7 @@ retry_lookup:
65841 */
65842 }
65843 mutex_lock(&dir->d_inode->i_mutex);
65844 - error = lookup_open(nd, path, file, op, got_write, opened);
65845 + error = lookup_open(nd, path, link, file, op, got_write, opened);
65846 mutex_unlock(&dir->d_inode->i_mutex);
65847
65848 if (error <= 0) {
65849 @@ -2964,11 +3024,28 @@ retry_lookup:
65850 goto finish_open_created;
65851 }
65852
65853 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
65854 + error = -ENOENT;
65855 + goto exit_dput;
65856 + }
65857 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
65858 + error = -EACCES;
65859 + goto exit_dput;
65860 + }
65861 +
65862 /*
65863 * create/update audit record if it already exists.
65864 */
65865 - if (d_is_positive(path->dentry))
65866 + if (d_is_positive(path->dentry)) {
65867 + /* only check if O_CREAT is specified, all other checks need to go
65868 + into may_open */
65869 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
65870 + error = -EACCES;
65871 + goto exit_dput;
65872 + }
65873 +
65874 audit_inode(name, path->dentry, 0);
65875 + }
65876
65877 /*
65878 * If atomic_open() acquired write access it is dropped now due to
65879 @@ -3009,6 +3086,11 @@ finish_lookup:
65880 }
65881 }
65882 BUG_ON(inode != path->dentry->d_inode);
65883 + /* if we're resolving a symlink to another symlink */
65884 + if (link && gr_handle_symlink_owner(link, inode)) {
65885 + error = -EACCES;
65886 + goto out;
65887 + }
65888 return 1;
65889 }
65890
65891 @@ -3018,7 +3100,6 @@ finish_lookup:
65892 save_parent.dentry = nd->path.dentry;
65893 save_parent.mnt = mntget(path->mnt);
65894 nd->path.dentry = path->dentry;
65895 -
65896 }
65897 nd->inode = inode;
65898 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
65899 @@ -3028,7 +3109,18 @@ finish_open:
65900 path_put(&save_parent);
65901 return error;
65902 }
65903 +
65904 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
65905 + error = -ENOENT;
65906 + goto out;
65907 + }
65908 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
65909 + error = -EACCES;
65910 + goto out;
65911 + }
65912 +
65913 audit_inode(name, nd->path.dentry, 0);
65914 +
65915 error = -EISDIR;
65916 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
65917 goto out;
65918 @@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65919 if (unlikely(error))
65920 goto out;
65921
65922 - error = do_last(nd, &path, file, op, &opened, pathname);
65923 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
65924 while (unlikely(error > 0)) { /* trailing symlink */
65925 struct path link = path;
65926 void *cookie;
65927 @@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
65928 error = follow_link(&link, nd, &cookie);
65929 if (unlikely(error))
65930 break;
65931 - error = do_last(nd, &path, file, op, &opened, pathname);
65932 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
65933 put_link(nd, &link, cookie);
65934 }
65935 out:
65936 @@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
65937 goto unlock;
65938
65939 error = -EEXIST;
65940 - if (d_is_positive(dentry))
65941 + if (d_is_positive(dentry)) {
65942 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
65943 + error = -ENOENT;
65944 goto fail;
65945 -
65946 + }
65947 /*
65948 * Special case - lookup gave negative, but... we had foo/bar/
65949 * From the vfs_mknod() POV we just have a negative dentry -
65950 @@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
65951 }
65952 EXPORT_SYMBOL(user_path_create);
65953
65954 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
65955 +{
65956 + struct filename *tmp = getname(pathname);
65957 + struct dentry *res;
65958 + if (IS_ERR(tmp))
65959 + return ERR_CAST(tmp);
65960 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
65961 + if (IS_ERR(res))
65962 + putname(tmp);
65963 + else
65964 + *to = tmp;
65965 + return res;
65966 +}
65967 +
65968 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
65969 {
65970 int error = may_create(dir, dentry);
65971 @@ -3426,6 +3534,17 @@ retry:
65972
65973 if (!IS_POSIXACL(path.dentry->d_inode))
65974 mode &= ~current_umask();
65975 +
65976 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
65977 + error = -EPERM;
65978 + goto out;
65979 + }
65980 +
65981 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
65982 + error = -EACCES;
65983 + goto out;
65984 + }
65985 +
65986 error = security_path_mknod(&path, dentry, mode, dev);
65987 if (error)
65988 goto out;
65989 @@ -3442,6 +3561,8 @@ retry:
65990 break;
65991 }
65992 out:
65993 + if (!error)
65994 + gr_handle_create(dentry, path.mnt);
65995 done_path_create(&path, dentry);
65996 if (retry_estale(error, lookup_flags)) {
65997 lookup_flags |= LOOKUP_REVAL;
65998 @@ -3495,9 +3616,16 @@ retry:
65999
66000 if (!IS_POSIXACL(path.dentry->d_inode))
66001 mode &= ~current_umask();
66002 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
66003 + error = -EACCES;
66004 + goto out;
66005 + }
66006 error = security_path_mkdir(&path, dentry, mode);
66007 if (!error)
66008 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
66009 + if (!error)
66010 + gr_handle_create(dentry, path.mnt);
66011 +out:
66012 done_path_create(&path, dentry);
66013 if (retry_estale(error, lookup_flags)) {
66014 lookup_flags |= LOOKUP_REVAL;
66015 @@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
66016 struct filename *name;
66017 struct dentry *dentry;
66018 struct nameidata nd;
66019 + ino_t saved_ino = 0;
66020 + dev_t saved_dev = 0;
66021 unsigned int lookup_flags = 0;
66022 retry:
66023 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
66024 @@ -3612,10 +3742,21 @@ retry:
66025 error = -ENOENT;
66026 goto exit3;
66027 }
66028 +
66029 + saved_ino = dentry->d_inode->i_ino;
66030 + saved_dev = gr_get_dev_from_dentry(dentry);
66031 +
66032 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
66033 + error = -EACCES;
66034 + goto exit3;
66035 + }
66036 +
66037 error = security_path_rmdir(&nd.path, dentry);
66038 if (error)
66039 goto exit3;
66040 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
66041 + if (!error && (saved_dev || saved_ino))
66042 + gr_handle_delete(saved_ino, saved_dev);
66043 exit3:
66044 dput(dentry);
66045 exit2:
66046 @@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
66047 struct nameidata nd;
66048 struct inode *inode = NULL;
66049 struct inode *delegated_inode = NULL;
66050 + ino_t saved_ino = 0;
66051 + dev_t saved_dev = 0;
66052 unsigned int lookup_flags = 0;
66053 retry:
66054 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
66055 @@ -3732,10 +3875,22 @@ retry_deleg:
66056 if (d_is_negative(dentry))
66057 goto slashes;
66058 ihold(inode);
66059 +
66060 + if (inode->i_nlink <= 1) {
66061 + saved_ino = inode->i_ino;
66062 + saved_dev = gr_get_dev_from_dentry(dentry);
66063 + }
66064 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
66065 + error = -EACCES;
66066 + goto exit2;
66067 + }
66068 +
66069 error = security_path_unlink(&nd.path, dentry);
66070 if (error)
66071 goto exit2;
66072 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
66073 + if (!error && (saved_ino || saved_dev))
66074 + gr_handle_delete(saved_ino, saved_dev);
66075 exit2:
66076 dput(dentry);
66077 }
66078 @@ -3824,9 +3979,17 @@ retry:
66079 if (IS_ERR(dentry))
66080 goto out_putname;
66081
66082 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
66083 + error = -EACCES;
66084 + goto out;
66085 + }
66086 +
66087 error = security_path_symlink(&path, dentry, from->name);
66088 if (!error)
66089 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
66090 + if (!error)
66091 + gr_handle_create(dentry, path.mnt);
66092 +out:
66093 done_path_create(&path, dentry);
66094 if (retry_estale(error, lookup_flags)) {
66095 lookup_flags |= LOOKUP_REVAL;
66096 @@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
66097 struct dentry *new_dentry;
66098 struct path old_path, new_path;
66099 struct inode *delegated_inode = NULL;
66100 + struct filename *to = NULL;
66101 int how = 0;
66102 int error;
66103
66104 @@ -3953,7 +4117,7 @@ retry:
66105 if (error)
66106 return error;
66107
66108 - new_dentry = user_path_create(newdfd, newname, &new_path,
66109 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
66110 (how & LOOKUP_REVAL));
66111 error = PTR_ERR(new_dentry);
66112 if (IS_ERR(new_dentry))
66113 @@ -3965,11 +4129,28 @@ retry:
66114 error = may_linkat(&old_path);
66115 if (unlikely(error))
66116 goto out_dput;
66117 +
66118 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
66119 + old_path.dentry->d_inode,
66120 + old_path.dentry->d_inode->i_mode, to)) {
66121 + error = -EACCES;
66122 + goto out_dput;
66123 + }
66124 +
66125 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
66126 + old_path.dentry, old_path.mnt, to)) {
66127 + error = -EACCES;
66128 + goto out_dput;
66129 + }
66130 +
66131 error = security_path_link(old_path.dentry, &new_path, new_dentry);
66132 if (error)
66133 goto out_dput;
66134 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
66135 + if (!error)
66136 + gr_handle_create(new_dentry, new_path.mnt);
66137 out_dput:
66138 + putname(to);
66139 done_path_create(&new_path, new_dentry);
66140 if (delegated_inode) {
66141 error = break_deleg_wait(&delegated_inode);
66142 @@ -4279,6 +4460,12 @@ retry_deleg:
66143 if (new_dentry == trap)
66144 goto exit5;
66145
66146 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
66147 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
66148 + to, flags);
66149 + if (error)
66150 + goto exit5;
66151 +
66152 error = security_path_rename(&oldnd.path, old_dentry,
66153 &newnd.path, new_dentry, flags);
66154 if (error)
66155 @@ -4286,6 +4473,9 @@ retry_deleg:
66156 error = vfs_rename(old_dir->d_inode, old_dentry,
66157 new_dir->d_inode, new_dentry,
66158 &delegated_inode, flags);
66159 + if (!error)
66160 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
66161 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
66162 exit5:
66163 dput(new_dentry);
66164 exit4:
66165 @@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
66166
66167 int readlink_copy(char __user *buffer, int buflen, const char *link)
66168 {
66169 + char tmpbuf[64];
66170 + const char *newlink;
66171 int len = PTR_ERR(link);
66172 +
66173 if (IS_ERR(link))
66174 goto out;
66175
66176 len = strlen(link);
66177 if (len > (unsigned) buflen)
66178 len = buflen;
66179 - if (copy_to_user(buffer, link, len))
66180 +
66181 + if (len < sizeof(tmpbuf)) {
66182 + memcpy(tmpbuf, link, len);
66183 + newlink = tmpbuf;
66184 + } else
66185 + newlink = link;
66186 +
66187 + if (copy_to_user(buffer, newlink, len))
66188 len = -EFAULT;
66189 out:
66190 return len;
66191 diff --git a/fs/namespace.c b/fs/namespace.c
66192 index 182bc41..72e3cf1 100644
66193 --- a/fs/namespace.c
66194 +++ b/fs/namespace.c
66195 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
66196 if (!(sb->s_flags & MS_RDONLY))
66197 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
66198 up_write(&sb->s_umount);
66199 +
66200 + gr_log_remount(mnt->mnt_devname, retval);
66201 +
66202 return retval;
66203 }
66204
66205 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
66206 }
66207 unlock_mount_hash();
66208 namespace_unlock();
66209 +
66210 + gr_log_unmount(mnt->mnt_devname, retval);
66211 +
66212 return retval;
66213 }
66214
66215 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
66216 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
66217 */
66218
66219 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
66220 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
66221 {
66222 struct path path;
66223 struct mount *mnt;
66224 @@ -1431,7 +1437,7 @@ out:
66225 /*
66226 * The 2.0 compatible umount. No flags.
66227 */
66228 -SYSCALL_DEFINE1(oldumount, char __user *, name)
66229 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
66230 {
66231 return sys_umount(name, 0);
66232 }
66233 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
66234 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
66235 MS_STRICTATIME);
66236
66237 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
66238 + retval = -EPERM;
66239 + goto dput_out;
66240 + }
66241 +
66242 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
66243 + retval = -EPERM;
66244 + goto dput_out;
66245 + }
66246 +
66247 if (flags & MS_REMOUNT)
66248 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
66249 data_page);
66250 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
66251 dev_name, data_page);
66252 dput_out:
66253 path_put(&path);
66254 +
66255 + gr_log_mount(dev_name, dir_name, retval);
66256 +
66257 return retval;
66258 }
66259
66260 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
66261 * number incrementing at 10Ghz will take 12,427 years to wrap which
66262 * is effectively never, so we can ignore the possibility.
66263 */
66264 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
66265 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
66266
66267 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
66268 {
66269 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
66270 kfree(new_ns);
66271 return ERR_PTR(ret);
66272 }
66273 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
66274 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
66275 atomic_set(&new_ns->count, 1);
66276 new_ns->root = NULL;
66277 INIT_LIST_HEAD(&new_ns->list);
66278 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
66279 return new_ns;
66280 }
66281
66282 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
66283 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
66284 struct user_namespace *user_ns, struct fs_struct *new_fs)
66285 {
66286 struct mnt_namespace *new_ns;
66287 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
66288 }
66289 EXPORT_SYMBOL(mount_subtree);
66290
66291 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
66292 - char __user *, type, unsigned long, flags, void __user *, data)
66293 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
66294 + const char __user *, type, unsigned long, flags, void __user *, data)
66295 {
66296 int ret;
66297 char *kernel_type;
66298 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
66299 if (error)
66300 goto out2;
66301
66302 + if (gr_handle_chroot_pivot()) {
66303 + error = -EPERM;
66304 + goto out2;
66305 + }
66306 +
66307 get_fs_root(current->fs, &root);
66308 old_mp = lock_mount(&old);
66309 error = PTR_ERR(old_mp);
66310 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
66311 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
66312 return -EPERM;
66313
66314 - if (fs->users != 1)
66315 + if (atomic_read(&fs->users) != 1)
66316 return -EINVAL;
66317
66318 get_mnt_ns(mnt_ns);
66319 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
66320 index f4ccfe6..a5cf064 100644
66321 --- a/fs/nfs/callback_xdr.c
66322 +++ b/fs/nfs/callback_xdr.c
66323 @@ -51,7 +51,7 @@ struct callback_op {
66324 callback_decode_arg_t decode_args;
66325 callback_encode_res_t encode_res;
66326 long res_maxsize;
66327 -};
66328 +} __do_const;
66329
66330 static struct callback_op callback_ops[];
66331
66332 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
66333 index 9927913..faffc5c 100644
66334 --- a/fs/nfs/inode.c
66335 +++ b/fs/nfs/inode.c
66336 @@ -1219,16 +1219,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
66337 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
66338 }
66339
66340 -static atomic_long_t nfs_attr_generation_counter;
66341 +static atomic_long_unchecked_t nfs_attr_generation_counter;
66342
66343 static unsigned long nfs_read_attr_generation_counter(void)
66344 {
66345 - return atomic_long_read(&nfs_attr_generation_counter);
66346 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
66347 }
66348
66349 unsigned long nfs_inc_attr_generation_counter(void)
66350 {
66351 - return atomic_long_inc_return(&nfs_attr_generation_counter);
66352 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
66353 }
66354
66355 void nfs_fattr_init(struct nfs_fattr *fattr)
66356 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
66357 index 8f029db..3688b84 100644
66358 --- a/fs/nfsd/nfs4proc.c
66359 +++ b/fs/nfsd/nfs4proc.c
66360 @@ -1157,7 +1157,7 @@ struct nfsd4_operation {
66361 nfsd4op_rsize op_rsize_bop;
66362 stateid_getter op_get_currentstateid;
66363 stateid_setter op_set_currentstateid;
66364 -};
66365 +} __do_const;
66366
66367 static struct nfsd4_operation nfsd4_ops[];
66368
66369 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
66370 index 944275c..6fc40a7 100644
66371 --- a/fs/nfsd/nfs4xdr.c
66372 +++ b/fs/nfsd/nfs4xdr.c
66373 @@ -1539,7 +1539,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
66374
66375 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
66376
66377 -static nfsd4_dec nfsd4_dec_ops[] = {
66378 +static const nfsd4_dec nfsd4_dec_ops[] = {
66379 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
66380 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
66381 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
66382 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
66383 index 6040da8..4348565 100644
66384 --- a/fs/nfsd/nfscache.c
66385 +++ b/fs/nfsd/nfscache.c
66386 @@ -518,17 +518,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
66387 {
66388 struct svc_cacherep *rp = rqstp->rq_cacherep;
66389 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
66390 - int len;
66391 + long len;
66392 size_t bufsize = 0;
66393
66394 if (!rp)
66395 return;
66396
66397 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
66398 - len >>= 2;
66399 + if (statp) {
66400 + len = (char*)statp - (char*)resv->iov_base;
66401 + len = resv->iov_len - len;
66402 + len >>= 2;
66403 + }
66404
66405 /* Don't cache excessive amounts of data and XDR failures */
66406 - if (!statp || len > (256 >> 2)) {
66407 + if (!statp || len > (256 >> 2) || len < 0) {
66408 nfsd_reply_cache_free(rp);
66409 return;
66410 }
66411 @@ -536,7 +539,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
66412 switch (cachetype) {
66413 case RC_REPLSTAT:
66414 if (len != 1)
66415 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
66416 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
66417 rp->c_replstat = *statp;
66418 break;
66419 case RC_REPLBUFF:
66420 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
66421 index 140c496..e9cbf14 100644
66422 --- a/fs/nfsd/vfs.c
66423 +++ b/fs/nfsd/vfs.c
66424 @@ -855,7 +855,7 @@ int nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
66425
66426 oldfs = get_fs();
66427 set_fs(KERNEL_DS);
66428 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
66429 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
66430 set_fs(oldfs);
66431 return nfsd_finish_read(file, count, host_err);
66432 }
66433 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
66434
66435 /* Write the data. */
66436 oldfs = get_fs(); set_fs(KERNEL_DS);
66437 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
66438 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
66439 set_fs(oldfs);
66440 if (host_err < 0)
66441 goto out_nfserr;
66442 @@ -1482,7 +1482,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
66443 */
66444
66445 oldfs = get_fs(); set_fs(KERNEL_DS);
66446 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
66447 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
66448 set_fs(oldfs);
66449
66450 if (host_err < 0)
66451 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
66452 index 52ccd34..7a6b202 100644
66453 --- a/fs/nls/nls_base.c
66454 +++ b/fs/nls/nls_base.c
66455 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
66456
66457 int __register_nls(struct nls_table *nls, struct module *owner)
66458 {
66459 - struct nls_table ** tmp = &tables;
66460 + struct nls_table *tmp = tables;
66461
66462 if (nls->next)
66463 return -EBUSY;
66464
66465 - nls->owner = owner;
66466 + pax_open_kernel();
66467 + *(void **)&nls->owner = owner;
66468 + pax_close_kernel();
66469 spin_lock(&nls_lock);
66470 - while (*tmp) {
66471 - if (nls == *tmp) {
66472 + while (tmp) {
66473 + if (nls == tmp) {
66474 spin_unlock(&nls_lock);
66475 return -EBUSY;
66476 }
66477 - tmp = &(*tmp)->next;
66478 + tmp = tmp->next;
66479 }
66480 - nls->next = tables;
66481 + pax_open_kernel();
66482 + *(struct nls_table **)&nls->next = tables;
66483 + pax_close_kernel();
66484 tables = nls;
66485 spin_unlock(&nls_lock);
66486 return 0;
66487 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
66488
66489 int unregister_nls(struct nls_table * nls)
66490 {
66491 - struct nls_table ** tmp = &tables;
66492 + struct nls_table * const * tmp = &tables;
66493
66494 spin_lock(&nls_lock);
66495 while (*tmp) {
66496 if (nls == *tmp) {
66497 - *tmp = nls->next;
66498 + pax_open_kernel();
66499 + *(struct nls_table **)tmp = nls->next;
66500 + pax_close_kernel();
66501 spin_unlock(&nls_lock);
66502 return 0;
66503 }
66504 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
66505 return -EINVAL;
66506 }
66507
66508 -static struct nls_table *find_nls(char *charset)
66509 +static struct nls_table *find_nls(const char *charset)
66510 {
66511 struct nls_table *nls;
66512 spin_lock(&nls_lock);
66513 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
66514 return nls;
66515 }
66516
66517 -struct nls_table *load_nls(char *charset)
66518 +struct nls_table *load_nls(const char *charset)
66519 {
66520 return try_then_request_module(find_nls(charset), "nls_%s", charset);
66521 }
66522 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
66523 index 162b3f1..6076a7c 100644
66524 --- a/fs/nls/nls_euc-jp.c
66525 +++ b/fs/nls/nls_euc-jp.c
66526 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
66527 p_nls = load_nls("cp932");
66528
66529 if (p_nls) {
66530 - table.charset2upper = p_nls->charset2upper;
66531 - table.charset2lower = p_nls->charset2lower;
66532 + pax_open_kernel();
66533 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
66534 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
66535 + pax_close_kernel();
66536 return register_nls(&table);
66537 }
66538
66539 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
66540 index a80a741..7b96e1b 100644
66541 --- a/fs/nls/nls_koi8-ru.c
66542 +++ b/fs/nls/nls_koi8-ru.c
66543 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
66544 p_nls = load_nls("koi8-u");
66545
66546 if (p_nls) {
66547 - table.charset2upper = p_nls->charset2upper;
66548 - table.charset2lower = p_nls->charset2lower;
66549 + pax_open_kernel();
66550 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
66551 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
66552 + pax_close_kernel();
66553 return register_nls(&table);
66554 }
66555
66556 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
66557 index 3fdc8a3..5888623 100644
66558 --- a/fs/notify/fanotify/fanotify_user.c
66559 +++ b/fs/notify/fanotify/fanotify_user.c
66560 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
66561
66562 fd = fanotify_event_metadata.fd;
66563 ret = -EFAULT;
66564 - if (copy_to_user(buf, &fanotify_event_metadata,
66565 - fanotify_event_metadata.event_len))
66566 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
66567 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
66568 goto out_close_fd;
66569
66570 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
66571 diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c
66572 index 238a593..9d7e2b9 100644
66573 --- a/fs/notify/fdinfo.c
66574 +++ b/fs/notify/fdinfo.c
66575 @@ -42,7 +42,7 @@ static int show_mark_fhandle(struct seq_file *m, struct inode *inode)
66576 {
66577 struct {
66578 struct file_handle handle;
66579 - u8 pad[64];
66580 + u8 pad[MAX_HANDLE_SZ];
66581 } f;
66582 int size, ret, i;
66583
66584 @@ -50,7 +50,7 @@ static int show_mark_fhandle(struct seq_file *m, struct inode *inode)
66585 size = f.handle.handle_bytes >> 2;
66586
66587 ret = exportfs_encode_inode_fh(inode, (struct fid *)f.handle.f_handle, &size, 0);
66588 - if ((ret == 255) || (ret == -ENOSPC)) {
66589 + if ((ret == FILEID_INVALID) || (ret < 0)) {
66590 WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret);
66591 return 0;
66592 }
66593 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
66594 index 1e58402..bb2d6f4 100644
66595 --- a/fs/notify/notification.c
66596 +++ b/fs/notify/notification.c
66597 @@ -48,7 +48,7 @@
66598 #include <linux/fsnotify_backend.h>
66599 #include "fsnotify.h"
66600
66601 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66602 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66603
66604 /**
66605 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
66606 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
66607 */
66608 u32 fsnotify_get_cookie(void)
66609 {
66610 - return atomic_inc_return(&fsnotify_sync_cookie);
66611 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
66612 }
66613 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
66614
66615 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
66616 index 9e38daf..5727cae 100644
66617 --- a/fs/ntfs/dir.c
66618 +++ b/fs/ntfs/dir.c
66619 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
66620 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
66621 ~(s64)(ndir->itype.index.block_size - 1)));
66622 /* Bounds checks. */
66623 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
66624 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
66625 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
66626 "inode 0x%lx or driver bug.", vdir->i_ino);
66627 goto err_out;
66628 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
66629 index 5c9e2c8..96e4ba0 100644
66630 --- a/fs/ntfs/file.c
66631 +++ b/fs/ntfs/file.c
66632 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
66633 char *addr;
66634 size_t total = 0;
66635 unsigned len;
66636 - int left;
66637 + unsigned left;
66638
66639 do {
66640 len = PAGE_CACHE_SIZE - ofs;
66641 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
66642 index 6c3296e..c0b99f0 100644
66643 --- a/fs/ntfs/super.c
66644 +++ b/fs/ntfs/super.c
66645 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66646 if (!silent)
66647 ntfs_error(sb, "Primary boot sector is invalid.");
66648 } else if (!silent)
66649 - ntfs_error(sb, read_err_str, "primary");
66650 + ntfs_error(sb, read_err_str, "%s", "primary");
66651 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
66652 if (bh_primary)
66653 brelse(bh_primary);
66654 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66655 goto hotfix_primary_boot_sector;
66656 brelse(bh_backup);
66657 } else if (!silent)
66658 - ntfs_error(sb, read_err_str, "backup");
66659 + ntfs_error(sb, read_err_str, "%s", "backup");
66660 /* Try to read NT3.51- backup boot sector. */
66661 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
66662 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
66663 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
66664 "sector.");
66665 brelse(bh_backup);
66666 } else if (!silent)
66667 - ntfs_error(sb, read_err_str, "backup");
66668 + ntfs_error(sb, read_err_str, "%s", "backup");
66669 /* We failed. Cleanup and return. */
66670 if (bh_primary)
66671 brelse(bh_primary);
66672 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
66673 index 0440134..d52c93a 100644
66674 --- a/fs/ocfs2/localalloc.c
66675 +++ b/fs/ocfs2/localalloc.c
66676 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
66677 goto bail;
66678 }
66679
66680 - atomic_inc(&osb->alloc_stats.moves);
66681 + atomic_inc_unchecked(&osb->alloc_stats.moves);
66682
66683 bail:
66684 if (handle)
66685 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
66686 index bbec539..7b266d5 100644
66687 --- a/fs/ocfs2/ocfs2.h
66688 +++ b/fs/ocfs2/ocfs2.h
66689 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
66690
66691 struct ocfs2_alloc_stats
66692 {
66693 - atomic_t moves;
66694 - atomic_t local_data;
66695 - atomic_t bitmap_data;
66696 - atomic_t bg_allocs;
66697 - atomic_t bg_extends;
66698 + atomic_unchecked_t moves;
66699 + atomic_unchecked_t local_data;
66700 + atomic_unchecked_t bitmap_data;
66701 + atomic_unchecked_t bg_allocs;
66702 + atomic_unchecked_t bg_extends;
66703 };
66704
66705 enum ocfs2_local_alloc_state
66706 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
66707 index 0cb889a..6a26b24 100644
66708 --- a/fs/ocfs2/suballoc.c
66709 +++ b/fs/ocfs2/suballoc.c
66710 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
66711 mlog_errno(status);
66712 goto bail;
66713 }
66714 - atomic_inc(&osb->alloc_stats.bg_extends);
66715 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
66716
66717 /* You should never ask for this much metadata */
66718 BUG_ON(bits_wanted >
66719 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
66720 mlog_errno(status);
66721 goto bail;
66722 }
66723 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66724 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66725
66726 *suballoc_loc = res.sr_bg_blkno;
66727 *suballoc_bit_start = res.sr_bit_offset;
66728 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
66729 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
66730 res->sr_bits);
66731
66732 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66733 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66734
66735 BUG_ON(res->sr_bits != 1);
66736
66737 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
66738 mlog_errno(status);
66739 goto bail;
66740 }
66741 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66742 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
66743
66744 BUG_ON(res.sr_bits != 1);
66745
66746 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66747 cluster_start,
66748 num_clusters);
66749 if (!status)
66750 - atomic_inc(&osb->alloc_stats.local_data);
66751 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
66752 } else {
66753 if (min_clusters > (osb->bitmap_cpg - 1)) {
66754 /* The only paths asking for contiguousness
66755 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
66756 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
66757 res.sr_bg_blkno,
66758 res.sr_bit_offset);
66759 - atomic_inc(&osb->alloc_stats.bitmap_data);
66760 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
66761 *num_clusters = res.sr_bits;
66762 }
66763 }
66764 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
66765 index ddb662b..f701c83 100644
66766 --- a/fs/ocfs2/super.c
66767 +++ b/fs/ocfs2/super.c
66768 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
66769 "%10s => GlobalAllocs: %d LocalAllocs: %d "
66770 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
66771 "Stats",
66772 - atomic_read(&osb->alloc_stats.bitmap_data),
66773 - atomic_read(&osb->alloc_stats.local_data),
66774 - atomic_read(&osb->alloc_stats.bg_allocs),
66775 - atomic_read(&osb->alloc_stats.moves),
66776 - atomic_read(&osb->alloc_stats.bg_extends));
66777 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
66778 + atomic_read_unchecked(&osb->alloc_stats.local_data),
66779 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
66780 + atomic_read_unchecked(&osb->alloc_stats.moves),
66781 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
66782
66783 out += snprintf(buf + out, len - out,
66784 "%10s => State: %u Descriptor: %llu Size: %u bits "
66785 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
66786
66787 mutex_init(&osb->system_file_mutex);
66788
66789 - atomic_set(&osb->alloc_stats.moves, 0);
66790 - atomic_set(&osb->alloc_stats.local_data, 0);
66791 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
66792 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
66793 - atomic_set(&osb->alloc_stats.bg_extends, 0);
66794 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
66795 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
66796 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
66797 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
66798 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
66799
66800 /* Copy the blockcheck stats from the superblock probe */
66801 osb->osb_ecc_stats = *stats;
66802 diff --git a/fs/open.c b/fs/open.c
66803 index d6fd3ac..6ccf474 100644
66804 --- a/fs/open.c
66805 +++ b/fs/open.c
66806 @@ -32,6 +32,8 @@
66807 #include <linux/dnotify.h>
66808 #include <linux/compat.h>
66809
66810 +#define CREATE_TRACE_POINTS
66811 +#include <trace/events/fs.h>
66812 #include "internal.h"
66813
66814 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
66815 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
66816 error = locks_verify_truncate(inode, NULL, length);
66817 if (!error)
66818 error = security_path_truncate(path);
66819 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
66820 + error = -EACCES;
66821 if (!error)
66822 error = do_truncate(path->dentry, length, 0, NULL);
66823
66824 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
66825 error = locks_verify_truncate(inode, f.file, length);
66826 if (!error)
66827 error = security_path_truncate(&f.file->f_path);
66828 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
66829 + error = -EACCES;
66830 if (!error)
66831 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
66832 sb_end_write(inode->i_sb);
66833 @@ -380,6 +386,9 @@ retry:
66834 if (__mnt_is_readonly(path.mnt))
66835 res = -EROFS;
66836
66837 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
66838 + res = -EACCES;
66839 +
66840 out_path_release:
66841 path_put(&path);
66842 if (retry_estale(res, lookup_flags)) {
66843 @@ -411,6 +420,8 @@ retry:
66844 if (error)
66845 goto dput_and_out;
66846
66847 + gr_log_chdir(path.dentry, path.mnt);
66848 +
66849 set_fs_pwd(current->fs, &path);
66850
66851 dput_and_out:
66852 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
66853 goto out_putf;
66854
66855 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
66856 +
66857 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
66858 + error = -EPERM;
66859 +
66860 + if (!error)
66861 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
66862 +
66863 if (!error)
66864 set_fs_pwd(current->fs, &f.file->f_path);
66865 out_putf:
66866 @@ -469,7 +487,13 @@ retry:
66867 if (error)
66868 goto dput_and_out;
66869
66870 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
66871 + goto dput_and_out;
66872 +
66873 set_fs_root(current->fs, &path);
66874 +
66875 + gr_handle_chroot_chdir(&path);
66876 +
66877 error = 0;
66878 dput_and_out:
66879 path_put(&path);
66880 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
66881 return error;
66882 retry_deleg:
66883 mutex_lock(&inode->i_mutex);
66884 +
66885 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
66886 + error = -EACCES;
66887 + goto out_unlock;
66888 + }
66889 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
66890 + error = -EACCES;
66891 + goto out_unlock;
66892 + }
66893 +
66894 error = security_path_chmod(path, mode);
66895 if (error)
66896 goto out_unlock;
66897 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
66898 uid = make_kuid(current_user_ns(), user);
66899 gid = make_kgid(current_user_ns(), group);
66900
66901 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
66902 + return -EACCES;
66903 +
66904 newattrs.ia_valid = ATTR_CTIME;
66905 if (user != (uid_t) -1) {
66906 if (!uid_valid(uid))
66907 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
66908 } else {
66909 fsnotify_open(f);
66910 fd_install(fd, f);
66911 + trace_do_sys_open(tmp->name, flags, mode);
66912 }
66913 }
66914 putname(tmp);
66915 diff --git a/fs/pipe.c b/fs/pipe.c
66916 index 21981e5..3d5f55c 100644
66917 --- a/fs/pipe.c
66918 +++ b/fs/pipe.c
66919 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
66920
66921 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
66922 {
66923 - if (pipe->files)
66924 + if (atomic_read(&pipe->files))
66925 mutex_lock_nested(&pipe->mutex, subclass);
66926 }
66927
66928 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
66929
66930 void pipe_unlock(struct pipe_inode_info *pipe)
66931 {
66932 - if (pipe->files)
66933 + if (atomic_read(&pipe->files))
66934 mutex_unlock(&pipe->mutex);
66935 }
66936 EXPORT_SYMBOL(pipe_unlock);
66937 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
66938 }
66939 if (bufs) /* More to do? */
66940 continue;
66941 - if (!pipe->writers)
66942 + if (!atomic_read(&pipe->writers))
66943 break;
66944 - if (!pipe->waiting_writers) {
66945 + if (!atomic_read(&pipe->waiting_writers)) {
66946 /* syscall merging: Usually we must not sleep
66947 * if O_NONBLOCK is set, or if we got some data.
66948 * But if a writer sleeps in kernel space, then
66949 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66950
66951 __pipe_lock(pipe);
66952
66953 - if (!pipe->readers) {
66954 + if (!atomic_read(&pipe->readers)) {
66955 send_sig(SIGPIPE, current, 0);
66956 ret = -EPIPE;
66957 goto out;
66958 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66959 for (;;) {
66960 int bufs;
66961
66962 - if (!pipe->readers) {
66963 + if (!atomic_read(&pipe->readers)) {
66964 send_sig(SIGPIPE, current, 0);
66965 if (!ret)
66966 ret = -EPIPE;
66967 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
66968 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
66969 do_wakeup = 0;
66970 }
66971 - pipe->waiting_writers++;
66972 + atomic_inc(&pipe->waiting_writers);
66973 pipe_wait(pipe);
66974 - pipe->waiting_writers--;
66975 + atomic_dec(&pipe->waiting_writers);
66976 }
66977 out:
66978 __pipe_unlock(pipe);
66979 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66980 mask = 0;
66981 if (filp->f_mode & FMODE_READ) {
66982 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
66983 - if (!pipe->writers && filp->f_version != pipe->w_counter)
66984 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
66985 mask |= POLLHUP;
66986 }
66987
66988 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
66989 * Most Unices do not set POLLERR for FIFOs but on Linux they
66990 * behave exactly like pipes for poll().
66991 */
66992 - if (!pipe->readers)
66993 + if (!atomic_read(&pipe->readers))
66994 mask |= POLLERR;
66995 }
66996
66997 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
66998 int kill = 0;
66999
67000 spin_lock(&inode->i_lock);
67001 - if (!--pipe->files) {
67002 + if (atomic_dec_and_test(&pipe->files)) {
67003 inode->i_pipe = NULL;
67004 kill = 1;
67005 }
67006 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
67007
67008 __pipe_lock(pipe);
67009 if (file->f_mode & FMODE_READ)
67010 - pipe->readers--;
67011 + atomic_dec(&pipe->readers);
67012 if (file->f_mode & FMODE_WRITE)
67013 - pipe->writers--;
67014 + atomic_dec(&pipe->writers);
67015
67016 - if (pipe->readers || pipe->writers) {
67017 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
67018 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
67019 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
67020 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
67021 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
67022 kfree(pipe);
67023 }
67024
67025 -static struct vfsmount *pipe_mnt __read_mostly;
67026 +struct vfsmount *pipe_mnt __read_mostly;
67027
67028 /*
67029 * pipefs_dname() is called from d_path().
67030 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
67031 goto fail_iput;
67032
67033 inode->i_pipe = pipe;
67034 - pipe->files = 2;
67035 - pipe->readers = pipe->writers = 1;
67036 + atomic_set(&pipe->files, 2);
67037 + atomic_set(&pipe->readers, 1);
67038 + atomic_set(&pipe->writers, 1);
67039 inode->i_fop = &pipefifo_fops;
67040
67041 /*
67042 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
67043 spin_lock(&inode->i_lock);
67044 if (inode->i_pipe) {
67045 pipe = inode->i_pipe;
67046 - pipe->files++;
67047 + atomic_inc(&pipe->files);
67048 spin_unlock(&inode->i_lock);
67049 } else {
67050 spin_unlock(&inode->i_lock);
67051 pipe = alloc_pipe_info();
67052 if (!pipe)
67053 return -ENOMEM;
67054 - pipe->files = 1;
67055 + atomic_set(&pipe->files, 1);
67056 spin_lock(&inode->i_lock);
67057 if (unlikely(inode->i_pipe)) {
67058 - inode->i_pipe->files++;
67059 + atomic_inc(&inode->i_pipe->files);
67060 spin_unlock(&inode->i_lock);
67061 free_pipe_info(pipe);
67062 pipe = inode->i_pipe;
67063 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
67064 * opened, even when there is no process writing the FIFO.
67065 */
67066 pipe->r_counter++;
67067 - if (pipe->readers++ == 0)
67068 + if (atomic_inc_return(&pipe->readers) == 1)
67069 wake_up_partner(pipe);
67070
67071 - if (!is_pipe && !pipe->writers) {
67072 + if (!is_pipe && !atomic_read(&pipe->writers)) {
67073 if ((filp->f_flags & O_NONBLOCK)) {
67074 /* suppress POLLHUP until we have
67075 * seen a writer */
67076 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
67077 * errno=ENXIO when there is no process reading the FIFO.
67078 */
67079 ret = -ENXIO;
67080 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
67081 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
67082 goto err;
67083
67084 pipe->w_counter++;
67085 - if (!pipe->writers++)
67086 + if (atomic_inc_return(&pipe->writers) == 1)
67087 wake_up_partner(pipe);
67088
67089 - if (!is_pipe && !pipe->readers) {
67090 + if (!is_pipe && !atomic_read(&pipe->readers)) {
67091 if (wait_for_partner(pipe, &pipe->r_counter))
67092 goto err_wr;
67093 }
67094 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
67095 * the process can at least talk to itself.
67096 */
67097
67098 - pipe->readers++;
67099 - pipe->writers++;
67100 + atomic_inc(&pipe->readers);
67101 + atomic_inc(&pipe->writers);
67102 pipe->r_counter++;
67103 pipe->w_counter++;
67104 - if (pipe->readers == 1 || pipe->writers == 1)
67105 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
67106 wake_up_partner(pipe);
67107 break;
67108
67109 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
67110 return 0;
67111
67112 err_rd:
67113 - if (!--pipe->readers)
67114 + if (atomic_dec_and_test(&pipe->readers))
67115 wake_up_interruptible(&pipe->wait);
67116 ret = -ERESTARTSYS;
67117 goto err;
67118
67119 err_wr:
67120 - if (!--pipe->writers)
67121 + if (atomic_dec_and_test(&pipe->writers))
67122 wake_up_interruptible(&pipe->wait);
67123 ret = -ERESTARTSYS;
67124 goto err;
67125 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
67126 index 0855f77..6787d50 100644
67127 --- a/fs/posix_acl.c
67128 +++ b/fs/posix_acl.c
67129 @@ -20,6 +20,7 @@
67130 #include <linux/xattr.h>
67131 #include <linux/export.h>
67132 #include <linux/user_namespace.h>
67133 +#include <linux/grsecurity.h>
67134
67135 struct posix_acl **acl_by_type(struct inode *inode, int type)
67136 {
67137 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
67138 }
67139 }
67140 if (mode_p)
67141 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
67142 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
67143 return not_equiv;
67144 }
67145 EXPORT_SYMBOL(posix_acl_equiv_mode);
67146 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
67147 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
67148 }
67149
67150 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
67151 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
67152 return not_equiv;
67153 }
67154
67155 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
67156 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
67157 int err = -ENOMEM;
67158 if (clone) {
67159 + *mode_p &= ~gr_acl_umask();
67160 +
67161 err = posix_acl_create_masq(clone, mode_p);
67162 if (err < 0) {
67163 posix_acl_release(clone);
67164 @@ -659,11 +662,12 @@ struct posix_acl *
67165 posix_acl_from_xattr(struct user_namespace *user_ns,
67166 const void *value, size_t size)
67167 {
67168 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
67169 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
67170 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
67171 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
67172 int count;
67173 struct posix_acl *acl;
67174 struct posix_acl_entry *acl_e;
67175 + umode_t umask = gr_acl_umask();
67176
67177 if (!value)
67178 return NULL;
67179 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
67180
67181 switch(acl_e->e_tag) {
67182 case ACL_USER_OBJ:
67183 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
67184 + break;
67185 case ACL_GROUP_OBJ:
67186 case ACL_MASK:
67187 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
67188 + break;
67189 case ACL_OTHER:
67190 + acl_e->e_perm &= ~(umask & S_IRWXO);
67191 break;
67192
67193 case ACL_USER:
67194 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
67195 acl_e->e_uid =
67196 make_kuid(user_ns,
67197 le32_to_cpu(entry->e_id));
67198 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
67199 goto fail;
67200 break;
67201 case ACL_GROUP:
67202 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
67203 acl_e->e_gid =
67204 make_kgid(user_ns,
67205 le32_to_cpu(entry->e_id));
67206 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
67207 index 2183fcf..3c32a98 100644
67208 --- a/fs/proc/Kconfig
67209 +++ b/fs/proc/Kconfig
67210 @@ -30,7 +30,7 @@ config PROC_FS
67211
67212 config PROC_KCORE
67213 bool "/proc/kcore support" if !ARM
67214 - depends on PROC_FS && MMU
67215 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
67216 help
67217 Provides a virtual ELF core file of the live kernel. This can
67218 be read with gdb and other ELF tools. No modifications can be
67219 @@ -38,8 +38,8 @@ config PROC_KCORE
67220
67221 config PROC_VMCORE
67222 bool "/proc/vmcore support"
67223 - depends on PROC_FS && CRASH_DUMP
67224 - default y
67225 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
67226 + default n
67227 help
67228 Exports the dump image of crashed kernel in ELF format.
67229
67230 @@ -63,8 +63,8 @@ config PROC_SYSCTL
67231 limited in memory.
67232
67233 config PROC_PAGE_MONITOR
67234 - default y
67235 - depends on PROC_FS && MMU
67236 + default n
67237 + depends on PROC_FS && MMU && !GRKERNSEC
67238 bool "Enable /proc page monitoring" if EXPERT
67239 help
67240 Various /proc files exist to monitor process memory utilization:
67241 diff --git a/fs/proc/array.c b/fs/proc/array.c
67242 index 64db2bc..a8185d6 100644
67243 --- a/fs/proc/array.c
67244 +++ b/fs/proc/array.c
67245 @@ -60,6 +60,7 @@
67246 #include <linux/tty.h>
67247 #include <linux/string.h>
67248 #include <linux/mman.h>
67249 +#include <linux/grsecurity.h>
67250 #include <linux/proc_fs.h>
67251 #include <linux/ioport.h>
67252 #include <linux/uaccess.h>
67253 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
67254 seq_putc(m, '\n');
67255 }
67256
67257 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67258 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
67259 +{
67260 + if (p->mm)
67261 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
67262 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
67263 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
67264 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
67265 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
67266 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
67267 + else
67268 + seq_printf(m, "PaX:\t-----\n");
67269 +}
67270 +#endif
67271 +
67272 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
67273 struct pid *pid, struct task_struct *task)
67274 {
67275 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
67276 task_cpus_allowed(m, task);
67277 cpuset_task_status_allowed(m, task);
67278 task_context_switch_counts(m, task);
67279 +
67280 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67281 + task_pax(m, task);
67282 +#endif
67283 +
67284 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
67285 + task_grsec_rbac(m, task);
67286 +#endif
67287 +
67288 return 0;
67289 }
67290
67291 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67292 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67293 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67294 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67295 +#endif
67296 +
67297 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
67298 struct pid *pid, struct task_struct *task, int whole)
67299 {
67300 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
67301 char tcomm[sizeof(task->comm)];
67302 unsigned long flags;
67303
67304 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67305 + if (current->exec_id != m->exec_id) {
67306 + gr_log_badprocpid("stat");
67307 + return 0;
67308 + }
67309 +#endif
67310 +
67311 state = *get_task_state(task);
67312 vsize = eip = esp = 0;
67313 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
67314 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
67315 gtime = task_gtime(task);
67316 }
67317
67318 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67319 + if (PAX_RAND_FLAGS(mm)) {
67320 + eip = 0;
67321 + esp = 0;
67322 + wchan = 0;
67323 + }
67324 +#endif
67325 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67326 + wchan = 0;
67327 + eip =0;
67328 + esp =0;
67329 +#endif
67330 +
67331 /* scale priority and nice values from timeslices to -20..20 */
67332 /* to make it look like a "normal" Unix priority/nice value */
67333 priority = task_prio(task);
67334 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
67335 seq_put_decimal_ull(m, ' ', vsize);
67336 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
67337 seq_put_decimal_ull(m, ' ', rsslim);
67338 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67339 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
67340 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
67341 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
67342 +#else
67343 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
67344 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
67345 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
67346 +#endif
67347 seq_put_decimal_ull(m, ' ', esp);
67348 seq_put_decimal_ull(m, ' ', eip);
67349 /* The signal information here is obsolete.
67350 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
67351 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
67352 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
67353
67354 - if (mm && permitted) {
67355 + if (mm && permitted
67356 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67357 + && !PAX_RAND_FLAGS(mm)
67358 +#endif
67359 + ) {
67360 seq_put_decimal_ull(m, ' ', mm->start_data);
67361 seq_put_decimal_ull(m, ' ', mm->end_data);
67362 seq_put_decimal_ull(m, ' ', mm->start_brk);
67363 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
67364 struct pid *pid, struct task_struct *task)
67365 {
67366 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
67367 - struct mm_struct *mm = get_task_mm(task);
67368 + struct mm_struct *mm;
67369
67370 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67371 + if (current->exec_id != m->exec_id) {
67372 + gr_log_badprocpid("statm");
67373 + return 0;
67374 + }
67375 +#endif
67376 + mm = get_task_mm(task);
67377 if (mm) {
67378 size = task_statm(mm, &shared, &text, &data, &resident);
67379 mmput(mm);
67380 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
67381 return 0;
67382 }
67383
67384 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67385 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
67386 +{
67387 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
67388 +}
67389 +#endif
67390 +
67391 #ifdef CONFIG_CHECKPOINT_RESTORE
67392 static struct pid *
67393 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
67394 diff --git a/fs/proc/base.c b/fs/proc/base.c
67395 index 2d696b0..b9da447 100644
67396 --- a/fs/proc/base.c
67397 +++ b/fs/proc/base.c
67398 @@ -113,6 +113,14 @@ struct pid_entry {
67399 union proc_op op;
67400 };
67401
67402 +struct getdents_callback {
67403 + struct linux_dirent __user * current_dir;
67404 + struct linux_dirent __user * previous;
67405 + struct file * file;
67406 + int count;
67407 + int error;
67408 +};
67409 +
67410 #define NOD(NAME, MODE, IOP, FOP, OP) { \
67411 .name = (NAME), \
67412 .len = sizeof(NAME) - 1, \
67413 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
67414 return get_cmdline(task, buffer, PAGE_SIZE);
67415 }
67416
67417 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67418 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67419 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67420 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67421 +#endif
67422 +
67423 static int proc_pid_auxv(struct task_struct *task, char *buffer)
67424 {
67425 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
67426 int res = PTR_ERR(mm);
67427 if (mm && !IS_ERR(mm)) {
67428 unsigned int nwords = 0;
67429 +
67430 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67431 + /* allow if we're currently ptracing this task */
67432 + if (PAX_RAND_FLAGS(mm) &&
67433 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
67434 + mmput(mm);
67435 + return 0;
67436 + }
67437 +#endif
67438 +
67439 do {
67440 nwords += 2;
67441 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
67442 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
67443 }
67444
67445
67446 -#ifdef CONFIG_KALLSYMS
67447 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67448 /*
67449 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
67450 * Returns the resolved symbol. If that fails, simply return the address.
67451 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
67452 mutex_unlock(&task->signal->cred_guard_mutex);
67453 }
67454
67455 -#ifdef CONFIG_STACKTRACE
67456 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67457
67458 #define MAX_STACK_TRACE_DEPTH 64
67459
67460 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
67461 return count;
67462 }
67463
67464 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67465 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67466 static int proc_pid_syscall(struct task_struct *task, char *buffer)
67467 {
67468 long nr;
67469 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
67470 /************************************************************************/
67471
67472 /* permission checks */
67473 -static int proc_fd_access_allowed(struct inode *inode)
67474 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
67475 {
67476 struct task_struct *task;
67477 int allowed = 0;
67478 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
67479 */
67480 task = get_proc_task(inode);
67481 if (task) {
67482 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
67483 + if (log)
67484 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
67485 + else
67486 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
67487 put_task_struct(task);
67488 }
67489 return allowed;
67490 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
67491 struct task_struct *task,
67492 int hide_pid_min)
67493 {
67494 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67495 + return false;
67496 +
67497 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67498 + rcu_read_lock();
67499 + {
67500 + const struct cred *tmpcred = current_cred();
67501 + const struct cred *cred = __task_cred(task);
67502 +
67503 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
67504 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67505 + || in_group_p(grsec_proc_gid)
67506 +#endif
67507 + ) {
67508 + rcu_read_unlock();
67509 + return true;
67510 + }
67511 + }
67512 + rcu_read_unlock();
67513 +
67514 + if (!pid->hide_pid)
67515 + return false;
67516 +#endif
67517 +
67518 if (pid->hide_pid < hide_pid_min)
67519 return true;
67520 if (in_group_p(pid->pid_gid))
67521 return true;
67522 +
67523 return ptrace_may_access(task, PTRACE_MODE_READ);
67524 }
67525
67526 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
67527 put_task_struct(task);
67528
67529 if (!has_perms) {
67530 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67531 + {
67532 +#else
67533 if (pid->hide_pid == 2) {
67534 +#endif
67535 /*
67536 * Let's make getdents(), stat(), and open()
67537 * consistent with each other. If a process
67538 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
67539 if (!task)
67540 return -ESRCH;
67541
67542 + if (gr_acl_handle_procpidmem(task)) {
67543 + put_task_struct(task);
67544 + return -EPERM;
67545 + }
67546 +
67547 mm = mm_access(task, mode);
67548 put_task_struct(task);
67549
67550 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
67551
67552 file->private_data = mm;
67553
67554 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67555 + file->f_version = current->exec_id;
67556 +#endif
67557 +
67558 return 0;
67559 }
67560
67561 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
67562 ssize_t copied;
67563 char *page;
67564
67565 +#ifdef CONFIG_GRKERNSEC
67566 + if (write)
67567 + return -EPERM;
67568 +#endif
67569 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67570 + if (file->f_version != current->exec_id) {
67571 + gr_log_badprocpid("mem");
67572 + return 0;
67573 + }
67574 +#endif
67575 +
67576 if (!mm)
67577 return 0;
67578
67579 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
67580 goto free;
67581
67582 while (count > 0) {
67583 - int this_len = min_t(int, count, PAGE_SIZE);
67584 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
67585
67586 if (write && copy_from_user(page, buf, this_len)) {
67587 copied = -EFAULT;
67588 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
67589 if (!mm)
67590 return 0;
67591
67592 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67593 + if (file->f_version != current->exec_id) {
67594 + gr_log_badprocpid("environ");
67595 + return 0;
67596 + }
67597 +#endif
67598 +
67599 page = (char *)__get_free_page(GFP_TEMPORARY);
67600 if (!page)
67601 return -ENOMEM;
67602 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
67603 goto free;
67604 while (count > 0) {
67605 size_t this_len, max_len;
67606 - int retval;
67607 + ssize_t retval;
67608
67609 if (src >= (mm->env_end - mm->env_start))
67610 break;
67611 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
67612 int error = -EACCES;
67613
67614 /* Are we allowed to snoop on the tasks file descriptors? */
67615 - if (!proc_fd_access_allowed(inode))
67616 + if (!proc_fd_access_allowed(inode, 0))
67617 goto out;
67618
67619 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67620 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
67621 struct path path;
67622
67623 /* Are we allowed to snoop on the tasks file descriptors? */
67624 - if (!proc_fd_access_allowed(inode))
67625 - goto out;
67626 + /* logging this is needed for learning on chromium to work properly,
67627 + but we don't want to flood the logs from 'ps' which does a readlink
67628 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
67629 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
67630 + */
67631 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
67632 + if (!proc_fd_access_allowed(inode,0))
67633 + goto out;
67634 + } else {
67635 + if (!proc_fd_access_allowed(inode,1))
67636 + goto out;
67637 + }
67638
67639 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
67640 if (error)
67641 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
67642 rcu_read_lock();
67643 cred = __task_cred(task);
67644 inode->i_uid = cred->euid;
67645 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67646 + inode->i_gid = grsec_proc_gid;
67647 +#else
67648 inode->i_gid = cred->egid;
67649 +#endif
67650 rcu_read_unlock();
67651 }
67652 security_task_to_inode(task, inode);
67653 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
67654 return -ENOENT;
67655 }
67656 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67657 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67658 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67659 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67660 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67661 +#endif
67662 task_dumpable(task)) {
67663 cred = __task_cred(task);
67664 stat->uid = cred->euid;
67665 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67666 + stat->gid = grsec_proc_gid;
67667 +#else
67668 stat->gid = cred->egid;
67669 +#endif
67670 }
67671 }
67672 rcu_read_unlock();
67673 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
67674
67675 if (task) {
67676 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
67677 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67678 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
67679 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67680 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
67681 +#endif
67682 task_dumpable(task)) {
67683 rcu_read_lock();
67684 cred = __task_cred(task);
67685 inode->i_uid = cred->euid;
67686 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67687 + inode->i_gid = grsec_proc_gid;
67688 +#else
67689 inode->i_gid = cred->egid;
67690 +#endif
67691 rcu_read_unlock();
67692 } else {
67693 inode->i_uid = GLOBAL_ROOT_UID;
67694 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
67695 if (!task)
67696 goto out_no_task;
67697
67698 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67699 + goto out;
67700 +
67701 /*
67702 * Yes, it does not scale. And it should not. Don't add
67703 * new entries into /proc/<tgid>/ without very good reasons.
67704 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
67705 if (!task)
67706 return -ENOENT;
67707
67708 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67709 + goto out;
67710 +
67711 if (!dir_emit_dots(file, ctx))
67712 goto out;
67713
67714 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
67715 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
67716 #endif
67717 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67718 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67719 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67720 INF("syscall", S_IRUSR, proc_pid_syscall),
67721 #endif
67722 INF("cmdline", S_IRUGO, proc_pid_cmdline),
67723 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
67724 #ifdef CONFIG_SECURITY
67725 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67726 #endif
67727 -#ifdef CONFIG_KALLSYMS
67728 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67729 INF("wchan", S_IRUGO, proc_pid_wchan),
67730 #endif
67731 -#ifdef CONFIG_STACKTRACE
67732 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67733 ONE("stack", S_IRUSR, proc_pid_stack),
67734 #endif
67735 #ifdef CONFIG_SCHEDSTATS
67736 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
67737 #ifdef CONFIG_HARDWALL
67738 INF("hardwall", S_IRUGO, proc_pid_hardwall),
67739 #endif
67740 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
67741 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
67742 +#endif
67743 #ifdef CONFIG_USER_NS
67744 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
67745 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
67746 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
67747 if (!inode)
67748 goto out;
67749
67750 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67751 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
67752 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67753 + inode->i_gid = grsec_proc_gid;
67754 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
67755 +#else
67756 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
67757 +#endif
67758 inode->i_op = &proc_tgid_base_inode_operations;
67759 inode->i_fop = &proc_tgid_base_operations;
67760 inode->i_flags|=S_IMMUTABLE;
67761 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
67762 if (!task)
67763 goto out;
67764
67765 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
67766 + goto out_put_task;
67767 +
67768 result = proc_pid_instantiate(dir, dentry, task, NULL);
67769 +out_put_task:
67770 put_task_struct(task);
67771 out:
67772 return ERR_PTR(result);
67773 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
67774 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
67775 #endif
67776 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
67777 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
67778 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
67779 INF("syscall", S_IRUSR, proc_pid_syscall),
67780 #endif
67781 INF("cmdline", S_IRUGO, proc_pid_cmdline),
67782 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
67783 #ifdef CONFIG_SECURITY
67784 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
67785 #endif
67786 -#ifdef CONFIG_KALLSYMS
67787 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67788 INF("wchan", S_IRUGO, proc_pid_wchan),
67789 #endif
67790 -#ifdef CONFIG_STACKTRACE
67791 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67792 ONE("stack", S_IRUSR, proc_pid_stack),
67793 #endif
67794 #ifdef CONFIG_SCHEDSTATS
67795 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
67796 index cbd82df..c0407d2 100644
67797 --- a/fs/proc/cmdline.c
67798 +++ b/fs/proc/cmdline.c
67799 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
67800
67801 static int __init proc_cmdline_init(void)
67802 {
67803 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67804 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
67805 +#else
67806 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
67807 +#endif
67808 return 0;
67809 }
67810 fs_initcall(proc_cmdline_init);
67811 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
67812 index 50493ed..248166b 100644
67813 --- a/fs/proc/devices.c
67814 +++ b/fs/proc/devices.c
67815 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
67816
67817 static int __init proc_devices_init(void)
67818 {
67819 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67820 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
67821 +#else
67822 proc_create("devices", 0, NULL, &proc_devinfo_operations);
67823 +#endif
67824 return 0;
67825 }
67826 fs_initcall(proc_devices_init);
67827 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
67828 index 0788d09..9cc1385 100644
67829 --- a/fs/proc/fd.c
67830 +++ b/fs/proc/fd.c
67831 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
67832 if (!task)
67833 return -ENOENT;
67834
67835 - files = get_files_struct(task);
67836 + if (!gr_acl_handle_procpidmem(task))
67837 + files = get_files_struct(task);
67838 put_task_struct(task);
67839
67840 if (files) {
67841 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
67842 */
67843 int proc_fd_permission(struct inode *inode, int mask)
67844 {
67845 + struct task_struct *task;
67846 int rv = generic_permission(inode, mask);
67847 - if (rv == 0)
67848 - return 0;
67849 +
67850 if (task_tgid(current) == proc_pid(inode))
67851 rv = 0;
67852 +
67853 + task = get_proc_task(inode);
67854 + if (task == NULL)
67855 + return rv;
67856 +
67857 + if (gr_acl_handle_procpidmem(task))
67858 + rv = -EACCES;
67859 +
67860 + put_task_struct(task);
67861 +
67862 return rv;
67863 }
67864
67865 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
67866 index b7f268e..3bea6b7 100644
67867 --- a/fs/proc/generic.c
67868 +++ b/fs/proc/generic.c
67869 @@ -23,6 +23,7 @@
67870 #include <linux/bitops.h>
67871 #include <linux/spinlock.h>
67872 #include <linux/completion.h>
67873 +#include <linux/grsecurity.h>
67874 #include <asm/uaccess.h>
67875
67876 #include "internal.h"
67877 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
67878 return proc_lookup_de(PDE(dir), dir, dentry);
67879 }
67880
67881 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
67882 + unsigned int flags)
67883 +{
67884 + if (gr_proc_is_restricted())
67885 + return ERR_PTR(-EACCES);
67886 +
67887 + return proc_lookup_de(PDE(dir), dir, dentry);
67888 +}
67889 +
67890 /*
67891 * This returns non-zero if at EOF, so that the /proc
67892 * root directory can use this and check if it should
67893 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
67894 return proc_readdir_de(PDE(inode), file, ctx);
67895 }
67896
67897 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
67898 +{
67899 + struct inode *inode = file_inode(file);
67900 +
67901 + if (gr_proc_is_restricted())
67902 + return -EACCES;
67903 +
67904 + return proc_readdir_de(PDE(inode), file, ctx);
67905 +}
67906 +
67907 /*
67908 * These are the generic /proc directory operations. They
67909 * use the in-memory "struct proc_dir_entry" tree to parse
67910 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
67911 .iterate = proc_readdir,
67912 };
67913
67914 +static const struct file_operations proc_dir_restricted_operations = {
67915 + .llseek = generic_file_llseek,
67916 + .read = generic_read_dir,
67917 + .iterate = proc_readdir_restrict,
67918 +};
67919 +
67920 /*
67921 * proc directories can do almost nothing..
67922 */
67923 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
67924 .setattr = proc_notify_change,
67925 };
67926
67927 +static const struct inode_operations proc_dir_restricted_inode_operations = {
67928 + .lookup = proc_lookup_restrict,
67929 + .getattr = proc_getattr,
67930 + .setattr = proc_notify_change,
67931 +};
67932 +
67933 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
67934 {
67935 struct proc_dir_entry *tmp;
67936 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
67937 return ret;
67938
67939 if (S_ISDIR(dp->mode)) {
67940 - dp->proc_fops = &proc_dir_operations;
67941 - dp->proc_iops = &proc_dir_inode_operations;
67942 + if (dp->restricted) {
67943 + dp->proc_fops = &proc_dir_restricted_operations;
67944 + dp->proc_iops = &proc_dir_restricted_inode_operations;
67945 + } else {
67946 + dp->proc_fops = &proc_dir_operations;
67947 + dp->proc_iops = &proc_dir_inode_operations;
67948 + }
67949 dir->nlink++;
67950 } else if (S_ISLNK(dp->mode)) {
67951 dp->proc_iops = &proc_link_inode_operations;
67952 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
67953 }
67954 EXPORT_SYMBOL_GPL(proc_mkdir_data);
67955
67956 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
67957 + struct proc_dir_entry *parent, void *data)
67958 +{
67959 + struct proc_dir_entry *ent;
67960 +
67961 + if (mode == 0)
67962 + mode = S_IRUGO | S_IXUGO;
67963 +
67964 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
67965 + if (ent) {
67966 + ent->data = data;
67967 + ent->restricted = 1;
67968 + if (proc_register(parent, ent) < 0) {
67969 + kfree(ent);
67970 + ent = NULL;
67971 + }
67972 + }
67973 + return ent;
67974 +}
67975 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
67976 +
67977 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
67978 struct proc_dir_entry *parent)
67979 {
67980 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
67981 }
67982 EXPORT_SYMBOL(proc_mkdir);
67983
67984 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
67985 + struct proc_dir_entry *parent)
67986 +{
67987 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
67988 +}
67989 +EXPORT_SYMBOL(proc_mkdir_restrict);
67990 +
67991 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
67992 struct proc_dir_entry *parent,
67993 const struct file_operations *proc_fops,
67994 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
67995 index 0adbc02..bee4d0b 100644
67996 --- a/fs/proc/inode.c
67997 +++ b/fs/proc/inode.c
67998 @@ -23,11 +23,17 @@
67999 #include <linux/slab.h>
68000 #include <linux/mount.h>
68001 #include <linux/magic.h>
68002 +#include <linux/grsecurity.h>
68003
68004 #include <asm/uaccess.h>
68005
68006 #include "internal.h"
68007
68008 +#ifdef CONFIG_PROC_SYSCTL
68009 +extern const struct inode_operations proc_sys_inode_operations;
68010 +extern const struct inode_operations proc_sys_dir_operations;
68011 +#endif
68012 +
68013 static void proc_evict_inode(struct inode *inode)
68014 {
68015 struct proc_dir_entry *de;
68016 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
68017 ns = PROC_I(inode)->ns.ns;
68018 if (ns_ops && ns)
68019 ns_ops->put(ns);
68020 +
68021 +#ifdef CONFIG_PROC_SYSCTL
68022 + if (inode->i_op == &proc_sys_inode_operations ||
68023 + inode->i_op == &proc_sys_dir_operations)
68024 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
68025 +#endif
68026 +
68027 }
68028
68029 static struct kmem_cache * proc_inode_cachep;
68030 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
68031 if (de->mode) {
68032 inode->i_mode = de->mode;
68033 inode->i_uid = de->uid;
68034 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68035 + inode->i_gid = grsec_proc_gid;
68036 +#else
68037 inode->i_gid = de->gid;
68038 +#endif
68039 }
68040 if (de->size)
68041 inode->i_size = de->size;
68042 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
68043 index 3ab6d14..b26174e 100644
68044 --- a/fs/proc/internal.h
68045 +++ b/fs/proc/internal.h
68046 @@ -46,9 +46,10 @@ struct proc_dir_entry {
68047 struct completion *pde_unload_completion;
68048 struct list_head pde_openers; /* who did ->open, but not ->release */
68049 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
68050 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
68051 u8 namelen;
68052 char name[];
68053 -};
68054 +} __randomize_layout;
68055
68056 union proc_op {
68057 int (*proc_get_link)(struct dentry *, struct path *);
68058 @@ -67,7 +68,7 @@ struct proc_inode {
68059 struct ctl_table *sysctl_entry;
68060 struct proc_ns ns;
68061 struct inode vfs_inode;
68062 -};
68063 +} __randomize_layout;
68064
68065 /*
68066 * General functions
68067 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
68068 struct pid *, struct task_struct *);
68069 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
68070 struct pid *, struct task_struct *);
68071 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
68072 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
68073 +#endif
68074
68075 /*
68076 * base.c
68077 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
68078 extern spinlock_t proc_subdir_lock;
68079
68080 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
68081 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
68082 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
68083 struct dentry *);
68084 extern int proc_readdir(struct file *, struct dir_context *);
68085 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
68086 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
68087
68088 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
68089 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
68090 index a352d57..cb94a5c 100644
68091 --- a/fs/proc/interrupts.c
68092 +++ b/fs/proc/interrupts.c
68093 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
68094
68095 static int __init proc_interrupts_init(void)
68096 {
68097 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68098 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
68099 +#else
68100 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
68101 +#endif
68102 return 0;
68103 }
68104 fs_initcall(proc_interrupts_init);
68105 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
68106 index 39e6ef3..2f9cb5e 100644
68107 --- a/fs/proc/kcore.c
68108 +++ b/fs/proc/kcore.c
68109 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
68110 * the addresses in the elf_phdr on our list.
68111 */
68112 start = kc_offset_to_vaddr(*fpos - elf_buflen);
68113 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
68114 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
68115 + if (tsz > buflen)
68116 tsz = buflen;
68117 -
68118 +
68119 while (buflen) {
68120 struct kcore_list *m;
68121
68122 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
68123 kfree(elf_buf);
68124 } else {
68125 if (kern_addr_valid(start)) {
68126 - unsigned long n;
68127 + char *elf_buf;
68128 + mm_segment_t oldfs;
68129
68130 - n = copy_to_user(buffer, (char *)start, tsz);
68131 - /*
68132 - * We cannot distinguish between fault on source
68133 - * and fault on destination. When this happens
68134 - * we clear too and hope it will trigger the
68135 - * EFAULT again.
68136 - */
68137 - if (n) {
68138 - if (clear_user(buffer + tsz - n,
68139 - n))
68140 + elf_buf = kmalloc(tsz, GFP_KERNEL);
68141 + if (!elf_buf)
68142 + return -ENOMEM;
68143 + oldfs = get_fs();
68144 + set_fs(KERNEL_DS);
68145 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
68146 + set_fs(oldfs);
68147 + if (copy_to_user(buffer, elf_buf, tsz)) {
68148 + kfree(elf_buf);
68149 return -EFAULT;
68150 + }
68151 }
68152 + set_fs(oldfs);
68153 + kfree(elf_buf);
68154 } else {
68155 if (clear_user(buffer, tsz))
68156 return -EFAULT;
68157 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
68158
68159 static int open_kcore(struct inode *inode, struct file *filp)
68160 {
68161 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68162 + return -EPERM;
68163 +#endif
68164 if (!capable(CAP_SYS_RAWIO))
68165 return -EPERM;
68166 if (kcore_need_update)
68167 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
68168 index 7445af0..7c5113c 100644
68169 --- a/fs/proc/meminfo.c
68170 +++ b/fs/proc/meminfo.c
68171 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
68172 vmi.used >> 10,
68173 vmi.largest_chunk >> 10
68174 #ifdef CONFIG_MEMORY_FAILURE
68175 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
68176 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
68177 #endif
68178 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
68179 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
68180 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
68181 index d4a3574..b421ce9 100644
68182 --- a/fs/proc/nommu.c
68183 +++ b/fs/proc/nommu.c
68184 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
68185
68186 if (file) {
68187 seq_pad(m, ' ');
68188 - seq_path(m, &file->f_path, "");
68189 + seq_path(m, &file->f_path, "\n\\");
68190 }
68191
68192 seq_putc(m, '\n');
68193 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
68194 index 4677bb7..dad3045 100644
68195 --- a/fs/proc/proc_net.c
68196 +++ b/fs/proc/proc_net.c
68197 @@ -23,9 +23,27 @@
68198 #include <linux/nsproxy.h>
68199 #include <net/net_namespace.h>
68200 #include <linux/seq_file.h>
68201 +#include <linux/grsecurity.h>
68202
68203 #include "internal.h"
68204
68205 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
68206 +static struct seq_operations *ipv6_seq_ops_addr;
68207 +
68208 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
68209 +{
68210 + ipv6_seq_ops_addr = addr;
68211 +}
68212 +
68213 +void unregister_ipv6_seq_ops_addr(void)
68214 +{
68215 + ipv6_seq_ops_addr = NULL;
68216 +}
68217 +
68218 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
68219 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
68220 +#endif
68221 +
68222 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
68223 {
68224 return pde->parent->data;
68225 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
68226 return maybe_get_net(PDE_NET(PDE(inode)));
68227 }
68228
68229 +extern const struct seq_operations dev_seq_ops;
68230 +
68231 int seq_open_net(struct inode *ino, struct file *f,
68232 const struct seq_operations *ops, int size)
68233 {
68234 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
68235
68236 BUG_ON(size < sizeof(*p));
68237
68238 + /* only permit access to /proc/net/dev */
68239 + if (
68240 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
68241 + ops != ipv6_seq_ops_addr &&
68242 +#endif
68243 + ops != &dev_seq_ops && gr_proc_is_restricted())
68244 + return -EACCES;
68245 +
68246 net = get_proc_net(ino);
68247 if (net == NULL)
68248 return -ENXIO;
68249 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
68250 int err;
68251 struct net *net;
68252
68253 + if (gr_proc_is_restricted())
68254 + return -EACCES;
68255 +
68256 err = -ENXIO;
68257 net = get_proc_net(inode);
68258 if (net == NULL)
68259 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
68260 index 7129046..6914844 100644
68261 --- a/fs/proc/proc_sysctl.c
68262 +++ b/fs/proc/proc_sysctl.c
68263 @@ -11,13 +11,21 @@
68264 #include <linux/namei.h>
68265 #include <linux/mm.h>
68266 #include <linux/module.h>
68267 +#include <linux/nsproxy.h>
68268 +#ifdef CONFIG_GRKERNSEC
68269 +#include <net/net_namespace.h>
68270 +#endif
68271 #include "internal.h"
68272
68273 +extern int gr_handle_chroot_sysctl(const int op);
68274 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
68275 + const int op);
68276 +
68277 static const struct dentry_operations proc_sys_dentry_operations;
68278 static const struct file_operations proc_sys_file_operations;
68279 -static const struct inode_operations proc_sys_inode_operations;
68280 +const struct inode_operations proc_sys_inode_operations;
68281 static const struct file_operations proc_sys_dir_file_operations;
68282 -static const struct inode_operations proc_sys_dir_operations;
68283 +const struct inode_operations proc_sys_dir_operations;
68284
68285 void proc_sys_poll_notify(struct ctl_table_poll *poll)
68286 {
68287 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
68288
68289 err = NULL;
68290 d_set_d_op(dentry, &proc_sys_dentry_operations);
68291 +
68292 + gr_handle_proc_create(dentry, inode);
68293 +
68294 d_add(dentry, inode);
68295
68296 out:
68297 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
68298 struct inode *inode = file_inode(filp);
68299 struct ctl_table_header *head = grab_header(inode);
68300 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
68301 + int op = write ? MAY_WRITE : MAY_READ;
68302 ssize_t error;
68303 size_t res;
68304
68305 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
68306 * and won't be until we finish.
68307 */
68308 error = -EPERM;
68309 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
68310 + if (sysctl_perm(head, table, op))
68311 goto out;
68312
68313 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
68314 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
68315 if (!table->proc_handler)
68316 goto out;
68317
68318 +#ifdef CONFIG_GRKERNSEC
68319 + error = -EPERM;
68320 + if (gr_handle_chroot_sysctl(op))
68321 + goto out;
68322 + dget(filp->f_path.dentry);
68323 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
68324 + dput(filp->f_path.dentry);
68325 + goto out;
68326 + }
68327 + dput(filp->f_path.dentry);
68328 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
68329 + goto out;
68330 + if (write) {
68331 + if (current->nsproxy->net_ns != table->extra2) {
68332 + if (!capable(CAP_SYS_ADMIN))
68333 + goto out;
68334 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
68335 + goto out;
68336 + }
68337 +#endif
68338 +
68339 /* careful: calling conventions are nasty here */
68340 res = count;
68341 error = table->proc_handler(table, write, buf, &res, ppos);
68342 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
68343 return false;
68344 } else {
68345 d_set_d_op(child, &proc_sys_dentry_operations);
68346 +
68347 + gr_handle_proc_create(child, inode);
68348 +
68349 d_add(child, inode);
68350 }
68351 } else {
68352 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
68353 if ((*pos)++ < ctx->pos)
68354 return true;
68355
68356 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
68357 + return 0;
68358 +
68359 if (unlikely(S_ISLNK(table->mode)))
68360 res = proc_sys_link_fill_cache(file, ctx, head, table);
68361 else
68362 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
68363 if (IS_ERR(head))
68364 return PTR_ERR(head);
68365
68366 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
68367 + return -ENOENT;
68368 +
68369 generic_fillattr(inode, stat);
68370 if (table)
68371 stat->mode = (stat->mode & S_IFMT) | table->mode;
68372 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
68373 .llseek = generic_file_llseek,
68374 };
68375
68376 -static const struct inode_operations proc_sys_inode_operations = {
68377 +const struct inode_operations proc_sys_inode_operations = {
68378 .permission = proc_sys_permission,
68379 .setattr = proc_sys_setattr,
68380 .getattr = proc_sys_getattr,
68381 };
68382
68383 -static const struct inode_operations proc_sys_dir_operations = {
68384 +const struct inode_operations proc_sys_dir_operations = {
68385 .lookup = proc_sys_lookup,
68386 .permission = proc_sys_permission,
68387 .setattr = proc_sys_setattr,
68388 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
68389 static struct ctl_dir *new_dir(struct ctl_table_set *set,
68390 const char *name, int namelen)
68391 {
68392 - struct ctl_table *table;
68393 + ctl_table_no_const *table;
68394 struct ctl_dir *new;
68395 struct ctl_node *node;
68396 char *new_name;
68397 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
68398 return NULL;
68399
68400 node = (struct ctl_node *)(new + 1);
68401 - table = (struct ctl_table *)(node + 1);
68402 + table = (ctl_table_no_const *)(node + 1);
68403 new_name = (char *)(table + 2);
68404 memcpy(new_name, name, namelen);
68405 new_name[namelen] = '\0';
68406 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
68407 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
68408 struct ctl_table_root *link_root)
68409 {
68410 - struct ctl_table *link_table, *entry, *link;
68411 + ctl_table_no_const *link_table, *link;
68412 + struct ctl_table *entry;
68413 struct ctl_table_header *links;
68414 struct ctl_node *node;
68415 char *link_name;
68416 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
68417 return NULL;
68418
68419 node = (struct ctl_node *)(links + 1);
68420 - link_table = (struct ctl_table *)(node + nr_entries);
68421 + link_table = (ctl_table_no_const *)(node + nr_entries);
68422 link_name = (char *)&link_table[nr_entries + 1];
68423
68424 for (link = link_table, entry = table; entry->procname; link++, entry++) {
68425 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
68426 struct ctl_table_header ***subheader, struct ctl_table_set *set,
68427 struct ctl_table *table)
68428 {
68429 - struct ctl_table *ctl_table_arg = NULL;
68430 - struct ctl_table *entry, *files;
68431 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
68432 + struct ctl_table *entry;
68433 int nr_files = 0;
68434 int nr_dirs = 0;
68435 int err = -ENOMEM;
68436 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
68437 nr_files++;
68438 }
68439
68440 - files = table;
68441 /* If there are mixed files and directories we need a new table */
68442 if (nr_dirs && nr_files) {
68443 - struct ctl_table *new;
68444 + ctl_table_no_const *new;
68445 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
68446 GFP_KERNEL);
68447 if (!files)
68448 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
68449 /* Register everything except a directory full of subdirectories */
68450 if (nr_files || !nr_dirs) {
68451 struct ctl_table_header *header;
68452 - header = __register_sysctl_table(set, path, files);
68453 + header = __register_sysctl_table(set, path, files ? files : table);
68454 if (!header) {
68455 kfree(ctl_table_arg);
68456 goto out;
68457 diff --git a/fs/proc/root.c b/fs/proc/root.c
68458 index 5dbadec..473af2f 100644
68459 --- a/fs/proc/root.c
68460 +++ b/fs/proc/root.c
68461 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
68462 proc_mkdir("openprom", NULL);
68463 #endif
68464 proc_tty_init();
68465 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68466 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68467 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
68468 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68469 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
68470 +#endif
68471 +#else
68472 proc_mkdir("bus", NULL);
68473 +#endif
68474 proc_sys_init();
68475 }
68476
68477 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
68478 index bf2d03f..f058f9c 100644
68479 --- a/fs/proc/stat.c
68480 +++ b/fs/proc/stat.c
68481 @@ -11,6 +11,7 @@
68482 #include <linux/irqnr.h>
68483 #include <linux/cputime.h>
68484 #include <linux/tick.h>
68485 +#include <linux/grsecurity.h>
68486
68487 #ifndef arch_irq_stat_cpu
68488 #define arch_irq_stat_cpu(cpu) 0
68489 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
68490 u64 sum_softirq = 0;
68491 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
68492 struct timespec boottime;
68493 + int unrestricted = 1;
68494 +
68495 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68496 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68497 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
68498 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68499 + && !in_group_p(grsec_proc_gid)
68500 +#endif
68501 + )
68502 + unrestricted = 0;
68503 +#endif
68504 +#endif
68505
68506 user = nice = system = idle = iowait =
68507 irq = softirq = steal = 0;
68508 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
68509 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
68510 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
68511 idle += get_idle_time(i);
68512 - iowait += get_iowait_time(i);
68513 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
68514 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
68515 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
68516 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
68517 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
68518 - sum += kstat_cpu_irqs_sum(i);
68519 - sum += arch_irq_stat_cpu(i);
68520 + if (unrestricted) {
68521 + iowait += get_iowait_time(i);
68522 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
68523 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
68524 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
68525 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
68526 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
68527 + sum += kstat_cpu_irqs_sum(i);
68528 + sum += arch_irq_stat_cpu(i);
68529 + for (j = 0; j < NR_SOFTIRQS; j++) {
68530 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
68531
68532 - for (j = 0; j < NR_SOFTIRQS; j++) {
68533 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
68534 -
68535 - per_softirq_sums[j] += softirq_stat;
68536 - sum_softirq += softirq_stat;
68537 + per_softirq_sums[j] += softirq_stat;
68538 + sum_softirq += softirq_stat;
68539 + }
68540 }
68541 }
68542 - sum += arch_irq_stat();
68543 + if (unrestricted)
68544 + sum += arch_irq_stat();
68545
68546 seq_puts(p, "cpu ");
68547 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
68548 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
68549 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
68550 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
68551 idle = get_idle_time(i);
68552 - iowait = get_iowait_time(i);
68553 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
68554 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
68555 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
68556 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
68557 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
68558 + if (unrestricted) {
68559 + iowait = get_iowait_time(i);
68560 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
68561 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
68562 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
68563 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
68564 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
68565 + }
68566 seq_printf(p, "cpu%d", i);
68567 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
68568 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
68569 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
68570
68571 /* sum again ? it could be updated? */
68572 for_each_irq_nr(j)
68573 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
68574 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
68575
68576 seq_printf(p,
68577 "\nctxt %llu\n"
68578 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
68579 "processes %lu\n"
68580 "procs_running %lu\n"
68581 "procs_blocked %lu\n",
68582 - nr_context_switches(),
68583 + unrestricted ? nr_context_switches() : 0ULL,
68584 (unsigned long)jif,
68585 - total_forks,
68586 - nr_running(),
68587 - nr_iowait());
68588 + unrestricted ? total_forks : 0UL,
68589 + unrestricted ? nr_running() : 0UL,
68590 + unrestricted ? nr_iowait() : 0UL);
68591
68592 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
68593
68594 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
68595 index cfa63ee..fce112e 100644
68596 --- a/fs/proc/task_mmu.c
68597 +++ b/fs/proc/task_mmu.c
68598 @@ -13,12 +13,19 @@
68599 #include <linux/swap.h>
68600 #include <linux/swapops.h>
68601 #include <linux/mmu_notifier.h>
68602 +#include <linux/grsecurity.h>
68603
68604 #include <asm/elf.h>
68605 #include <asm/uaccess.h>
68606 #include <asm/tlbflush.h>
68607 #include "internal.h"
68608
68609 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68610 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
68611 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
68612 + _mm->pax_flags & MF_PAX_SEGMEXEC))
68613 +#endif
68614 +
68615 void task_mem(struct seq_file *m, struct mm_struct *mm)
68616 {
68617 unsigned long data, text, lib, swap;
68618 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68619 "VmExe:\t%8lu kB\n"
68620 "VmLib:\t%8lu kB\n"
68621 "VmPTE:\t%8lu kB\n"
68622 - "VmSwap:\t%8lu kB\n",
68623 - hiwater_vm << (PAGE_SHIFT-10),
68624 + "VmSwap:\t%8lu kB\n"
68625 +
68626 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68627 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
68628 +#endif
68629 +
68630 + ,hiwater_vm << (PAGE_SHIFT-10),
68631 total_vm << (PAGE_SHIFT-10),
68632 mm->locked_vm << (PAGE_SHIFT-10),
68633 mm->pinned_vm << (PAGE_SHIFT-10),
68634 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68635 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
68636 (PTRS_PER_PTE * sizeof(pte_t) *
68637 atomic_long_read(&mm->nr_ptes)) >> 10,
68638 - swap << (PAGE_SHIFT-10));
68639 + swap << (PAGE_SHIFT-10)
68640 +
68641 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68642 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68643 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
68644 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
68645 +#else
68646 + , mm->context.user_cs_base
68647 + , mm->context.user_cs_limit
68648 +#endif
68649 +#endif
68650 +
68651 + );
68652 }
68653
68654 unsigned long task_vsize(struct mm_struct *mm)
68655 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68656 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
68657 }
68658
68659 - /* We don't show the stack guard page in /proc/maps */
68660 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68661 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
68662 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
68663 +#else
68664 start = vma->vm_start;
68665 - if (stack_guard_page_start(vma, start))
68666 - start += PAGE_SIZE;
68667 end = vma->vm_end;
68668 - if (stack_guard_page_end(vma, end))
68669 - end -= PAGE_SIZE;
68670 +#endif
68671
68672 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
68673 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
68674 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68675 flags & VM_WRITE ? 'w' : '-',
68676 flags & VM_EXEC ? 'x' : '-',
68677 flags & VM_MAYSHARE ? 's' : 'p',
68678 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68679 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
68680 +#else
68681 pgoff,
68682 +#endif
68683 MAJOR(dev), MINOR(dev), ino);
68684
68685 /*
68686 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68687 */
68688 if (file) {
68689 seq_pad(m, ' ');
68690 - seq_path(m, &file->f_path, "\n");
68691 + seq_path(m, &file->f_path, "\n\\");
68692 goto done;
68693 }
68694
68695 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
68696 * Thread stack in /proc/PID/task/TID/maps or
68697 * the main process stack.
68698 */
68699 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
68700 - vma->vm_end >= mm->start_stack)) {
68701 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
68702 + (vma->vm_start <= mm->start_stack &&
68703 + vma->vm_end >= mm->start_stack)) {
68704 name = "[stack]";
68705 } else {
68706 /* Thread stack in /proc/PID/maps */
68707 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
68708 struct proc_maps_private *priv = m->private;
68709 struct task_struct *task = priv->task;
68710
68711 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68712 + if (current->exec_id != m->exec_id) {
68713 + gr_log_badprocpid("maps");
68714 + return 0;
68715 + }
68716 +#endif
68717 +
68718 show_map_vma(m, vma, is_pid);
68719
68720 if (m->count < m->size) /* vma is copied successfully */
68721 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68722 .private = &mss,
68723 };
68724
68725 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68726 + if (current->exec_id != m->exec_id) {
68727 + gr_log_badprocpid("smaps");
68728 + return 0;
68729 + }
68730 +#endif
68731 memset(&mss, 0, sizeof mss);
68732 - mss.vma = vma;
68733 - /* mmap_sem is held in m_start */
68734 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68735 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68736 -
68737 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68738 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
68739 +#endif
68740 + mss.vma = vma;
68741 + /* mmap_sem is held in m_start */
68742 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
68743 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
68744 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68745 + }
68746 +#endif
68747 show_map_vma(m, vma, is_pid);
68748
68749 seq_printf(m,
68750 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
68751 "KernelPageSize: %8lu kB\n"
68752 "MMUPageSize: %8lu kB\n"
68753 "Locked: %8lu kB\n",
68754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68755 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
68756 +#else
68757 (vma->vm_end - vma->vm_start) >> 10,
68758 +#endif
68759 mss.resident >> 10,
68760 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
68761 mss.shared_clean >> 10,
68762 @@ -1398,6 +1449,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68763 char buffer[64];
68764 int nid;
68765
68766 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68767 + if (current->exec_id != m->exec_id) {
68768 + gr_log_badprocpid("numa_maps");
68769 + return 0;
68770 + }
68771 +#endif
68772 +
68773 if (!mm)
68774 return 0;
68775
68776 @@ -1415,11 +1473,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
68777 mpol_to_str(buffer, sizeof(buffer), pol);
68778 mpol_cond_put(pol);
68779
68780 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68781 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
68782 +#else
68783 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
68784 +#endif
68785
68786 if (file) {
68787 seq_puts(m, " file=");
68788 - seq_path(m, &file->f_path, "\n\t= ");
68789 + seq_path(m, &file->f_path, "\n\t\\= ");
68790 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
68791 seq_puts(m, " heap");
68792 } else {
68793 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
68794 index 678455d..ebd3245 100644
68795 --- a/fs/proc/task_nommu.c
68796 +++ b/fs/proc/task_nommu.c
68797 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
68798 else
68799 bytes += kobjsize(mm);
68800
68801 - if (current->fs && current->fs->users > 1)
68802 + if (current->fs && atomic_read(&current->fs->users) > 1)
68803 sbytes += kobjsize(current->fs);
68804 else
68805 bytes += kobjsize(current->fs);
68806 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
68807
68808 if (file) {
68809 seq_pad(m, ' ');
68810 - seq_path(m, &file->f_path, "");
68811 + seq_path(m, &file->f_path, "\n\\");
68812 } else if (mm) {
68813 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
68814
68815 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
68816 index 382aa89..6b03974 100644
68817 --- a/fs/proc/vmcore.c
68818 +++ b/fs/proc/vmcore.c
68819 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
68820 nr_bytes = count;
68821
68822 /* If pfn is not ram, return zeros for sparse dump files */
68823 - if (pfn_is_ram(pfn) == 0)
68824 - memset(buf, 0, nr_bytes);
68825 - else {
68826 + if (pfn_is_ram(pfn) == 0) {
68827 + if (userbuf) {
68828 + if (clear_user((char __force_user *)buf, nr_bytes))
68829 + return -EFAULT;
68830 + } else
68831 + memset(buf, 0, nr_bytes);
68832 + } else {
68833 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
68834 offset, userbuf);
68835 if (tmp < 0)
68836 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
68837 static int copy_to(void *target, void *src, size_t size, int userbuf)
68838 {
68839 if (userbuf) {
68840 - if (copy_to_user((char __user *) target, src, size))
68841 + if (copy_to_user((char __force_user *) target, src, size))
68842 return -EFAULT;
68843 } else {
68844 memcpy(target, src, size);
68845 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68846 if (*fpos < m->offset + m->size) {
68847 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
68848 start = m->paddr + *fpos - m->offset;
68849 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
68850 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
68851 if (tmp < 0)
68852 return tmp;
68853 buflen -= tsz;
68854 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
68855 static ssize_t read_vmcore(struct file *file, char __user *buffer,
68856 size_t buflen, loff_t *fpos)
68857 {
68858 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
68859 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
68860 }
68861
68862 /*
68863 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
68864 index b00fcc9..e0c6381 100644
68865 --- a/fs/qnx6/qnx6.h
68866 +++ b/fs/qnx6/qnx6.h
68867 @@ -74,7 +74,7 @@ enum {
68868 BYTESEX_BE,
68869 };
68870
68871 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68872 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
68873 {
68874 if (sbi->s_bytesex == BYTESEX_LE)
68875 return le64_to_cpu((__force __le64)n);
68876 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
68877 return (__force __fs64)cpu_to_be64(n);
68878 }
68879
68880 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68881 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
68882 {
68883 if (sbi->s_bytesex == BYTESEX_LE)
68884 return le32_to_cpu((__force __le32)n);
68885 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
68886 index 72d2917..c917c12 100644
68887 --- a/fs/quota/netlink.c
68888 +++ b/fs/quota/netlink.c
68889 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
68890 void quota_send_warning(struct kqid qid, dev_t dev,
68891 const char warntype)
68892 {
68893 - static atomic_t seq;
68894 + static atomic_unchecked_t seq;
68895 struct sk_buff *skb;
68896 void *msg_head;
68897 int ret;
68898 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
68899 "VFS: Not enough memory to send quota warning.\n");
68900 return;
68901 }
68902 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
68903 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
68904 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
68905 if (!msg_head) {
68906 printk(KERN_ERR
68907 diff --git a/fs/read_write.c b/fs/read_write.c
68908 index 009d854..16ce214 100644
68909 --- a/fs/read_write.c
68910 +++ b/fs/read_write.c
68911 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
68912
68913 old_fs = get_fs();
68914 set_fs(get_ds());
68915 - p = (__force const char __user *)buf;
68916 + p = (const char __force_user *)buf;
68917 if (count > MAX_RW_COUNT)
68918 count = MAX_RW_COUNT;
68919 if (file->f_op->write)
68920 diff --git a/fs/readdir.c b/fs/readdir.c
68921 index 33fd922..e0d6094 100644
68922 --- a/fs/readdir.c
68923 +++ b/fs/readdir.c
68924 @@ -18,6 +18,7 @@
68925 #include <linux/security.h>
68926 #include <linux/syscalls.h>
68927 #include <linux/unistd.h>
68928 +#include <linux/namei.h>
68929
68930 #include <asm/uaccess.h>
68931
68932 @@ -71,6 +72,7 @@ struct old_linux_dirent {
68933 struct readdir_callback {
68934 struct dir_context ctx;
68935 struct old_linux_dirent __user * dirent;
68936 + struct file * file;
68937 int result;
68938 };
68939
68940 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
68941 buf->result = -EOVERFLOW;
68942 return -EOVERFLOW;
68943 }
68944 +
68945 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68946 + return 0;
68947 +
68948 buf->result++;
68949 dirent = buf->dirent;
68950 if (!access_ok(VERIFY_WRITE, dirent,
68951 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
68952 if (!f.file)
68953 return -EBADF;
68954
68955 + buf.file = f.file;
68956 error = iterate_dir(f.file, &buf.ctx);
68957 if (buf.result)
68958 error = buf.result;
68959 @@ -144,6 +151,7 @@ struct getdents_callback {
68960 struct dir_context ctx;
68961 struct linux_dirent __user * current_dir;
68962 struct linux_dirent __user * previous;
68963 + struct file * file;
68964 int count;
68965 int error;
68966 };
68967 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
68968 buf->error = -EOVERFLOW;
68969 return -EOVERFLOW;
68970 }
68971 +
68972 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
68973 + return 0;
68974 +
68975 dirent = buf->previous;
68976 if (dirent) {
68977 if (__put_user(offset, &dirent->d_off))
68978 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
68979 if (!f.file)
68980 return -EBADF;
68981
68982 + buf.file = f.file;
68983 error = iterate_dir(f.file, &buf.ctx);
68984 if (error >= 0)
68985 error = buf.error;
68986 @@ -228,6 +241,7 @@ struct getdents_callback64 {
68987 struct dir_context ctx;
68988 struct linux_dirent64 __user * current_dir;
68989 struct linux_dirent64 __user * previous;
68990 + struct file *file;
68991 int count;
68992 int error;
68993 };
68994 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
68995 buf->error = -EINVAL; /* only used if we fail.. */
68996 if (reclen > buf->count)
68997 return -EINVAL;
68998 +
68999 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
69000 + return 0;
69001 +
69002 dirent = buf->previous;
69003 if (dirent) {
69004 if (__put_user(offset, &dirent->d_off))
69005 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
69006 if (!f.file)
69007 return -EBADF;
69008
69009 + buf.file = f.file;
69010 error = iterate_dir(f.file, &buf.ctx);
69011 if (error >= 0)
69012 error = buf.error;
69013 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
69014 index 54fdf19..987862b 100644
69015 --- a/fs/reiserfs/do_balan.c
69016 +++ b/fs/reiserfs/do_balan.c
69017 @@ -1872,7 +1872,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
69018 return;
69019 }
69020
69021 - atomic_inc(&fs_generation(tb->tb_sb));
69022 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
69023 do_balance_starts(tb);
69024
69025 /*
69026 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
69027 index cfaee91..b9d0d60 100644
69028 --- a/fs/reiserfs/item_ops.c
69029 +++ b/fs/reiserfs/item_ops.c
69030 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
69031 }
69032
69033 static struct item_operations errcatch_ops = {
69034 - errcatch_bytes_number,
69035 - errcatch_decrement_key,
69036 - errcatch_is_left_mergeable,
69037 - errcatch_print_item,
69038 - errcatch_check_item,
69039 + .bytes_number = errcatch_bytes_number,
69040 + .decrement_key = errcatch_decrement_key,
69041 + .is_left_mergeable = errcatch_is_left_mergeable,
69042 + .print_item = errcatch_print_item,
69043 + .check_item = errcatch_check_item,
69044
69045 - errcatch_create_vi,
69046 - errcatch_check_left,
69047 - errcatch_check_right,
69048 - errcatch_part_size,
69049 - errcatch_unit_num,
69050 - errcatch_print_vi
69051 + .create_vi = errcatch_create_vi,
69052 + .check_left = errcatch_check_left,
69053 + .check_right = errcatch_check_right,
69054 + .part_size = errcatch_part_size,
69055 + .unit_num = errcatch_unit_num,
69056 + .print_vi = errcatch_print_vi
69057 };
69058
69059 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
69060 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
69061 index 02b0b7d..c85018b 100644
69062 --- a/fs/reiserfs/procfs.c
69063 +++ b/fs/reiserfs/procfs.c
69064 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
69065 "SMALL_TAILS " : "NO_TAILS ",
69066 replay_only(sb) ? "REPLAY_ONLY " : "",
69067 convert_reiserfs(sb) ? "CONV " : "",
69068 - atomic_read(&r->s_generation_counter),
69069 + atomic_read_unchecked(&r->s_generation_counter),
69070 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
69071 SF(s_do_balance), SF(s_unneeded_left_neighbor),
69072 SF(s_good_search_by_key_reada), SF(s_bmaps),
69073 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
69074 index bf53888..227f5ae 100644
69075 --- a/fs/reiserfs/reiserfs.h
69076 +++ b/fs/reiserfs/reiserfs.h
69077 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
69078 /* Comment? -Hans */
69079 wait_queue_head_t s_wait;
69080 /* increased by one every time the tree gets re-balanced */
69081 - atomic_t s_generation_counter;
69082 + atomic_unchecked_t s_generation_counter;
69083
69084 /* File system properties. Currently holds on-disk FS format */
69085 unsigned long s_properties;
69086 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
69087 #define REISERFS_USER_MEM 1 /* user memory mode */
69088
69089 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
69090 -#define get_generation(s) atomic_read (&fs_generation(s))
69091 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
69092 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
69093 #define __fs_changed(gen,s) (gen != get_generation (s))
69094 #define fs_changed(gen,s) \
69095 diff --git a/fs/select.c b/fs/select.c
69096 index 467bb1c..cf9d65a 100644
69097 --- a/fs/select.c
69098 +++ b/fs/select.c
69099 @@ -20,6 +20,7 @@
69100 #include <linux/export.h>
69101 #include <linux/slab.h>
69102 #include <linux/poll.h>
69103 +#include <linux/security.h>
69104 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
69105 #include <linux/file.h>
69106 #include <linux/fdtable.h>
69107 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
69108 struct poll_list *walk = head;
69109 unsigned long todo = nfds;
69110
69111 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
69112 if (nfds > rlimit(RLIMIT_NOFILE))
69113 return -EINVAL;
69114
69115 diff --git a/fs/seq_file.c b/fs/seq_file.c
69116 index 3857b72..0b7281e 100644
69117 --- a/fs/seq_file.c
69118 +++ b/fs/seq_file.c
69119 @@ -12,6 +12,8 @@
69120 #include <linux/slab.h>
69121 #include <linux/cred.h>
69122 #include <linux/mm.h>
69123 +#include <linux/sched.h>
69124 +#include <linux/grsecurity.h>
69125
69126 #include <asm/uaccess.h>
69127 #include <asm/page.h>
69128 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
69129
69130 static void *seq_buf_alloc(unsigned long size)
69131 {
69132 - void *buf;
69133 -
69134 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
69135 - if (!buf && size > PAGE_SIZE)
69136 - buf = vmalloc(size);
69137 - return buf;
69138 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
69139 }
69140
69141 /**
69142 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
69143 #ifdef CONFIG_USER_NS
69144 p->user_ns = file->f_cred->user_ns;
69145 #endif
69146 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69147 + p->exec_id = current->exec_id;
69148 +#endif
69149
69150 /*
69151 * Wrappers around seq_open(e.g. swaps_open) need to be
69152 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
69153 }
69154 EXPORT_SYMBOL(seq_open);
69155
69156 +
69157 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
69158 +{
69159 + if (gr_proc_is_restricted())
69160 + return -EACCES;
69161 +
69162 + return seq_open(file, op);
69163 +}
69164 +EXPORT_SYMBOL(seq_open_restrict);
69165 +
69166 static int traverse(struct seq_file *m, loff_t offset)
69167 {
69168 loff_t pos = 0, index;
69169 @@ -165,7 +175,7 @@ Eoverflow:
69170 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
69171 {
69172 struct seq_file *m = file->private_data;
69173 - size_t copied = 0;
69174 + ssize_t copied = 0;
69175 loff_t pos;
69176 size_t n;
69177 void *p;
69178 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
69179 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
69180 void *data)
69181 {
69182 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
69183 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
69184 int res = -ENOMEM;
69185
69186 if (op) {
69187 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
69188 }
69189 EXPORT_SYMBOL(single_open_size);
69190
69191 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
69192 + void *data)
69193 +{
69194 + if (gr_proc_is_restricted())
69195 + return -EACCES;
69196 +
69197 + return single_open(file, show, data);
69198 +}
69199 +EXPORT_SYMBOL(single_open_restrict);
69200 +
69201 +
69202 int single_release(struct inode *inode, struct file *file)
69203 {
69204 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
69205 diff --git a/fs/splice.c b/fs/splice.c
69206 index f5cb9ba..8ddb1e9 100644
69207 --- a/fs/splice.c
69208 +++ b/fs/splice.c
69209 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
69210 pipe_lock(pipe);
69211
69212 for (;;) {
69213 - if (!pipe->readers) {
69214 + if (!atomic_read(&pipe->readers)) {
69215 send_sig(SIGPIPE, current, 0);
69216 if (!ret)
69217 ret = -EPIPE;
69218 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
69219 page_nr++;
69220 ret += buf->len;
69221
69222 - if (pipe->files)
69223 + if (atomic_read(&pipe->files))
69224 do_wakeup = 1;
69225
69226 if (!--spd->nr_pages)
69227 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
69228 do_wakeup = 0;
69229 }
69230
69231 - pipe->waiting_writers++;
69232 + atomic_inc(&pipe->waiting_writers);
69233 pipe_wait(pipe);
69234 - pipe->waiting_writers--;
69235 + atomic_dec(&pipe->waiting_writers);
69236 }
69237
69238 pipe_unlock(pipe);
69239 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
69240 old_fs = get_fs();
69241 set_fs(get_ds());
69242 /* The cast to a user pointer is valid due to the set_fs() */
69243 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
69244 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
69245 set_fs(old_fs);
69246
69247 return res;
69248 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
69249 old_fs = get_fs();
69250 set_fs(get_ds());
69251 /* The cast to a user pointer is valid due to the set_fs() */
69252 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
69253 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
69254 set_fs(old_fs);
69255
69256 return res;
69257 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
69258 goto err;
69259
69260 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
69261 - vec[i].iov_base = (void __user *) page_address(page);
69262 + vec[i].iov_base = (void __force_user *) page_address(page);
69263 vec[i].iov_len = this_len;
69264 spd.pages[i] = page;
69265 spd.nr_pages++;
69266 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
69267 ops->release(pipe, buf);
69268 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
69269 pipe->nrbufs--;
69270 - if (pipe->files)
69271 + if (atomic_read(&pipe->files))
69272 sd->need_wakeup = true;
69273 }
69274
69275 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
69276 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
69277 {
69278 while (!pipe->nrbufs) {
69279 - if (!pipe->writers)
69280 + if (!atomic_read(&pipe->writers))
69281 return 0;
69282
69283 - if (!pipe->waiting_writers && sd->num_spliced)
69284 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
69285 return 0;
69286
69287 if (sd->flags & SPLICE_F_NONBLOCK)
69288 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
69289 ops->release(pipe, buf);
69290 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
69291 pipe->nrbufs--;
69292 - if (pipe->files)
69293 + if (atomic_read(&pipe->files))
69294 sd.need_wakeup = true;
69295 } else {
69296 buf->offset += ret;
69297 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
69298 * out of the pipe right after the splice_to_pipe(). So set
69299 * PIPE_READERS appropriately.
69300 */
69301 - pipe->readers = 1;
69302 + atomic_set(&pipe->readers, 1);
69303
69304 current->splice_pipe = pipe;
69305 }
69306 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
69307
69308 partial[buffers].offset = off;
69309 partial[buffers].len = plen;
69310 + partial[buffers].private = 0;
69311
69312 off = 0;
69313 len -= plen;
69314 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
69315 ret = -ERESTARTSYS;
69316 break;
69317 }
69318 - if (!pipe->writers)
69319 + if (!atomic_read(&pipe->writers))
69320 break;
69321 - if (!pipe->waiting_writers) {
69322 + if (!atomic_read(&pipe->waiting_writers)) {
69323 if (flags & SPLICE_F_NONBLOCK) {
69324 ret = -EAGAIN;
69325 break;
69326 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
69327 pipe_lock(pipe);
69328
69329 while (pipe->nrbufs >= pipe->buffers) {
69330 - if (!pipe->readers) {
69331 + if (!atomic_read(&pipe->readers)) {
69332 send_sig(SIGPIPE, current, 0);
69333 ret = -EPIPE;
69334 break;
69335 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
69336 ret = -ERESTARTSYS;
69337 break;
69338 }
69339 - pipe->waiting_writers++;
69340 + atomic_inc(&pipe->waiting_writers);
69341 pipe_wait(pipe);
69342 - pipe->waiting_writers--;
69343 + atomic_dec(&pipe->waiting_writers);
69344 }
69345
69346 pipe_unlock(pipe);
69347 @@ -1817,14 +1818,14 @@ retry:
69348 pipe_double_lock(ipipe, opipe);
69349
69350 do {
69351 - if (!opipe->readers) {
69352 + if (!atomic_read(&opipe->readers)) {
69353 send_sig(SIGPIPE, current, 0);
69354 if (!ret)
69355 ret = -EPIPE;
69356 break;
69357 }
69358
69359 - if (!ipipe->nrbufs && !ipipe->writers)
69360 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
69361 break;
69362
69363 /*
69364 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
69365 pipe_double_lock(ipipe, opipe);
69366
69367 do {
69368 - if (!opipe->readers) {
69369 + if (!atomic_read(&opipe->readers)) {
69370 send_sig(SIGPIPE, current, 0);
69371 if (!ret)
69372 ret = -EPIPE;
69373 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
69374 * return EAGAIN if we have the potential of some data in the
69375 * future, otherwise just return 0
69376 */
69377 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
69378 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
69379 ret = -EAGAIN;
69380
69381 pipe_unlock(ipipe);
69382 diff --git a/fs/stat.c b/fs/stat.c
69383 index ae0c3ce..9ee641c 100644
69384 --- a/fs/stat.c
69385 +++ b/fs/stat.c
69386 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
69387 stat->gid = inode->i_gid;
69388 stat->rdev = inode->i_rdev;
69389 stat->size = i_size_read(inode);
69390 - stat->atime = inode->i_atime;
69391 - stat->mtime = inode->i_mtime;
69392 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
69393 + stat->atime = inode->i_ctime;
69394 + stat->mtime = inode->i_ctime;
69395 + } else {
69396 + stat->atime = inode->i_atime;
69397 + stat->mtime = inode->i_mtime;
69398 + }
69399 stat->ctime = inode->i_ctime;
69400 stat->blksize = (1 << inode->i_blkbits);
69401 stat->blocks = inode->i_blocks;
69402 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
69403 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
69404 {
69405 struct inode *inode = path->dentry->d_inode;
69406 + int retval;
69407
69408 - if (inode->i_op->getattr)
69409 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
69410 + if (inode->i_op->getattr) {
69411 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
69412 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
69413 + stat->atime = stat->ctime;
69414 + stat->mtime = stat->ctime;
69415 + }
69416 + return retval;
69417 + }
69418
69419 generic_fillattr(inode, stat);
69420 return 0;
69421 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
69422 index 0b45ff4..847de5b 100644
69423 --- a/fs/sysfs/dir.c
69424 +++ b/fs/sysfs/dir.c
69425 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
69426 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
69427 {
69428 struct kernfs_node *parent, *kn;
69429 + const char *name;
69430 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
69431 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
69432 + const char *parent_name;
69433 +#endif
69434
69435 BUG_ON(!kobj);
69436
69437 + name = kobject_name(kobj);
69438 +
69439 if (kobj->parent)
69440 parent = kobj->parent->sd;
69441 else
69442 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
69443 if (!parent)
69444 return -ENOENT;
69445
69446 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
69447 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
69448 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
69449 + parent_name = parent->name;
69450 + mode = S_IRWXU;
69451 +
69452 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
69453 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
69454 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
69455 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
69456 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
69457 +#endif
69458 +
69459 + kn = kernfs_create_dir_ns(parent, name,
69460 + mode, kobj, ns);
69461 if (IS_ERR(kn)) {
69462 if (PTR_ERR(kn) == -EEXIST)
69463 - sysfs_warn_dup(parent, kobject_name(kobj));
69464 + sysfs_warn_dup(parent, name);
69465 return PTR_ERR(kn);
69466 }
69467
69468 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
69469 index 69d4889..a810bd4 100644
69470 --- a/fs/sysv/sysv.h
69471 +++ b/fs/sysv/sysv.h
69472 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
69473 #endif
69474 }
69475
69476 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
69477 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
69478 {
69479 if (sbi->s_bytesex == BYTESEX_PDP)
69480 return PDP_swab((__force __u32)n);
69481 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
69482 index 2290d58..7791371 100644
69483 --- a/fs/ubifs/io.c
69484 +++ b/fs/ubifs/io.c
69485 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
69486 return err;
69487 }
69488
69489 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
69490 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
69491 {
69492 int err;
69493
69494 diff --git a/fs/udf/inode.c b/fs/udf/inode.c
69495 index 236cd48..a6a4053 100644
69496 --- a/fs/udf/inode.c
69497 +++ b/fs/udf/inode.c
69498 @@ -51,7 +51,6 @@ MODULE_LICENSE("GPL");
69499
69500 static umode_t udf_convert_permissions(struct fileEntry *);
69501 static int udf_update_inode(struct inode *, int);
69502 -static void udf_fill_inode(struct inode *, struct buffer_head *);
69503 static int udf_sync_inode(struct inode *inode);
69504 static int udf_alloc_i_data(struct inode *inode, size_t size);
69505 static sector_t inode_getblk(struct inode *, sector_t, int *, int *);
69506 @@ -1271,13 +1270,25 @@ update_time:
69507 return 0;
69508 }
69509
69510 +/*
69511 + * Maximum length of linked list formed by ICB hierarchy. The chosen number is
69512 + * arbitrary - just that we hopefully don't limit any real use of rewritten
69513 + * inode on write-once media but avoid looping for too long on corrupted media.
69514 + */
69515 +#define UDF_MAX_ICB_NESTING 1024
69516 +
69517 static void __udf_read_inode(struct inode *inode)
69518 {
69519 struct buffer_head *bh = NULL;
69520 struct fileEntry *fe;
69521 + struct extendedFileEntry *efe;
69522 uint16_t ident;
69523 struct udf_inode_info *iinfo = UDF_I(inode);
69524 + struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
69525 + unsigned int link_count;
69526 + unsigned int indirections = 0;
69527
69528 +reread:
69529 /*
69530 * Set defaults, but the inode is still incomplete!
69531 * Note: get_new_inode() sets the following on a new inode:
69532 @@ -1307,6 +1318,7 @@ static void __udf_read_inode(struct inode *inode)
69533 }
69534
69535 fe = (struct fileEntry *)bh->b_data;
69536 + efe = (struct extendedFileEntry *)bh->b_data;
69537
69538 if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
69539 struct buffer_head *ibh;
69540 @@ -1314,28 +1326,26 @@ static void __udf_read_inode(struct inode *inode)
69541 ibh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 1,
69542 &ident);
69543 if (ident == TAG_IDENT_IE && ibh) {
69544 - struct buffer_head *nbh = NULL;
69545 struct kernel_lb_addr loc;
69546 struct indirectEntry *ie;
69547
69548 ie = (struct indirectEntry *)ibh->b_data;
69549 loc = lelb_to_cpu(ie->indirectICB.extLocation);
69550
69551 - if (ie->indirectICB.extLength &&
69552 - (nbh = udf_read_ptagged(inode->i_sb, &loc, 0,
69553 - &ident))) {
69554 - if (ident == TAG_IDENT_FE ||
69555 - ident == TAG_IDENT_EFE) {
69556 - memcpy(&iinfo->i_location,
69557 - &loc,
69558 - sizeof(struct kernel_lb_addr));
69559 - brelse(bh);
69560 - brelse(ibh);
69561 - brelse(nbh);
69562 - __udf_read_inode(inode);
69563 + if (ie->indirectICB.extLength) {
69564 + brelse(bh);
69565 + brelse(ibh);
69566 + memcpy(&iinfo->i_location, &loc,
69567 + sizeof(struct kernel_lb_addr));
69568 + if (++indirections > UDF_MAX_ICB_NESTING) {
69569 + udf_err(inode->i_sb,
69570 + "too many ICBs in ICB hierarchy"
69571 + " (max %d supported)\n",
69572 + UDF_MAX_ICB_NESTING);
69573 + make_bad_inode(inode);
69574 return;
69575 }
69576 - brelse(nbh);
69577 + goto reread;
69578 }
69579 }
69580 brelse(ibh);
69581 @@ -1346,22 +1356,6 @@ static void __udf_read_inode(struct inode *inode)
69582 make_bad_inode(inode);
69583 return;
69584 }
69585 - udf_fill_inode(inode, bh);
69586 -
69587 - brelse(bh);
69588 -}
69589 -
69590 -static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
69591 -{
69592 - struct fileEntry *fe;
69593 - struct extendedFileEntry *efe;
69594 - struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
69595 - struct udf_inode_info *iinfo = UDF_I(inode);
69596 - unsigned int link_count;
69597 -
69598 - fe = (struct fileEntry *)bh->b_data;
69599 - efe = (struct extendedFileEntry *)bh->b_data;
69600 -
69601 if (fe->icbTag.strategyType == cpu_to_le16(4))
69602 iinfo->i_strat4096 = 0;
69603 else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */
69604 @@ -1551,6 +1545,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
69605 } else
69606 make_bad_inode(inode);
69607 }
69608 + brelse(bh);
69609 }
69610
69611 static int udf_alloc_i_data(struct inode *inode, size_t size)
69612 @@ -1664,7 +1659,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
69613 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
69614 fe->permissions = cpu_to_le32(udfperms);
69615
69616 - if (S_ISDIR(inode->i_mode))
69617 + if (S_ISDIR(inode->i_mode) && inode->i_nlink > 0)
69618 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
69619 else
69620 fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
69621 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
69622 index c175b4d..8f36a16 100644
69623 --- a/fs/udf/misc.c
69624 +++ b/fs/udf/misc.c
69625 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
69626
69627 u8 udf_tag_checksum(const struct tag *t)
69628 {
69629 - u8 *data = (u8 *)t;
69630 + const u8 *data = (const u8 *)t;
69631 u8 checksum = 0;
69632 int i;
69633 for (i = 0; i < sizeof(struct tag); ++i)
69634 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
69635 index 8d974c4..b82f6ec 100644
69636 --- a/fs/ufs/swab.h
69637 +++ b/fs/ufs/swab.h
69638 @@ -22,7 +22,7 @@ enum {
69639 BYTESEX_BE
69640 };
69641
69642 -static inline u64
69643 +static inline u64 __intentional_overflow(-1)
69644 fs64_to_cpu(struct super_block *sbp, __fs64 n)
69645 {
69646 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
69647 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
69648 return (__force __fs64)cpu_to_be64(n);
69649 }
69650
69651 -static inline u32
69652 +static inline u32 __intentional_overflow(-1)
69653 fs32_to_cpu(struct super_block *sbp, __fs32 n)
69654 {
69655 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
69656 diff --git a/fs/utimes.c b/fs/utimes.c
69657 index aa138d6..5f3a811 100644
69658 --- a/fs/utimes.c
69659 +++ b/fs/utimes.c
69660 @@ -1,6 +1,7 @@
69661 #include <linux/compiler.h>
69662 #include <linux/file.h>
69663 #include <linux/fs.h>
69664 +#include <linux/security.h>
69665 #include <linux/linkage.h>
69666 #include <linux/mount.h>
69667 #include <linux/namei.h>
69668 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
69669 }
69670 }
69671 retry_deleg:
69672 +
69673 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
69674 + error = -EACCES;
69675 + goto mnt_drop_write_and_out;
69676 + }
69677 +
69678 mutex_lock(&inode->i_mutex);
69679 error = notify_change(path->dentry, &newattrs, &delegated_inode);
69680 mutex_unlock(&inode->i_mutex);
69681 diff --git a/fs/xattr.c b/fs/xattr.c
69682 index c69e6d4..cc56af5 100644
69683 --- a/fs/xattr.c
69684 +++ b/fs/xattr.c
69685 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
69686 return rc;
69687 }
69688
69689 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
69690 +ssize_t
69691 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
69692 +{
69693 + struct inode *inode = dentry->d_inode;
69694 + ssize_t error;
69695 +
69696 + error = inode_permission(inode, MAY_EXEC);
69697 + if (error)
69698 + return error;
69699 +
69700 + if (inode->i_op->getxattr)
69701 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
69702 + else
69703 + error = -EOPNOTSUPP;
69704 +
69705 + return error;
69706 +}
69707 +EXPORT_SYMBOL(pax_getxattr);
69708 +#endif
69709 +
69710 ssize_t
69711 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
69712 {
69713 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
69714 * Extended attribute SET operations
69715 */
69716 static long
69717 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
69718 +setxattr(struct path *path, const char __user *name, const void __user *value,
69719 size_t size, int flags)
69720 {
69721 int error;
69722 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
69723 posix_acl_fix_xattr_from_user(kvalue, size);
69724 }
69725
69726 - error = vfs_setxattr(d, kname, kvalue, size, flags);
69727 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
69728 + error = -EACCES;
69729 + goto out;
69730 + }
69731 +
69732 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
69733 out:
69734 if (vvalue)
69735 vfree(vvalue);
69736 @@ -377,7 +403,7 @@ retry:
69737 return error;
69738 error = mnt_want_write(path.mnt);
69739 if (!error) {
69740 - error = setxattr(path.dentry, name, value, size, flags);
69741 + error = setxattr(&path, name, value, size, flags);
69742 mnt_drop_write(path.mnt);
69743 }
69744 path_put(&path);
69745 @@ -401,7 +427,7 @@ retry:
69746 return error;
69747 error = mnt_want_write(path.mnt);
69748 if (!error) {
69749 - error = setxattr(path.dentry, name, value, size, flags);
69750 + error = setxattr(&path, name, value, size, flags);
69751 mnt_drop_write(path.mnt);
69752 }
69753 path_put(&path);
69754 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
69755 const void __user *,value, size_t, size, int, flags)
69756 {
69757 struct fd f = fdget(fd);
69758 - struct dentry *dentry;
69759 int error = -EBADF;
69760
69761 if (!f.file)
69762 return error;
69763 - dentry = f.file->f_path.dentry;
69764 - audit_inode(NULL, dentry, 0);
69765 + audit_inode(NULL, f.file->f_path.dentry, 0);
69766 error = mnt_want_write_file(f.file);
69767 if (!error) {
69768 - error = setxattr(dentry, name, value, size, flags);
69769 + error = setxattr(&f.file->f_path, name, value, size, flags);
69770 mnt_drop_write_file(f.file);
69771 }
69772 fdput(f);
69773 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
69774 * Extended attribute REMOVE operations
69775 */
69776 static long
69777 -removexattr(struct dentry *d, const char __user *name)
69778 +removexattr(struct path *path, const char __user *name)
69779 {
69780 int error;
69781 char kname[XATTR_NAME_MAX + 1];
69782 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
69783 if (error < 0)
69784 return error;
69785
69786 - return vfs_removexattr(d, kname);
69787 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
69788 + return -EACCES;
69789 +
69790 + return vfs_removexattr(path->dentry, kname);
69791 }
69792
69793 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
69794 @@ -652,7 +679,7 @@ retry:
69795 return error;
69796 error = mnt_want_write(path.mnt);
69797 if (!error) {
69798 - error = removexattr(path.dentry, name);
69799 + error = removexattr(&path, name);
69800 mnt_drop_write(path.mnt);
69801 }
69802 path_put(&path);
69803 @@ -675,7 +702,7 @@ retry:
69804 return error;
69805 error = mnt_want_write(path.mnt);
69806 if (!error) {
69807 - error = removexattr(path.dentry, name);
69808 + error = removexattr(&path, name);
69809 mnt_drop_write(path.mnt);
69810 }
69811 path_put(&path);
69812 @@ -689,16 +716,16 @@ retry:
69813 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
69814 {
69815 struct fd f = fdget(fd);
69816 - struct dentry *dentry;
69817 + struct path *path;
69818 int error = -EBADF;
69819
69820 if (!f.file)
69821 return error;
69822 - dentry = f.file->f_path.dentry;
69823 - audit_inode(NULL, dentry, 0);
69824 + path = &f.file->f_path;
69825 + audit_inode(NULL, path->dentry, 0);
69826 error = mnt_want_write_file(f.file);
69827 if (!error) {
69828 - error = removexattr(dentry, name);
69829 + error = removexattr(path, name);
69830 mnt_drop_write_file(f.file);
69831 }
69832 fdput(f);
69833 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
69834 index 75c3fe5..b0f6bbe 100644
69835 --- a/fs/xfs/xfs_bmap.c
69836 +++ b/fs/xfs/xfs_bmap.c
69837 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
69838
69839 #else
69840 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
69841 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
69842 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
69843 #endif /* DEBUG */
69844
69845 /*
69846 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
69847 index 48e99af..54ebae3 100644
69848 --- a/fs/xfs/xfs_dir2_readdir.c
69849 +++ b/fs/xfs/xfs_dir2_readdir.c
69850 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
69851 ino = dp->d_ops->sf_get_ino(sfp, sfep);
69852 filetype = dp->d_ops->sf_get_ftype(sfep);
69853 ctx->pos = off & 0x7fffffff;
69854 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69855 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
69856 + char name[sfep->namelen];
69857 + memcpy(name, sfep->name, sfep->namelen);
69858 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
69859 + return 0;
69860 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
69861 xfs_dir3_get_dtype(dp->i_mount, filetype)))
69862 return 0;
69863 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
69864 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
69865 index 8bc1bbc..0d6911b 100644
69866 --- a/fs/xfs/xfs_ioctl.c
69867 +++ b/fs/xfs/xfs_ioctl.c
69868 @@ -122,7 +122,7 @@ xfs_find_handle(
69869 }
69870
69871 error = -EFAULT;
69872 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
69873 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
69874 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
69875 goto out_put;
69876
69877 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
69878 new file mode 100644
69879 index 0000000..27cec32
69880 --- /dev/null
69881 +++ b/grsecurity/Kconfig
69882 @@ -0,0 +1,1166 @@
69883 +#
69884 +# grecurity configuration
69885 +#
69886 +menu "Memory Protections"
69887 +depends on GRKERNSEC
69888 +
69889 +config GRKERNSEC_KMEM
69890 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
69891 + default y if GRKERNSEC_CONFIG_AUTO
69892 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
69893 + help
69894 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
69895 + be written to or read from to modify or leak the contents of the running
69896 + kernel. /dev/port will also not be allowed to be opened, writing to
69897 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
69898 + If you have module support disabled, enabling this will close up several
69899 + ways that are currently used to insert malicious code into the running
69900 + kernel.
69901 +
69902 + Even with this feature enabled, we still highly recommend that
69903 + you use the RBAC system, as it is still possible for an attacker to
69904 + modify the running kernel through other more obscure methods.
69905 +
69906 + It is highly recommended that you say Y here if you meet all the
69907 + conditions above.
69908 +
69909 +config GRKERNSEC_VM86
69910 + bool "Restrict VM86 mode"
69911 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69912 + depends on X86_32
69913 +
69914 + help
69915 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
69916 + make use of a special execution mode on 32bit x86 processors called
69917 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
69918 + video cards and will still work with this option enabled. The purpose
69919 + of the option is to prevent exploitation of emulation errors in
69920 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
69921 + Nearly all users should be able to enable this option.
69922 +
69923 +config GRKERNSEC_IO
69924 + bool "Disable privileged I/O"
69925 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69926 + depends on X86
69927 + select RTC_CLASS
69928 + select RTC_INTF_DEV
69929 + select RTC_DRV_CMOS
69930 +
69931 + help
69932 + If you say Y here, all ioperm and iopl calls will return an error.
69933 + Ioperm and iopl can be used to modify the running kernel.
69934 + Unfortunately, some programs need this access to operate properly,
69935 + the most notable of which are XFree86 and hwclock. hwclock can be
69936 + remedied by having RTC support in the kernel, so real-time
69937 + clock support is enabled if this option is enabled, to ensure
69938 + that hwclock operates correctly. If hwclock still does not work,
69939 + either update udev or symlink /dev/rtc to /dev/rtc0.
69940 +
69941 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
69942 + you may not be able to boot into a graphical environment with this
69943 + option enabled. In this case, you should use the RBAC system instead.
69944 +
69945 +config GRKERNSEC_JIT_HARDEN
69946 + bool "Harden BPF JIT against spray attacks"
69947 + default y if GRKERNSEC_CONFIG_AUTO
69948 + depends on BPF_JIT && X86
69949 + help
69950 + If you say Y here, the native code generated by the kernel's Berkeley
69951 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
69952 + attacks that attempt to fit attacker-beneficial instructions in
69953 + 32bit immediate fields of JIT-generated native instructions. The
69954 + attacker will generally aim to cause an unintended instruction sequence
69955 + of JIT-generated native code to execute by jumping into the middle of
69956 + a generated instruction. This feature effectively randomizes the 32bit
69957 + immediate constants present in the generated code to thwart such attacks.
69958 +
69959 + If you're using KERNEXEC, it's recommended that you enable this option
69960 + to supplement the hardening of the kernel.
69961 +
69962 +config GRKERNSEC_PERF_HARDEN
69963 + bool "Disable unprivileged PERF_EVENTS usage by default"
69964 + default y if GRKERNSEC_CONFIG_AUTO
69965 + depends on PERF_EVENTS
69966 + help
69967 + If you say Y here, the range of acceptable values for the
69968 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
69969 + default to a new value: 3. When the sysctl is set to this value, no
69970 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
69971 +
69972 + Though PERF_EVENTS can be used legitimately for performance monitoring
69973 + and low-level application profiling, it is forced on regardless of
69974 + configuration, has been at fault for several vulnerabilities, and
69975 + creates new opportunities for side channels and other information leaks.
69976 +
69977 + This feature puts PERF_EVENTS into a secure default state and permits
69978 + the administrator to change out of it temporarily if unprivileged
69979 + application profiling is needed.
69980 +
69981 +config GRKERNSEC_RAND_THREADSTACK
69982 + bool "Insert random gaps between thread stacks"
69983 + default y if GRKERNSEC_CONFIG_AUTO
69984 + depends on PAX_RANDMMAP && !PPC
69985 + help
69986 + If you say Y here, a random-sized gap will be enforced between allocated
69987 + thread stacks. Glibc's NPTL and other threading libraries that
69988 + pass MAP_STACK to the kernel for thread stack allocation are supported.
69989 + The implementation currently provides 8 bits of entropy for the gap.
69990 +
69991 + Many distributions do not compile threaded remote services with the
69992 + -fstack-check argument to GCC, causing the variable-sized stack-based
69993 + allocator, alloca(), to not probe the stack on allocation. This
69994 + permits an unbounded alloca() to skip over any guard page and potentially
69995 + modify another thread's stack reliably. An enforced random gap
69996 + reduces the reliability of such an attack and increases the chance
69997 + that such a read/write to another thread's stack instead lands in
69998 + an unmapped area, causing a crash and triggering grsecurity's
69999 + anti-bruteforcing logic.
70000 +
70001 +config GRKERNSEC_PROC_MEMMAP
70002 + bool "Harden ASLR against information leaks and entropy reduction"
70003 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
70004 + depends on PAX_NOEXEC || PAX_ASLR
70005 + help
70006 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
70007 + give no information about the addresses of its mappings if
70008 + PaX features that rely on random addresses are enabled on the task.
70009 + In addition to sanitizing this information and disabling other
70010 + dangerous sources of information, this option causes reads of sensitive
70011 + /proc/<pid> entries where the file descriptor was opened in a different
70012 + task than the one performing the read. Such attempts are logged.
70013 + This option also limits argv/env strings for suid/sgid binaries
70014 + to 512KB to prevent a complete exhaustion of the stack entropy provided
70015 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
70016 + binaries to prevent alternative mmap layouts from being abused.
70017 +
70018 + If you use PaX it is essential that you say Y here as it closes up
70019 + several holes that make full ASLR useless locally.
70020 +
70021 +
70022 +config GRKERNSEC_KSTACKOVERFLOW
70023 + bool "Prevent kernel stack overflows"
70024 + default y if GRKERNSEC_CONFIG_AUTO
70025 + depends on !IA64 && 64BIT
70026 + help
70027 + If you say Y here, the kernel's process stacks will be allocated
70028 + with vmalloc instead of the kernel's default allocator. This
70029 + introduces guard pages that in combination with the alloca checking
70030 + of the STACKLEAK feature prevents all forms of kernel process stack
70031 + overflow abuse. Note that this is different from kernel stack
70032 + buffer overflows.
70033 +
70034 +config GRKERNSEC_BRUTE
70035 + bool "Deter exploit bruteforcing"
70036 + default y if GRKERNSEC_CONFIG_AUTO
70037 + help
70038 + If you say Y here, attempts to bruteforce exploits against forking
70039 + daemons such as apache or sshd, as well as against suid/sgid binaries
70040 + will be deterred. When a child of a forking daemon is killed by PaX
70041 + or crashes due to an illegal instruction or other suspicious signal,
70042 + the parent process will be delayed 30 seconds upon every subsequent
70043 + fork until the administrator is able to assess the situation and
70044 + restart the daemon.
70045 + In the suid/sgid case, the attempt is logged, the user has all their
70046 + existing instances of the suid/sgid binary terminated and will
70047 + be unable to execute any suid/sgid binaries for 15 minutes.
70048 +
70049 + It is recommended that you also enable signal logging in the auditing
70050 + section so that logs are generated when a process triggers a suspicious
70051 + signal.
70052 + If the sysctl option is enabled, a sysctl option with name
70053 + "deter_bruteforce" is created.
70054 +
70055 +config GRKERNSEC_MODHARDEN
70056 + bool "Harden module auto-loading"
70057 + default y if GRKERNSEC_CONFIG_AUTO
70058 + depends on MODULES
70059 + help
70060 + If you say Y here, module auto-loading in response to use of some
70061 + feature implemented by an unloaded module will be restricted to
70062 + root users. Enabling this option helps defend against attacks
70063 + by unprivileged users who abuse the auto-loading behavior to
70064 + cause a vulnerable module to load that is then exploited.
70065 +
70066 + If this option prevents a legitimate use of auto-loading for a
70067 + non-root user, the administrator can execute modprobe manually
70068 + with the exact name of the module mentioned in the alert log.
70069 + Alternatively, the administrator can add the module to the list
70070 + of modules loaded at boot by modifying init scripts.
70071 +
70072 + Modification of init scripts will most likely be needed on
70073 + Ubuntu servers with encrypted home directory support enabled,
70074 + as the first non-root user logging in will cause the ecb(aes),
70075 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
70076 +
70077 +config GRKERNSEC_HIDESYM
70078 + bool "Hide kernel symbols"
70079 + default y if GRKERNSEC_CONFIG_AUTO
70080 + select PAX_USERCOPY_SLABS
70081 + help
70082 + If you say Y here, getting information on loaded modules, and
70083 + displaying all kernel symbols through a syscall will be restricted
70084 + to users with CAP_SYS_MODULE. For software compatibility reasons,
70085 + /proc/kallsyms will be restricted to the root user. The RBAC
70086 + system can hide that entry even from root.
70087 +
70088 + This option also prevents leaking of kernel addresses through
70089 + several /proc entries.
70090 +
70091 + Note that this option is only effective provided the following
70092 + conditions are met:
70093 + 1) The kernel using grsecurity is not precompiled by some distribution
70094 + 2) You have also enabled GRKERNSEC_DMESG
70095 + 3) You are using the RBAC system and hiding other files such as your
70096 + kernel image and System.map. Alternatively, enabling this option
70097 + causes the permissions on /boot, /lib/modules, and the kernel
70098 + source directory to change at compile time to prevent
70099 + reading by non-root users.
70100 + If the above conditions are met, this option will aid in providing a
70101 + useful protection against local kernel exploitation of overflows
70102 + and arbitrary read/write vulnerabilities.
70103 +
70104 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
70105 + in addition to this feature.
70106 +
70107 +config GRKERNSEC_RANDSTRUCT
70108 + bool "Randomize layout of sensitive kernel structures"
70109 + default y if GRKERNSEC_CONFIG_AUTO
70110 + select GRKERNSEC_HIDESYM
70111 + select MODVERSIONS if MODULES
70112 + help
70113 + If you say Y here, the layouts of a number of sensitive kernel
70114 + structures (task, fs, cred, etc) and all structures composed entirely
70115 + of function pointers (aka "ops" structs) will be randomized at compile-time.
70116 + This can introduce the requirement of an additional infoleak
70117 + vulnerability for exploits targeting these structure types.
70118 +
70119 + Enabling this feature will introduce some performance impact, slightly
70120 + increase memory usage, and prevent the use of forensic tools like
70121 + Volatility against the system (unless the kernel source tree isn't
70122 + cleaned after kernel installation).
70123 +
70124 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
70125 + It remains after a make clean to allow for external modules to be compiled
70126 + with the existing seed and will be removed by a make mrproper or
70127 + make distclean.
70128 +
70129 + Note that the implementation requires gcc 4.6.4. or newer. You may need
70130 + to install the supporting headers explicitly in addition to the normal
70131 + gcc package.
70132 +
70133 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
70134 + bool "Use cacheline-aware structure randomization"
70135 + depends on GRKERNSEC_RANDSTRUCT
70136 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
70137 + help
70138 + If you say Y here, the RANDSTRUCT randomization will make a best effort
70139 + at restricting randomization to cacheline-sized groups of elements. It
70140 + will further not randomize bitfields in structures. This reduces the
70141 + performance hit of RANDSTRUCT at the cost of weakened randomization.
70142 +
70143 +config GRKERNSEC_KERN_LOCKOUT
70144 + bool "Active kernel exploit response"
70145 + default y if GRKERNSEC_CONFIG_AUTO
70146 + depends on X86 || ARM || PPC || SPARC
70147 + help
70148 + If you say Y here, when a PaX alert is triggered due to suspicious
70149 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
70150 + or an OOPS occurs due to bad memory accesses, instead of just
70151 + terminating the offending process (and potentially allowing
70152 + a subsequent exploit from the same user), we will take one of two
70153 + actions:
70154 + If the user was root, we will panic the system
70155 + If the user was non-root, we will log the attempt, terminate
70156 + all processes owned by the user, then prevent them from creating
70157 + any new processes until the system is restarted
70158 + This deters repeated kernel exploitation/bruteforcing attempts
70159 + and is useful for later forensics.
70160 +
70161 +config GRKERNSEC_OLD_ARM_USERLAND
70162 + bool "Old ARM userland compatibility"
70163 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
70164 + help
70165 + If you say Y here, stubs of executable code to perform such operations
70166 + as "compare-exchange" will be placed at fixed locations in the ARM vector
70167 + table. This is unfortunately needed for old ARM userland meant to run
70168 + across a wide range of processors. Without this option enabled,
70169 + the get_tls and data memory barrier stubs will be emulated by the kernel,
70170 + which is enough for Linaro userlands or other userlands designed for v6
70171 + and newer ARM CPUs. It's recommended that you try without this option enabled
70172 + first, and only enable it if your userland does not boot (it will likely fail
70173 + at init time).
70174 +
70175 +endmenu
70176 +menu "Role Based Access Control Options"
70177 +depends on GRKERNSEC
70178 +
70179 +config GRKERNSEC_RBAC_DEBUG
70180 + bool
70181 +
70182 +config GRKERNSEC_NO_RBAC
70183 + bool "Disable RBAC system"
70184 + help
70185 + If you say Y here, the /dev/grsec device will be removed from the kernel,
70186 + preventing the RBAC system from being enabled. You should only say Y
70187 + here if you have no intention of using the RBAC system, so as to prevent
70188 + an attacker with root access from misusing the RBAC system to hide files
70189 + and processes when loadable module support and /dev/[k]mem have been
70190 + locked down.
70191 +
70192 +config GRKERNSEC_ACL_HIDEKERN
70193 + bool "Hide kernel processes"
70194 + help
70195 + If you say Y here, all kernel threads will be hidden to all
70196 + processes but those whose subject has the "view hidden processes"
70197 + flag.
70198 +
70199 +config GRKERNSEC_ACL_MAXTRIES
70200 + int "Maximum tries before password lockout"
70201 + default 3
70202 + help
70203 + This option enforces the maximum number of times a user can attempt
70204 + to authorize themselves with the grsecurity RBAC system before being
70205 + denied the ability to attempt authorization again for a specified time.
70206 + The lower the number, the harder it will be to brute-force a password.
70207 +
70208 +config GRKERNSEC_ACL_TIMEOUT
70209 + int "Time to wait after max password tries, in seconds"
70210 + default 30
70211 + help
70212 + This option specifies the time the user must wait after attempting to
70213 + authorize to the RBAC system with the maximum number of invalid
70214 + passwords. The higher the number, the harder it will be to brute-force
70215 + a password.
70216 +
70217 +endmenu
70218 +menu "Filesystem Protections"
70219 +depends on GRKERNSEC
70220 +
70221 +config GRKERNSEC_PROC
70222 + bool "Proc restrictions"
70223 + default y if GRKERNSEC_CONFIG_AUTO
70224 + help
70225 + If you say Y here, the permissions of the /proc filesystem
70226 + will be altered to enhance system security and privacy. You MUST
70227 + choose either a user only restriction or a user and group restriction.
70228 + Depending upon the option you choose, you can either restrict users to
70229 + see only the processes they themselves run, or choose a group that can
70230 + view all processes and files normally restricted to root if you choose
70231 + the "restrict to user only" option. NOTE: If you're running identd or
70232 + ntpd as a non-root user, you will have to run it as the group you
70233 + specify here.
70234 +
70235 +config GRKERNSEC_PROC_USER
70236 + bool "Restrict /proc to user only"
70237 + depends on GRKERNSEC_PROC
70238 + help
70239 + If you say Y here, non-root users will only be able to view their own
70240 + processes, and restricts them from viewing network-related information,
70241 + and viewing kernel symbol and module information.
70242 +
70243 +config GRKERNSEC_PROC_USERGROUP
70244 + bool "Allow special group"
70245 + default y if GRKERNSEC_CONFIG_AUTO
70246 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
70247 + help
70248 + If you say Y here, you will be able to select a group that will be
70249 + able to view all processes and network-related information. If you've
70250 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
70251 + remain hidden. This option is useful if you want to run identd as
70252 + a non-root user. The group you select may also be chosen at boot time
70253 + via "grsec_proc_gid=" on the kernel commandline.
70254 +
70255 +config GRKERNSEC_PROC_GID
70256 + int "GID for special group"
70257 + depends on GRKERNSEC_PROC_USERGROUP
70258 + default 1001
70259 +
70260 +config GRKERNSEC_PROC_ADD
70261 + bool "Additional restrictions"
70262 + default y if GRKERNSEC_CONFIG_AUTO
70263 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
70264 + help
70265 + If you say Y here, additional restrictions will be placed on
70266 + /proc that keep normal users from viewing device information and
70267 + slabinfo information that could be useful for exploits.
70268 +
70269 +config GRKERNSEC_LINK
70270 + bool "Linking restrictions"
70271 + default y if GRKERNSEC_CONFIG_AUTO
70272 + help
70273 + If you say Y here, /tmp race exploits will be prevented, since users
70274 + will no longer be able to follow symlinks owned by other users in
70275 + world-writable +t directories (e.g. /tmp), unless the owner of the
70276 + symlink is the owner of the directory. users will also not be
70277 + able to hardlink to files they do not own. If the sysctl option is
70278 + enabled, a sysctl option with name "linking_restrictions" is created.
70279 +
70280 +config GRKERNSEC_SYMLINKOWN
70281 + bool "Kernel-enforced SymlinksIfOwnerMatch"
70282 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
70283 + help
70284 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
70285 + that prevents it from being used as a security feature. As Apache
70286 + verifies the symlink by performing a stat() against the target of
70287 + the symlink before it is followed, an attacker can setup a symlink
70288 + to point to a same-owned file, then replace the symlink with one
70289 + that targets another user's file just after Apache "validates" the
70290 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
70291 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
70292 + will be in place for the group you specify. If the sysctl option
70293 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
70294 + created.
70295 +
70296 +config GRKERNSEC_SYMLINKOWN_GID
70297 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
70298 + depends on GRKERNSEC_SYMLINKOWN
70299 + default 1006
70300 + help
70301 + Setting this GID determines what group kernel-enforced
70302 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
70303 + is enabled, a sysctl option with name "symlinkown_gid" is created.
70304 +
70305 +config GRKERNSEC_FIFO
70306 + bool "FIFO restrictions"
70307 + default y if GRKERNSEC_CONFIG_AUTO
70308 + help
70309 + If you say Y here, users will not be able to write to FIFOs they don't
70310 + own in world-writable +t directories (e.g. /tmp), unless the owner of
70311 + the FIFO is the same owner of the directory it's held in. If the sysctl
70312 + option is enabled, a sysctl option with name "fifo_restrictions" is
70313 + created.
70314 +
70315 +config GRKERNSEC_SYSFS_RESTRICT
70316 + bool "Sysfs/debugfs restriction"
70317 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
70318 + depends on SYSFS
70319 + help
70320 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
70321 + any filesystem normally mounted under it (e.g. debugfs) will be
70322 + mostly accessible only by root. These filesystems generally provide access
70323 + to hardware and debug information that isn't appropriate for unprivileged
70324 + users of the system. Sysfs and debugfs have also become a large source
70325 + of new vulnerabilities, ranging from infoleaks to local compromise.
70326 + There has been very little oversight with an eye toward security involved
70327 + in adding new exporters of information to these filesystems, so their
70328 + use is discouraged.
70329 + For reasons of compatibility, a few directories have been whitelisted
70330 + for access by non-root users:
70331 + /sys/fs/selinux
70332 + /sys/fs/fuse
70333 + /sys/devices/system/cpu
70334 +
70335 +config GRKERNSEC_ROFS
70336 + bool "Runtime read-only mount protection"
70337 + depends on SYSCTL
70338 + help
70339 + If you say Y here, a sysctl option with name "romount_protect" will
70340 + be created. By setting this option to 1 at runtime, filesystems
70341 + will be protected in the following ways:
70342 + * No new writable mounts will be allowed
70343 + * Existing read-only mounts won't be able to be remounted read/write
70344 + * Write operations will be denied on all block devices
70345 + This option acts independently of grsec_lock: once it is set to 1,
70346 + it cannot be turned off. Therefore, please be mindful of the resulting
70347 + behavior if this option is enabled in an init script on a read-only
70348 + filesystem.
70349 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
70350 + and GRKERNSEC_IO should be enabled and module loading disabled via
70351 + config or at runtime.
70352 + This feature is mainly intended for secure embedded systems.
70353 +
70354 +
70355 +config GRKERNSEC_DEVICE_SIDECHANNEL
70356 + bool "Eliminate stat/notify-based device sidechannels"
70357 + default y if GRKERNSEC_CONFIG_AUTO
70358 + help
70359 + If you say Y here, timing analyses on block or character
70360 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
70361 + will be thwarted for unprivileged users. If a process without
70362 + CAP_MKNOD stats such a device, the last access and last modify times
70363 + will match the device's create time. No access or modify events
70364 + will be triggered through inotify/dnotify/fanotify for such devices.
70365 + This feature will prevent attacks that may at a minimum
70366 + allow an attacker to determine the administrator's password length.
70367 +
70368 +config GRKERNSEC_CHROOT
70369 + bool "Chroot jail restrictions"
70370 + default y if GRKERNSEC_CONFIG_AUTO
70371 + help
70372 + If you say Y here, you will be able to choose several options that will
70373 + make breaking out of a chrooted jail much more difficult. If you
70374 + encounter no software incompatibilities with the following options, it
70375 + is recommended that you enable each one.
70376 +
70377 + Note that the chroot restrictions are not intended to apply to "chroots"
70378 + to directories that are simple bind mounts of the global root filesystem.
70379 + For several other reasons, a user shouldn't expect any significant
70380 + security by performing such a chroot.
70381 +
70382 +config GRKERNSEC_CHROOT_MOUNT
70383 + bool "Deny mounts"
70384 + default y if GRKERNSEC_CONFIG_AUTO
70385 + depends on GRKERNSEC_CHROOT
70386 + help
70387 + If you say Y here, processes inside a chroot will not be able to
70388 + mount or remount filesystems. If the sysctl option is enabled, a
70389 + sysctl option with name "chroot_deny_mount" is created.
70390 +
70391 +config GRKERNSEC_CHROOT_DOUBLE
70392 + bool "Deny double-chroots"
70393 + default y if GRKERNSEC_CONFIG_AUTO
70394 + depends on GRKERNSEC_CHROOT
70395 + help
70396 + If you say Y here, processes inside a chroot will not be able to chroot
70397 + again outside the chroot. This is a widely used method of breaking
70398 + out of a chroot jail and should not be allowed. If the sysctl
70399 + option is enabled, a sysctl option with name
70400 + "chroot_deny_chroot" is created.
70401 +
70402 +config GRKERNSEC_CHROOT_PIVOT
70403 + bool "Deny pivot_root in chroot"
70404 + default y if GRKERNSEC_CONFIG_AUTO
70405 + depends on GRKERNSEC_CHROOT
70406 + help
70407 + If you say Y here, processes inside a chroot will not be able to use
70408 + a function called pivot_root() that was introduced in Linux 2.3.41. It
70409 + works similar to chroot in that it changes the root filesystem. This
70410 + function could be misused in a chrooted process to attempt to break out
70411 + of the chroot, and therefore should not be allowed. If the sysctl
70412 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
70413 + created.
70414 +
70415 +config GRKERNSEC_CHROOT_CHDIR
70416 + bool "Enforce chdir(\"/\") on all chroots"
70417 + default y if GRKERNSEC_CONFIG_AUTO
70418 + depends on GRKERNSEC_CHROOT
70419 + help
70420 + If you say Y here, the current working directory of all newly-chrooted
70421 + applications will be set to the the root directory of the chroot.
70422 + The man page on chroot(2) states:
70423 + Note that this call does not change the current working
70424 + directory, so that `.' can be outside the tree rooted at
70425 + `/'. In particular, the super-user can escape from a
70426 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
70427 +
70428 + It is recommended that you say Y here, since it's not known to break
70429 + any software. If the sysctl option is enabled, a sysctl option with
70430 + name "chroot_enforce_chdir" is created.
70431 +
70432 +config GRKERNSEC_CHROOT_CHMOD
70433 + bool "Deny (f)chmod +s"
70434 + default y if GRKERNSEC_CONFIG_AUTO
70435 + depends on GRKERNSEC_CHROOT
70436 + help
70437 + If you say Y here, processes inside a chroot will not be able to chmod
70438 + or fchmod files to make them have suid or sgid bits. This protects
70439 + against another published method of breaking a chroot. If the sysctl
70440 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
70441 + created.
70442 +
70443 +config GRKERNSEC_CHROOT_FCHDIR
70444 + bool "Deny fchdir and fhandle out of chroot"
70445 + default y if GRKERNSEC_CONFIG_AUTO
70446 + depends on GRKERNSEC_CHROOT
70447 + help
70448 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
70449 + to a file descriptor of the chrooting process that points to a directory
70450 + outside the filesystem will be stopped. Additionally, this option prevents
70451 + use of the recently-created syscall for opening files by a guessable "file
70452 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
70453 + with name "chroot_deny_fchdir" is created.
70454 +
70455 +config GRKERNSEC_CHROOT_MKNOD
70456 + bool "Deny mknod"
70457 + default y if GRKERNSEC_CONFIG_AUTO
70458 + depends on GRKERNSEC_CHROOT
70459 + help
70460 + If you say Y here, processes inside a chroot will not be allowed to
70461 + mknod. The problem with using mknod inside a chroot is that it
70462 + would allow an attacker to create a device entry that is the same
70463 + as one on the physical root of your system, which could range from
70464 + anything from the console device to a device for your harddrive (which
70465 + they could then use to wipe the drive or steal data). It is recommended
70466 + that you say Y here, unless you run into software incompatibilities.
70467 + If the sysctl option is enabled, a sysctl option with name
70468 + "chroot_deny_mknod" is created.
70469 +
70470 +config GRKERNSEC_CHROOT_SHMAT
70471 + bool "Deny shmat() out of chroot"
70472 + default y if GRKERNSEC_CONFIG_AUTO
70473 + depends on GRKERNSEC_CHROOT
70474 + help
70475 + If you say Y here, processes inside a chroot will not be able to attach
70476 + to shared memory segments that were created outside of the chroot jail.
70477 + It is recommended that you say Y here. If the sysctl option is enabled,
70478 + a sysctl option with name "chroot_deny_shmat" is created.
70479 +
70480 +config GRKERNSEC_CHROOT_UNIX
70481 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
70482 + default y if GRKERNSEC_CONFIG_AUTO
70483 + depends on GRKERNSEC_CHROOT
70484 + help
70485 + If you say Y here, processes inside a chroot will not be able to
70486 + connect to abstract (meaning not belonging to a filesystem) Unix
70487 + domain sockets that were bound outside of a chroot. It is recommended
70488 + that you say Y here. If the sysctl option is enabled, a sysctl option
70489 + with name "chroot_deny_unix" is created.
70490 +
70491 +config GRKERNSEC_CHROOT_FINDTASK
70492 + bool "Protect outside processes"
70493 + default y if GRKERNSEC_CONFIG_AUTO
70494 + depends on GRKERNSEC_CHROOT
70495 + help
70496 + If you say Y here, processes inside a chroot will not be able to
70497 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
70498 + getsid, or view any process outside of the chroot. If the sysctl
70499 + option is enabled, a sysctl option with name "chroot_findtask" is
70500 + created.
70501 +
70502 +config GRKERNSEC_CHROOT_NICE
70503 + bool "Restrict priority changes"
70504 + default y if GRKERNSEC_CONFIG_AUTO
70505 + depends on GRKERNSEC_CHROOT
70506 + help
70507 + If you say Y here, processes inside a chroot will not be able to raise
70508 + the priority of processes in the chroot, or alter the priority of
70509 + processes outside the chroot. This provides more security than simply
70510 + removing CAP_SYS_NICE from the process' capability set. If the
70511 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
70512 + is created.
70513 +
70514 +config GRKERNSEC_CHROOT_SYSCTL
70515 + bool "Deny sysctl writes"
70516 + default y if GRKERNSEC_CONFIG_AUTO
70517 + depends on GRKERNSEC_CHROOT
70518 + help
70519 + If you say Y here, an attacker in a chroot will not be able to
70520 + write to sysctl entries, either by sysctl(2) or through a /proc
70521 + interface. It is strongly recommended that you say Y here. If the
70522 + sysctl option is enabled, a sysctl option with name
70523 + "chroot_deny_sysctl" is created.
70524 +
70525 +config GRKERNSEC_CHROOT_CAPS
70526 + bool "Capability restrictions"
70527 + default y if GRKERNSEC_CONFIG_AUTO
70528 + depends on GRKERNSEC_CHROOT
70529 + help
70530 + If you say Y here, the capabilities on all processes within a
70531 + chroot jail will be lowered to stop module insertion, raw i/o,
70532 + system and net admin tasks, rebooting the system, modifying immutable
70533 + files, modifying IPC owned by another, and changing the system time.
70534 + This is left an option because it can break some apps. Disable this
70535 + if your chrooted apps are having problems performing those kinds of
70536 + tasks. If the sysctl option is enabled, a sysctl option with
70537 + name "chroot_caps" is created.
70538 +
70539 +config GRKERNSEC_CHROOT_INITRD
70540 + bool "Exempt initrd tasks from restrictions"
70541 + default y if GRKERNSEC_CONFIG_AUTO
70542 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
70543 + help
70544 + If you say Y here, tasks started prior to init will be exempted from
70545 + grsecurity's chroot restrictions. This option is mainly meant to
70546 + resolve Plymouth's performing privileged operations unnecessarily
70547 + in a chroot.
70548 +
70549 +endmenu
70550 +menu "Kernel Auditing"
70551 +depends on GRKERNSEC
70552 +
70553 +config GRKERNSEC_AUDIT_GROUP
70554 + bool "Single group for auditing"
70555 + help
70556 + If you say Y here, the exec and chdir logging features will only operate
70557 + on a group you specify. This option is recommended if you only want to
70558 + watch certain users instead of having a large amount of logs from the
70559 + entire system. If the sysctl option is enabled, a sysctl option with
70560 + name "audit_group" is created.
70561 +
70562 +config GRKERNSEC_AUDIT_GID
70563 + int "GID for auditing"
70564 + depends on GRKERNSEC_AUDIT_GROUP
70565 + default 1007
70566 +
70567 +config GRKERNSEC_EXECLOG
70568 + bool "Exec logging"
70569 + help
70570 + If you say Y here, all execve() calls will be logged (since the
70571 + other exec*() calls are frontends to execve(), all execution
70572 + will be logged). Useful for shell-servers that like to keep track
70573 + of their users. If the sysctl option is enabled, a sysctl option with
70574 + name "exec_logging" is created.
70575 + WARNING: This option when enabled will produce a LOT of logs, especially
70576 + on an active system.
70577 +
70578 +config GRKERNSEC_RESLOG
70579 + bool "Resource logging"
70580 + default y if GRKERNSEC_CONFIG_AUTO
70581 + help
70582 + If you say Y here, all attempts to overstep resource limits will
70583 + be logged with the resource name, the requested size, and the current
70584 + limit. It is highly recommended that you say Y here. If the sysctl
70585 + option is enabled, a sysctl option with name "resource_logging" is
70586 + created. If the RBAC system is enabled, the sysctl value is ignored.
70587 +
70588 +config GRKERNSEC_CHROOT_EXECLOG
70589 + bool "Log execs within chroot"
70590 + help
70591 + If you say Y here, all executions inside a chroot jail will be logged
70592 + to syslog. This can cause a large amount of logs if certain
70593 + applications (eg. djb's daemontools) are installed on the system, and
70594 + is therefore left as an option. If the sysctl option is enabled, a
70595 + sysctl option with name "chroot_execlog" is created.
70596 +
70597 +config GRKERNSEC_AUDIT_PTRACE
70598 + bool "Ptrace logging"
70599 + help
70600 + If you say Y here, all attempts to attach to a process via ptrace
70601 + will be logged. If the sysctl option is enabled, a sysctl option
70602 + with name "audit_ptrace" is created.
70603 +
70604 +config GRKERNSEC_AUDIT_CHDIR
70605 + bool "Chdir logging"
70606 + help
70607 + If you say Y here, all chdir() calls will be logged. If the sysctl
70608 + option is enabled, a sysctl option with name "audit_chdir" is created.
70609 +
70610 +config GRKERNSEC_AUDIT_MOUNT
70611 + bool "(Un)Mount logging"
70612 + help
70613 + If you say Y here, all mounts and unmounts will be logged. If the
70614 + sysctl option is enabled, a sysctl option with name "audit_mount" is
70615 + created.
70616 +
70617 +config GRKERNSEC_SIGNAL
70618 + bool "Signal logging"
70619 + default y if GRKERNSEC_CONFIG_AUTO
70620 + help
70621 + If you say Y here, certain important signals will be logged, such as
70622 + SIGSEGV, which will as a result inform you of when a error in a program
70623 + occurred, which in some cases could mean a possible exploit attempt.
70624 + If the sysctl option is enabled, a sysctl option with name
70625 + "signal_logging" is created.
70626 +
70627 +config GRKERNSEC_FORKFAIL
70628 + bool "Fork failure logging"
70629 + help
70630 + If you say Y here, all failed fork() attempts will be logged.
70631 + This could suggest a fork bomb, or someone attempting to overstep
70632 + their process limit. If the sysctl option is enabled, a sysctl option
70633 + with name "forkfail_logging" is created.
70634 +
70635 +config GRKERNSEC_TIME
70636 + bool "Time change logging"
70637 + default y if GRKERNSEC_CONFIG_AUTO
70638 + help
70639 + If you say Y here, any changes of the system clock will be logged.
70640 + If the sysctl option is enabled, a sysctl option with name
70641 + "timechange_logging" is created.
70642 +
70643 +config GRKERNSEC_PROC_IPADDR
70644 + bool "/proc/<pid>/ipaddr support"
70645 + default y if GRKERNSEC_CONFIG_AUTO
70646 + help
70647 + If you say Y here, a new entry will be added to each /proc/<pid>
70648 + directory that contains the IP address of the person using the task.
70649 + The IP is carried across local TCP and AF_UNIX stream sockets.
70650 + This information can be useful for IDS/IPSes to perform remote response
70651 + to a local attack. The entry is readable by only the owner of the
70652 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
70653 + the RBAC system), and thus does not create privacy concerns.
70654 +
70655 +config GRKERNSEC_RWXMAP_LOG
70656 + bool 'Denied RWX mmap/mprotect logging'
70657 + default y if GRKERNSEC_CONFIG_AUTO
70658 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
70659 + help
70660 + If you say Y here, calls to mmap() and mprotect() with explicit
70661 + usage of PROT_WRITE and PROT_EXEC together will be logged when
70662 + denied by the PAX_MPROTECT feature. This feature will also
70663 + log other problematic scenarios that can occur when PAX_MPROTECT
70664 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
70665 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
70666 + is created.
70667 +
70668 +endmenu
70669 +
70670 +menu "Executable Protections"
70671 +depends on GRKERNSEC
70672 +
70673 +config GRKERNSEC_DMESG
70674 + bool "Dmesg(8) restriction"
70675 + default y if GRKERNSEC_CONFIG_AUTO
70676 + help
70677 + If you say Y here, non-root users will not be able to use dmesg(8)
70678 + to view the contents of the kernel's circular log buffer.
70679 + The kernel's log buffer often contains kernel addresses and other
70680 + identifying information useful to an attacker in fingerprinting a
70681 + system for a targeted exploit.
70682 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
70683 + created.
70684 +
70685 +config GRKERNSEC_HARDEN_PTRACE
70686 + bool "Deter ptrace-based process snooping"
70687 + default y if GRKERNSEC_CONFIG_AUTO
70688 + help
70689 + If you say Y here, TTY sniffers and other malicious monitoring
70690 + programs implemented through ptrace will be defeated. If you
70691 + have been using the RBAC system, this option has already been
70692 + enabled for several years for all users, with the ability to make
70693 + fine-grained exceptions.
70694 +
70695 + This option only affects the ability of non-root users to ptrace
70696 + processes that are not a descendent of the ptracing process.
70697 + This means that strace ./binary and gdb ./binary will still work,
70698 + but attaching to arbitrary processes will not. If the sysctl
70699 + option is enabled, a sysctl option with name "harden_ptrace" is
70700 + created.
70701 +
70702 +config GRKERNSEC_PTRACE_READEXEC
70703 + bool "Require read access to ptrace sensitive binaries"
70704 + default y if GRKERNSEC_CONFIG_AUTO
70705 + help
70706 + If you say Y here, unprivileged users will not be able to ptrace unreadable
70707 + binaries. This option is useful in environments that
70708 + remove the read bits (e.g. file mode 4711) from suid binaries to
70709 + prevent infoleaking of their contents. This option adds
70710 + consistency to the use of that file mode, as the binary could normally
70711 + be read out when run without privileges while ptracing.
70712 +
70713 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
70714 + is created.
70715 +
70716 +config GRKERNSEC_SETXID
70717 + bool "Enforce consistent multithreaded privileges"
70718 + default y if GRKERNSEC_CONFIG_AUTO
70719 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
70720 + help
70721 + If you say Y here, a change from a root uid to a non-root uid
70722 + in a multithreaded application will cause the resulting uids,
70723 + gids, supplementary groups, and capabilities in that thread
70724 + to be propagated to the other threads of the process. In most
70725 + cases this is unnecessary, as glibc will emulate this behavior
70726 + on behalf of the application. Other libcs do not act in the
70727 + same way, allowing the other threads of the process to continue
70728 + running with root privileges. If the sysctl option is enabled,
70729 + a sysctl option with name "consistent_setxid" is created.
70730 +
70731 +config GRKERNSEC_HARDEN_IPC
70732 + bool "Disallow access to overly-permissive IPC objects"
70733 + default y if GRKERNSEC_CONFIG_AUTO
70734 + depends on SYSVIPC
70735 + help
70736 + If you say Y here, access to overly-permissive IPC objects (shared
70737 + memory, message queues, and semaphores) will be denied for processes
70738 + given the following criteria beyond normal permission checks:
70739 + 1) If the IPC object is world-accessible and the euid doesn't match
70740 + that of the creator or current uid for the IPC object
70741 + 2) If the IPC object is group-accessible and the egid doesn't
70742 + match that of the creator or current gid for the IPC object
70743 + It's a common error to grant too much permission to these objects,
70744 + with impact ranging from denial of service and information leaking to
70745 + privilege escalation. This feature was developed in response to
70746 + research by Tim Brown:
70747 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
70748 + who found hundreds of such insecure usages. Processes with
70749 + CAP_IPC_OWNER are still permitted to access these IPC objects.
70750 + If the sysctl option is enabled, a sysctl option with name
70751 + "harden_ipc" is created.
70752 +
70753 +config GRKERNSEC_TPE
70754 + bool "Trusted Path Execution (TPE)"
70755 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
70756 + help
70757 + If you say Y here, you will be able to choose a gid to add to the
70758 + supplementary groups of users you want to mark as "untrusted."
70759 + These users will not be able to execute any files that are not in
70760 + root-owned directories writable only by root. If the sysctl option
70761 + is enabled, a sysctl option with name "tpe" is created.
70762 +
70763 +config GRKERNSEC_TPE_ALL
70764 + bool "Partially restrict all non-root users"
70765 + depends on GRKERNSEC_TPE
70766 + help
70767 + If you say Y here, all non-root users will be covered under
70768 + a weaker TPE restriction. This is separate from, and in addition to,
70769 + the main TPE options that you have selected elsewhere. Thus, if a
70770 + "trusted" GID is chosen, this restriction applies to even that GID.
70771 + Under this restriction, all non-root users will only be allowed to
70772 + execute files in directories they own that are not group or
70773 + world-writable, or in directories owned by root and writable only by
70774 + root. If the sysctl option is enabled, a sysctl option with name
70775 + "tpe_restrict_all" is created.
70776 +
70777 +config GRKERNSEC_TPE_INVERT
70778 + bool "Invert GID option"
70779 + depends on GRKERNSEC_TPE
70780 + help
70781 + If you say Y here, the group you specify in the TPE configuration will
70782 + decide what group TPE restrictions will be *disabled* for. This
70783 + option is useful if you want TPE restrictions to be applied to most
70784 + users on the system. If the sysctl option is enabled, a sysctl option
70785 + with name "tpe_invert" is created. Unlike other sysctl options, this
70786 + entry will default to on for backward-compatibility.
70787 +
70788 +config GRKERNSEC_TPE_GID
70789 + int
70790 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
70791 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
70792 +
70793 +config GRKERNSEC_TPE_UNTRUSTED_GID
70794 + int "GID for TPE-untrusted users"
70795 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
70796 + default 1005
70797 + help
70798 + Setting this GID determines what group TPE restrictions will be
70799 + *enabled* for. If the sysctl option is enabled, a sysctl option
70800 + with name "tpe_gid" is created.
70801 +
70802 +config GRKERNSEC_TPE_TRUSTED_GID
70803 + int "GID for TPE-trusted users"
70804 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
70805 + default 1005
70806 + help
70807 + Setting this GID determines what group TPE restrictions will be
70808 + *disabled* for. If the sysctl option is enabled, a sysctl option
70809 + with name "tpe_gid" is created.
70810 +
70811 +endmenu
70812 +menu "Network Protections"
70813 +depends on GRKERNSEC
70814 +
70815 +config GRKERNSEC_BLACKHOLE
70816 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
70817 + default y if GRKERNSEC_CONFIG_AUTO
70818 + depends on NET
70819 + help
70820 + If you say Y here, neither TCP resets nor ICMP
70821 + destination-unreachable packets will be sent in response to packets
70822 + sent to ports for which no associated listening process exists.
70823 + This feature supports both IPV4 and IPV6 and exempts the
70824 + loopback interface from blackholing. Enabling this feature
70825 + makes a host more resilient to DoS attacks and reduces network
70826 + visibility against scanners.
70827 +
70828 + The blackhole feature as-implemented is equivalent to the FreeBSD
70829 + blackhole feature, as it prevents RST responses to all packets, not
70830 + just SYNs. Under most application behavior this causes no
70831 + problems, but applications (like haproxy) may not close certain
70832 + connections in a way that cleanly terminates them on the remote
70833 + end, leaving the remote host in LAST_ACK state. Because of this
70834 + side-effect and to prevent intentional LAST_ACK DoSes, this
70835 + feature also adds automatic mitigation against such attacks.
70836 + The mitigation drastically reduces the amount of time a socket
70837 + can spend in LAST_ACK state. If you're using haproxy and not
70838 + all servers it connects to have this option enabled, consider
70839 + disabling this feature on the haproxy host.
70840 +
70841 + If the sysctl option is enabled, two sysctl options with names
70842 + "ip_blackhole" and "lastack_retries" will be created.
70843 + While "ip_blackhole" takes the standard zero/non-zero on/off
70844 + toggle, "lastack_retries" uses the same kinds of values as
70845 + "tcp_retries1" and "tcp_retries2". The default value of 4
70846 + prevents a socket from lasting more than 45 seconds in LAST_ACK
70847 + state.
70848 +
70849 +config GRKERNSEC_NO_SIMULT_CONNECT
70850 + bool "Disable TCP Simultaneous Connect"
70851 + default y if GRKERNSEC_CONFIG_AUTO
70852 + depends on NET
70853 + help
70854 + If you say Y here, a feature by Willy Tarreau will be enabled that
70855 + removes a weakness in Linux's strict implementation of TCP that
70856 + allows two clients to connect to each other without either entering
70857 + a listening state. The weakness allows an attacker to easily prevent
70858 + a client from connecting to a known server provided the source port
70859 + for the connection is guessed correctly.
70860 +
70861 + As the weakness could be used to prevent an antivirus or IPS from
70862 + fetching updates, or prevent an SSL gateway from fetching a CRL,
70863 + it should be eliminated by enabling this option. Though Linux is
70864 + one of few operating systems supporting simultaneous connect, it
70865 + has no legitimate use in practice and is rarely supported by firewalls.
70866 +
70867 +config GRKERNSEC_SOCKET
70868 + bool "Socket restrictions"
70869 + depends on NET
70870 + help
70871 + If you say Y here, you will be able to choose from several options.
70872 + If you assign a GID on your system and add it to the supplementary
70873 + groups of users you want to restrict socket access to, this patch
70874 + will perform up to three things, based on the option(s) you choose.
70875 +
70876 +config GRKERNSEC_SOCKET_ALL
70877 + bool "Deny any sockets to group"
70878 + depends on GRKERNSEC_SOCKET
70879 + help
70880 + If you say Y here, you will be able to choose a GID of whose users will
70881 + be unable to connect to other hosts from your machine or run server
70882 + applications from your machine. If the sysctl option is enabled, a
70883 + sysctl option with name "socket_all" is created.
70884 +
70885 +config GRKERNSEC_SOCKET_ALL_GID
70886 + int "GID to deny all sockets for"
70887 + depends on GRKERNSEC_SOCKET_ALL
70888 + default 1004
70889 + help
70890 + Here you can choose the GID to disable socket access for. Remember to
70891 + add the users you want socket access disabled for to the GID
70892 + specified here. If the sysctl option is enabled, a sysctl option
70893 + with name "socket_all_gid" is created.
70894 +
70895 +config GRKERNSEC_SOCKET_CLIENT
70896 + bool "Deny client sockets to group"
70897 + depends on GRKERNSEC_SOCKET
70898 + help
70899 + If you say Y here, you will be able to choose a GID of whose users will
70900 + be unable to connect to other hosts from your machine, but will be
70901 + able to run servers. If this option is enabled, all users in the group
70902 + you specify will have to use passive mode when initiating ftp transfers
70903 + from the shell on your machine. If the sysctl option is enabled, a
70904 + sysctl option with name "socket_client" is created.
70905 +
70906 +config GRKERNSEC_SOCKET_CLIENT_GID
70907 + int "GID to deny client sockets for"
70908 + depends on GRKERNSEC_SOCKET_CLIENT
70909 + default 1003
70910 + help
70911 + Here you can choose the GID to disable client socket access for.
70912 + Remember to add the users you want client socket access disabled for to
70913 + the GID specified here. If the sysctl option is enabled, a sysctl
70914 + option with name "socket_client_gid" is created.
70915 +
70916 +config GRKERNSEC_SOCKET_SERVER
70917 + bool "Deny server sockets to group"
70918 + depends on GRKERNSEC_SOCKET
70919 + help
70920 + If you say Y here, you will be able to choose a GID of whose users will
70921 + be unable to run server applications from your machine. If the sysctl
70922 + option is enabled, a sysctl option with name "socket_server" is created.
70923 +
70924 +config GRKERNSEC_SOCKET_SERVER_GID
70925 + int "GID to deny server sockets for"
70926 + depends on GRKERNSEC_SOCKET_SERVER
70927 + default 1002
70928 + help
70929 + Here you can choose the GID to disable server socket access for.
70930 + Remember to add the users you want server socket access disabled for to
70931 + the GID specified here. If the sysctl option is enabled, a sysctl
70932 + option with name "socket_server_gid" is created.
70933 +
70934 +endmenu
70935 +
70936 +menu "Physical Protections"
70937 +depends on GRKERNSEC
70938 +
70939 +config GRKERNSEC_DENYUSB
70940 + bool "Deny new USB connections after toggle"
70941 + default y if GRKERNSEC_CONFIG_AUTO
70942 + depends on SYSCTL && USB_SUPPORT
70943 + help
70944 + If you say Y here, a new sysctl option with name "deny_new_usb"
70945 + will be created. Setting its value to 1 will prevent any new
70946 + USB devices from being recognized by the OS. Any attempted USB
70947 + device insertion will be logged. This option is intended to be
70948 + used against custom USB devices designed to exploit vulnerabilities
70949 + in various USB device drivers.
70950 +
70951 + For greatest effectiveness, this sysctl should be set after any
70952 + relevant init scripts. This option is safe to enable in distros
70953 + as each user can choose whether or not to toggle the sysctl.
70954 +
70955 +config GRKERNSEC_DENYUSB_FORCE
70956 + bool "Reject all USB devices not connected at boot"
70957 + select USB
70958 + depends on GRKERNSEC_DENYUSB
70959 + help
70960 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
70961 + that doesn't involve a sysctl entry. This option should only be
70962 + enabled if you're sure you want to deny all new USB connections
70963 + at runtime and don't want to modify init scripts. This should not
70964 + be enabled by distros. It forces the core USB code to be built
70965 + into the kernel image so that all devices connected at boot time
70966 + can be recognized and new USB device connections can be prevented
70967 + prior to init running.
70968 +
70969 +endmenu
70970 +
70971 +menu "Sysctl Support"
70972 +depends on GRKERNSEC && SYSCTL
70973 +
70974 +config GRKERNSEC_SYSCTL
70975 + bool "Sysctl support"
70976 + default y if GRKERNSEC_CONFIG_AUTO
70977 + help
70978 + If you say Y here, you will be able to change the options that
70979 + grsecurity runs with at bootup, without having to recompile your
70980 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
70981 + to enable (1) or disable (0) various features. All the sysctl entries
70982 + are mutable until the "grsec_lock" entry is set to a non-zero value.
70983 + All features enabled in the kernel configuration are disabled at boot
70984 + if you do not say Y to the "Turn on features by default" option.
70985 + All options should be set at startup, and the grsec_lock entry should
70986 + be set to a non-zero value after all the options are set.
70987 + *THIS IS EXTREMELY IMPORTANT*
70988 +
70989 +config GRKERNSEC_SYSCTL_DISTRO
70990 + bool "Extra sysctl support for distro makers (READ HELP)"
70991 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
70992 + help
70993 + If you say Y here, additional sysctl options will be created
70994 + for features that affect processes running as root. Therefore,
70995 + it is critical when using this option that the grsec_lock entry be
70996 + enabled after boot. Only distros with prebuilt kernel packages
70997 + with this option enabled that can ensure grsec_lock is enabled
70998 + after boot should use this option.
70999 + *Failure to set grsec_lock after boot makes all grsec features
71000 + this option covers useless*
71001 +
71002 + Currently this option creates the following sysctl entries:
71003 + "Disable Privileged I/O": "disable_priv_io"
71004 +
71005 +config GRKERNSEC_SYSCTL_ON
71006 + bool "Turn on features by default"
71007 + default y if GRKERNSEC_CONFIG_AUTO
71008 + depends on GRKERNSEC_SYSCTL
71009 + help
71010 + If you say Y here, instead of having all features enabled in the
71011 + kernel configuration disabled at boot time, the features will be
71012 + enabled at boot time. It is recommended you say Y here unless
71013 + there is some reason you would want all sysctl-tunable features to
71014 + be disabled by default. As mentioned elsewhere, it is important
71015 + to enable the grsec_lock entry once you have finished modifying
71016 + the sysctl entries.
71017 +
71018 +endmenu
71019 +menu "Logging Options"
71020 +depends on GRKERNSEC
71021 +
71022 +config GRKERNSEC_FLOODTIME
71023 + int "Seconds in between log messages (minimum)"
71024 + default 10
71025 + help
71026 + This option allows you to enforce the number of seconds between
71027 + grsecurity log messages. The default should be suitable for most
71028 + people, however, if you choose to change it, choose a value small enough
71029 + to allow informative logs to be produced, but large enough to
71030 + prevent flooding.
71031 +
71032 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
71033 + any rate limiting on grsecurity log messages.
71034 +
71035 +config GRKERNSEC_FLOODBURST
71036 + int "Number of messages in a burst (maximum)"
71037 + default 6
71038 + help
71039 + This option allows you to choose the maximum number of messages allowed
71040 + within the flood time interval you chose in a separate option. The
71041 + default should be suitable for most people, however if you find that
71042 + many of your logs are being interpreted as flooding, you may want to
71043 + raise this value.
71044 +
71045 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
71046 + any rate limiting on grsecurity log messages.
71047 +
71048 +endmenu
71049 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
71050 new file mode 100644
71051 index 0000000..30ababb
71052 --- /dev/null
71053 +++ b/grsecurity/Makefile
71054 @@ -0,0 +1,54 @@
71055 +# grsecurity – access control and security hardening for Linux
71056 +# All code in this directory and various hooks located throughout the Linux kernel are
71057 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
71058 +# http://www.grsecurity.net spender@grsecurity.net
71059 +#
71060 +# This program is free software; you can redistribute it and/or
71061 +# modify it under the terms of the GNU General Public License version 2
71062 +# as published by the Free Software Foundation.
71063 +#
71064 +# This program is distributed in the hope that it will be useful,
71065 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
71066 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71067 +# GNU General Public License for more details.
71068 +#
71069 +# You should have received a copy of the GNU General Public License
71070 +# along with this program; if not, write to the Free Software
71071 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
71072 +
71073 +KBUILD_CFLAGS += -Werror
71074 +
71075 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
71076 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
71077 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
71078 + grsec_usb.o grsec_ipc.o grsec_proc.o
71079 +
71080 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
71081 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
71082 + gracl_learn.o grsec_log.o gracl_policy.o
71083 +ifdef CONFIG_COMPAT
71084 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
71085 +endif
71086 +
71087 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
71088 +
71089 +ifdef CONFIG_NET
71090 +obj-y += grsec_sock.o
71091 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
71092 +endif
71093 +
71094 +ifndef CONFIG_GRKERNSEC
71095 +obj-y += grsec_disabled.o
71096 +endif
71097 +
71098 +ifdef CONFIG_GRKERNSEC_HIDESYM
71099 +extra-y := grsec_hidesym.o
71100 +$(obj)/grsec_hidesym.o:
71101 + @-chmod -f 500 /boot
71102 + @-chmod -f 500 /lib/modules
71103 + @-chmod -f 500 /lib64/modules
71104 + @-chmod -f 500 /lib32/modules
71105 + @-chmod -f 700 .
71106 + @-chmod -f 700 $(objtree)
71107 + @echo ' grsec: protected kernel image paths'
71108 +endif
71109 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
71110 new file mode 100644
71111 index 0000000..58223f6
71112 --- /dev/null
71113 +++ b/grsecurity/gracl.c
71114 @@ -0,0 +1,2702 @@
71115 +#include <linux/kernel.h>
71116 +#include <linux/module.h>
71117 +#include <linux/sched.h>
71118 +#include <linux/mm.h>
71119 +#include <linux/file.h>
71120 +#include <linux/fs.h>
71121 +#include <linux/namei.h>
71122 +#include <linux/mount.h>
71123 +#include <linux/tty.h>
71124 +#include <linux/proc_fs.h>
71125 +#include <linux/lglock.h>
71126 +#include <linux/slab.h>
71127 +#include <linux/vmalloc.h>
71128 +#include <linux/types.h>
71129 +#include <linux/sysctl.h>
71130 +#include <linux/netdevice.h>
71131 +#include <linux/ptrace.h>
71132 +#include <linux/gracl.h>
71133 +#include <linux/gralloc.h>
71134 +#include <linux/security.h>
71135 +#include <linux/grinternal.h>
71136 +#include <linux/pid_namespace.h>
71137 +#include <linux/stop_machine.h>
71138 +#include <linux/fdtable.h>
71139 +#include <linux/percpu.h>
71140 +#include <linux/lglock.h>
71141 +#include <linux/hugetlb.h>
71142 +#include <linux/posix-timers.h>
71143 +#include <linux/prefetch.h>
71144 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71145 +#include <linux/magic.h>
71146 +#include <linux/pagemap.h>
71147 +#include "../fs/btrfs/async-thread.h"
71148 +#include "../fs/btrfs/ctree.h"
71149 +#include "../fs/btrfs/btrfs_inode.h"
71150 +#endif
71151 +#include "../fs/mount.h"
71152 +
71153 +#include <asm/uaccess.h>
71154 +#include <asm/errno.h>
71155 +#include <asm/mman.h>
71156 +
71157 +#define FOR_EACH_ROLE_START(role) \
71158 + role = running_polstate.role_list; \
71159 + while (role) {
71160 +
71161 +#define FOR_EACH_ROLE_END(role) \
71162 + role = role->prev; \
71163 + }
71164 +
71165 +extern struct path gr_real_root;
71166 +
71167 +static struct gr_policy_state running_polstate;
71168 +struct gr_policy_state *polstate = &running_polstate;
71169 +extern struct gr_alloc_state *current_alloc_state;
71170 +
71171 +extern char *gr_shared_page[4];
71172 +DEFINE_RWLOCK(gr_inode_lock);
71173 +
71174 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
71175 +
71176 +#ifdef CONFIG_NET
71177 +extern struct vfsmount *sock_mnt;
71178 +#endif
71179 +
71180 +extern struct vfsmount *pipe_mnt;
71181 +extern struct vfsmount *shm_mnt;
71182 +
71183 +#ifdef CONFIG_HUGETLBFS
71184 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
71185 +#endif
71186 +
71187 +extern u16 acl_sp_role_value;
71188 +extern struct acl_object_label *fakefs_obj_rw;
71189 +extern struct acl_object_label *fakefs_obj_rwx;
71190 +
71191 +int gr_acl_is_enabled(void)
71192 +{
71193 + return (gr_status & GR_READY);
71194 +}
71195 +
71196 +void gr_enable_rbac_system(void)
71197 +{
71198 + pax_open_kernel();
71199 + gr_status |= GR_READY;
71200 + pax_close_kernel();
71201 +}
71202 +
71203 +int gr_rbac_disable(void *unused)
71204 +{
71205 + pax_open_kernel();
71206 + gr_status &= ~GR_READY;
71207 + pax_close_kernel();
71208 +
71209 + return 0;
71210 +}
71211 +
71212 +static inline dev_t __get_dev(const struct dentry *dentry)
71213 +{
71214 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71215 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71216 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
71217 + else
71218 +#endif
71219 + return dentry->d_sb->s_dev;
71220 +}
71221 +
71222 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
71223 +{
71224 + return __get_dev(dentry);
71225 +}
71226 +
71227 +static char gr_task_roletype_to_char(struct task_struct *task)
71228 +{
71229 + switch (task->role->roletype &
71230 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
71231 + GR_ROLE_SPECIAL)) {
71232 + case GR_ROLE_DEFAULT:
71233 + return 'D';
71234 + case GR_ROLE_USER:
71235 + return 'U';
71236 + case GR_ROLE_GROUP:
71237 + return 'G';
71238 + case GR_ROLE_SPECIAL:
71239 + return 'S';
71240 + }
71241 +
71242 + return 'X';
71243 +}
71244 +
71245 +char gr_roletype_to_char(void)
71246 +{
71247 + return gr_task_roletype_to_char(current);
71248 +}
71249 +
71250 +__inline__ int
71251 +gr_acl_tpe_check(void)
71252 +{
71253 + if (unlikely(!(gr_status & GR_READY)))
71254 + return 0;
71255 + if (current->role->roletype & GR_ROLE_TPE)
71256 + return 1;
71257 + else
71258 + return 0;
71259 +}
71260 +
71261 +int
71262 +gr_handle_rawio(const struct inode *inode)
71263 +{
71264 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71265 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
71266 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
71267 + !capable(CAP_SYS_RAWIO))
71268 + return 1;
71269 +#endif
71270 + return 0;
71271 +}
71272 +
71273 +int
71274 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
71275 +{
71276 + if (likely(lena != lenb))
71277 + return 0;
71278 +
71279 + return !memcmp(a, b, lena);
71280 +}
71281 +
71282 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
71283 +{
71284 + *buflen -= namelen;
71285 + if (*buflen < 0)
71286 + return -ENAMETOOLONG;
71287 + *buffer -= namelen;
71288 + memcpy(*buffer, str, namelen);
71289 + return 0;
71290 +}
71291 +
71292 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
71293 +{
71294 + return prepend(buffer, buflen, name->name, name->len);
71295 +}
71296 +
71297 +static int prepend_path(const struct path *path, struct path *root,
71298 + char **buffer, int *buflen)
71299 +{
71300 + struct dentry *dentry = path->dentry;
71301 + struct vfsmount *vfsmnt = path->mnt;
71302 + struct mount *mnt = real_mount(vfsmnt);
71303 + bool slash = false;
71304 + int error = 0;
71305 +
71306 + while (dentry != root->dentry || vfsmnt != root->mnt) {
71307 + struct dentry * parent;
71308 +
71309 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
71310 + /* Global root? */
71311 + if (!mnt_has_parent(mnt)) {
71312 + goto out;
71313 + }
71314 + dentry = mnt->mnt_mountpoint;
71315 + mnt = mnt->mnt_parent;
71316 + vfsmnt = &mnt->mnt;
71317 + continue;
71318 + }
71319 + parent = dentry->d_parent;
71320 + prefetch(parent);
71321 + spin_lock(&dentry->d_lock);
71322 + error = prepend_name(buffer, buflen, &dentry->d_name);
71323 + spin_unlock(&dentry->d_lock);
71324 + if (!error)
71325 + error = prepend(buffer, buflen, "/", 1);
71326 + if (error)
71327 + break;
71328 +
71329 + slash = true;
71330 + dentry = parent;
71331 + }
71332 +
71333 +out:
71334 + if (!error && !slash)
71335 + error = prepend(buffer, buflen, "/", 1);
71336 +
71337 + return error;
71338 +}
71339 +
71340 +/* this must be called with mount_lock and rename_lock held */
71341 +
71342 +static char *__our_d_path(const struct path *path, struct path *root,
71343 + char *buf, int buflen)
71344 +{
71345 + char *res = buf + buflen;
71346 + int error;
71347 +
71348 + prepend(&res, &buflen, "\0", 1);
71349 + error = prepend_path(path, root, &res, &buflen);
71350 + if (error)
71351 + return ERR_PTR(error);
71352 +
71353 + return res;
71354 +}
71355 +
71356 +static char *
71357 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
71358 +{
71359 + char *retval;
71360 +
71361 + retval = __our_d_path(path, root, buf, buflen);
71362 + if (unlikely(IS_ERR(retval)))
71363 + retval = strcpy(buf, "<path too long>");
71364 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
71365 + retval[1] = '\0';
71366 +
71367 + return retval;
71368 +}
71369 +
71370 +static char *
71371 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
71372 + char *buf, int buflen)
71373 +{
71374 + struct path path;
71375 + char *res;
71376 +
71377 + path.dentry = (struct dentry *)dentry;
71378 + path.mnt = (struct vfsmount *)vfsmnt;
71379 +
71380 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
71381 + by the RBAC system */
71382 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
71383 +
71384 + return res;
71385 +}
71386 +
71387 +static char *
71388 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
71389 + char *buf, int buflen)
71390 +{
71391 + char *res;
71392 + struct path path;
71393 + struct path root;
71394 + struct task_struct *reaper = init_pid_ns.child_reaper;
71395 +
71396 + path.dentry = (struct dentry *)dentry;
71397 + path.mnt = (struct vfsmount *)vfsmnt;
71398 +
71399 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
71400 + get_fs_root(reaper->fs, &root);
71401 +
71402 + read_seqlock_excl(&mount_lock);
71403 + write_seqlock(&rename_lock);
71404 + res = gen_full_path(&path, &root, buf, buflen);
71405 + write_sequnlock(&rename_lock);
71406 + read_sequnlock_excl(&mount_lock);
71407 +
71408 + path_put(&root);
71409 + return res;
71410 +}
71411 +
71412 +char *
71413 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
71414 +{
71415 + char *ret;
71416 + read_seqlock_excl(&mount_lock);
71417 + write_seqlock(&rename_lock);
71418 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
71419 + PAGE_SIZE);
71420 + write_sequnlock(&rename_lock);
71421 + read_sequnlock_excl(&mount_lock);
71422 + return ret;
71423 +}
71424 +
71425 +static char *
71426 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
71427 +{
71428 + char *ret;
71429 + char *buf;
71430 + int buflen;
71431 +
71432 + read_seqlock_excl(&mount_lock);
71433 + write_seqlock(&rename_lock);
71434 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
71435 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
71436 + buflen = (int)(ret - buf);
71437 + if (buflen >= 5)
71438 + prepend(&ret, &buflen, "/proc", 5);
71439 + else
71440 + ret = strcpy(buf, "<path too long>");
71441 + write_sequnlock(&rename_lock);
71442 + read_sequnlock_excl(&mount_lock);
71443 + return ret;
71444 +}
71445 +
71446 +char *
71447 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
71448 +{
71449 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
71450 + PAGE_SIZE);
71451 +}
71452 +
71453 +char *
71454 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
71455 +{
71456 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
71457 + PAGE_SIZE);
71458 +}
71459 +
71460 +char *
71461 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
71462 +{
71463 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
71464 + PAGE_SIZE);
71465 +}
71466 +
71467 +char *
71468 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
71469 +{
71470 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
71471 + PAGE_SIZE);
71472 +}
71473 +
71474 +char *
71475 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
71476 +{
71477 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
71478 + PAGE_SIZE);
71479 +}
71480 +
71481 +__inline__ __u32
71482 +to_gr_audit(const __u32 reqmode)
71483 +{
71484 + /* masks off auditable permission flags, then shifts them to create
71485 + auditing flags, and adds the special case of append auditing if
71486 + we're requesting write */
71487 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
71488 +}
71489 +
71490 +struct acl_role_label *
71491 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
71492 + const gid_t gid)
71493 +{
71494 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
71495 + struct acl_role_label *match;
71496 + struct role_allowed_ip *ipp;
71497 + unsigned int x;
71498 + u32 curr_ip = task->signal->saved_ip;
71499 +
71500 + match = state->acl_role_set.r_hash[index];
71501 +
71502 + while (match) {
71503 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
71504 + for (x = 0; x < match->domain_child_num; x++) {
71505 + if (match->domain_children[x] == uid)
71506 + goto found;
71507 + }
71508 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
71509 + break;
71510 + match = match->next;
71511 + }
71512 +found:
71513 + if (match == NULL) {
71514 + try_group:
71515 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
71516 + match = state->acl_role_set.r_hash[index];
71517 +
71518 + while (match) {
71519 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
71520 + for (x = 0; x < match->domain_child_num; x++) {
71521 + if (match->domain_children[x] == gid)
71522 + goto found2;
71523 + }
71524 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
71525 + break;
71526 + match = match->next;
71527 + }
71528 +found2:
71529 + if (match == NULL)
71530 + match = state->default_role;
71531 + if (match->allowed_ips == NULL)
71532 + return match;
71533 + else {
71534 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
71535 + if (likely
71536 + ((ntohl(curr_ip) & ipp->netmask) ==
71537 + (ntohl(ipp->addr) & ipp->netmask)))
71538 + return match;
71539 + }
71540 + match = state->default_role;
71541 + }
71542 + } else if (match->allowed_ips == NULL) {
71543 + return match;
71544 + } else {
71545 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
71546 + if (likely
71547 + ((ntohl(curr_ip) & ipp->netmask) ==
71548 + (ntohl(ipp->addr) & ipp->netmask)))
71549 + return match;
71550 + }
71551 + goto try_group;
71552 + }
71553 +
71554 + return match;
71555 +}
71556 +
71557 +static struct acl_role_label *
71558 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
71559 + const gid_t gid)
71560 +{
71561 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
71562 +}
71563 +
71564 +struct acl_subject_label *
71565 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
71566 + const struct acl_role_label *role)
71567 +{
71568 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
71569 + struct acl_subject_label *match;
71570 +
71571 + match = role->subj_hash[index];
71572 +
71573 + while (match && (match->inode != ino || match->device != dev ||
71574 + (match->mode & GR_DELETED))) {
71575 + match = match->next;
71576 + }
71577 +
71578 + if (match && !(match->mode & GR_DELETED))
71579 + return match;
71580 + else
71581 + return NULL;
71582 +}
71583 +
71584 +struct acl_subject_label *
71585 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
71586 + const struct acl_role_label *role)
71587 +{
71588 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
71589 + struct acl_subject_label *match;
71590 +
71591 + match = role->subj_hash[index];
71592 +
71593 + while (match && (match->inode != ino || match->device != dev ||
71594 + !(match->mode & GR_DELETED))) {
71595 + match = match->next;
71596 + }
71597 +
71598 + if (match && (match->mode & GR_DELETED))
71599 + return match;
71600 + else
71601 + return NULL;
71602 +}
71603 +
71604 +static struct acl_object_label *
71605 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
71606 + const struct acl_subject_label *subj)
71607 +{
71608 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
71609 + struct acl_object_label *match;
71610 +
71611 + match = subj->obj_hash[index];
71612 +
71613 + while (match && (match->inode != ino || match->device != dev ||
71614 + (match->mode & GR_DELETED))) {
71615 + match = match->next;
71616 + }
71617 +
71618 + if (match && !(match->mode & GR_DELETED))
71619 + return match;
71620 + else
71621 + return NULL;
71622 +}
71623 +
71624 +static struct acl_object_label *
71625 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
71626 + const struct acl_subject_label *subj)
71627 +{
71628 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
71629 + struct acl_object_label *match;
71630 +
71631 + match = subj->obj_hash[index];
71632 +
71633 + while (match && (match->inode != ino || match->device != dev ||
71634 + !(match->mode & GR_DELETED))) {
71635 + match = match->next;
71636 + }
71637 +
71638 + if (match && (match->mode & GR_DELETED))
71639 + return match;
71640 +
71641 + match = subj->obj_hash[index];
71642 +
71643 + while (match && (match->inode != ino || match->device != dev ||
71644 + (match->mode & GR_DELETED))) {
71645 + match = match->next;
71646 + }
71647 +
71648 + if (match && !(match->mode & GR_DELETED))
71649 + return match;
71650 + else
71651 + return NULL;
71652 +}
71653 +
71654 +struct name_entry *
71655 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
71656 +{
71657 + unsigned int len = strlen(name);
71658 + unsigned int key = full_name_hash(name, len);
71659 + unsigned int index = key % state->name_set.n_size;
71660 + struct name_entry *match;
71661 +
71662 + match = state->name_set.n_hash[index];
71663 +
71664 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
71665 + match = match->next;
71666 +
71667 + return match;
71668 +}
71669 +
71670 +static struct name_entry *
71671 +lookup_name_entry(const char *name)
71672 +{
71673 + return __lookup_name_entry(&running_polstate, name);
71674 +}
71675 +
71676 +static struct name_entry *
71677 +lookup_name_entry_create(const char *name)
71678 +{
71679 + unsigned int len = strlen(name);
71680 + unsigned int key = full_name_hash(name, len);
71681 + unsigned int index = key % running_polstate.name_set.n_size;
71682 + struct name_entry *match;
71683 +
71684 + match = running_polstate.name_set.n_hash[index];
71685 +
71686 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
71687 + !match->deleted))
71688 + match = match->next;
71689 +
71690 + if (match && match->deleted)
71691 + return match;
71692 +
71693 + match = running_polstate.name_set.n_hash[index];
71694 +
71695 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
71696 + match->deleted))
71697 + match = match->next;
71698 +
71699 + if (match && !match->deleted)
71700 + return match;
71701 + else
71702 + return NULL;
71703 +}
71704 +
71705 +static struct inodev_entry *
71706 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
71707 +{
71708 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
71709 + struct inodev_entry *match;
71710 +
71711 + match = running_polstate.inodev_set.i_hash[index];
71712 +
71713 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
71714 + match = match->next;
71715 +
71716 + return match;
71717 +}
71718 +
71719 +void
71720 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
71721 +{
71722 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
71723 + state->inodev_set.i_size);
71724 + struct inodev_entry **curr;
71725 +
71726 + entry->prev = NULL;
71727 +
71728 + curr = &state->inodev_set.i_hash[index];
71729 + if (*curr != NULL)
71730 + (*curr)->prev = entry;
71731 +
71732 + entry->next = *curr;
71733 + *curr = entry;
71734 +
71735 + return;
71736 +}
71737 +
71738 +static void
71739 +insert_inodev_entry(struct inodev_entry *entry)
71740 +{
71741 + __insert_inodev_entry(&running_polstate, entry);
71742 +}
71743 +
71744 +void
71745 +insert_acl_obj_label(struct acl_object_label *obj,
71746 + struct acl_subject_label *subj)
71747 +{
71748 + unsigned int index =
71749 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
71750 + struct acl_object_label **curr;
71751 +
71752 + obj->prev = NULL;
71753 +
71754 + curr = &subj->obj_hash[index];
71755 + if (*curr != NULL)
71756 + (*curr)->prev = obj;
71757 +
71758 + obj->next = *curr;
71759 + *curr = obj;
71760 +
71761 + return;
71762 +}
71763 +
71764 +void
71765 +insert_acl_subj_label(struct acl_subject_label *obj,
71766 + struct acl_role_label *role)
71767 +{
71768 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
71769 + struct acl_subject_label **curr;
71770 +
71771 + obj->prev = NULL;
71772 +
71773 + curr = &role->subj_hash[index];
71774 + if (*curr != NULL)
71775 + (*curr)->prev = obj;
71776 +
71777 + obj->next = *curr;
71778 + *curr = obj;
71779 +
71780 + return;
71781 +}
71782 +
71783 +/* derived from glibc fnmatch() 0: match, 1: no match*/
71784 +
71785 +static int
71786 +glob_match(const char *p, const char *n)
71787 +{
71788 + char c;
71789 +
71790 + while ((c = *p++) != '\0') {
71791 + switch (c) {
71792 + case '?':
71793 + if (*n == '\0')
71794 + return 1;
71795 + else if (*n == '/')
71796 + return 1;
71797 + break;
71798 + case '\\':
71799 + if (*n != c)
71800 + return 1;
71801 + break;
71802 + case '*':
71803 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
71804 + if (*n == '/')
71805 + return 1;
71806 + else if (c == '?') {
71807 + if (*n == '\0')
71808 + return 1;
71809 + else
71810 + ++n;
71811 + }
71812 + }
71813 + if (c == '\0') {
71814 + return 0;
71815 + } else {
71816 + const char *endp;
71817 +
71818 + if ((endp = strchr(n, '/')) == NULL)
71819 + endp = n + strlen(n);
71820 +
71821 + if (c == '[') {
71822 + for (--p; n < endp; ++n)
71823 + if (!glob_match(p, n))
71824 + return 0;
71825 + } else if (c == '/') {
71826 + while (*n != '\0' && *n != '/')
71827 + ++n;
71828 + if (*n == '/' && !glob_match(p, n + 1))
71829 + return 0;
71830 + } else {
71831 + for (--p; n < endp; ++n)
71832 + if (*n == c && !glob_match(p, n))
71833 + return 0;
71834 + }
71835 +
71836 + return 1;
71837 + }
71838 + case '[':
71839 + {
71840 + int not;
71841 + char cold;
71842 +
71843 + if (*n == '\0' || *n == '/')
71844 + return 1;
71845 +
71846 + not = (*p == '!' || *p == '^');
71847 + if (not)
71848 + ++p;
71849 +
71850 + c = *p++;
71851 + for (;;) {
71852 + unsigned char fn = (unsigned char)*n;
71853 +
71854 + if (c == '\0')
71855 + return 1;
71856 + else {
71857 + if (c == fn)
71858 + goto matched;
71859 + cold = c;
71860 + c = *p++;
71861 +
71862 + if (c == '-' && *p != ']') {
71863 + unsigned char cend = *p++;
71864 +
71865 + if (cend == '\0')
71866 + return 1;
71867 +
71868 + if (cold <= fn && fn <= cend)
71869 + goto matched;
71870 +
71871 + c = *p++;
71872 + }
71873 + }
71874 +
71875 + if (c == ']')
71876 + break;
71877 + }
71878 + if (!not)
71879 + return 1;
71880 + break;
71881 + matched:
71882 + while (c != ']') {
71883 + if (c == '\0')
71884 + return 1;
71885 +
71886 + c = *p++;
71887 + }
71888 + if (not)
71889 + return 1;
71890 + }
71891 + break;
71892 + default:
71893 + if (c != *n)
71894 + return 1;
71895 + }
71896 +
71897 + ++n;
71898 + }
71899 +
71900 + if (*n == '\0')
71901 + return 0;
71902 +
71903 + if (*n == '/')
71904 + return 0;
71905 +
71906 + return 1;
71907 +}
71908 +
71909 +static struct acl_object_label *
71910 +chk_glob_label(struct acl_object_label *globbed,
71911 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
71912 +{
71913 + struct acl_object_label *tmp;
71914 +
71915 + if (*path == NULL)
71916 + *path = gr_to_filename_nolock(dentry, mnt);
71917 +
71918 + tmp = globbed;
71919 +
71920 + while (tmp) {
71921 + if (!glob_match(tmp->filename, *path))
71922 + return tmp;
71923 + tmp = tmp->next;
71924 + }
71925 +
71926 + return NULL;
71927 +}
71928 +
71929 +static struct acl_object_label *
71930 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71931 + const ino_t curr_ino, const dev_t curr_dev,
71932 + const struct acl_subject_label *subj, char **path, const int checkglob)
71933 +{
71934 + struct acl_subject_label *tmpsubj;
71935 + struct acl_object_label *retval;
71936 + struct acl_object_label *retval2;
71937 +
71938 + tmpsubj = (struct acl_subject_label *) subj;
71939 + read_lock(&gr_inode_lock);
71940 + do {
71941 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
71942 + if (retval) {
71943 + if (checkglob && retval->globbed) {
71944 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
71945 + if (retval2)
71946 + retval = retval2;
71947 + }
71948 + break;
71949 + }
71950 + } while ((tmpsubj = tmpsubj->parent_subject));
71951 + read_unlock(&gr_inode_lock);
71952 +
71953 + return retval;
71954 +}
71955 +
71956 +static __inline__ struct acl_object_label *
71957 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
71958 + struct dentry *curr_dentry,
71959 + const struct acl_subject_label *subj, char **path, const int checkglob)
71960 +{
71961 + int newglob = checkglob;
71962 + ino_t inode;
71963 + dev_t device;
71964 +
71965 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
71966 + as we don't want a / * rule to match instead of the / object
71967 + don't do this for create lookups that call this function though, since they're looking up
71968 + on the parent and thus need globbing checks on all paths
71969 + */
71970 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
71971 + newglob = GR_NO_GLOB;
71972 +
71973 + spin_lock(&curr_dentry->d_lock);
71974 + inode = curr_dentry->d_inode->i_ino;
71975 + device = __get_dev(curr_dentry);
71976 + spin_unlock(&curr_dentry->d_lock);
71977 +
71978 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
71979 +}
71980 +
71981 +#ifdef CONFIG_HUGETLBFS
71982 +static inline bool
71983 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
71984 +{
71985 + int i;
71986 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
71987 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
71988 + return true;
71989 + }
71990 +
71991 + return false;
71992 +}
71993 +#endif
71994 +
71995 +static struct acl_object_label *
71996 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
71997 + const struct acl_subject_label *subj, char *path, const int checkglob)
71998 +{
71999 + struct dentry *dentry = (struct dentry *) l_dentry;
72000 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
72001 + struct mount *real_mnt = real_mount(mnt);
72002 + struct acl_object_label *retval;
72003 + struct dentry *parent;
72004 +
72005 + read_seqlock_excl(&mount_lock);
72006 + write_seqlock(&rename_lock);
72007 +
72008 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
72009 +#ifdef CONFIG_NET
72010 + mnt == sock_mnt ||
72011 +#endif
72012 +#ifdef CONFIG_HUGETLBFS
72013 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
72014 +#endif
72015 + /* ignore Eric Biederman */
72016 + IS_PRIVATE(l_dentry->d_inode))) {
72017 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
72018 + goto out;
72019 + }
72020 +
72021 + for (;;) {
72022 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
72023 + break;
72024 +
72025 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
72026 + if (!mnt_has_parent(real_mnt))
72027 + break;
72028 +
72029 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
72030 + if (retval != NULL)
72031 + goto out;
72032 +
72033 + dentry = real_mnt->mnt_mountpoint;
72034 + real_mnt = real_mnt->mnt_parent;
72035 + mnt = &real_mnt->mnt;
72036 + continue;
72037 + }
72038 +
72039 + parent = dentry->d_parent;
72040 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
72041 + if (retval != NULL)
72042 + goto out;
72043 +
72044 + dentry = parent;
72045 + }
72046 +
72047 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
72048 +
72049 + /* gr_real_root is pinned so we don't have to hold a reference */
72050 + if (retval == NULL)
72051 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
72052 +out:
72053 + write_sequnlock(&rename_lock);
72054 + read_sequnlock_excl(&mount_lock);
72055 +
72056 + BUG_ON(retval == NULL);
72057 +
72058 + return retval;
72059 +}
72060 +
72061 +static __inline__ struct acl_object_label *
72062 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
72063 + const struct acl_subject_label *subj)
72064 +{
72065 + char *path = NULL;
72066 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
72067 +}
72068 +
72069 +static __inline__ struct acl_object_label *
72070 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
72071 + const struct acl_subject_label *subj)
72072 +{
72073 + char *path = NULL;
72074 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
72075 +}
72076 +
72077 +static __inline__ struct acl_object_label *
72078 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
72079 + const struct acl_subject_label *subj, char *path)
72080 +{
72081 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
72082 +}
72083 +
72084 +struct acl_subject_label *
72085 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
72086 + const struct acl_role_label *role)
72087 +{
72088 + struct dentry *dentry = (struct dentry *) l_dentry;
72089 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
72090 + struct mount *real_mnt = real_mount(mnt);
72091 + struct acl_subject_label *retval;
72092 + struct dentry *parent;
72093 +
72094 + read_seqlock_excl(&mount_lock);
72095 + write_seqlock(&rename_lock);
72096 +
72097 + for (;;) {
72098 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
72099 + break;
72100 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
72101 + if (!mnt_has_parent(real_mnt))
72102 + break;
72103 +
72104 + spin_lock(&dentry->d_lock);
72105 + read_lock(&gr_inode_lock);
72106 + retval =
72107 + lookup_acl_subj_label(dentry->d_inode->i_ino,
72108 + __get_dev(dentry), role);
72109 + read_unlock(&gr_inode_lock);
72110 + spin_unlock(&dentry->d_lock);
72111 + if (retval != NULL)
72112 + goto out;
72113 +
72114 + dentry = real_mnt->mnt_mountpoint;
72115 + real_mnt = real_mnt->mnt_parent;
72116 + mnt = &real_mnt->mnt;
72117 + continue;
72118 + }
72119 +
72120 + spin_lock(&dentry->d_lock);
72121 + read_lock(&gr_inode_lock);
72122 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
72123 + __get_dev(dentry), role);
72124 + read_unlock(&gr_inode_lock);
72125 + parent = dentry->d_parent;
72126 + spin_unlock(&dentry->d_lock);
72127 +
72128 + if (retval != NULL)
72129 + goto out;
72130 +
72131 + dentry = parent;
72132 + }
72133 +
72134 + spin_lock(&dentry->d_lock);
72135 + read_lock(&gr_inode_lock);
72136 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
72137 + __get_dev(dentry), role);
72138 + read_unlock(&gr_inode_lock);
72139 + spin_unlock(&dentry->d_lock);
72140 +
72141 + if (unlikely(retval == NULL)) {
72142 + /* gr_real_root is pinned, we don't need to hold a reference */
72143 + read_lock(&gr_inode_lock);
72144 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
72145 + __get_dev(gr_real_root.dentry), role);
72146 + read_unlock(&gr_inode_lock);
72147 + }
72148 +out:
72149 + write_sequnlock(&rename_lock);
72150 + read_sequnlock_excl(&mount_lock);
72151 +
72152 + BUG_ON(retval == NULL);
72153 +
72154 + return retval;
72155 +}
72156 +
72157 +void
72158 +assign_special_role(const char *rolename)
72159 +{
72160 + struct acl_object_label *obj;
72161 + struct acl_role_label *r;
72162 + struct acl_role_label *assigned = NULL;
72163 + struct task_struct *tsk;
72164 + struct file *filp;
72165 +
72166 + FOR_EACH_ROLE_START(r)
72167 + if (!strcmp(rolename, r->rolename) &&
72168 + (r->roletype & GR_ROLE_SPECIAL)) {
72169 + assigned = r;
72170 + break;
72171 + }
72172 + FOR_EACH_ROLE_END(r)
72173 +
72174 + if (!assigned)
72175 + return;
72176 +
72177 + read_lock(&tasklist_lock);
72178 + read_lock(&grsec_exec_file_lock);
72179 +
72180 + tsk = current->real_parent;
72181 + if (tsk == NULL)
72182 + goto out_unlock;
72183 +
72184 + filp = tsk->exec_file;
72185 + if (filp == NULL)
72186 + goto out_unlock;
72187 +
72188 + tsk->is_writable = 0;
72189 + tsk->inherited = 0;
72190 +
72191 + tsk->acl_sp_role = 1;
72192 + tsk->acl_role_id = ++acl_sp_role_value;
72193 + tsk->role = assigned;
72194 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
72195 +
72196 + /* ignore additional mmap checks for processes that are writable
72197 + by the default ACL */
72198 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72199 + if (unlikely(obj->mode & GR_WRITE))
72200 + tsk->is_writable = 1;
72201 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
72202 + if (unlikely(obj->mode & GR_WRITE))
72203 + tsk->is_writable = 1;
72204 +
72205 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72206 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
72207 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
72208 +#endif
72209 +
72210 +out_unlock:
72211 + read_unlock(&grsec_exec_file_lock);
72212 + read_unlock(&tasklist_lock);
72213 + return;
72214 +}
72215 +
72216 +
72217 +static void
72218 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
72219 +{
72220 + struct task_struct *task = current;
72221 + const struct cred *cred = current_cred();
72222 +
72223 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
72224 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
72225 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
72226 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
72227 +
72228 + return;
72229 +}
72230 +
72231 +static void
72232 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
72233 +{
72234 + struct task_struct *task = current;
72235 + const struct cred *cred = current_cred();
72236 +
72237 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
72238 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
72239 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
72240 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
72241 +
72242 + return;
72243 +}
72244 +
72245 +static void
72246 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
72247 +{
72248 + struct task_struct *task = current;
72249 + const struct cred *cred = current_cred();
72250 +
72251 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
72252 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
72253 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
72254 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
72255 +
72256 + return;
72257 +}
72258 +
72259 +static void
72260 +gr_set_proc_res(struct task_struct *task)
72261 +{
72262 + struct acl_subject_label *proc;
72263 + unsigned short i;
72264 +
72265 + proc = task->acl;
72266 +
72267 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
72268 + return;
72269 +
72270 + for (i = 0; i < RLIM_NLIMITS; i++) {
72271 + if (!(proc->resmask & (1U << i)))
72272 + continue;
72273 +
72274 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
72275 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
72276 +
72277 + if (i == RLIMIT_CPU)
72278 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
72279 + }
72280 +
72281 + return;
72282 +}
72283 +
72284 +/* both of the below must be called with
72285 + rcu_read_lock();
72286 + read_lock(&tasklist_lock);
72287 + read_lock(&grsec_exec_file_lock);
72288 +*/
72289 +
72290 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
72291 +{
72292 + char *tmpname;
72293 + struct acl_subject_label *tmpsubj;
72294 + struct file *filp;
72295 + struct name_entry *nmatch;
72296 +
72297 + filp = task->exec_file;
72298 + if (filp == NULL)
72299 + return NULL;
72300 +
72301 + /* the following is to apply the correct subject
72302 + on binaries running when the RBAC system
72303 + is enabled, when the binaries have been
72304 + replaced or deleted since their execution
72305 + -----
72306 + when the RBAC system starts, the inode/dev
72307 + from exec_file will be one the RBAC system
72308 + is unaware of. It only knows the inode/dev
72309 + of the present file on disk, or the absence
72310 + of it.
72311 + */
72312 +
72313 + if (filename)
72314 + nmatch = __lookup_name_entry(state, filename);
72315 + else {
72316 + preempt_disable();
72317 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
72318 +
72319 + nmatch = __lookup_name_entry(state, tmpname);
72320 + preempt_enable();
72321 + }
72322 + tmpsubj = NULL;
72323 + if (nmatch) {
72324 + if (nmatch->deleted)
72325 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
72326 + else
72327 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
72328 + }
72329 + /* this also works for the reload case -- if we don't match a potentially inherited subject
72330 + then we fall back to a normal lookup based on the binary's ino/dev
72331 + */
72332 + if (tmpsubj == NULL)
72333 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
72334 +
72335 + return tmpsubj;
72336 +}
72337 +
72338 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
72339 +{
72340 + return __gr_get_subject_for_task(&running_polstate, task, filename);
72341 +}
72342 +
72343 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
72344 +{
72345 + struct acl_object_label *obj;
72346 + struct file *filp;
72347 +
72348 + filp = task->exec_file;
72349 +
72350 + task->acl = subj;
72351 + task->is_writable = 0;
72352 + /* ignore additional mmap checks for processes that are writable
72353 + by the default ACL */
72354 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
72355 + if (unlikely(obj->mode & GR_WRITE))
72356 + task->is_writable = 1;
72357 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
72358 + if (unlikely(obj->mode & GR_WRITE))
72359 + task->is_writable = 1;
72360 +
72361 + gr_set_proc_res(task);
72362 +
72363 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72364 + 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);
72365 +#endif
72366 +}
72367 +
72368 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
72369 +{
72370 + __gr_apply_subject_to_task(&running_polstate, task, subj);
72371 +}
72372 +
72373 +__u32
72374 +gr_search_file(const struct dentry * dentry, const __u32 mode,
72375 + const struct vfsmount * mnt)
72376 +{
72377 + __u32 retval = mode;
72378 + struct acl_subject_label *curracl;
72379 + struct acl_object_label *currobj;
72380 +
72381 + if (unlikely(!(gr_status & GR_READY)))
72382 + return (mode & ~GR_AUDITS);
72383 +
72384 + curracl = current->acl;
72385 +
72386 + currobj = chk_obj_label(dentry, mnt, curracl);
72387 + retval = currobj->mode & mode;
72388 +
72389 + /* if we're opening a specified transfer file for writing
72390 + (e.g. /dev/initctl), then transfer our role to init
72391 + */
72392 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
72393 + current->role->roletype & GR_ROLE_PERSIST)) {
72394 + struct task_struct *task = init_pid_ns.child_reaper;
72395 +
72396 + if (task->role != current->role) {
72397 + struct acl_subject_label *subj;
72398 +
72399 + task->acl_sp_role = 0;
72400 + task->acl_role_id = current->acl_role_id;
72401 + task->role = current->role;
72402 + rcu_read_lock();
72403 + read_lock(&grsec_exec_file_lock);
72404 + subj = gr_get_subject_for_task(task, NULL);
72405 + gr_apply_subject_to_task(task, subj);
72406 + read_unlock(&grsec_exec_file_lock);
72407 + rcu_read_unlock();
72408 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
72409 + }
72410 + }
72411 +
72412 + if (unlikely
72413 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
72414 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
72415 + __u32 new_mode = mode;
72416 +
72417 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
72418 +
72419 + retval = new_mode;
72420 +
72421 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
72422 + new_mode |= GR_INHERIT;
72423 +
72424 + if (!(mode & GR_NOLEARN))
72425 + gr_log_learn(dentry, mnt, new_mode);
72426 + }
72427 +
72428 + return retval;
72429 +}
72430 +
72431 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
72432 + const struct dentry *parent,
72433 + const struct vfsmount *mnt)
72434 +{
72435 + struct name_entry *match;
72436 + struct acl_object_label *matchpo;
72437 + struct acl_subject_label *curracl;
72438 + char *path;
72439 +
72440 + if (unlikely(!(gr_status & GR_READY)))
72441 + return NULL;
72442 +
72443 + preempt_disable();
72444 + path = gr_to_filename_rbac(new_dentry, mnt);
72445 + match = lookup_name_entry_create(path);
72446 +
72447 + curracl = current->acl;
72448 +
72449 + if (match) {
72450 + read_lock(&gr_inode_lock);
72451 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
72452 + read_unlock(&gr_inode_lock);
72453 +
72454 + if (matchpo) {
72455 + preempt_enable();
72456 + return matchpo;
72457 + }
72458 + }
72459 +
72460 + // lookup parent
72461 +
72462 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
72463 +
72464 + preempt_enable();
72465 + return matchpo;
72466 +}
72467 +
72468 +__u32
72469 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
72470 + const struct vfsmount * mnt, const __u32 mode)
72471 +{
72472 + struct acl_object_label *matchpo;
72473 + __u32 retval;
72474 +
72475 + if (unlikely(!(gr_status & GR_READY)))
72476 + return (mode & ~GR_AUDITS);
72477 +
72478 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
72479 +
72480 + retval = matchpo->mode & mode;
72481 +
72482 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
72483 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
72484 + __u32 new_mode = mode;
72485 +
72486 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
72487 +
72488 + gr_log_learn(new_dentry, mnt, new_mode);
72489 + return new_mode;
72490 + }
72491 +
72492 + return retval;
72493 +}
72494 +
72495 +__u32
72496 +gr_check_link(const struct dentry * new_dentry,
72497 + const struct dentry * parent_dentry,
72498 + const struct vfsmount * parent_mnt,
72499 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
72500 +{
72501 + struct acl_object_label *obj;
72502 + __u32 oldmode, newmode;
72503 + __u32 needmode;
72504 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
72505 + GR_DELETE | GR_INHERIT;
72506 +
72507 + if (unlikely(!(gr_status & GR_READY)))
72508 + return (GR_CREATE | GR_LINK);
72509 +
72510 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
72511 + oldmode = obj->mode;
72512 +
72513 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
72514 + newmode = obj->mode;
72515 +
72516 + needmode = newmode & checkmodes;
72517 +
72518 + // old name for hardlink must have at least the permissions of the new name
72519 + if ((oldmode & needmode) != needmode)
72520 + goto bad;
72521 +
72522 + // if old name had restrictions/auditing, make sure the new name does as well
72523 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
72524 +
72525 + // don't allow hardlinking of suid/sgid/fcapped files without permission
72526 + if (is_privileged_binary(old_dentry))
72527 + needmode |= GR_SETID;
72528 +
72529 + if ((newmode & needmode) != needmode)
72530 + goto bad;
72531 +
72532 + // enforce minimum permissions
72533 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
72534 + return newmode;
72535 +bad:
72536 + needmode = oldmode;
72537 + if (is_privileged_binary(old_dentry))
72538 + needmode |= GR_SETID;
72539 +
72540 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72541 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
72542 + return (GR_CREATE | GR_LINK);
72543 + } else if (newmode & GR_SUPPRESS)
72544 + return GR_SUPPRESS;
72545 + else
72546 + return 0;
72547 +}
72548 +
72549 +int
72550 +gr_check_hidden_task(const struct task_struct *task)
72551 +{
72552 + if (unlikely(!(gr_status & GR_READY)))
72553 + return 0;
72554 +
72555 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
72556 + return 1;
72557 +
72558 + return 0;
72559 +}
72560 +
72561 +int
72562 +gr_check_protected_task(const struct task_struct *task)
72563 +{
72564 + if (unlikely(!(gr_status & GR_READY) || !task))
72565 + return 0;
72566 +
72567 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
72568 + task->acl != current->acl)
72569 + return 1;
72570 +
72571 + return 0;
72572 +}
72573 +
72574 +int
72575 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72576 +{
72577 + struct task_struct *p;
72578 + int ret = 0;
72579 +
72580 + if (unlikely(!(gr_status & GR_READY) || !pid))
72581 + return ret;
72582 +
72583 + read_lock(&tasklist_lock);
72584 + do_each_pid_task(pid, type, p) {
72585 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
72586 + p->acl != current->acl) {
72587 + ret = 1;
72588 + goto out;
72589 + }
72590 + } while_each_pid_task(pid, type, p);
72591 +out:
72592 + read_unlock(&tasklist_lock);
72593 +
72594 + return ret;
72595 +}
72596 +
72597 +void
72598 +gr_copy_label(struct task_struct *tsk)
72599 +{
72600 + struct task_struct *p = current;
72601 +
72602 + tsk->inherited = p->inherited;
72603 + tsk->acl_sp_role = 0;
72604 + tsk->acl_role_id = p->acl_role_id;
72605 + tsk->acl = p->acl;
72606 + tsk->role = p->role;
72607 + tsk->signal->used_accept = 0;
72608 + tsk->signal->curr_ip = p->signal->curr_ip;
72609 + tsk->signal->saved_ip = p->signal->saved_ip;
72610 + if (p->exec_file)
72611 + get_file(p->exec_file);
72612 + tsk->exec_file = p->exec_file;
72613 + tsk->is_writable = p->is_writable;
72614 + if (unlikely(p->signal->used_accept)) {
72615 + p->signal->curr_ip = 0;
72616 + p->signal->saved_ip = 0;
72617 + }
72618 +
72619 + return;
72620 +}
72621 +
72622 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
72623 +
72624 +int
72625 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72626 +{
72627 + unsigned int i;
72628 + __u16 num;
72629 + uid_t *uidlist;
72630 + uid_t curuid;
72631 + int realok = 0;
72632 + int effectiveok = 0;
72633 + int fsok = 0;
72634 + uid_t globalreal, globaleffective, globalfs;
72635 +
72636 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
72637 + struct user_struct *user;
72638 +
72639 + if (!uid_valid(real))
72640 + goto skipit;
72641 +
72642 + /* find user based on global namespace */
72643 +
72644 + globalreal = GR_GLOBAL_UID(real);
72645 +
72646 + user = find_user(make_kuid(&init_user_ns, globalreal));
72647 + if (user == NULL)
72648 + goto skipit;
72649 +
72650 + if (gr_process_kernel_setuid_ban(user)) {
72651 + /* for find_user */
72652 + free_uid(user);
72653 + return 1;
72654 + }
72655 +
72656 + /* for find_user */
72657 + free_uid(user);
72658 +
72659 +skipit:
72660 +#endif
72661 +
72662 + if (unlikely(!(gr_status & GR_READY)))
72663 + return 0;
72664 +
72665 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72666 + gr_log_learn_uid_change(real, effective, fs);
72667 +
72668 + num = current->acl->user_trans_num;
72669 + uidlist = current->acl->user_transitions;
72670 +
72671 + if (uidlist == NULL)
72672 + return 0;
72673 +
72674 + if (!uid_valid(real)) {
72675 + realok = 1;
72676 + globalreal = (uid_t)-1;
72677 + } else {
72678 + globalreal = GR_GLOBAL_UID(real);
72679 + }
72680 + if (!uid_valid(effective)) {
72681 + effectiveok = 1;
72682 + globaleffective = (uid_t)-1;
72683 + } else {
72684 + globaleffective = GR_GLOBAL_UID(effective);
72685 + }
72686 + if (!uid_valid(fs)) {
72687 + fsok = 1;
72688 + globalfs = (uid_t)-1;
72689 + } else {
72690 + globalfs = GR_GLOBAL_UID(fs);
72691 + }
72692 +
72693 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
72694 + for (i = 0; i < num; i++) {
72695 + curuid = uidlist[i];
72696 + if (globalreal == curuid)
72697 + realok = 1;
72698 + if (globaleffective == curuid)
72699 + effectiveok = 1;
72700 + if (globalfs == curuid)
72701 + fsok = 1;
72702 + }
72703 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
72704 + for (i = 0; i < num; i++) {
72705 + curuid = uidlist[i];
72706 + if (globalreal == curuid)
72707 + break;
72708 + if (globaleffective == curuid)
72709 + break;
72710 + if (globalfs == curuid)
72711 + break;
72712 + }
72713 + /* not in deny list */
72714 + if (i == num) {
72715 + realok = 1;
72716 + effectiveok = 1;
72717 + fsok = 1;
72718 + }
72719 + }
72720 +
72721 + if (realok && effectiveok && fsok)
72722 + return 0;
72723 + else {
72724 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
72725 + return 1;
72726 + }
72727 +}
72728 +
72729 +int
72730 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72731 +{
72732 + unsigned int i;
72733 + __u16 num;
72734 + gid_t *gidlist;
72735 + gid_t curgid;
72736 + int realok = 0;
72737 + int effectiveok = 0;
72738 + int fsok = 0;
72739 + gid_t globalreal, globaleffective, globalfs;
72740 +
72741 + if (unlikely(!(gr_status & GR_READY)))
72742 + return 0;
72743 +
72744 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72745 + gr_log_learn_gid_change(real, effective, fs);
72746 +
72747 + num = current->acl->group_trans_num;
72748 + gidlist = current->acl->group_transitions;
72749 +
72750 + if (gidlist == NULL)
72751 + return 0;
72752 +
72753 + if (!gid_valid(real)) {
72754 + realok = 1;
72755 + globalreal = (gid_t)-1;
72756 + } else {
72757 + globalreal = GR_GLOBAL_GID(real);
72758 + }
72759 + if (!gid_valid(effective)) {
72760 + effectiveok = 1;
72761 + globaleffective = (gid_t)-1;
72762 + } else {
72763 + globaleffective = GR_GLOBAL_GID(effective);
72764 + }
72765 + if (!gid_valid(fs)) {
72766 + fsok = 1;
72767 + globalfs = (gid_t)-1;
72768 + } else {
72769 + globalfs = GR_GLOBAL_GID(fs);
72770 + }
72771 +
72772 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
72773 + for (i = 0; i < num; i++) {
72774 + curgid = gidlist[i];
72775 + if (globalreal == curgid)
72776 + realok = 1;
72777 + if (globaleffective == curgid)
72778 + effectiveok = 1;
72779 + if (globalfs == curgid)
72780 + fsok = 1;
72781 + }
72782 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
72783 + for (i = 0; i < num; i++) {
72784 + curgid = gidlist[i];
72785 + if (globalreal == curgid)
72786 + break;
72787 + if (globaleffective == curgid)
72788 + break;
72789 + if (globalfs == curgid)
72790 + break;
72791 + }
72792 + /* not in deny list */
72793 + if (i == num) {
72794 + realok = 1;
72795 + effectiveok = 1;
72796 + fsok = 1;
72797 + }
72798 + }
72799 +
72800 + if (realok && effectiveok && fsok)
72801 + return 0;
72802 + else {
72803 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
72804 + return 1;
72805 + }
72806 +}
72807 +
72808 +extern int gr_acl_is_capable(const int cap);
72809 +
72810 +void
72811 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
72812 +{
72813 + struct acl_role_label *role = task->role;
72814 + struct acl_subject_label *subj = NULL;
72815 + struct acl_object_label *obj;
72816 + struct file *filp;
72817 + uid_t uid;
72818 + gid_t gid;
72819 +
72820 + if (unlikely(!(gr_status & GR_READY)))
72821 + return;
72822 +
72823 + uid = GR_GLOBAL_UID(kuid);
72824 + gid = GR_GLOBAL_GID(kgid);
72825 +
72826 + filp = task->exec_file;
72827 +
72828 + /* kernel process, we'll give them the kernel role */
72829 + if (unlikely(!filp)) {
72830 + task->role = running_polstate.kernel_role;
72831 + task->acl = running_polstate.kernel_role->root_label;
72832 + return;
72833 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
72834 + /* save the current ip at time of role lookup so that the proper
72835 + IP will be learned for role_allowed_ip */
72836 + task->signal->saved_ip = task->signal->curr_ip;
72837 + role = lookup_acl_role_label(task, uid, gid);
72838 + }
72839 +
72840 + /* don't change the role if we're not a privileged process */
72841 + if (role && task->role != role &&
72842 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
72843 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
72844 + return;
72845 +
72846 + /* perform subject lookup in possibly new role
72847 + we can use this result below in the case where role == task->role
72848 + */
72849 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
72850 +
72851 + /* if we changed uid/gid, but result in the same role
72852 + and are using inheritance, don't lose the inherited subject
72853 + if current subject is other than what normal lookup
72854 + would result in, we arrived via inheritance, don't
72855 + lose subject
72856 + */
72857 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
72858 + (subj == task->acl)))
72859 + task->acl = subj;
72860 +
72861 + /* leave task->inherited unaffected */
72862 +
72863 + task->role = role;
72864 +
72865 + task->is_writable = 0;
72866 +
72867 + /* ignore additional mmap checks for processes that are writable
72868 + by the default ACL */
72869 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72870 + if (unlikely(obj->mode & GR_WRITE))
72871 + task->is_writable = 1;
72872 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
72873 + if (unlikely(obj->mode & GR_WRITE))
72874 + task->is_writable = 1;
72875 +
72876 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72877 + 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);
72878 +#endif
72879 +
72880 + gr_set_proc_res(task);
72881 +
72882 + return;
72883 +}
72884 +
72885 +int
72886 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72887 + const int unsafe_flags)
72888 +{
72889 + struct task_struct *task = current;
72890 + struct acl_subject_label *newacl;
72891 + struct acl_object_label *obj;
72892 + __u32 retmode;
72893 +
72894 + if (unlikely(!(gr_status & GR_READY)))
72895 + return 0;
72896 +
72897 + newacl = chk_subj_label(dentry, mnt, task->role);
72898 +
72899 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
72900 + did an exec
72901 + */
72902 + rcu_read_lock();
72903 + read_lock(&tasklist_lock);
72904 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
72905 + (task->parent->acl->mode & GR_POVERRIDE))) {
72906 + read_unlock(&tasklist_lock);
72907 + rcu_read_unlock();
72908 + goto skip_check;
72909 + }
72910 + read_unlock(&tasklist_lock);
72911 + rcu_read_unlock();
72912 +
72913 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
72914 + !(task->role->roletype & GR_ROLE_GOD) &&
72915 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
72916 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
72917 + if (unsafe_flags & LSM_UNSAFE_SHARE)
72918 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
72919 + else
72920 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
72921 + return -EACCES;
72922 + }
72923 +
72924 +skip_check:
72925 +
72926 + obj = chk_obj_label(dentry, mnt, task->acl);
72927 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
72928 +
72929 + if (!(task->acl->mode & GR_INHERITLEARN) &&
72930 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
72931 + if (obj->nested)
72932 + task->acl = obj->nested;
72933 + else
72934 + task->acl = newacl;
72935 + task->inherited = 0;
72936 + } else {
72937 + task->inherited = 1;
72938 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
72939 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
72940 + }
72941 +
72942 + task->is_writable = 0;
72943 +
72944 + /* ignore additional mmap checks for processes that are writable
72945 + by the default ACL */
72946 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
72947 + if (unlikely(obj->mode & GR_WRITE))
72948 + task->is_writable = 1;
72949 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
72950 + if (unlikely(obj->mode & GR_WRITE))
72951 + task->is_writable = 1;
72952 +
72953 + gr_set_proc_res(task);
72954 +
72955 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72956 + 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);
72957 +#endif
72958 + return 0;
72959 +}
72960 +
72961 +/* always called with valid inodev ptr */
72962 +static void
72963 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
72964 +{
72965 + struct acl_object_label *matchpo;
72966 + struct acl_subject_label *matchps;
72967 + struct acl_subject_label *subj;
72968 + struct acl_role_label *role;
72969 + unsigned int x;
72970 +
72971 + FOR_EACH_ROLE_START(role)
72972 + FOR_EACH_SUBJECT_START(role, subj, x)
72973 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72974 + matchpo->mode |= GR_DELETED;
72975 + FOR_EACH_SUBJECT_END(subj,x)
72976 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
72977 + /* nested subjects aren't in the role's subj_hash table */
72978 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
72979 + matchpo->mode |= GR_DELETED;
72980 + FOR_EACH_NESTED_SUBJECT_END(subj)
72981 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
72982 + matchps->mode |= GR_DELETED;
72983 + FOR_EACH_ROLE_END(role)
72984 +
72985 + inodev->nentry->deleted = 1;
72986 +
72987 + return;
72988 +}
72989 +
72990 +void
72991 +gr_handle_delete(const ino_t ino, const dev_t dev)
72992 +{
72993 + struct inodev_entry *inodev;
72994 +
72995 + if (unlikely(!(gr_status & GR_READY)))
72996 + return;
72997 +
72998 + write_lock(&gr_inode_lock);
72999 + inodev = lookup_inodev_entry(ino, dev);
73000 + if (inodev != NULL)
73001 + do_handle_delete(inodev, ino, dev);
73002 + write_unlock(&gr_inode_lock);
73003 +
73004 + return;
73005 +}
73006 +
73007 +static void
73008 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
73009 + const ino_t newinode, const dev_t newdevice,
73010 + struct acl_subject_label *subj)
73011 +{
73012 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
73013 + struct acl_object_label *match;
73014 +
73015 + match = subj->obj_hash[index];
73016 +
73017 + while (match && (match->inode != oldinode ||
73018 + match->device != olddevice ||
73019 + !(match->mode & GR_DELETED)))
73020 + match = match->next;
73021 +
73022 + if (match && (match->inode == oldinode)
73023 + && (match->device == olddevice)
73024 + && (match->mode & GR_DELETED)) {
73025 + if (match->prev == NULL) {
73026 + subj->obj_hash[index] = match->next;
73027 + if (match->next != NULL)
73028 + match->next->prev = NULL;
73029 + } else {
73030 + match->prev->next = match->next;
73031 + if (match->next != NULL)
73032 + match->next->prev = match->prev;
73033 + }
73034 + match->prev = NULL;
73035 + match->next = NULL;
73036 + match->inode = newinode;
73037 + match->device = newdevice;
73038 + match->mode &= ~GR_DELETED;
73039 +
73040 + insert_acl_obj_label(match, subj);
73041 + }
73042 +
73043 + return;
73044 +}
73045 +
73046 +static void
73047 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
73048 + const ino_t newinode, const dev_t newdevice,
73049 + struct acl_role_label *role)
73050 +{
73051 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
73052 + struct acl_subject_label *match;
73053 +
73054 + match = role->subj_hash[index];
73055 +
73056 + while (match && (match->inode != oldinode ||
73057 + match->device != olddevice ||
73058 + !(match->mode & GR_DELETED)))
73059 + match = match->next;
73060 +
73061 + if (match && (match->inode == oldinode)
73062 + && (match->device == olddevice)
73063 + && (match->mode & GR_DELETED)) {
73064 + if (match->prev == NULL) {
73065 + role->subj_hash[index] = match->next;
73066 + if (match->next != NULL)
73067 + match->next->prev = NULL;
73068 + } else {
73069 + match->prev->next = match->next;
73070 + if (match->next != NULL)
73071 + match->next->prev = match->prev;
73072 + }
73073 + match->prev = NULL;
73074 + match->next = NULL;
73075 + match->inode = newinode;
73076 + match->device = newdevice;
73077 + match->mode &= ~GR_DELETED;
73078 +
73079 + insert_acl_subj_label(match, role);
73080 + }
73081 +
73082 + return;
73083 +}
73084 +
73085 +static void
73086 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
73087 + const ino_t newinode, const dev_t newdevice)
73088 +{
73089 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
73090 + struct inodev_entry *match;
73091 +
73092 + match = running_polstate.inodev_set.i_hash[index];
73093 +
73094 + while (match && (match->nentry->inode != oldinode ||
73095 + match->nentry->device != olddevice || !match->nentry->deleted))
73096 + match = match->next;
73097 +
73098 + if (match && (match->nentry->inode == oldinode)
73099 + && (match->nentry->device == olddevice) &&
73100 + match->nentry->deleted) {
73101 + if (match->prev == NULL) {
73102 + running_polstate.inodev_set.i_hash[index] = match->next;
73103 + if (match->next != NULL)
73104 + match->next->prev = NULL;
73105 + } else {
73106 + match->prev->next = match->next;
73107 + if (match->next != NULL)
73108 + match->next->prev = match->prev;
73109 + }
73110 + match->prev = NULL;
73111 + match->next = NULL;
73112 + match->nentry->inode = newinode;
73113 + match->nentry->device = newdevice;
73114 + match->nentry->deleted = 0;
73115 +
73116 + insert_inodev_entry(match);
73117 + }
73118 +
73119 + return;
73120 +}
73121 +
73122 +static void
73123 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
73124 +{
73125 + struct acl_subject_label *subj;
73126 + struct acl_role_label *role;
73127 + unsigned int x;
73128 +
73129 + FOR_EACH_ROLE_START(role)
73130 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
73131 +
73132 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
73133 + if ((subj->inode == ino) && (subj->device == dev)) {
73134 + subj->inode = ino;
73135 + subj->device = dev;
73136 + }
73137 + /* nested subjects aren't in the role's subj_hash table */
73138 + update_acl_obj_label(matchn->inode, matchn->device,
73139 + ino, dev, subj);
73140 + FOR_EACH_NESTED_SUBJECT_END(subj)
73141 + FOR_EACH_SUBJECT_START(role, subj, x)
73142 + update_acl_obj_label(matchn->inode, matchn->device,
73143 + ino, dev, subj);
73144 + FOR_EACH_SUBJECT_END(subj,x)
73145 + FOR_EACH_ROLE_END(role)
73146 +
73147 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
73148 +
73149 + return;
73150 +}
73151 +
73152 +static void
73153 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
73154 + const struct vfsmount *mnt)
73155 +{
73156 + ino_t ino = dentry->d_inode->i_ino;
73157 + dev_t dev = __get_dev(dentry);
73158 +
73159 + __do_handle_create(matchn, ino, dev);
73160 +
73161 + return;
73162 +}
73163 +
73164 +void
73165 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73166 +{
73167 + struct name_entry *matchn;
73168 +
73169 + if (unlikely(!(gr_status & GR_READY)))
73170 + return;
73171 +
73172 + preempt_disable();
73173 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
73174 +
73175 + if (unlikely((unsigned long)matchn)) {
73176 + write_lock(&gr_inode_lock);
73177 + do_handle_create(matchn, dentry, mnt);
73178 + write_unlock(&gr_inode_lock);
73179 + }
73180 + preempt_enable();
73181 +
73182 + return;
73183 +}
73184 +
73185 +void
73186 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73187 +{
73188 + struct name_entry *matchn;
73189 +
73190 + if (unlikely(!(gr_status & GR_READY)))
73191 + return;
73192 +
73193 + preempt_disable();
73194 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
73195 +
73196 + if (unlikely((unsigned long)matchn)) {
73197 + write_lock(&gr_inode_lock);
73198 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
73199 + write_unlock(&gr_inode_lock);
73200 + }
73201 + preempt_enable();
73202 +
73203 + return;
73204 +}
73205 +
73206 +void
73207 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73208 + struct dentry *old_dentry,
73209 + struct dentry *new_dentry,
73210 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
73211 +{
73212 + struct name_entry *matchn;
73213 + struct name_entry *matchn2 = NULL;
73214 + struct inodev_entry *inodev;
73215 + struct inode *inode = new_dentry->d_inode;
73216 + ino_t old_ino = old_dentry->d_inode->i_ino;
73217 + dev_t old_dev = __get_dev(old_dentry);
73218 + unsigned int exchange = flags & RENAME_EXCHANGE;
73219 +
73220 + /* vfs_rename swaps the name and parent link for old_dentry and
73221 + new_dentry
73222 + at this point, old_dentry has the new name, parent link, and inode
73223 + for the renamed file
73224 + if a file is being replaced by a rename, new_dentry has the inode
73225 + and name for the replaced file
73226 + */
73227 +
73228 + if (unlikely(!(gr_status & GR_READY)))
73229 + return;
73230 +
73231 + preempt_disable();
73232 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
73233 +
73234 + /* exchange cases:
73235 + a filename exists for the source, but not dest
73236 + do a recreate on source
73237 + a filename exists for the dest, but not source
73238 + do a recreate on dest
73239 + a filename exists for both source and dest
73240 + delete source and dest, then create source and dest
73241 + a filename exists for neither source nor dest
73242 + no updates needed
73243 +
73244 + the name entry lookups get us the old inode/dev associated with
73245 + each name, so do the deletes first (if possible) so that when
73246 + we do the create, we pick up on the right entries
73247 + */
73248 +
73249 + if (exchange)
73250 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
73251 +
73252 + /* we wouldn't have to check d_inode if it weren't for
73253 + NFS silly-renaming
73254 + */
73255 +
73256 + write_lock(&gr_inode_lock);
73257 + if (unlikely((replace || exchange) && inode)) {
73258 + ino_t new_ino = inode->i_ino;
73259 + dev_t new_dev = __get_dev(new_dentry);
73260 +
73261 + inodev = lookup_inodev_entry(new_ino, new_dev);
73262 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
73263 + do_handle_delete(inodev, new_ino, new_dev);
73264 + }
73265 +
73266 + inodev = lookup_inodev_entry(old_ino, old_dev);
73267 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
73268 + do_handle_delete(inodev, old_ino, old_dev);
73269 +
73270 + if (unlikely(matchn != NULL))
73271 + do_handle_create(matchn, old_dentry, mnt);
73272 +
73273 + if (unlikely(matchn2 != NULL))
73274 + do_handle_create(matchn2, new_dentry, mnt);
73275 +
73276 + write_unlock(&gr_inode_lock);
73277 + preempt_enable();
73278 +
73279 + return;
73280 +}
73281 +
73282 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
73283 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
73284 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
73285 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
73286 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
73287 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
73288 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
73289 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
73290 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
73291 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
73292 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
73293 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
73294 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
73295 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
73296 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
73297 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
73298 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
73299 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
73300 +};
73301 +
73302 +void
73303 +gr_learn_resource(const struct task_struct *task,
73304 + const int res, const unsigned long wanted, const int gt)
73305 +{
73306 + struct acl_subject_label *acl;
73307 + const struct cred *cred;
73308 +
73309 + if (unlikely((gr_status & GR_READY) &&
73310 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
73311 + goto skip_reslog;
73312 +
73313 + gr_log_resource(task, res, wanted, gt);
73314 +skip_reslog:
73315 +
73316 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
73317 + return;
73318 +
73319 + acl = task->acl;
73320 +
73321 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
73322 + !(acl->resmask & (1U << (unsigned short) res))))
73323 + return;
73324 +
73325 + if (wanted >= acl->res[res].rlim_cur) {
73326 + unsigned long res_add;
73327 +
73328 + res_add = wanted + res_learn_bumps[res];
73329 +
73330 + acl->res[res].rlim_cur = res_add;
73331 +
73332 + if (wanted > acl->res[res].rlim_max)
73333 + acl->res[res].rlim_max = res_add;
73334 +
73335 + /* only log the subject filename, since resource logging is supported for
73336 + single-subject learning only */
73337 + rcu_read_lock();
73338 + cred = __task_cred(task);
73339 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
73340 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
73341 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
73342 + "", (unsigned long) res, &task->signal->saved_ip);
73343 + rcu_read_unlock();
73344 + }
73345 +
73346 + return;
73347 +}
73348 +EXPORT_SYMBOL_GPL(gr_learn_resource);
73349 +#endif
73350 +
73351 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
73352 +void
73353 +pax_set_initial_flags(struct linux_binprm *bprm)
73354 +{
73355 + struct task_struct *task = current;
73356 + struct acl_subject_label *proc;
73357 + unsigned long flags;
73358 +
73359 + if (unlikely(!(gr_status & GR_READY)))
73360 + return;
73361 +
73362 + flags = pax_get_flags(task);
73363 +
73364 + proc = task->acl;
73365 +
73366 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
73367 + flags &= ~MF_PAX_PAGEEXEC;
73368 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
73369 + flags &= ~MF_PAX_SEGMEXEC;
73370 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
73371 + flags &= ~MF_PAX_RANDMMAP;
73372 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
73373 + flags &= ~MF_PAX_EMUTRAMP;
73374 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
73375 + flags &= ~MF_PAX_MPROTECT;
73376 +
73377 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
73378 + flags |= MF_PAX_PAGEEXEC;
73379 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
73380 + flags |= MF_PAX_SEGMEXEC;
73381 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
73382 + flags |= MF_PAX_RANDMMAP;
73383 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
73384 + flags |= MF_PAX_EMUTRAMP;
73385 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
73386 + flags |= MF_PAX_MPROTECT;
73387 +
73388 + pax_set_flags(task, flags);
73389 +
73390 + return;
73391 +}
73392 +#endif
73393 +
73394 +int
73395 +gr_handle_proc_ptrace(struct task_struct *task)
73396 +{
73397 + struct file *filp;
73398 + struct task_struct *tmp = task;
73399 + struct task_struct *curtemp = current;
73400 + __u32 retmode;
73401 +
73402 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
73403 + if (unlikely(!(gr_status & GR_READY)))
73404 + return 0;
73405 +#endif
73406 +
73407 + read_lock(&tasklist_lock);
73408 + read_lock(&grsec_exec_file_lock);
73409 + filp = task->exec_file;
73410 +
73411 + while (task_pid_nr(tmp) > 0) {
73412 + if (tmp == curtemp)
73413 + break;
73414 + tmp = tmp->real_parent;
73415 + }
73416 +
73417 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
73418 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
73419 + read_unlock(&grsec_exec_file_lock);
73420 + read_unlock(&tasklist_lock);
73421 + return 1;
73422 + }
73423 +
73424 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73425 + if (!(gr_status & GR_READY)) {
73426 + read_unlock(&grsec_exec_file_lock);
73427 + read_unlock(&tasklist_lock);
73428 + return 0;
73429 + }
73430 +#endif
73431 +
73432 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
73433 + read_unlock(&grsec_exec_file_lock);
73434 + read_unlock(&tasklist_lock);
73435 +
73436 + if (retmode & GR_NOPTRACE)
73437 + return 1;
73438 +
73439 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
73440 + && (current->acl != task->acl || (current->acl != current->role->root_label
73441 + && task_pid_nr(current) != task_pid_nr(task))))
73442 + return 1;
73443 +
73444 + return 0;
73445 +}
73446 +
73447 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
73448 +{
73449 + if (unlikely(!(gr_status & GR_READY)))
73450 + return;
73451 +
73452 + if (!(current->role->roletype & GR_ROLE_GOD))
73453 + return;
73454 +
73455 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
73456 + p->role->rolename, gr_task_roletype_to_char(p),
73457 + p->acl->filename);
73458 +}
73459 +
73460 +int
73461 +gr_handle_ptrace(struct task_struct *task, const long request)
73462 +{
73463 + struct task_struct *tmp = task;
73464 + struct task_struct *curtemp = current;
73465 + __u32 retmode;
73466 +
73467 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
73468 + if (unlikely(!(gr_status & GR_READY)))
73469 + return 0;
73470 +#endif
73471 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
73472 + read_lock(&tasklist_lock);
73473 + while (task_pid_nr(tmp) > 0) {
73474 + if (tmp == curtemp)
73475 + break;
73476 + tmp = tmp->real_parent;
73477 + }
73478 +
73479 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
73480 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
73481 + read_unlock(&tasklist_lock);
73482 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
73483 + return 1;
73484 + }
73485 + read_unlock(&tasklist_lock);
73486 + }
73487 +
73488 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73489 + if (!(gr_status & GR_READY))
73490 + return 0;
73491 +#endif
73492 +
73493 + read_lock(&grsec_exec_file_lock);
73494 + if (unlikely(!task->exec_file)) {
73495 + read_unlock(&grsec_exec_file_lock);
73496 + return 0;
73497 + }
73498 +
73499 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
73500 + read_unlock(&grsec_exec_file_lock);
73501 +
73502 + if (retmode & GR_NOPTRACE) {
73503 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
73504 + return 1;
73505 + }
73506 +
73507 + if (retmode & GR_PTRACERD) {
73508 + switch (request) {
73509 + case PTRACE_SEIZE:
73510 + case PTRACE_POKETEXT:
73511 + case PTRACE_POKEDATA:
73512 + case PTRACE_POKEUSR:
73513 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
73514 + case PTRACE_SETREGS:
73515 + case PTRACE_SETFPREGS:
73516 +#endif
73517 +#ifdef CONFIG_X86
73518 + case PTRACE_SETFPXREGS:
73519 +#endif
73520 +#ifdef CONFIG_ALTIVEC
73521 + case PTRACE_SETVRREGS:
73522 +#endif
73523 + return 1;
73524 + default:
73525 + return 0;
73526 + }
73527 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
73528 + !(current->role->roletype & GR_ROLE_GOD) &&
73529 + (current->acl != task->acl)) {
73530 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
73531 + return 1;
73532 + }
73533 +
73534 + return 0;
73535 +}
73536 +
73537 +static int is_writable_mmap(const struct file *filp)
73538 +{
73539 + struct task_struct *task = current;
73540 + struct acl_object_label *obj, *obj2;
73541 +
73542 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
73543 + !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))) {
73544 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
73545 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
73546 + task->role->root_label);
73547 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
73548 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
73549 + return 1;
73550 + }
73551 + }
73552 + return 0;
73553 +}
73554 +
73555 +int
73556 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
73557 +{
73558 + __u32 mode;
73559 +
73560 + if (unlikely(!file || !(prot & PROT_EXEC)))
73561 + return 1;
73562 +
73563 + if (is_writable_mmap(file))
73564 + return 0;
73565 +
73566 + mode =
73567 + gr_search_file(file->f_path.dentry,
73568 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
73569 + file->f_path.mnt);
73570 +
73571 + if (!gr_tpe_allow(file))
73572 + return 0;
73573 +
73574 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
73575 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
73576 + return 0;
73577 + } else if (unlikely(!(mode & GR_EXEC))) {
73578 + return 0;
73579 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
73580 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
73581 + return 1;
73582 + }
73583 +
73584 + return 1;
73585 +}
73586 +
73587 +int
73588 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73589 +{
73590 + __u32 mode;
73591 +
73592 + if (unlikely(!file || !(prot & PROT_EXEC)))
73593 + return 1;
73594 +
73595 + if (is_writable_mmap(file))
73596 + return 0;
73597 +
73598 + mode =
73599 + gr_search_file(file->f_path.dentry,
73600 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
73601 + file->f_path.mnt);
73602 +
73603 + if (!gr_tpe_allow(file))
73604 + return 0;
73605 +
73606 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
73607 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
73608 + return 0;
73609 + } else if (unlikely(!(mode & GR_EXEC))) {
73610 + return 0;
73611 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
73612 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
73613 + return 1;
73614 + }
73615 +
73616 + return 1;
73617 +}
73618 +
73619 +void
73620 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73621 +{
73622 + unsigned long runtime, cputime;
73623 + cputime_t utime, stime;
73624 + unsigned int wday, cday;
73625 + __u8 whr, chr;
73626 + __u8 wmin, cmin;
73627 + __u8 wsec, csec;
73628 + struct timespec timeval;
73629 +
73630 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
73631 + !(task->acl->mode & GR_PROCACCT)))
73632 + return;
73633 +
73634 + do_posix_clock_monotonic_gettime(&timeval);
73635 + runtime = timeval.tv_sec - task->start_time.tv_sec;
73636 + wday = runtime / (60 * 60 * 24);
73637 + runtime -= wday * (60 * 60 * 24);
73638 + whr = runtime / (60 * 60);
73639 + runtime -= whr * (60 * 60);
73640 + wmin = runtime / 60;
73641 + runtime -= wmin * 60;
73642 + wsec = runtime;
73643 +
73644 + task_cputime(task, &utime, &stime);
73645 + cputime = cputime_to_secs(utime + stime);
73646 + cday = cputime / (60 * 60 * 24);
73647 + cputime -= cday * (60 * 60 * 24);
73648 + chr = cputime / (60 * 60);
73649 + cputime -= chr * (60 * 60);
73650 + cmin = cputime / 60;
73651 + cputime -= cmin * 60;
73652 + csec = cputime;
73653 +
73654 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
73655 +
73656 + return;
73657 +}
73658 +
73659 +#ifdef CONFIG_TASKSTATS
73660 +int gr_is_taskstats_denied(int pid)
73661 +{
73662 + struct task_struct *task;
73663 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73664 + const struct cred *cred;
73665 +#endif
73666 + int ret = 0;
73667 +
73668 + /* restrict taskstats viewing to un-chrooted root users
73669 + who have the 'view' subject flag if the RBAC system is enabled
73670 + */
73671 +
73672 + rcu_read_lock();
73673 + read_lock(&tasklist_lock);
73674 + task = find_task_by_vpid(pid);
73675 + if (task) {
73676 +#ifdef CONFIG_GRKERNSEC_CHROOT
73677 + if (proc_is_chrooted(task))
73678 + ret = -EACCES;
73679 +#endif
73680 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73681 + cred = __task_cred(task);
73682 +#ifdef CONFIG_GRKERNSEC_PROC_USER
73683 + if (gr_is_global_nonroot(cred->uid))
73684 + ret = -EACCES;
73685 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73686 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
73687 + ret = -EACCES;
73688 +#endif
73689 +#endif
73690 + if (gr_status & GR_READY) {
73691 + if (!(task->acl->mode & GR_VIEW))
73692 + ret = -EACCES;
73693 + }
73694 + } else
73695 + ret = -ENOENT;
73696 +
73697 + read_unlock(&tasklist_lock);
73698 + rcu_read_unlock();
73699 +
73700 + return ret;
73701 +}
73702 +#endif
73703 +
73704 +/* AUXV entries are filled via a descendant of search_binary_handler
73705 + after we've already applied the subject for the target
73706 +*/
73707 +int gr_acl_enable_at_secure(void)
73708 +{
73709 + if (unlikely(!(gr_status & GR_READY)))
73710 + return 0;
73711 +
73712 + if (current->acl->mode & GR_ATSECURE)
73713 + return 1;
73714 +
73715 + return 0;
73716 +}
73717 +
73718 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
73719 +{
73720 + struct task_struct *task = current;
73721 + struct dentry *dentry = file->f_path.dentry;
73722 + struct vfsmount *mnt = file->f_path.mnt;
73723 + struct acl_object_label *obj, *tmp;
73724 + struct acl_subject_label *subj;
73725 + unsigned int bufsize;
73726 + int is_not_root;
73727 + char *path;
73728 + dev_t dev = __get_dev(dentry);
73729 +
73730 + if (unlikely(!(gr_status & GR_READY)))
73731 + return 1;
73732 +
73733 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
73734 + return 1;
73735 +
73736 + /* ignore Eric Biederman */
73737 + if (IS_PRIVATE(dentry->d_inode))
73738 + return 1;
73739 +
73740 + subj = task->acl;
73741 + read_lock(&gr_inode_lock);
73742 + do {
73743 + obj = lookup_acl_obj_label(ino, dev, subj);
73744 + if (obj != NULL) {
73745 + read_unlock(&gr_inode_lock);
73746 + return (obj->mode & GR_FIND) ? 1 : 0;
73747 + }
73748 + } while ((subj = subj->parent_subject));
73749 + read_unlock(&gr_inode_lock);
73750 +
73751 + /* this is purely an optimization since we're looking for an object
73752 + for the directory we're doing a readdir on
73753 + if it's possible for any globbed object to match the entry we're
73754 + filling into the directory, then the object we find here will be
73755 + an anchor point with attached globbed objects
73756 + */
73757 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
73758 + if (obj->globbed == NULL)
73759 + return (obj->mode & GR_FIND) ? 1 : 0;
73760 +
73761 + is_not_root = ((obj->filename[0] == '/') &&
73762 + (obj->filename[1] == '\0')) ? 0 : 1;
73763 + bufsize = PAGE_SIZE - namelen - is_not_root;
73764 +
73765 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
73766 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
73767 + return 1;
73768 +
73769 + preempt_disable();
73770 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
73771 + bufsize);
73772 +
73773 + bufsize = strlen(path);
73774 +
73775 + /* if base is "/", don't append an additional slash */
73776 + if (is_not_root)
73777 + *(path + bufsize) = '/';
73778 + memcpy(path + bufsize + is_not_root, name, namelen);
73779 + *(path + bufsize + namelen + is_not_root) = '\0';
73780 +
73781 + tmp = obj->globbed;
73782 + while (tmp) {
73783 + if (!glob_match(tmp->filename, path)) {
73784 + preempt_enable();
73785 + return (tmp->mode & GR_FIND) ? 1 : 0;
73786 + }
73787 + tmp = tmp->next;
73788 + }
73789 + preempt_enable();
73790 + return (obj->mode & GR_FIND) ? 1 : 0;
73791 +}
73792 +
73793 +void gr_put_exec_file(struct task_struct *task)
73794 +{
73795 + struct file *filp;
73796 +
73797 + write_lock(&grsec_exec_file_lock);
73798 + filp = task->exec_file;
73799 + task->exec_file = NULL;
73800 + write_unlock(&grsec_exec_file_lock);
73801 +
73802 + if (filp)
73803 + fput(filp);
73804 +
73805 + return;
73806 +}
73807 +
73808 +
73809 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
73810 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
73811 +#endif
73812 +#ifdef CONFIG_SECURITY
73813 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73814 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73815 +#endif
73816 +
73817 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
73818 new file mode 100644
73819 index 0000000..18ffbbd
73820 --- /dev/null
73821 +++ b/grsecurity/gracl_alloc.c
73822 @@ -0,0 +1,105 @@
73823 +#include <linux/kernel.h>
73824 +#include <linux/mm.h>
73825 +#include <linux/slab.h>
73826 +#include <linux/vmalloc.h>
73827 +#include <linux/gracl.h>
73828 +#include <linux/grsecurity.h>
73829 +
73830 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
73831 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
73832 +
73833 +static __inline__ int
73834 +alloc_pop(void)
73835 +{
73836 + if (current_alloc_state->alloc_stack_next == 1)
73837 + return 0;
73838 +
73839 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
73840 +
73841 + current_alloc_state->alloc_stack_next--;
73842 +
73843 + return 1;
73844 +}
73845 +
73846 +static __inline__ int
73847 +alloc_push(void *buf)
73848 +{
73849 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
73850 + return 1;
73851 +
73852 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
73853 +
73854 + current_alloc_state->alloc_stack_next++;
73855 +
73856 + return 0;
73857 +}
73858 +
73859 +void *
73860 +acl_alloc(unsigned long len)
73861 +{
73862 + void *ret = NULL;
73863 +
73864 + if (!len || len > PAGE_SIZE)
73865 + goto out;
73866 +
73867 + ret = kmalloc(len, GFP_KERNEL);
73868 +
73869 + if (ret) {
73870 + if (alloc_push(ret)) {
73871 + kfree(ret);
73872 + ret = NULL;
73873 + }
73874 + }
73875 +
73876 +out:
73877 + return ret;
73878 +}
73879 +
73880 +void *
73881 +acl_alloc_num(unsigned long num, unsigned long len)
73882 +{
73883 + if (!len || (num > (PAGE_SIZE / len)))
73884 + return NULL;
73885 +
73886 + return acl_alloc(num * len);
73887 +}
73888 +
73889 +void
73890 +acl_free_all(void)
73891 +{
73892 + if (!current_alloc_state->alloc_stack)
73893 + return;
73894 +
73895 + while (alloc_pop()) ;
73896 +
73897 + if (current_alloc_state->alloc_stack) {
73898 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
73899 + kfree(current_alloc_state->alloc_stack);
73900 + else
73901 + vfree(current_alloc_state->alloc_stack);
73902 + }
73903 +
73904 + current_alloc_state->alloc_stack = NULL;
73905 + current_alloc_state->alloc_stack_size = 1;
73906 + current_alloc_state->alloc_stack_next = 1;
73907 +
73908 + return;
73909 +}
73910 +
73911 +int
73912 +acl_alloc_stack_init(unsigned long size)
73913 +{
73914 + if ((size * sizeof (void *)) <= PAGE_SIZE)
73915 + current_alloc_state->alloc_stack =
73916 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
73917 + else
73918 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
73919 +
73920 + current_alloc_state->alloc_stack_size = size;
73921 + current_alloc_state->alloc_stack_next = 1;
73922 +
73923 + if (!current_alloc_state->alloc_stack)
73924 + return 0;
73925 + else
73926 + return 1;
73927 +}
73928 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
73929 new file mode 100644
73930 index 0000000..1a94c11
73931 --- /dev/null
73932 +++ b/grsecurity/gracl_cap.c
73933 @@ -0,0 +1,127 @@
73934 +#include <linux/kernel.h>
73935 +#include <linux/module.h>
73936 +#include <linux/sched.h>
73937 +#include <linux/gracl.h>
73938 +#include <linux/grsecurity.h>
73939 +#include <linux/grinternal.h>
73940 +
73941 +extern const char *captab_log[];
73942 +extern int captab_log_entries;
73943 +
73944 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
73945 +{
73946 + struct acl_subject_label *curracl;
73947 +
73948 + if (!gr_acl_is_enabled())
73949 + return 1;
73950 +
73951 + curracl = task->acl;
73952 +
73953 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
73954 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
73955 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
73956 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
73957 + gr_to_filename(task->exec_file->f_path.dentry,
73958 + task->exec_file->f_path.mnt) : curracl->filename,
73959 + curracl->filename, 0UL,
73960 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
73961 + return 1;
73962 + }
73963 +
73964 + return 0;
73965 +}
73966 +
73967 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73968 +{
73969 + struct acl_subject_label *curracl;
73970 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
73971 + kernel_cap_t cap_audit = __cap_empty_set;
73972 +
73973 + if (!gr_acl_is_enabled())
73974 + return 1;
73975 +
73976 + curracl = task->acl;
73977 +
73978 + cap_drop = curracl->cap_lower;
73979 + cap_mask = curracl->cap_mask;
73980 + cap_audit = curracl->cap_invert_audit;
73981 +
73982 + while ((curracl = curracl->parent_subject)) {
73983 + /* if the cap isn't specified in the current computed mask but is specified in the
73984 + current level subject, and is lowered in the current level subject, then add
73985 + it to the set of dropped capabilities
73986 + otherwise, add the current level subject's mask to the current computed mask
73987 + */
73988 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
73989 + cap_raise(cap_mask, cap);
73990 + if (cap_raised(curracl->cap_lower, cap))
73991 + cap_raise(cap_drop, cap);
73992 + if (cap_raised(curracl->cap_invert_audit, cap))
73993 + cap_raise(cap_audit, cap);
73994 + }
73995 + }
73996 +
73997 + if (!cap_raised(cap_drop, cap)) {
73998 + if (cap_raised(cap_audit, cap))
73999 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
74000 + return 1;
74001 + }
74002 +
74003 + /* only learn the capability use if the process has the capability in the
74004 + general case, the two uses in sys.c of gr_learn_cap are an exception
74005 + to this rule to ensure any role transition involves what the full-learned
74006 + policy believes in a privileged process
74007 + */
74008 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
74009 + return 1;
74010 +
74011 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
74012 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
74013 +
74014 + return 0;
74015 +}
74016 +
74017 +int
74018 +gr_acl_is_capable(const int cap)
74019 +{
74020 + return gr_task_acl_is_capable(current, current_cred(), cap);
74021 +}
74022 +
74023 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
74024 +{
74025 + struct acl_subject_label *curracl;
74026 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
74027 +
74028 + if (!gr_acl_is_enabled())
74029 + return 1;
74030 +
74031 + curracl = task->acl;
74032 +
74033 + cap_drop = curracl->cap_lower;
74034 + cap_mask = curracl->cap_mask;
74035 +
74036 + while ((curracl = curracl->parent_subject)) {
74037 + /* if the cap isn't specified in the current computed mask but is specified in the
74038 + current level subject, and is lowered in the current level subject, then add
74039 + it to the set of dropped capabilities
74040 + otherwise, add the current level subject's mask to the current computed mask
74041 + */
74042 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
74043 + cap_raise(cap_mask, cap);
74044 + if (cap_raised(curracl->cap_lower, cap))
74045 + cap_raise(cap_drop, cap);
74046 + }
74047 + }
74048 +
74049 + if (!cap_raised(cap_drop, cap))
74050 + return 1;
74051 +
74052 + return 0;
74053 +}
74054 +
74055 +int
74056 +gr_acl_is_capable_nolog(const int cap)
74057 +{
74058 + return gr_task_acl_is_capable_nolog(current, cap);
74059 +}
74060 +
74061 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
74062 new file mode 100644
74063 index 0000000..ca25605
74064 --- /dev/null
74065 +++ b/grsecurity/gracl_compat.c
74066 @@ -0,0 +1,270 @@
74067 +#include <linux/kernel.h>
74068 +#include <linux/gracl.h>
74069 +#include <linux/compat.h>
74070 +#include <linux/gracl_compat.h>
74071 +
74072 +#include <asm/uaccess.h>
74073 +
74074 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
74075 +{
74076 + struct gr_arg_wrapper_compat uwrapcompat;
74077 +
74078 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
74079 + return -EFAULT;
74080 +
74081 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
74082 + (uwrapcompat.version != 0x2901)) ||
74083 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
74084 + return -EINVAL;
74085 +
74086 + uwrap->arg = compat_ptr(uwrapcompat.arg);
74087 + uwrap->version = uwrapcompat.version;
74088 + uwrap->size = sizeof(struct gr_arg);
74089 +
74090 + return 0;
74091 +}
74092 +
74093 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
74094 +{
74095 + struct gr_arg_compat argcompat;
74096 +
74097 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
74098 + return -EFAULT;
74099 +
74100 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
74101 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
74102 + arg->role_db.num_roles = argcompat.role_db.num_roles;
74103 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
74104 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
74105 + arg->role_db.num_objects = argcompat.role_db.num_objects;
74106 +
74107 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
74108 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
74109 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
74110 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
74111 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
74112 + arg->segv_device = argcompat.segv_device;
74113 + arg->segv_inode = argcompat.segv_inode;
74114 + arg->segv_uid = argcompat.segv_uid;
74115 + arg->num_sprole_pws = argcompat.num_sprole_pws;
74116 + arg->mode = argcompat.mode;
74117 +
74118 + return 0;
74119 +}
74120 +
74121 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
74122 +{
74123 + struct acl_object_label_compat objcompat;
74124 +
74125 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
74126 + return -EFAULT;
74127 +
74128 + obj->filename = compat_ptr(objcompat.filename);
74129 + obj->inode = objcompat.inode;
74130 + obj->device = objcompat.device;
74131 + obj->mode = objcompat.mode;
74132 +
74133 + obj->nested = compat_ptr(objcompat.nested);
74134 + obj->globbed = compat_ptr(objcompat.globbed);
74135 +
74136 + obj->prev = compat_ptr(objcompat.prev);
74137 + obj->next = compat_ptr(objcompat.next);
74138 +
74139 + return 0;
74140 +}
74141 +
74142 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74143 +{
74144 + unsigned int i;
74145 + struct acl_subject_label_compat subjcompat;
74146 +
74147 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
74148 + return -EFAULT;
74149 +
74150 + subj->filename = compat_ptr(subjcompat.filename);
74151 + subj->inode = subjcompat.inode;
74152 + subj->device = subjcompat.device;
74153 + subj->mode = subjcompat.mode;
74154 + subj->cap_mask = subjcompat.cap_mask;
74155 + subj->cap_lower = subjcompat.cap_lower;
74156 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
74157 +
74158 + for (i = 0; i < GR_NLIMITS; i++) {
74159 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
74160 + subj->res[i].rlim_cur = RLIM_INFINITY;
74161 + else
74162 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
74163 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
74164 + subj->res[i].rlim_max = RLIM_INFINITY;
74165 + else
74166 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
74167 + }
74168 + subj->resmask = subjcompat.resmask;
74169 +
74170 + subj->user_trans_type = subjcompat.user_trans_type;
74171 + subj->group_trans_type = subjcompat.group_trans_type;
74172 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
74173 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
74174 + subj->user_trans_num = subjcompat.user_trans_num;
74175 + subj->group_trans_num = subjcompat.group_trans_num;
74176 +
74177 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
74178 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
74179 + subj->ip_type = subjcompat.ip_type;
74180 + subj->ips = compat_ptr(subjcompat.ips);
74181 + subj->ip_num = subjcompat.ip_num;
74182 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
74183 +
74184 + subj->crashes = subjcompat.crashes;
74185 + subj->expires = subjcompat.expires;
74186 +
74187 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
74188 + subj->hash = compat_ptr(subjcompat.hash);
74189 + subj->prev = compat_ptr(subjcompat.prev);
74190 + subj->next = compat_ptr(subjcompat.next);
74191 +
74192 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
74193 + subj->obj_hash_size = subjcompat.obj_hash_size;
74194 + subj->pax_flags = subjcompat.pax_flags;
74195 +
74196 + return 0;
74197 +}
74198 +
74199 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
74200 +{
74201 + struct acl_role_label_compat rolecompat;
74202 +
74203 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
74204 + return -EFAULT;
74205 +
74206 + role->rolename = compat_ptr(rolecompat.rolename);
74207 + role->uidgid = rolecompat.uidgid;
74208 + role->roletype = rolecompat.roletype;
74209 +
74210 + role->auth_attempts = rolecompat.auth_attempts;
74211 + role->expires = rolecompat.expires;
74212 +
74213 + role->root_label = compat_ptr(rolecompat.root_label);
74214 + role->hash = compat_ptr(rolecompat.hash);
74215 +
74216 + role->prev = compat_ptr(rolecompat.prev);
74217 + role->next = compat_ptr(rolecompat.next);
74218 +
74219 + role->transitions = compat_ptr(rolecompat.transitions);
74220 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
74221 + role->domain_children = compat_ptr(rolecompat.domain_children);
74222 + role->domain_child_num = rolecompat.domain_child_num;
74223 +
74224 + role->umask = rolecompat.umask;
74225 +
74226 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
74227 + role->subj_hash_size = rolecompat.subj_hash_size;
74228 +
74229 + return 0;
74230 +}
74231 +
74232 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74233 +{
74234 + struct role_allowed_ip_compat roleip_compat;
74235 +
74236 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
74237 + return -EFAULT;
74238 +
74239 + roleip->addr = roleip_compat.addr;
74240 + roleip->netmask = roleip_compat.netmask;
74241 +
74242 + roleip->prev = compat_ptr(roleip_compat.prev);
74243 + roleip->next = compat_ptr(roleip_compat.next);
74244 +
74245 + return 0;
74246 +}
74247 +
74248 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
74249 +{
74250 + struct role_transition_compat trans_compat;
74251 +
74252 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
74253 + return -EFAULT;
74254 +
74255 + trans->rolename = compat_ptr(trans_compat.rolename);
74256 +
74257 + trans->prev = compat_ptr(trans_compat.prev);
74258 + trans->next = compat_ptr(trans_compat.next);
74259 +
74260 + return 0;
74261 +
74262 +}
74263 +
74264 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74265 +{
74266 + struct gr_hash_struct_compat hash_compat;
74267 +
74268 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
74269 + return -EFAULT;
74270 +
74271 + hash->table = compat_ptr(hash_compat.table);
74272 + hash->nametable = compat_ptr(hash_compat.nametable);
74273 + hash->first = compat_ptr(hash_compat.first);
74274 +
74275 + hash->table_size = hash_compat.table_size;
74276 + hash->used_size = hash_compat.used_size;
74277 +
74278 + hash->type = hash_compat.type;
74279 +
74280 + return 0;
74281 +}
74282 +
74283 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
74284 +{
74285 + compat_uptr_t ptrcompat;
74286 +
74287 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
74288 + return -EFAULT;
74289 +
74290 + *(void **)ptr = compat_ptr(ptrcompat);
74291 +
74292 + return 0;
74293 +}
74294 +
74295 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74296 +{
74297 + struct acl_ip_label_compat ip_compat;
74298 +
74299 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
74300 + return -EFAULT;
74301 +
74302 + ip->iface = compat_ptr(ip_compat.iface);
74303 + ip->addr = ip_compat.addr;
74304 + ip->netmask = ip_compat.netmask;
74305 + ip->low = ip_compat.low;
74306 + ip->high = ip_compat.high;
74307 + ip->mode = ip_compat.mode;
74308 + ip->type = ip_compat.type;
74309 +
74310 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
74311 +
74312 + ip->prev = compat_ptr(ip_compat.prev);
74313 + ip->next = compat_ptr(ip_compat.next);
74314 +
74315 + return 0;
74316 +}
74317 +
74318 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74319 +{
74320 + struct sprole_pw_compat pw_compat;
74321 +
74322 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
74323 + return -EFAULT;
74324 +
74325 + pw->rolename = compat_ptr(pw_compat.rolename);
74326 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
74327 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
74328 +
74329 + return 0;
74330 +}
74331 +
74332 +size_t get_gr_arg_wrapper_size_compat(void)
74333 +{
74334 + return sizeof(struct gr_arg_wrapper_compat);
74335 +}
74336 +
74337 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
74338 new file mode 100644
74339 index 0000000..4008fdc
74340 --- /dev/null
74341 +++ b/grsecurity/gracl_fs.c
74342 @@ -0,0 +1,445 @@
74343 +#include <linux/kernel.h>
74344 +#include <linux/sched.h>
74345 +#include <linux/types.h>
74346 +#include <linux/fs.h>
74347 +#include <linux/file.h>
74348 +#include <linux/stat.h>
74349 +#include <linux/grsecurity.h>
74350 +#include <linux/grinternal.h>
74351 +#include <linux/gracl.h>
74352 +
74353 +umode_t
74354 +gr_acl_umask(void)
74355 +{
74356 + if (unlikely(!gr_acl_is_enabled()))
74357 + return 0;
74358 +
74359 + return current->role->umask;
74360 +}
74361 +
74362 +__u32
74363 +gr_acl_handle_hidden_file(const struct dentry * dentry,
74364 + const struct vfsmount * mnt)
74365 +{
74366 + __u32 mode;
74367 +
74368 + if (unlikely(d_is_negative(dentry)))
74369 + return GR_FIND;
74370 +
74371 + mode =
74372 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
74373 +
74374 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
74375 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
74376 + return mode;
74377 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
74378 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
74379 + return 0;
74380 + } else if (unlikely(!(mode & GR_FIND)))
74381 + return 0;
74382 +
74383 + return GR_FIND;
74384 +}
74385 +
74386 +__u32
74387 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74388 + int acc_mode)
74389 +{
74390 + __u32 reqmode = GR_FIND;
74391 + __u32 mode;
74392 +
74393 + if (unlikely(d_is_negative(dentry)))
74394 + return reqmode;
74395 +
74396 + if (acc_mode & MAY_APPEND)
74397 + reqmode |= GR_APPEND;
74398 + else if (acc_mode & MAY_WRITE)
74399 + reqmode |= GR_WRITE;
74400 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
74401 + reqmode |= GR_READ;
74402 +
74403 + mode =
74404 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
74405 + mnt);
74406 +
74407 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
74408 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
74409 + reqmode & GR_READ ? " reading" : "",
74410 + reqmode & GR_WRITE ? " writing" : reqmode &
74411 + GR_APPEND ? " appending" : "");
74412 + return reqmode;
74413 + } else
74414 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
74415 + {
74416 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
74417 + reqmode & GR_READ ? " reading" : "",
74418 + reqmode & GR_WRITE ? " writing" : reqmode &
74419 + GR_APPEND ? " appending" : "");
74420 + return 0;
74421 + } else if (unlikely((mode & reqmode) != reqmode))
74422 + return 0;
74423 +
74424 + return reqmode;
74425 +}
74426 +
74427 +__u32
74428 +gr_acl_handle_creat(const struct dentry * dentry,
74429 + const struct dentry * p_dentry,
74430 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74431 + const int imode)
74432 +{
74433 + __u32 reqmode = GR_WRITE | GR_CREATE;
74434 + __u32 mode;
74435 +
74436 + if (acc_mode & MAY_APPEND)
74437 + reqmode |= GR_APPEND;
74438 + // if a directory was required or the directory already exists, then
74439 + // don't count this open as a read
74440 + if ((acc_mode & MAY_READ) &&
74441 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
74442 + reqmode |= GR_READ;
74443 + if ((open_flags & O_CREAT) &&
74444 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
74445 + reqmode |= GR_SETID;
74446 +
74447 + mode =
74448 + gr_check_create(dentry, p_dentry, p_mnt,
74449 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
74450 +
74451 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
74452 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
74453 + reqmode & GR_READ ? " reading" : "",
74454 + reqmode & GR_WRITE ? " writing" : reqmode &
74455 + GR_APPEND ? " appending" : "");
74456 + return reqmode;
74457 + } else
74458 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
74459 + {
74460 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
74461 + reqmode & GR_READ ? " reading" : "",
74462 + reqmode & GR_WRITE ? " writing" : reqmode &
74463 + GR_APPEND ? " appending" : "");
74464 + return 0;
74465 + } else if (unlikely((mode & reqmode) != reqmode))
74466 + return 0;
74467 +
74468 + return reqmode;
74469 +}
74470 +
74471 +__u32
74472 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
74473 + const int fmode)
74474 +{
74475 + __u32 mode, reqmode = GR_FIND;
74476 +
74477 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
74478 + reqmode |= GR_EXEC;
74479 + if (fmode & S_IWOTH)
74480 + reqmode |= GR_WRITE;
74481 + if (fmode & S_IROTH)
74482 + reqmode |= GR_READ;
74483 +
74484 + mode =
74485 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
74486 + mnt);
74487 +
74488 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
74489 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
74490 + reqmode & GR_READ ? " reading" : "",
74491 + reqmode & GR_WRITE ? " writing" : "",
74492 + reqmode & GR_EXEC ? " executing" : "");
74493 + return reqmode;
74494 + } else
74495 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
74496 + {
74497 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
74498 + reqmode & GR_READ ? " reading" : "",
74499 + reqmode & GR_WRITE ? " writing" : "",
74500 + reqmode & GR_EXEC ? " executing" : "");
74501 + return 0;
74502 + } else if (unlikely((mode & reqmode) != reqmode))
74503 + return 0;
74504 +
74505 + return reqmode;
74506 +}
74507 +
74508 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
74509 +{
74510 + __u32 mode;
74511 +
74512 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
74513 +
74514 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
74515 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
74516 + return mode;
74517 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
74518 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
74519 + return 0;
74520 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
74521 + return 0;
74522 +
74523 + return (reqmode);
74524 +}
74525 +
74526 +__u32
74527 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74528 +{
74529 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
74530 +}
74531 +
74532 +__u32
74533 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
74534 +{
74535 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
74536 +}
74537 +
74538 +__u32
74539 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
74540 +{
74541 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
74542 +}
74543 +
74544 +__u32
74545 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
74546 +{
74547 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
74548 +}
74549 +
74550 +__u32
74551 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
74552 + umode_t *modeptr)
74553 +{
74554 + umode_t mode;
74555 +
74556 + *modeptr &= ~gr_acl_umask();
74557 + mode = *modeptr;
74558 +
74559 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
74560 + return 1;
74561 +
74562 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
74563 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
74564 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
74565 + GR_CHMOD_ACL_MSG);
74566 + } else {
74567 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
74568 + }
74569 +}
74570 +
74571 +__u32
74572 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
74573 +{
74574 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
74575 +}
74576 +
74577 +__u32
74578 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
74579 +{
74580 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
74581 +}
74582 +
74583 +__u32
74584 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
74585 +{
74586 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
74587 +}
74588 +
74589 +__u32
74590 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
74591 +{
74592 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
74593 +}
74594 +
74595 +__u32
74596 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
74597 +{
74598 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
74599 + GR_UNIXCONNECT_ACL_MSG);
74600 +}
74601 +
74602 +/* hardlinks require at minimum create and link permission,
74603 + any additional privilege required is based on the
74604 + privilege of the file being linked to
74605 +*/
74606 +__u32
74607 +gr_acl_handle_link(const struct dentry * new_dentry,
74608 + const struct dentry * parent_dentry,
74609 + const struct vfsmount * parent_mnt,
74610 + const struct dentry * old_dentry,
74611 + const struct vfsmount * old_mnt, const struct filename *to)
74612 +{
74613 + __u32 mode;
74614 + __u32 needmode = GR_CREATE | GR_LINK;
74615 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
74616 +
74617 + mode =
74618 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
74619 + old_mnt);
74620 +
74621 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
74622 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
74623 + return mode;
74624 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
74625 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
74626 + return 0;
74627 + } else if (unlikely((mode & needmode) != needmode))
74628 + return 0;
74629 +
74630 + return 1;
74631 +}
74632 +
74633 +__u32
74634 +gr_acl_handle_symlink(const struct dentry * new_dentry,
74635 + const struct dentry * parent_dentry,
74636 + const struct vfsmount * parent_mnt, const struct filename *from)
74637 +{
74638 + __u32 needmode = GR_WRITE | GR_CREATE;
74639 + __u32 mode;
74640 +
74641 + mode =
74642 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
74643 + GR_CREATE | GR_AUDIT_CREATE |
74644 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
74645 +
74646 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
74647 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
74648 + return mode;
74649 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
74650 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
74651 + return 0;
74652 + } else if (unlikely((mode & needmode) != needmode))
74653 + return 0;
74654 +
74655 + return (GR_WRITE | GR_CREATE);
74656 +}
74657 +
74658 +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)
74659 +{
74660 + __u32 mode;
74661 +
74662 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
74663 +
74664 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
74665 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
74666 + return mode;
74667 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
74668 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
74669 + return 0;
74670 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
74671 + return 0;
74672 +
74673 + return (reqmode);
74674 +}
74675 +
74676 +__u32
74677 +gr_acl_handle_mknod(const struct dentry * new_dentry,
74678 + const struct dentry * parent_dentry,
74679 + const struct vfsmount * parent_mnt,
74680 + const int mode)
74681 +{
74682 + __u32 reqmode = GR_WRITE | GR_CREATE;
74683 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
74684 + reqmode |= GR_SETID;
74685 +
74686 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
74687 + reqmode, GR_MKNOD_ACL_MSG);
74688 +}
74689 +
74690 +__u32
74691 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
74692 + const struct dentry *parent_dentry,
74693 + const struct vfsmount *parent_mnt)
74694 +{
74695 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
74696 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
74697 +}
74698 +
74699 +#define RENAME_CHECK_SUCCESS(old, new) \
74700 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
74701 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
74702 +
74703 +int
74704 +gr_acl_handle_rename(struct dentry *new_dentry,
74705 + struct dentry *parent_dentry,
74706 + const struct vfsmount *parent_mnt,
74707 + struct dentry *old_dentry,
74708 + struct inode *old_parent_inode,
74709 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
74710 +{
74711 + __u32 comp1, comp2;
74712 + int error = 0;
74713 +
74714 + if (unlikely(!gr_acl_is_enabled()))
74715 + return 0;
74716 +
74717 + if (flags & RENAME_EXCHANGE) {
74718 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
74719 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74720 + GR_SUPPRESS, parent_mnt);
74721 + comp2 =
74722 + gr_search_file(old_dentry,
74723 + GR_READ | GR_WRITE | GR_AUDIT_READ |
74724 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
74725 + } else if (d_is_negative(new_dentry)) {
74726 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
74727 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
74728 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
74729 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
74730 + GR_DELETE | GR_AUDIT_DELETE |
74731 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74732 + GR_SUPPRESS, old_mnt);
74733 + } else {
74734 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
74735 + GR_CREATE | GR_DELETE |
74736 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
74737 + GR_AUDIT_READ | GR_AUDIT_WRITE |
74738 + GR_SUPPRESS, parent_mnt);
74739 + comp2 =
74740 + gr_search_file(old_dentry,
74741 + GR_READ | GR_WRITE | GR_AUDIT_READ |
74742 + GR_DELETE | GR_AUDIT_DELETE |
74743 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
74744 + }
74745 +
74746 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
74747 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
74748 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74749 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
74750 + && !(comp2 & GR_SUPPRESS)) {
74751 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
74752 + error = -EACCES;
74753 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
74754 + error = -EACCES;
74755 +
74756 + return error;
74757 +}
74758 +
74759 +void
74760 +gr_acl_handle_exit(void)
74761 +{
74762 + u16 id;
74763 + char *rolename;
74764 +
74765 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
74766 + !(current->role->roletype & GR_ROLE_PERSIST))) {
74767 + id = current->acl_role_id;
74768 + rolename = current->role->rolename;
74769 + gr_set_acls(1);
74770 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
74771 + }
74772 +
74773 + gr_put_exec_file(current);
74774 + return;
74775 +}
74776 +
74777 +int
74778 +gr_acl_handle_procpidmem(const struct task_struct *task)
74779 +{
74780 + if (unlikely(!gr_acl_is_enabled()))
74781 + return 0;
74782 +
74783 + if (task != current && task->acl->mode & GR_PROTPROCFD)
74784 + return -EACCES;
74785 +
74786 + return 0;
74787 +}
74788 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
74789 new file mode 100644
74790 index 0000000..f056b81
74791 --- /dev/null
74792 +++ b/grsecurity/gracl_ip.c
74793 @@ -0,0 +1,386 @@
74794 +#include <linux/kernel.h>
74795 +#include <asm/uaccess.h>
74796 +#include <asm/errno.h>
74797 +#include <net/sock.h>
74798 +#include <linux/file.h>
74799 +#include <linux/fs.h>
74800 +#include <linux/net.h>
74801 +#include <linux/in.h>
74802 +#include <linux/skbuff.h>
74803 +#include <linux/ip.h>
74804 +#include <linux/udp.h>
74805 +#include <linux/types.h>
74806 +#include <linux/sched.h>
74807 +#include <linux/netdevice.h>
74808 +#include <linux/inetdevice.h>
74809 +#include <linux/gracl.h>
74810 +#include <linux/grsecurity.h>
74811 +#include <linux/grinternal.h>
74812 +
74813 +#define GR_BIND 0x01
74814 +#define GR_CONNECT 0x02
74815 +#define GR_INVERT 0x04
74816 +#define GR_BINDOVERRIDE 0x08
74817 +#define GR_CONNECTOVERRIDE 0x10
74818 +#define GR_SOCK_FAMILY 0x20
74819 +
74820 +static const char * gr_protocols[IPPROTO_MAX] = {
74821 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
74822 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
74823 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
74824 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
74825 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
74826 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
74827 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
74828 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
74829 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
74830 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
74831 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
74832 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
74833 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
74834 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
74835 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
74836 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
74837 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
74838 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
74839 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
74840 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
74841 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
74842 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
74843 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
74844 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
74845 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
74846 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
74847 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
74848 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
74849 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
74850 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
74851 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
74852 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
74853 + };
74854 +
74855 +static const char * gr_socktypes[SOCK_MAX] = {
74856 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
74857 + "unknown:7", "unknown:8", "unknown:9", "packet"
74858 + };
74859 +
74860 +static const char * gr_sockfamilies[AF_MAX+1] = {
74861 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
74862 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
74863 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
74864 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
74865 + };
74866 +
74867 +const char *
74868 +gr_proto_to_name(unsigned char proto)
74869 +{
74870 + return gr_protocols[proto];
74871 +}
74872 +
74873 +const char *
74874 +gr_socktype_to_name(unsigned char type)
74875 +{
74876 + return gr_socktypes[type];
74877 +}
74878 +
74879 +const char *
74880 +gr_sockfamily_to_name(unsigned char family)
74881 +{
74882 + return gr_sockfamilies[family];
74883 +}
74884 +
74885 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
74886 +
74887 +int
74888 +gr_search_socket(const int domain, const int type, const int protocol)
74889 +{
74890 + struct acl_subject_label *curr;
74891 + const struct cred *cred = current_cred();
74892 +
74893 + if (unlikely(!gr_acl_is_enabled()))
74894 + goto exit;
74895 +
74896 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
74897 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
74898 + goto exit; // let the kernel handle it
74899 +
74900 + curr = current->acl;
74901 +
74902 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
74903 + /* the family is allowed, if this is PF_INET allow it only if
74904 + the extra sock type/protocol checks pass */
74905 + if (domain == PF_INET)
74906 + goto inet_check;
74907 + goto exit;
74908 + } else {
74909 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74910 + __u32 fakeip = 0;
74911 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74912 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74913 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74914 + gr_to_filename(current->exec_file->f_path.dentry,
74915 + current->exec_file->f_path.mnt) :
74916 + curr->filename, curr->filename,
74917 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
74918 + &current->signal->saved_ip);
74919 + goto exit;
74920 + }
74921 + goto exit_fail;
74922 + }
74923 +
74924 +inet_check:
74925 + /* the rest of this checking is for IPv4 only */
74926 + if (!curr->ips)
74927 + goto exit;
74928 +
74929 + if ((curr->ip_type & (1U << type)) &&
74930 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
74931 + goto exit;
74932 +
74933 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
74934 + /* we don't place acls on raw sockets , and sometimes
74935 + dgram/ip sockets are opened for ioctl and not
74936 + bind/connect, so we'll fake a bind learn log */
74937 + if (type == SOCK_RAW || type == SOCK_PACKET) {
74938 + __u32 fakeip = 0;
74939 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74940 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74941 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74942 + gr_to_filename(current->exec_file->f_path.dentry,
74943 + current->exec_file->f_path.mnt) :
74944 + curr->filename, curr->filename,
74945 + &fakeip, 0, type,
74946 + protocol, GR_CONNECT, &current->signal->saved_ip);
74947 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
74948 + __u32 fakeip = 0;
74949 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
74950 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
74951 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
74952 + gr_to_filename(current->exec_file->f_path.dentry,
74953 + current->exec_file->f_path.mnt) :
74954 + curr->filename, curr->filename,
74955 + &fakeip, 0, type,
74956 + protocol, GR_BIND, &current->signal->saved_ip);
74957 + }
74958 + /* we'll log when they use connect or bind */
74959 + goto exit;
74960 + }
74961 +
74962 +exit_fail:
74963 + if (domain == PF_INET)
74964 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
74965 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
74966 + else if (rcu_access_pointer(net_families[domain]) != NULL)
74967 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
74968 + gr_socktype_to_name(type), protocol);
74969 +
74970 + return 0;
74971 +exit:
74972 + return 1;
74973 +}
74974 +
74975 +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)
74976 +{
74977 + if ((ip->mode & mode) &&
74978 + (ip_port >= ip->low) &&
74979 + (ip_port <= ip->high) &&
74980 + ((ntohl(ip_addr) & our_netmask) ==
74981 + (ntohl(our_addr) & our_netmask))
74982 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
74983 + && (ip->type & (1U << type))) {
74984 + if (ip->mode & GR_INVERT)
74985 + return 2; // specifically denied
74986 + else
74987 + return 1; // allowed
74988 + }
74989 +
74990 + return 0; // not specifically allowed, may continue parsing
74991 +}
74992 +
74993 +static int
74994 +gr_search_connectbind(const int full_mode, struct sock *sk,
74995 + struct sockaddr_in *addr, const int type)
74996 +{
74997 + char iface[IFNAMSIZ] = {0};
74998 + struct acl_subject_label *curr;
74999 + struct acl_ip_label *ip;
75000 + struct inet_sock *isk;
75001 + struct net_device *dev;
75002 + struct in_device *idev;
75003 + unsigned long i;
75004 + int ret;
75005 + int mode = full_mode & (GR_BIND | GR_CONNECT);
75006 + __u32 ip_addr = 0;
75007 + __u32 our_addr;
75008 + __u32 our_netmask;
75009 + char *p;
75010 + __u16 ip_port = 0;
75011 + const struct cred *cred = current_cred();
75012 +
75013 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
75014 + return 0;
75015 +
75016 + curr = current->acl;
75017 + isk = inet_sk(sk);
75018 +
75019 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
75020 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
75021 + addr->sin_addr.s_addr = curr->inaddr_any_override;
75022 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
75023 + struct sockaddr_in saddr;
75024 + int err;
75025 +
75026 + saddr.sin_family = AF_INET;
75027 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
75028 + saddr.sin_port = isk->inet_sport;
75029 +
75030 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
75031 + if (err)
75032 + return err;
75033 +
75034 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
75035 + if (err)
75036 + return err;
75037 + }
75038 +
75039 + if (!curr->ips)
75040 + return 0;
75041 +
75042 + ip_addr = addr->sin_addr.s_addr;
75043 + ip_port = ntohs(addr->sin_port);
75044 +
75045 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
75046 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
75047 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
75048 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
75049 + gr_to_filename(current->exec_file->f_path.dentry,
75050 + current->exec_file->f_path.mnt) :
75051 + curr->filename, curr->filename,
75052 + &ip_addr, ip_port, type,
75053 + sk->sk_protocol, mode, &current->signal->saved_ip);
75054 + return 0;
75055 + }
75056 +
75057 + for (i = 0; i < curr->ip_num; i++) {
75058 + ip = *(curr->ips + i);
75059 + if (ip->iface != NULL) {
75060 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
75061 + p = strchr(iface, ':');
75062 + if (p != NULL)
75063 + *p = '\0';
75064 + dev = dev_get_by_name(sock_net(sk), iface);
75065 + if (dev == NULL)
75066 + continue;
75067 + idev = in_dev_get(dev);
75068 + if (idev == NULL) {
75069 + dev_put(dev);
75070 + continue;
75071 + }
75072 + rcu_read_lock();
75073 + for_ifa(idev) {
75074 + if (!strcmp(ip->iface, ifa->ifa_label)) {
75075 + our_addr = ifa->ifa_address;
75076 + our_netmask = 0xffffffff;
75077 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
75078 + if (ret == 1) {
75079 + rcu_read_unlock();
75080 + in_dev_put(idev);
75081 + dev_put(dev);
75082 + return 0;
75083 + } else if (ret == 2) {
75084 + rcu_read_unlock();
75085 + in_dev_put(idev);
75086 + dev_put(dev);
75087 + goto denied;
75088 + }
75089 + }
75090 + } endfor_ifa(idev);
75091 + rcu_read_unlock();
75092 + in_dev_put(idev);
75093 + dev_put(dev);
75094 + } else {
75095 + our_addr = ip->addr;
75096 + our_netmask = ip->netmask;
75097 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
75098 + if (ret == 1)
75099 + return 0;
75100 + else if (ret == 2)
75101 + goto denied;
75102 + }
75103 + }
75104 +
75105 +denied:
75106 + if (mode == GR_BIND)
75107 + 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));
75108 + else if (mode == GR_CONNECT)
75109 + 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));
75110 +
75111 + return -EACCES;
75112 +}
75113 +
75114 +int
75115 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
75116 +{
75117 + /* always allow disconnection of dgram sockets with connect */
75118 + if (addr->sin_family == AF_UNSPEC)
75119 + return 0;
75120 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
75121 +}
75122 +
75123 +int
75124 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
75125 +{
75126 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
75127 +}
75128 +
75129 +int gr_search_listen(struct socket *sock)
75130 +{
75131 + struct sock *sk = sock->sk;
75132 + struct sockaddr_in addr;
75133 +
75134 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
75135 + addr.sin_port = inet_sk(sk)->inet_sport;
75136 +
75137 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
75138 +}
75139 +
75140 +int gr_search_accept(struct socket *sock)
75141 +{
75142 + struct sock *sk = sock->sk;
75143 + struct sockaddr_in addr;
75144 +
75145 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
75146 + addr.sin_port = inet_sk(sk)->inet_sport;
75147 +
75148 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
75149 +}
75150 +
75151 +int
75152 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
75153 +{
75154 + if (addr)
75155 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
75156 + else {
75157 + struct sockaddr_in sin;
75158 + const struct inet_sock *inet = inet_sk(sk);
75159 +
75160 + sin.sin_addr.s_addr = inet->inet_daddr;
75161 + sin.sin_port = inet->inet_dport;
75162 +
75163 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
75164 + }
75165 +}
75166 +
75167 +int
75168 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
75169 +{
75170 + struct sockaddr_in sin;
75171 +
75172 + if (unlikely(skb->len < sizeof (struct udphdr)))
75173 + return 0; // skip this packet
75174 +
75175 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
75176 + sin.sin_port = udp_hdr(skb)->source;
75177 +
75178 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
75179 +}
75180 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
75181 new file mode 100644
75182 index 0000000..25f54ef
75183 --- /dev/null
75184 +++ b/grsecurity/gracl_learn.c
75185 @@ -0,0 +1,207 @@
75186 +#include <linux/kernel.h>
75187 +#include <linux/mm.h>
75188 +#include <linux/sched.h>
75189 +#include <linux/poll.h>
75190 +#include <linux/string.h>
75191 +#include <linux/file.h>
75192 +#include <linux/types.h>
75193 +#include <linux/vmalloc.h>
75194 +#include <linux/grinternal.h>
75195 +
75196 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
75197 + size_t count, loff_t *ppos);
75198 +extern int gr_acl_is_enabled(void);
75199 +
75200 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
75201 +static int gr_learn_attached;
75202 +
75203 +/* use a 512k buffer */
75204 +#define LEARN_BUFFER_SIZE (512 * 1024)
75205 +
75206 +static DEFINE_SPINLOCK(gr_learn_lock);
75207 +static DEFINE_MUTEX(gr_learn_user_mutex);
75208 +
75209 +/* we need to maintain two buffers, so that the kernel context of grlearn
75210 + uses a semaphore around the userspace copying, and the other kernel contexts
75211 + use a spinlock when copying into the buffer, since they cannot sleep
75212 +*/
75213 +static char *learn_buffer;
75214 +static char *learn_buffer_user;
75215 +static int learn_buffer_len;
75216 +static int learn_buffer_user_len;
75217 +
75218 +static ssize_t
75219 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
75220 +{
75221 + DECLARE_WAITQUEUE(wait, current);
75222 + ssize_t retval = 0;
75223 +
75224 + add_wait_queue(&learn_wait, &wait);
75225 + set_current_state(TASK_INTERRUPTIBLE);
75226 + do {
75227 + mutex_lock(&gr_learn_user_mutex);
75228 + spin_lock(&gr_learn_lock);
75229 + if (learn_buffer_len)
75230 + break;
75231 + spin_unlock(&gr_learn_lock);
75232 + mutex_unlock(&gr_learn_user_mutex);
75233 + if (file->f_flags & O_NONBLOCK) {
75234 + retval = -EAGAIN;
75235 + goto out;
75236 + }
75237 + if (signal_pending(current)) {
75238 + retval = -ERESTARTSYS;
75239 + goto out;
75240 + }
75241 +
75242 + schedule();
75243 + } while (1);
75244 +
75245 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
75246 + learn_buffer_user_len = learn_buffer_len;
75247 + retval = learn_buffer_len;
75248 + learn_buffer_len = 0;
75249 +
75250 + spin_unlock(&gr_learn_lock);
75251 +
75252 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
75253 + retval = -EFAULT;
75254 +
75255 + mutex_unlock(&gr_learn_user_mutex);
75256 +out:
75257 + set_current_state(TASK_RUNNING);
75258 + remove_wait_queue(&learn_wait, &wait);
75259 + return retval;
75260 +}
75261 +
75262 +static unsigned int
75263 +poll_learn(struct file * file, poll_table * wait)
75264 +{
75265 + poll_wait(file, &learn_wait, wait);
75266 +
75267 + if (learn_buffer_len)
75268 + return (POLLIN | POLLRDNORM);
75269 +
75270 + return 0;
75271 +}
75272 +
75273 +void
75274 +gr_clear_learn_entries(void)
75275 +{
75276 + char *tmp;
75277 +
75278 + mutex_lock(&gr_learn_user_mutex);
75279 + spin_lock(&gr_learn_lock);
75280 + tmp = learn_buffer;
75281 + learn_buffer = NULL;
75282 + spin_unlock(&gr_learn_lock);
75283 + if (tmp)
75284 + vfree(tmp);
75285 + if (learn_buffer_user != NULL) {
75286 + vfree(learn_buffer_user);
75287 + learn_buffer_user = NULL;
75288 + }
75289 + learn_buffer_len = 0;
75290 + mutex_unlock(&gr_learn_user_mutex);
75291 +
75292 + return;
75293 +}
75294 +
75295 +void
75296 +gr_add_learn_entry(const char *fmt, ...)
75297 +{
75298 + va_list args;
75299 + unsigned int len;
75300 +
75301 + if (!gr_learn_attached)
75302 + return;
75303 +
75304 + spin_lock(&gr_learn_lock);
75305 +
75306 + /* leave a gap at the end so we know when it's "full" but don't have to
75307 + compute the exact length of the string we're trying to append
75308 + */
75309 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
75310 + spin_unlock(&gr_learn_lock);
75311 + wake_up_interruptible(&learn_wait);
75312 + return;
75313 + }
75314 + if (learn_buffer == NULL) {
75315 + spin_unlock(&gr_learn_lock);
75316 + return;
75317 + }
75318 +
75319 + va_start(args, fmt);
75320 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
75321 + va_end(args);
75322 +
75323 + learn_buffer_len += len + 1;
75324 +
75325 + spin_unlock(&gr_learn_lock);
75326 + wake_up_interruptible(&learn_wait);
75327 +
75328 + return;
75329 +}
75330 +
75331 +static int
75332 +open_learn(struct inode *inode, struct file *file)
75333 +{
75334 + if (file->f_mode & FMODE_READ && gr_learn_attached)
75335 + return -EBUSY;
75336 + if (file->f_mode & FMODE_READ) {
75337 + int retval = 0;
75338 + mutex_lock(&gr_learn_user_mutex);
75339 + if (learn_buffer == NULL)
75340 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
75341 + if (learn_buffer_user == NULL)
75342 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
75343 + if (learn_buffer == NULL) {
75344 + retval = -ENOMEM;
75345 + goto out_error;
75346 + }
75347 + if (learn_buffer_user == NULL) {
75348 + retval = -ENOMEM;
75349 + goto out_error;
75350 + }
75351 + learn_buffer_len = 0;
75352 + learn_buffer_user_len = 0;
75353 + gr_learn_attached = 1;
75354 +out_error:
75355 + mutex_unlock(&gr_learn_user_mutex);
75356 + return retval;
75357 + }
75358 + return 0;
75359 +}
75360 +
75361 +static int
75362 +close_learn(struct inode *inode, struct file *file)
75363 +{
75364 + if (file->f_mode & FMODE_READ) {
75365 + char *tmp = NULL;
75366 + mutex_lock(&gr_learn_user_mutex);
75367 + spin_lock(&gr_learn_lock);
75368 + tmp = learn_buffer;
75369 + learn_buffer = NULL;
75370 + spin_unlock(&gr_learn_lock);
75371 + if (tmp)
75372 + vfree(tmp);
75373 + if (learn_buffer_user != NULL) {
75374 + vfree(learn_buffer_user);
75375 + learn_buffer_user = NULL;
75376 + }
75377 + learn_buffer_len = 0;
75378 + learn_buffer_user_len = 0;
75379 + gr_learn_attached = 0;
75380 + mutex_unlock(&gr_learn_user_mutex);
75381 + }
75382 +
75383 + return 0;
75384 +}
75385 +
75386 +const struct file_operations grsec_fops = {
75387 + .read = read_learn,
75388 + .write = write_grsec_handler,
75389 + .open = open_learn,
75390 + .release = close_learn,
75391 + .poll = poll_learn,
75392 +};
75393 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
75394 new file mode 100644
75395 index 0000000..3f8ade0
75396 --- /dev/null
75397 +++ b/grsecurity/gracl_policy.c
75398 @@ -0,0 +1,1782 @@
75399 +#include <linux/kernel.h>
75400 +#include <linux/module.h>
75401 +#include <linux/sched.h>
75402 +#include <linux/mm.h>
75403 +#include <linux/file.h>
75404 +#include <linux/fs.h>
75405 +#include <linux/namei.h>
75406 +#include <linux/mount.h>
75407 +#include <linux/tty.h>
75408 +#include <linux/proc_fs.h>
75409 +#include <linux/lglock.h>
75410 +#include <linux/slab.h>
75411 +#include <linux/vmalloc.h>
75412 +#include <linux/types.h>
75413 +#include <linux/sysctl.h>
75414 +#include <linux/netdevice.h>
75415 +#include <linux/ptrace.h>
75416 +#include <linux/gracl.h>
75417 +#include <linux/gralloc.h>
75418 +#include <linux/security.h>
75419 +#include <linux/grinternal.h>
75420 +#include <linux/pid_namespace.h>
75421 +#include <linux/stop_machine.h>
75422 +#include <linux/fdtable.h>
75423 +#include <linux/percpu.h>
75424 +#include <linux/lglock.h>
75425 +#include <linux/hugetlb.h>
75426 +#include <linux/posix-timers.h>
75427 +#include "../fs/mount.h"
75428 +
75429 +#include <asm/uaccess.h>
75430 +#include <asm/errno.h>
75431 +#include <asm/mman.h>
75432 +
75433 +extern struct gr_policy_state *polstate;
75434 +
75435 +#define FOR_EACH_ROLE_START(role) \
75436 + role = polstate->role_list; \
75437 + while (role) {
75438 +
75439 +#define FOR_EACH_ROLE_END(role) \
75440 + role = role->prev; \
75441 + }
75442 +
75443 +struct path gr_real_root;
75444 +
75445 +extern struct gr_alloc_state *current_alloc_state;
75446 +
75447 +u16 acl_sp_role_value;
75448 +
75449 +static DEFINE_MUTEX(gr_dev_mutex);
75450 +
75451 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
75452 +extern void gr_clear_learn_entries(void);
75453 +
75454 +struct gr_arg *gr_usermode __read_only;
75455 +unsigned char *gr_system_salt __read_only;
75456 +unsigned char *gr_system_sum __read_only;
75457 +
75458 +static unsigned int gr_auth_attempts = 0;
75459 +static unsigned long gr_auth_expires = 0UL;
75460 +
75461 +struct acl_object_label *fakefs_obj_rw;
75462 +struct acl_object_label *fakefs_obj_rwx;
75463 +
75464 +extern int gr_init_uidset(void);
75465 +extern void gr_free_uidset(void);
75466 +extern void gr_remove_uid(uid_t uid);
75467 +extern int gr_find_uid(uid_t uid);
75468 +
75469 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
75470 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
75471 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
75472 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
75473 +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);
75474 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
75475 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
75476 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
75477 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
75478 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
75479 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
75480 +extern void assign_special_role(const char *rolename);
75481 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
75482 +extern int gr_rbac_disable(void *unused);
75483 +extern void gr_enable_rbac_system(void);
75484 +
75485 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
75486 +{
75487 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
75488 + return -EFAULT;
75489 +
75490 + return 0;
75491 +}
75492 +
75493 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
75494 +{
75495 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
75496 + return -EFAULT;
75497 +
75498 + return 0;
75499 +}
75500 +
75501 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
75502 +{
75503 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
75504 + return -EFAULT;
75505 +
75506 + return 0;
75507 +}
75508 +
75509 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
75510 +{
75511 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
75512 + return -EFAULT;
75513 +
75514 + return 0;
75515 +}
75516 +
75517 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
75518 +{
75519 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
75520 + return -EFAULT;
75521 +
75522 + return 0;
75523 +}
75524 +
75525 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
75526 +{
75527 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
75528 + return -EFAULT;
75529 +
75530 + return 0;
75531 +}
75532 +
75533 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
75534 +{
75535 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
75536 + return -EFAULT;
75537 +
75538 + return 0;
75539 +}
75540 +
75541 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
75542 +{
75543 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
75544 + return -EFAULT;
75545 +
75546 + return 0;
75547 +}
75548 +
75549 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
75550 +{
75551 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
75552 + return -EFAULT;
75553 +
75554 + return 0;
75555 +}
75556 +
75557 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
75558 +{
75559 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
75560 + return -EFAULT;
75561 +
75562 + if (((uwrap->version != GRSECURITY_VERSION) &&
75563 + (uwrap->version != 0x2901)) ||
75564 + (uwrap->size != sizeof(struct gr_arg)))
75565 + return -EINVAL;
75566 +
75567 + return 0;
75568 +}
75569 +
75570 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
75571 +{
75572 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
75573 + return -EFAULT;
75574 +
75575 + return 0;
75576 +}
75577 +
75578 +static size_t get_gr_arg_wrapper_size_normal(void)
75579 +{
75580 + return sizeof(struct gr_arg_wrapper);
75581 +}
75582 +
75583 +#ifdef CONFIG_COMPAT
75584 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
75585 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
75586 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
75587 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
75588 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
75589 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
75590 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
75591 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
75592 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
75593 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
75594 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
75595 +extern size_t get_gr_arg_wrapper_size_compat(void);
75596 +
75597 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
75598 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
75599 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
75600 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
75601 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
75602 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
75603 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
75604 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
75605 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
75606 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
75607 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
75608 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
75609 +
75610 +#else
75611 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
75612 +#define copy_gr_arg copy_gr_arg_normal
75613 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
75614 +#define copy_acl_object_label copy_acl_object_label_normal
75615 +#define copy_acl_subject_label copy_acl_subject_label_normal
75616 +#define copy_acl_role_label copy_acl_role_label_normal
75617 +#define copy_acl_ip_label copy_acl_ip_label_normal
75618 +#define copy_pointer_from_array copy_pointer_from_array_normal
75619 +#define copy_sprole_pw copy_sprole_pw_normal
75620 +#define copy_role_transition copy_role_transition_normal
75621 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
75622 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
75623 +#endif
75624 +
75625 +static struct acl_subject_label *
75626 +lookup_subject_map(const struct acl_subject_label *userp)
75627 +{
75628 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
75629 + struct subject_map *match;
75630 +
75631 + match = polstate->subj_map_set.s_hash[index];
75632 +
75633 + while (match && match->user != userp)
75634 + match = match->next;
75635 +
75636 + if (match != NULL)
75637 + return match->kernel;
75638 + else
75639 + return NULL;
75640 +}
75641 +
75642 +static void
75643 +insert_subj_map_entry(struct subject_map *subjmap)
75644 +{
75645 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
75646 + struct subject_map **curr;
75647 +
75648 + subjmap->prev = NULL;
75649 +
75650 + curr = &polstate->subj_map_set.s_hash[index];
75651 + if (*curr != NULL)
75652 + (*curr)->prev = subjmap;
75653 +
75654 + subjmap->next = *curr;
75655 + *curr = subjmap;
75656 +
75657 + return;
75658 +}
75659 +
75660 +static void
75661 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
75662 +{
75663 + unsigned int index =
75664 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
75665 + struct acl_role_label **curr;
75666 + struct acl_role_label *tmp, *tmp2;
75667 +
75668 + curr = &polstate->acl_role_set.r_hash[index];
75669 +
75670 + /* simple case, slot is empty, just set it to our role */
75671 + if (*curr == NULL) {
75672 + *curr = role;
75673 + } else {
75674 + /* example:
75675 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
75676 + 2 -> 3
75677 + */
75678 + /* first check to see if we can already be reached via this slot */
75679 + tmp = *curr;
75680 + while (tmp && tmp != role)
75681 + tmp = tmp->next;
75682 + if (tmp == role) {
75683 + /* we don't need to add ourselves to this slot's chain */
75684 + return;
75685 + }
75686 + /* we need to add ourselves to this chain, two cases */
75687 + if (role->next == NULL) {
75688 + /* simple case, append the current chain to our role */
75689 + role->next = *curr;
75690 + *curr = role;
75691 + } else {
75692 + /* 1 -> 2 -> 3 -> 4
75693 + 2 -> 3 -> 4
75694 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
75695 + */
75696 + /* trickier case: walk our role's chain until we find
75697 + the role for the start of the current slot's chain */
75698 + tmp = role;
75699 + tmp2 = *curr;
75700 + while (tmp->next && tmp->next != tmp2)
75701 + tmp = tmp->next;
75702 + if (tmp->next == tmp2) {
75703 + /* from example above, we found 3, so just
75704 + replace this slot's chain with ours */
75705 + *curr = role;
75706 + } else {
75707 + /* we didn't find a subset of our role's chain
75708 + in the current slot's chain, so append their
75709 + chain to ours, and set us as the first role in
75710 + the slot's chain
75711 +
75712 + we could fold this case with the case above,
75713 + but making it explicit for clarity
75714 + */
75715 + tmp->next = tmp2;
75716 + *curr = role;
75717 + }
75718 + }
75719 + }
75720 +
75721 + return;
75722 +}
75723 +
75724 +static void
75725 +insert_acl_role_label(struct acl_role_label *role)
75726 +{
75727 + int i;
75728 +
75729 + if (polstate->role_list == NULL) {
75730 + polstate->role_list = role;
75731 + role->prev = NULL;
75732 + } else {
75733 + role->prev = polstate->role_list;
75734 + polstate->role_list = role;
75735 + }
75736 +
75737 + /* used for hash chains */
75738 + role->next = NULL;
75739 +
75740 + if (role->roletype & GR_ROLE_DOMAIN) {
75741 + for (i = 0; i < role->domain_child_num; i++)
75742 + __insert_acl_role_label(role, role->domain_children[i]);
75743 + } else
75744 + __insert_acl_role_label(role, role->uidgid);
75745 +}
75746 +
75747 +static int
75748 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
75749 +{
75750 + struct name_entry **curr, *nentry;
75751 + struct inodev_entry *ientry;
75752 + unsigned int len = strlen(name);
75753 + unsigned int key = full_name_hash(name, len);
75754 + unsigned int index = key % polstate->name_set.n_size;
75755 +
75756 + curr = &polstate->name_set.n_hash[index];
75757 +
75758 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
75759 + curr = &((*curr)->next);
75760 +
75761 + if (*curr != NULL)
75762 + return 1;
75763 +
75764 + nentry = acl_alloc(sizeof (struct name_entry));
75765 + if (nentry == NULL)
75766 + return 0;
75767 + ientry = acl_alloc(sizeof (struct inodev_entry));
75768 + if (ientry == NULL)
75769 + return 0;
75770 + ientry->nentry = nentry;
75771 +
75772 + nentry->key = key;
75773 + nentry->name = name;
75774 + nentry->inode = inode;
75775 + nentry->device = device;
75776 + nentry->len = len;
75777 + nentry->deleted = deleted;
75778 +
75779 + nentry->prev = NULL;
75780 + curr = &polstate->name_set.n_hash[index];
75781 + if (*curr != NULL)
75782 + (*curr)->prev = nentry;
75783 + nentry->next = *curr;
75784 + *curr = nentry;
75785 +
75786 + /* insert us into the table searchable by inode/dev */
75787 + __insert_inodev_entry(polstate, ientry);
75788 +
75789 + return 1;
75790 +}
75791 +
75792 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
75793 +
75794 +static void *
75795 +create_table(__u32 * len, int elementsize)
75796 +{
75797 + unsigned int table_sizes[] = {
75798 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
75799 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
75800 + 4194301, 8388593, 16777213, 33554393, 67108859
75801 + };
75802 + void *newtable = NULL;
75803 + unsigned int pwr = 0;
75804 +
75805 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
75806 + table_sizes[pwr] <= *len)
75807 + pwr++;
75808 +
75809 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
75810 + return newtable;
75811 +
75812 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
75813 + newtable =
75814 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
75815 + else
75816 + newtable = vmalloc(table_sizes[pwr] * elementsize);
75817 +
75818 + *len = table_sizes[pwr];
75819 +
75820 + return newtable;
75821 +}
75822 +
75823 +static int
75824 +init_variables(const struct gr_arg *arg, bool reload)
75825 +{
75826 + struct task_struct *reaper = init_pid_ns.child_reaper;
75827 + unsigned int stacksize;
75828 +
75829 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
75830 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
75831 + polstate->name_set.n_size = arg->role_db.num_objects;
75832 + polstate->inodev_set.i_size = arg->role_db.num_objects;
75833 +
75834 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
75835 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
75836 + return 1;
75837 +
75838 + if (!reload) {
75839 + if (!gr_init_uidset())
75840 + return 1;
75841 + }
75842 +
75843 + /* set up the stack that holds allocation info */
75844 +
75845 + stacksize = arg->role_db.num_pointers + 5;
75846 +
75847 + if (!acl_alloc_stack_init(stacksize))
75848 + return 1;
75849 +
75850 + if (!reload) {
75851 + /* grab reference for the real root dentry and vfsmount */
75852 + get_fs_root(reaper->fs, &gr_real_root);
75853 +
75854 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75855 + 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);
75856 +#endif
75857 +
75858 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75859 + if (fakefs_obj_rw == NULL)
75860 + return 1;
75861 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
75862 +
75863 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
75864 + if (fakefs_obj_rwx == NULL)
75865 + return 1;
75866 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
75867 + }
75868 +
75869 + polstate->subj_map_set.s_hash =
75870 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
75871 + polstate->acl_role_set.r_hash =
75872 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
75873 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
75874 + polstate->inodev_set.i_hash =
75875 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
75876 +
75877 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
75878 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
75879 + return 1;
75880 +
75881 + memset(polstate->subj_map_set.s_hash, 0,
75882 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
75883 + memset(polstate->acl_role_set.r_hash, 0,
75884 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
75885 + memset(polstate->name_set.n_hash, 0,
75886 + sizeof (struct name_entry *) * polstate->name_set.n_size);
75887 + memset(polstate->inodev_set.i_hash, 0,
75888 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
75889 +
75890 + return 0;
75891 +}
75892 +
75893 +/* free information not needed after startup
75894 + currently contains user->kernel pointer mappings for subjects
75895 +*/
75896 +
75897 +static void
75898 +free_init_variables(void)
75899 +{
75900 + __u32 i;
75901 +
75902 + if (polstate->subj_map_set.s_hash) {
75903 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
75904 + if (polstate->subj_map_set.s_hash[i]) {
75905 + kfree(polstate->subj_map_set.s_hash[i]);
75906 + polstate->subj_map_set.s_hash[i] = NULL;
75907 + }
75908 + }
75909 +
75910 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
75911 + PAGE_SIZE)
75912 + kfree(polstate->subj_map_set.s_hash);
75913 + else
75914 + vfree(polstate->subj_map_set.s_hash);
75915 + }
75916 +
75917 + return;
75918 +}
75919 +
75920 +static void
75921 +free_variables(bool reload)
75922 +{
75923 + struct acl_subject_label *s;
75924 + struct acl_role_label *r;
75925 + struct task_struct *task, *task2;
75926 + unsigned int x;
75927 +
75928 + if (!reload) {
75929 + gr_clear_learn_entries();
75930 +
75931 + read_lock(&tasklist_lock);
75932 + do_each_thread(task2, task) {
75933 + task->acl_sp_role = 0;
75934 + task->acl_role_id = 0;
75935 + task->inherited = 0;
75936 + task->acl = NULL;
75937 + task->role = NULL;
75938 + } while_each_thread(task2, task);
75939 + read_unlock(&tasklist_lock);
75940 +
75941 + kfree(fakefs_obj_rw);
75942 + fakefs_obj_rw = NULL;
75943 + kfree(fakefs_obj_rwx);
75944 + fakefs_obj_rwx = NULL;
75945 +
75946 + /* release the reference to the real root dentry and vfsmount */
75947 + path_put(&gr_real_root);
75948 + memset(&gr_real_root, 0, sizeof(gr_real_root));
75949 + }
75950 +
75951 + /* free all object hash tables */
75952 +
75953 + FOR_EACH_ROLE_START(r)
75954 + if (r->subj_hash == NULL)
75955 + goto next_role;
75956 + FOR_EACH_SUBJECT_START(r, s, x)
75957 + if (s->obj_hash == NULL)
75958 + break;
75959 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75960 + kfree(s->obj_hash);
75961 + else
75962 + vfree(s->obj_hash);
75963 + FOR_EACH_SUBJECT_END(s, x)
75964 + FOR_EACH_NESTED_SUBJECT_START(r, s)
75965 + if (s->obj_hash == NULL)
75966 + break;
75967 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
75968 + kfree(s->obj_hash);
75969 + else
75970 + vfree(s->obj_hash);
75971 + FOR_EACH_NESTED_SUBJECT_END(s)
75972 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
75973 + kfree(r->subj_hash);
75974 + else
75975 + vfree(r->subj_hash);
75976 + r->subj_hash = NULL;
75977 +next_role:
75978 + FOR_EACH_ROLE_END(r)
75979 +
75980 + acl_free_all();
75981 +
75982 + if (polstate->acl_role_set.r_hash) {
75983 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
75984 + PAGE_SIZE)
75985 + kfree(polstate->acl_role_set.r_hash);
75986 + else
75987 + vfree(polstate->acl_role_set.r_hash);
75988 + }
75989 + if (polstate->name_set.n_hash) {
75990 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
75991 + PAGE_SIZE)
75992 + kfree(polstate->name_set.n_hash);
75993 + else
75994 + vfree(polstate->name_set.n_hash);
75995 + }
75996 +
75997 + if (polstate->inodev_set.i_hash) {
75998 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
75999 + PAGE_SIZE)
76000 + kfree(polstate->inodev_set.i_hash);
76001 + else
76002 + vfree(polstate->inodev_set.i_hash);
76003 + }
76004 +
76005 + if (!reload)
76006 + gr_free_uidset();
76007 +
76008 + memset(&polstate->name_set, 0, sizeof (struct name_db));
76009 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
76010 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
76011 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
76012 +
76013 + polstate->default_role = NULL;
76014 + polstate->kernel_role = NULL;
76015 + polstate->role_list = NULL;
76016 +
76017 + return;
76018 +}
76019 +
76020 +static struct acl_subject_label *
76021 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
76022 +
76023 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
76024 +{
76025 + unsigned int len = strnlen_user(*name, maxlen);
76026 + char *tmp;
76027 +
76028 + if (!len || len >= maxlen)
76029 + return -EINVAL;
76030 +
76031 + if ((tmp = (char *) acl_alloc(len)) == NULL)
76032 + return -ENOMEM;
76033 +
76034 + if (copy_from_user(tmp, *name, len))
76035 + return -EFAULT;
76036 +
76037 + tmp[len-1] = '\0';
76038 + *name = tmp;
76039 +
76040 + return 0;
76041 +}
76042 +
76043 +static int
76044 +copy_user_glob(struct acl_object_label *obj)
76045 +{
76046 + struct acl_object_label *g_tmp, **guser;
76047 + int error;
76048 +
76049 + if (obj->globbed == NULL)
76050 + return 0;
76051 +
76052 + guser = &obj->globbed;
76053 + while (*guser) {
76054 + g_tmp = (struct acl_object_label *)
76055 + acl_alloc(sizeof (struct acl_object_label));
76056 + if (g_tmp == NULL)
76057 + return -ENOMEM;
76058 +
76059 + if (copy_acl_object_label(g_tmp, *guser))
76060 + return -EFAULT;
76061 +
76062 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
76063 + if (error)
76064 + return error;
76065 +
76066 + *guser = g_tmp;
76067 + guser = &(g_tmp->next);
76068 + }
76069 +
76070 + return 0;
76071 +}
76072 +
76073 +static int
76074 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
76075 + struct acl_role_label *role)
76076 +{
76077 + struct acl_object_label *o_tmp;
76078 + int ret;
76079 +
76080 + while (userp) {
76081 + if ((o_tmp = (struct acl_object_label *)
76082 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
76083 + return -ENOMEM;
76084 +
76085 + if (copy_acl_object_label(o_tmp, userp))
76086 + return -EFAULT;
76087 +
76088 + userp = o_tmp->prev;
76089 +
76090 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
76091 + if (ret)
76092 + return ret;
76093 +
76094 + insert_acl_obj_label(o_tmp, subj);
76095 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
76096 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
76097 + return -ENOMEM;
76098 +
76099 + ret = copy_user_glob(o_tmp);
76100 + if (ret)
76101 + return ret;
76102 +
76103 + if (o_tmp->nested) {
76104 + int already_copied;
76105 +
76106 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
76107 + if (IS_ERR(o_tmp->nested))
76108 + return PTR_ERR(o_tmp->nested);
76109 +
76110 + /* insert into nested subject list if we haven't copied this one yet
76111 + to prevent duplicate entries */
76112 + if (!already_copied) {
76113 + o_tmp->nested->next = role->hash->first;
76114 + role->hash->first = o_tmp->nested;
76115 + }
76116 + }
76117 + }
76118 +
76119 + return 0;
76120 +}
76121 +
76122 +static __u32
76123 +count_user_subjs(struct acl_subject_label *userp)
76124 +{
76125 + struct acl_subject_label s_tmp;
76126 + __u32 num = 0;
76127 +
76128 + while (userp) {
76129 + if (copy_acl_subject_label(&s_tmp, userp))
76130 + break;
76131 +
76132 + userp = s_tmp.prev;
76133 + }
76134 +
76135 + return num;
76136 +}
76137 +
76138 +static int
76139 +copy_user_allowedips(struct acl_role_label *rolep)
76140 +{
76141 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
76142 +
76143 + ruserip = rolep->allowed_ips;
76144 +
76145 + while (ruserip) {
76146 + rlast = rtmp;
76147 +
76148 + if ((rtmp = (struct role_allowed_ip *)
76149 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
76150 + return -ENOMEM;
76151 +
76152 + if (copy_role_allowed_ip(rtmp, ruserip))
76153 + return -EFAULT;
76154 +
76155 + ruserip = rtmp->prev;
76156 +
76157 + if (!rlast) {
76158 + rtmp->prev = NULL;
76159 + rolep->allowed_ips = rtmp;
76160 + } else {
76161 + rlast->next = rtmp;
76162 + rtmp->prev = rlast;
76163 + }
76164 +
76165 + if (!ruserip)
76166 + rtmp->next = NULL;
76167 + }
76168 +
76169 + return 0;
76170 +}
76171 +
76172 +static int
76173 +copy_user_transitions(struct acl_role_label *rolep)
76174 +{
76175 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
76176 + int error;
76177 +
76178 + rusertp = rolep->transitions;
76179 +
76180 + while (rusertp) {
76181 + rlast = rtmp;
76182 +
76183 + if ((rtmp = (struct role_transition *)
76184 + acl_alloc(sizeof (struct role_transition))) == NULL)
76185 + return -ENOMEM;
76186 +
76187 + if (copy_role_transition(rtmp, rusertp))
76188 + return -EFAULT;
76189 +
76190 + rusertp = rtmp->prev;
76191 +
76192 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
76193 + if (error)
76194 + return error;
76195 +
76196 + if (!rlast) {
76197 + rtmp->prev = NULL;
76198 + rolep->transitions = rtmp;
76199 + } else {
76200 + rlast->next = rtmp;
76201 + rtmp->prev = rlast;
76202 + }
76203 +
76204 + if (!rusertp)
76205 + rtmp->next = NULL;
76206 + }
76207 +
76208 + return 0;
76209 +}
76210 +
76211 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
76212 +{
76213 + struct acl_object_label o_tmp;
76214 + __u32 num = 0;
76215 +
76216 + while (userp) {
76217 + if (copy_acl_object_label(&o_tmp, userp))
76218 + break;
76219 +
76220 + userp = o_tmp.prev;
76221 + num++;
76222 + }
76223 +
76224 + return num;
76225 +}
76226 +
76227 +static struct acl_subject_label *
76228 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
76229 +{
76230 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
76231 + __u32 num_objs;
76232 + struct acl_ip_label **i_tmp, *i_utmp2;
76233 + struct gr_hash_struct ghash;
76234 + struct subject_map *subjmap;
76235 + unsigned int i_num;
76236 + int err;
76237 +
76238 + if (already_copied != NULL)
76239 + *already_copied = 0;
76240 +
76241 + s_tmp = lookup_subject_map(userp);
76242 +
76243 + /* we've already copied this subject into the kernel, just return
76244 + the reference to it, and don't copy it over again
76245 + */
76246 + if (s_tmp) {
76247 + if (already_copied != NULL)
76248 + *already_copied = 1;
76249 + return(s_tmp);
76250 + }
76251 +
76252 + if ((s_tmp = (struct acl_subject_label *)
76253 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
76254 + return ERR_PTR(-ENOMEM);
76255 +
76256 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
76257 + if (subjmap == NULL)
76258 + return ERR_PTR(-ENOMEM);
76259 +
76260 + subjmap->user = userp;
76261 + subjmap->kernel = s_tmp;
76262 + insert_subj_map_entry(subjmap);
76263 +
76264 + if (copy_acl_subject_label(s_tmp, userp))
76265 + return ERR_PTR(-EFAULT);
76266 +
76267 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
76268 + if (err)
76269 + return ERR_PTR(err);
76270 +
76271 + if (!strcmp(s_tmp->filename, "/"))
76272 + role->root_label = s_tmp;
76273 +
76274 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
76275 + return ERR_PTR(-EFAULT);
76276 +
76277 + /* copy user and group transition tables */
76278 +
76279 + if (s_tmp->user_trans_num) {
76280 + uid_t *uidlist;
76281 +
76282 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
76283 + if (uidlist == NULL)
76284 + return ERR_PTR(-ENOMEM);
76285 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
76286 + return ERR_PTR(-EFAULT);
76287 +
76288 + s_tmp->user_transitions = uidlist;
76289 + }
76290 +
76291 + if (s_tmp->group_trans_num) {
76292 + gid_t *gidlist;
76293 +
76294 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
76295 + if (gidlist == NULL)
76296 + return ERR_PTR(-ENOMEM);
76297 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
76298 + return ERR_PTR(-EFAULT);
76299 +
76300 + s_tmp->group_transitions = gidlist;
76301 + }
76302 +
76303 + /* set up object hash table */
76304 + num_objs = count_user_objs(ghash.first);
76305 +
76306 + s_tmp->obj_hash_size = num_objs;
76307 + s_tmp->obj_hash =
76308 + (struct acl_object_label **)
76309 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
76310 +
76311 + if (!s_tmp->obj_hash)
76312 + return ERR_PTR(-ENOMEM);
76313 +
76314 + memset(s_tmp->obj_hash, 0,
76315 + s_tmp->obj_hash_size *
76316 + sizeof (struct acl_object_label *));
76317 +
76318 + /* add in objects */
76319 + err = copy_user_objs(ghash.first, s_tmp, role);
76320 +
76321 + if (err)
76322 + return ERR_PTR(err);
76323 +
76324 + /* set pointer for parent subject */
76325 + if (s_tmp->parent_subject) {
76326 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
76327 +
76328 + if (IS_ERR(s_tmp2))
76329 + return s_tmp2;
76330 +
76331 + s_tmp->parent_subject = s_tmp2;
76332 + }
76333 +
76334 + /* add in ip acls */
76335 +
76336 + if (!s_tmp->ip_num) {
76337 + s_tmp->ips = NULL;
76338 + goto insert;
76339 + }
76340 +
76341 + i_tmp =
76342 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
76343 + sizeof (struct acl_ip_label *));
76344 +
76345 + if (!i_tmp)
76346 + return ERR_PTR(-ENOMEM);
76347 +
76348 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
76349 + *(i_tmp + i_num) =
76350 + (struct acl_ip_label *)
76351 + acl_alloc(sizeof (struct acl_ip_label));
76352 + if (!*(i_tmp + i_num))
76353 + return ERR_PTR(-ENOMEM);
76354 +
76355 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
76356 + return ERR_PTR(-EFAULT);
76357 +
76358 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
76359 + return ERR_PTR(-EFAULT);
76360 +
76361 + if ((*(i_tmp + i_num))->iface == NULL)
76362 + continue;
76363 +
76364 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
76365 + if (err)
76366 + return ERR_PTR(err);
76367 + }
76368 +
76369 + s_tmp->ips = i_tmp;
76370 +
76371 +insert:
76372 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
76373 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
76374 + return ERR_PTR(-ENOMEM);
76375 +
76376 + return s_tmp;
76377 +}
76378 +
76379 +static int
76380 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
76381 +{
76382 + struct acl_subject_label s_pre;
76383 + struct acl_subject_label * ret;
76384 + int err;
76385 +
76386 + while (userp) {
76387 + if (copy_acl_subject_label(&s_pre, userp))
76388 + return -EFAULT;
76389 +
76390 + ret = do_copy_user_subj(userp, role, NULL);
76391 +
76392 + err = PTR_ERR(ret);
76393 + if (IS_ERR(ret))
76394 + return err;
76395 +
76396 + insert_acl_subj_label(ret, role);
76397 +
76398 + userp = s_pre.prev;
76399 + }
76400 +
76401 + return 0;
76402 +}
76403 +
76404 +static int
76405 +copy_user_acl(struct gr_arg *arg)
76406 +{
76407 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
76408 + struct acl_subject_label *subj_list;
76409 + struct sprole_pw *sptmp;
76410 + struct gr_hash_struct *ghash;
76411 + uid_t *domainlist;
76412 + unsigned int r_num;
76413 + int err = 0;
76414 + __u16 i;
76415 + __u32 num_subjs;
76416 +
76417 + /* we need a default and kernel role */
76418 + if (arg->role_db.num_roles < 2)
76419 + return -EINVAL;
76420 +
76421 + /* copy special role authentication info from userspace */
76422 +
76423 + polstate->num_sprole_pws = arg->num_sprole_pws;
76424 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
76425 +
76426 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
76427 + return -ENOMEM;
76428 +
76429 + for (i = 0; i < polstate->num_sprole_pws; i++) {
76430 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
76431 + if (!sptmp)
76432 + return -ENOMEM;
76433 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
76434 + return -EFAULT;
76435 +
76436 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
76437 + if (err)
76438 + return err;
76439 +
76440 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
76441 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
76442 +#endif
76443 +
76444 + polstate->acl_special_roles[i] = sptmp;
76445 + }
76446 +
76447 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
76448 +
76449 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
76450 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
76451 +
76452 + if (!r_tmp)
76453 + return -ENOMEM;
76454 +
76455 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
76456 + return -EFAULT;
76457 +
76458 + if (copy_acl_role_label(r_tmp, r_utmp2))
76459 + return -EFAULT;
76460 +
76461 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
76462 + if (err)
76463 + return err;
76464 +
76465 + if (!strcmp(r_tmp->rolename, "default")
76466 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
76467 + polstate->default_role = r_tmp;
76468 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
76469 + polstate->kernel_role = r_tmp;
76470 + }
76471 +
76472 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
76473 + return -ENOMEM;
76474 +
76475 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
76476 + return -EFAULT;
76477 +
76478 + r_tmp->hash = ghash;
76479 +
76480 + num_subjs = count_user_subjs(r_tmp->hash->first);
76481 +
76482 + r_tmp->subj_hash_size = num_subjs;
76483 + r_tmp->subj_hash =
76484 + (struct acl_subject_label **)
76485 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
76486 +
76487 + if (!r_tmp->subj_hash)
76488 + return -ENOMEM;
76489 +
76490 + err = copy_user_allowedips(r_tmp);
76491 + if (err)
76492 + return err;
76493 +
76494 + /* copy domain info */
76495 + if (r_tmp->domain_children != NULL) {
76496 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
76497 + if (domainlist == NULL)
76498 + return -ENOMEM;
76499 +
76500 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
76501 + return -EFAULT;
76502 +
76503 + r_tmp->domain_children = domainlist;
76504 + }
76505 +
76506 + err = copy_user_transitions(r_tmp);
76507 + if (err)
76508 + return err;
76509 +
76510 + memset(r_tmp->subj_hash, 0,
76511 + r_tmp->subj_hash_size *
76512 + sizeof (struct acl_subject_label *));
76513 +
76514 + /* acquire the list of subjects, then NULL out
76515 + the list prior to parsing the subjects for this role,
76516 + as during this parsing the list is replaced with a list
76517 + of *nested* subjects for the role
76518 + */
76519 + subj_list = r_tmp->hash->first;
76520 +
76521 + /* set nested subject list to null */
76522 + r_tmp->hash->first = NULL;
76523 +
76524 + err = copy_user_subjs(subj_list, r_tmp);
76525 +
76526 + if (err)
76527 + return err;
76528 +
76529 + insert_acl_role_label(r_tmp);
76530 + }
76531 +
76532 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
76533 + return -EINVAL;
76534 +
76535 + return err;
76536 +}
76537 +
76538 +static int gracl_reload_apply_policies(void *reload)
76539 +{
76540 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
76541 + struct task_struct *task, *task2;
76542 + struct acl_role_label *role, *rtmp;
76543 + struct acl_subject_label *subj;
76544 + const struct cred *cred;
76545 + int role_applied;
76546 + int ret = 0;
76547 +
76548 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
76549 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
76550 +
76551 + /* first make sure we'll be able to apply the new policy cleanly */
76552 + do_each_thread(task2, task) {
76553 + if (task->exec_file == NULL)
76554 + continue;
76555 + role_applied = 0;
76556 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
76557 + /* preserve special roles */
76558 + FOR_EACH_ROLE_START(role)
76559 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
76560 + rtmp = task->role;
76561 + task->role = role;
76562 + role_applied = 1;
76563 + break;
76564 + }
76565 + FOR_EACH_ROLE_END(role)
76566 + }
76567 + if (!role_applied) {
76568 + cred = __task_cred(task);
76569 + rtmp = task->role;
76570 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
76571 + }
76572 + /* this handles non-nested inherited subjects, nested subjects will still
76573 + be dropped currently */
76574 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
76575 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
76576 + /* change the role back so that we've made no modifications to the policy */
76577 + task->role = rtmp;
76578 +
76579 + if (subj == NULL || task->tmpacl == NULL) {
76580 + ret = -EINVAL;
76581 + goto out;
76582 + }
76583 + } while_each_thread(task2, task);
76584 +
76585 + /* now actually apply the policy */
76586 +
76587 + do_each_thread(task2, task) {
76588 + if (task->exec_file) {
76589 + role_applied = 0;
76590 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
76591 + /* preserve special roles */
76592 + FOR_EACH_ROLE_START(role)
76593 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
76594 + task->role = role;
76595 + role_applied = 1;
76596 + break;
76597 + }
76598 + FOR_EACH_ROLE_END(role)
76599 + }
76600 + if (!role_applied) {
76601 + cred = __task_cred(task);
76602 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
76603 + }
76604 + /* this handles non-nested inherited subjects, nested subjects will still
76605 + be dropped currently */
76606 + if (!reload_state->oldmode && task->inherited)
76607 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
76608 + else {
76609 + /* looked up and tagged to the task previously */
76610 + subj = task->tmpacl;
76611 + }
76612 + /* subj will be non-null */
76613 + __gr_apply_subject_to_task(polstate, task, subj);
76614 + if (reload_state->oldmode) {
76615 + task->acl_role_id = 0;
76616 + task->acl_sp_role = 0;
76617 + task->inherited = 0;
76618 + }
76619 + } else {
76620 + // it's a kernel process
76621 + task->role = polstate->kernel_role;
76622 + task->acl = polstate->kernel_role->root_label;
76623 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
76624 + task->acl->mode &= ~GR_PROCFIND;
76625 +#endif
76626 + }
76627 + } while_each_thread(task2, task);
76628 +
76629 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
76630 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
76631 +
76632 +out:
76633 +
76634 + return ret;
76635 +}
76636 +
76637 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
76638 +{
76639 + struct gr_reload_state new_reload_state = { };
76640 + int err;
76641 +
76642 + new_reload_state.oldpolicy_ptr = polstate;
76643 + new_reload_state.oldalloc_ptr = current_alloc_state;
76644 + new_reload_state.oldmode = oldmode;
76645 +
76646 + current_alloc_state = &new_reload_state.newalloc;
76647 + polstate = &new_reload_state.newpolicy;
76648 +
76649 + /* everything relevant is now saved off, copy in the new policy */
76650 + if (init_variables(args, true)) {
76651 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
76652 + err = -ENOMEM;
76653 + goto error;
76654 + }
76655 +
76656 + err = copy_user_acl(args);
76657 + free_init_variables();
76658 + if (err)
76659 + goto error;
76660 + /* the new policy is copied in, with the old policy available via saved_state
76661 + first go through applying roles, making sure to preserve special roles
76662 + then apply new subjects, making sure to preserve inherited and nested subjects,
76663 + though currently only inherited subjects will be preserved
76664 + */
76665 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
76666 + if (err)
76667 + goto error;
76668 +
76669 + /* we've now applied the new policy, so restore the old policy state to free it */
76670 + polstate = &new_reload_state.oldpolicy;
76671 + current_alloc_state = &new_reload_state.oldalloc;
76672 + free_variables(true);
76673 +
76674 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
76675 + to running_polstate/current_alloc_state inside stop_machine
76676 + */
76677 + err = 0;
76678 + goto out;
76679 +error:
76680 + /* on error of loading the new policy, we'll just keep the previous
76681 + policy set around
76682 + */
76683 + free_variables(true);
76684 +
76685 + /* doesn't affect runtime, but maintains consistent state */
76686 +out:
76687 + polstate = new_reload_state.oldpolicy_ptr;
76688 + current_alloc_state = new_reload_state.oldalloc_ptr;
76689 +
76690 + return err;
76691 +}
76692 +
76693 +static int
76694 +gracl_init(struct gr_arg *args)
76695 +{
76696 + int error = 0;
76697 +
76698 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
76699 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
76700 +
76701 + if (init_variables(args, false)) {
76702 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
76703 + error = -ENOMEM;
76704 + goto out;
76705 + }
76706 +
76707 + error = copy_user_acl(args);
76708 + free_init_variables();
76709 + if (error)
76710 + goto out;
76711 +
76712 + error = gr_set_acls(0);
76713 + if (error)
76714 + goto out;
76715 +
76716 + gr_enable_rbac_system();
76717 +
76718 + return 0;
76719 +
76720 +out:
76721 + free_variables(false);
76722 + return error;
76723 +}
76724 +
76725 +static int
76726 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
76727 + unsigned char **sum)
76728 +{
76729 + struct acl_role_label *r;
76730 + struct role_allowed_ip *ipp;
76731 + struct role_transition *trans;
76732 + unsigned int i;
76733 + int found = 0;
76734 + u32 curr_ip = current->signal->curr_ip;
76735 +
76736 + current->signal->saved_ip = curr_ip;
76737 +
76738 + /* check transition table */
76739 +
76740 + for (trans = current->role->transitions; trans; trans = trans->next) {
76741 + if (!strcmp(rolename, trans->rolename)) {
76742 + found = 1;
76743 + break;
76744 + }
76745 + }
76746 +
76747 + if (!found)
76748 + return 0;
76749 +
76750 + /* handle special roles that do not require authentication
76751 + and check ip */
76752 +
76753 + FOR_EACH_ROLE_START(r)
76754 + if (!strcmp(rolename, r->rolename) &&
76755 + (r->roletype & GR_ROLE_SPECIAL)) {
76756 + found = 0;
76757 + if (r->allowed_ips != NULL) {
76758 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
76759 + if ((ntohl(curr_ip) & ipp->netmask) ==
76760 + (ntohl(ipp->addr) & ipp->netmask))
76761 + found = 1;
76762 + }
76763 + } else
76764 + found = 2;
76765 + if (!found)
76766 + return 0;
76767 +
76768 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
76769 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
76770 + *salt = NULL;
76771 + *sum = NULL;
76772 + return 1;
76773 + }
76774 + }
76775 + FOR_EACH_ROLE_END(r)
76776 +
76777 + for (i = 0; i < polstate->num_sprole_pws; i++) {
76778 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
76779 + *salt = polstate->acl_special_roles[i]->salt;
76780 + *sum = polstate->acl_special_roles[i]->sum;
76781 + return 1;
76782 + }
76783 + }
76784 +
76785 + return 0;
76786 +}
76787 +
76788 +int gr_check_secure_terminal(struct task_struct *task)
76789 +{
76790 + struct task_struct *p, *p2, *p3;
76791 + struct files_struct *files;
76792 + struct fdtable *fdt;
76793 + struct file *our_file = NULL, *file;
76794 + int i;
76795 +
76796 + if (task->signal->tty == NULL)
76797 + return 1;
76798 +
76799 + files = get_files_struct(task);
76800 + if (files != NULL) {
76801 + rcu_read_lock();
76802 + fdt = files_fdtable(files);
76803 + for (i=0; i < fdt->max_fds; i++) {
76804 + file = fcheck_files(files, i);
76805 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
76806 + get_file(file);
76807 + our_file = file;
76808 + }
76809 + }
76810 + rcu_read_unlock();
76811 + put_files_struct(files);
76812 + }
76813 +
76814 + if (our_file == NULL)
76815 + return 1;
76816 +
76817 + read_lock(&tasklist_lock);
76818 + do_each_thread(p2, p) {
76819 + files = get_files_struct(p);
76820 + if (files == NULL ||
76821 + (p->signal && p->signal->tty == task->signal->tty)) {
76822 + if (files != NULL)
76823 + put_files_struct(files);
76824 + continue;
76825 + }
76826 + rcu_read_lock();
76827 + fdt = files_fdtable(files);
76828 + for (i=0; i < fdt->max_fds; i++) {
76829 + file = fcheck_files(files, i);
76830 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
76831 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
76832 + p3 = task;
76833 + while (task_pid_nr(p3) > 0) {
76834 + if (p3 == p)
76835 + break;
76836 + p3 = p3->real_parent;
76837 + }
76838 + if (p3 == p)
76839 + break;
76840 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
76841 + gr_handle_alertkill(p);
76842 + rcu_read_unlock();
76843 + put_files_struct(files);
76844 + read_unlock(&tasklist_lock);
76845 + fput(our_file);
76846 + return 0;
76847 + }
76848 + }
76849 + rcu_read_unlock();
76850 + put_files_struct(files);
76851 + } while_each_thread(p2, p);
76852 + read_unlock(&tasklist_lock);
76853 +
76854 + fput(our_file);
76855 + return 1;
76856 +}
76857 +
76858 +ssize_t
76859 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
76860 +{
76861 + struct gr_arg_wrapper uwrap;
76862 + unsigned char *sprole_salt = NULL;
76863 + unsigned char *sprole_sum = NULL;
76864 + int error = 0;
76865 + int error2 = 0;
76866 + size_t req_count = 0;
76867 + unsigned char oldmode = 0;
76868 +
76869 + mutex_lock(&gr_dev_mutex);
76870 +
76871 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
76872 + error = -EPERM;
76873 + goto out;
76874 + }
76875 +
76876 +#ifdef CONFIG_COMPAT
76877 + pax_open_kernel();
76878 + if (is_compat_task()) {
76879 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
76880 + copy_gr_arg = &copy_gr_arg_compat;
76881 + copy_acl_object_label = &copy_acl_object_label_compat;
76882 + copy_acl_subject_label = &copy_acl_subject_label_compat;
76883 + copy_acl_role_label = &copy_acl_role_label_compat;
76884 + copy_acl_ip_label = &copy_acl_ip_label_compat;
76885 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
76886 + copy_role_transition = &copy_role_transition_compat;
76887 + copy_sprole_pw = &copy_sprole_pw_compat;
76888 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
76889 + copy_pointer_from_array = &copy_pointer_from_array_compat;
76890 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
76891 + } else {
76892 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
76893 + copy_gr_arg = &copy_gr_arg_normal;
76894 + copy_acl_object_label = &copy_acl_object_label_normal;
76895 + copy_acl_subject_label = &copy_acl_subject_label_normal;
76896 + copy_acl_role_label = &copy_acl_role_label_normal;
76897 + copy_acl_ip_label = &copy_acl_ip_label_normal;
76898 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
76899 + copy_role_transition = &copy_role_transition_normal;
76900 + copy_sprole_pw = &copy_sprole_pw_normal;
76901 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
76902 + copy_pointer_from_array = &copy_pointer_from_array_normal;
76903 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
76904 + }
76905 + pax_close_kernel();
76906 +#endif
76907 +
76908 + req_count = get_gr_arg_wrapper_size();
76909 +
76910 + if (count != req_count) {
76911 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
76912 + error = -EINVAL;
76913 + goto out;
76914 + }
76915 +
76916 +
76917 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
76918 + gr_auth_expires = 0;
76919 + gr_auth_attempts = 0;
76920 + }
76921 +
76922 + error = copy_gr_arg_wrapper(buf, &uwrap);
76923 + if (error)
76924 + goto out;
76925 +
76926 + error = copy_gr_arg(uwrap.arg, gr_usermode);
76927 + if (error)
76928 + goto out;
76929 +
76930 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76931 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
76932 + time_after(gr_auth_expires, get_seconds())) {
76933 + error = -EBUSY;
76934 + goto out;
76935 + }
76936 +
76937 + /* if non-root trying to do anything other than use a special role,
76938 + do not attempt authentication, do not count towards authentication
76939 + locking
76940 + */
76941 +
76942 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
76943 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
76944 + gr_is_global_nonroot(current_uid())) {
76945 + error = -EPERM;
76946 + goto out;
76947 + }
76948 +
76949 + /* ensure pw and special role name are null terminated */
76950 +
76951 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
76952 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
76953 +
76954 + /* Okay.
76955 + * We have our enough of the argument structure..(we have yet
76956 + * to copy_from_user the tables themselves) . Copy the tables
76957 + * only if we need them, i.e. for loading operations. */
76958 +
76959 + switch (gr_usermode->mode) {
76960 + case GR_STATUS:
76961 + if (gr_acl_is_enabled()) {
76962 + error = 1;
76963 + if (!gr_check_secure_terminal(current))
76964 + error = 3;
76965 + } else
76966 + error = 2;
76967 + goto out;
76968 + case GR_SHUTDOWN:
76969 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
76970 + stop_machine(gr_rbac_disable, NULL, NULL);
76971 + free_variables(false);
76972 + memset(gr_usermode, 0, sizeof(struct gr_arg));
76973 + memset(gr_system_salt, 0, GR_SALT_LEN);
76974 + memset(gr_system_sum, 0, GR_SHA_LEN);
76975 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
76976 + } else if (gr_acl_is_enabled()) {
76977 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
76978 + error = -EPERM;
76979 + } else {
76980 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
76981 + error = -EAGAIN;
76982 + }
76983 + break;
76984 + case GR_ENABLE:
76985 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
76986 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
76987 + else {
76988 + if (gr_acl_is_enabled())
76989 + error = -EAGAIN;
76990 + else
76991 + error = error2;
76992 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
76993 + }
76994 + break;
76995 + case GR_OLDRELOAD:
76996 + oldmode = 1;
76997 + case GR_RELOAD:
76998 + if (!gr_acl_is_enabled()) {
76999 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
77000 + error = -EAGAIN;
77001 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
77002 + error2 = gracl_reload(gr_usermode, oldmode);
77003 + if (!error2)
77004 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
77005 + else {
77006 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
77007 + error = error2;
77008 + }
77009 + } else {
77010 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
77011 + error = -EPERM;
77012 + }
77013 + break;
77014 + case GR_SEGVMOD:
77015 + if (unlikely(!gr_acl_is_enabled())) {
77016 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
77017 + error = -EAGAIN;
77018 + break;
77019 + }
77020 +
77021 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
77022 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
77023 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
77024 + struct acl_subject_label *segvacl;
77025 + segvacl =
77026 + lookup_acl_subj_label(gr_usermode->segv_inode,
77027 + gr_usermode->segv_device,
77028 + current->role);
77029 + if (segvacl) {
77030 + segvacl->crashes = 0;
77031 + segvacl->expires = 0;
77032 + }
77033 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
77034 + gr_remove_uid(gr_usermode->segv_uid);
77035 + }
77036 + } else {
77037 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
77038 + error = -EPERM;
77039 + }
77040 + break;
77041 + case GR_SPROLE:
77042 + case GR_SPROLEPAM:
77043 + if (unlikely(!gr_acl_is_enabled())) {
77044 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
77045 + error = -EAGAIN;
77046 + break;
77047 + }
77048 +
77049 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
77050 + current->role->expires = 0;
77051 + current->role->auth_attempts = 0;
77052 + }
77053 +
77054 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
77055 + time_after(current->role->expires, get_seconds())) {
77056 + error = -EBUSY;
77057 + goto out;
77058 + }
77059 +
77060 + if (lookup_special_role_auth
77061 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
77062 + && ((!sprole_salt && !sprole_sum)
77063 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
77064 + char *p = "";
77065 + assign_special_role(gr_usermode->sp_role);
77066 + read_lock(&tasklist_lock);
77067 + if (current->real_parent)
77068 + p = current->real_parent->role->rolename;
77069 + read_unlock(&tasklist_lock);
77070 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
77071 + p, acl_sp_role_value);
77072 + } else {
77073 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
77074 + error = -EPERM;
77075 + if(!(current->role->auth_attempts++))
77076 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
77077 +
77078 + goto out;
77079 + }
77080 + break;
77081 + case GR_UNSPROLE:
77082 + if (unlikely(!gr_acl_is_enabled())) {
77083 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
77084 + error = -EAGAIN;
77085 + break;
77086 + }
77087 +
77088 + if (current->role->roletype & GR_ROLE_SPECIAL) {
77089 + char *p = "";
77090 + int i = 0;
77091 +
77092 + read_lock(&tasklist_lock);
77093 + if (current->real_parent) {
77094 + p = current->real_parent->role->rolename;
77095 + i = current->real_parent->acl_role_id;
77096 + }
77097 + read_unlock(&tasklist_lock);
77098 +
77099 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
77100 + gr_set_acls(1);
77101 + } else {
77102 + error = -EPERM;
77103 + goto out;
77104 + }
77105 + break;
77106 + default:
77107 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
77108 + error = -EINVAL;
77109 + break;
77110 + }
77111 +
77112 + if (error != -EPERM)
77113 + goto out;
77114 +
77115 + if(!(gr_auth_attempts++))
77116 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
77117 +
77118 + out:
77119 + mutex_unlock(&gr_dev_mutex);
77120 +
77121 + if (!error)
77122 + error = req_count;
77123 +
77124 + return error;
77125 +}
77126 +
77127 +int
77128 +gr_set_acls(const int type)
77129 +{
77130 + struct task_struct *task, *task2;
77131 + struct acl_role_label *role = current->role;
77132 + struct acl_subject_label *subj;
77133 + __u16 acl_role_id = current->acl_role_id;
77134 + const struct cred *cred;
77135 + int ret;
77136 +
77137 + rcu_read_lock();
77138 + read_lock(&tasklist_lock);
77139 + read_lock(&grsec_exec_file_lock);
77140 + do_each_thread(task2, task) {
77141 + /* check to see if we're called from the exit handler,
77142 + if so, only replace ACLs that have inherited the admin
77143 + ACL */
77144 +
77145 + if (type && (task->role != role ||
77146 + task->acl_role_id != acl_role_id))
77147 + continue;
77148 +
77149 + task->acl_role_id = 0;
77150 + task->acl_sp_role = 0;
77151 + task->inherited = 0;
77152 +
77153 + if (task->exec_file) {
77154 + cred = __task_cred(task);
77155 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
77156 + subj = __gr_get_subject_for_task(polstate, task, NULL);
77157 + if (subj == NULL) {
77158 + ret = -EINVAL;
77159 + read_unlock(&grsec_exec_file_lock);
77160 + read_unlock(&tasklist_lock);
77161 + rcu_read_unlock();
77162 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
77163 + return ret;
77164 + }
77165 + __gr_apply_subject_to_task(polstate, task, subj);
77166 + } else {
77167 + // it's a kernel process
77168 + task->role = polstate->kernel_role;
77169 + task->acl = polstate->kernel_role->root_label;
77170 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
77171 + task->acl->mode &= ~GR_PROCFIND;
77172 +#endif
77173 + }
77174 + } while_each_thread(task2, task);
77175 + read_unlock(&grsec_exec_file_lock);
77176 + read_unlock(&tasklist_lock);
77177 + rcu_read_unlock();
77178 +
77179 + return 0;
77180 +}
77181 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
77182 new file mode 100644
77183 index 0000000..39645c9
77184 --- /dev/null
77185 +++ b/grsecurity/gracl_res.c
77186 @@ -0,0 +1,68 @@
77187 +#include <linux/kernel.h>
77188 +#include <linux/sched.h>
77189 +#include <linux/gracl.h>
77190 +#include <linux/grinternal.h>
77191 +
77192 +static const char *restab_log[] = {
77193 + [RLIMIT_CPU] = "RLIMIT_CPU",
77194 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
77195 + [RLIMIT_DATA] = "RLIMIT_DATA",
77196 + [RLIMIT_STACK] = "RLIMIT_STACK",
77197 + [RLIMIT_CORE] = "RLIMIT_CORE",
77198 + [RLIMIT_RSS] = "RLIMIT_RSS",
77199 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
77200 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
77201 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
77202 + [RLIMIT_AS] = "RLIMIT_AS",
77203 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
77204 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
77205 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
77206 + [RLIMIT_NICE] = "RLIMIT_NICE",
77207 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
77208 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
77209 + [GR_CRASH_RES] = "RLIMIT_CRASH"
77210 +};
77211 +
77212 +void
77213 +gr_log_resource(const struct task_struct *task,
77214 + const int res, const unsigned long wanted, const int gt)
77215 +{
77216 + const struct cred *cred;
77217 + unsigned long rlim;
77218 +
77219 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
77220 + return;
77221 +
77222 + // not yet supported resource
77223 + if (unlikely(!restab_log[res]))
77224 + return;
77225 +
77226 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
77227 + rlim = task_rlimit_max(task, res);
77228 + else
77229 + rlim = task_rlimit(task, res);
77230 +
77231 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
77232 + return;
77233 +
77234 + rcu_read_lock();
77235 + cred = __task_cred(task);
77236 +
77237 + if (res == RLIMIT_NPROC &&
77238 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
77239 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
77240 + goto out_rcu_unlock;
77241 + else if (res == RLIMIT_MEMLOCK &&
77242 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
77243 + goto out_rcu_unlock;
77244 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
77245 + goto out_rcu_unlock;
77246 + rcu_read_unlock();
77247 +
77248 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
77249 +
77250 + return;
77251 +out_rcu_unlock:
77252 + rcu_read_unlock();
77253 + return;
77254 +}
77255 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
77256 new file mode 100644
77257 index 0000000..2040e61
77258 --- /dev/null
77259 +++ b/grsecurity/gracl_segv.c
77260 @@ -0,0 +1,313 @@
77261 +#include <linux/kernel.h>
77262 +#include <linux/mm.h>
77263 +#include <asm/uaccess.h>
77264 +#include <asm/errno.h>
77265 +#include <asm/mman.h>
77266 +#include <net/sock.h>
77267 +#include <linux/file.h>
77268 +#include <linux/fs.h>
77269 +#include <linux/net.h>
77270 +#include <linux/in.h>
77271 +#include <linux/slab.h>
77272 +#include <linux/types.h>
77273 +#include <linux/sched.h>
77274 +#include <linux/timer.h>
77275 +#include <linux/gracl.h>
77276 +#include <linux/grsecurity.h>
77277 +#include <linux/grinternal.h>
77278 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
77279 +#include <linux/magic.h>
77280 +#include <linux/pagemap.h>
77281 +#include "../fs/btrfs/async-thread.h"
77282 +#include "../fs/btrfs/ctree.h"
77283 +#include "../fs/btrfs/btrfs_inode.h"
77284 +#endif
77285 +
77286 +static struct crash_uid *uid_set;
77287 +static unsigned short uid_used;
77288 +static DEFINE_SPINLOCK(gr_uid_lock);
77289 +extern rwlock_t gr_inode_lock;
77290 +extern struct acl_subject_label *
77291 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
77292 + struct acl_role_label *role);
77293 +
77294 +static inline dev_t __get_dev(const struct dentry *dentry)
77295 +{
77296 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
77297 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
77298 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
77299 + else
77300 +#endif
77301 + return dentry->d_sb->s_dev;
77302 +}
77303 +
77304 +int
77305 +gr_init_uidset(void)
77306 +{
77307 + uid_set =
77308 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
77309 + uid_used = 0;
77310 +
77311 + return uid_set ? 1 : 0;
77312 +}
77313 +
77314 +void
77315 +gr_free_uidset(void)
77316 +{
77317 + if (uid_set) {
77318 + struct crash_uid *tmpset;
77319 + spin_lock(&gr_uid_lock);
77320 + tmpset = uid_set;
77321 + uid_set = NULL;
77322 + uid_used = 0;
77323 + spin_unlock(&gr_uid_lock);
77324 + if (tmpset)
77325 + kfree(tmpset);
77326 + }
77327 +
77328 + return;
77329 +}
77330 +
77331 +int
77332 +gr_find_uid(const uid_t uid)
77333 +{
77334 + struct crash_uid *tmp = uid_set;
77335 + uid_t buid;
77336 + int low = 0, high = uid_used - 1, mid;
77337 +
77338 + while (high >= low) {
77339 + mid = (low + high) >> 1;
77340 + buid = tmp[mid].uid;
77341 + if (buid == uid)
77342 + return mid;
77343 + if (buid > uid)
77344 + high = mid - 1;
77345 + if (buid < uid)
77346 + low = mid + 1;
77347 + }
77348 +
77349 + return -1;
77350 +}
77351 +
77352 +static __inline__ void
77353 +gr_insertsort(void)
77354 +{
77355 + unsigned short i, j;
77356 + struct crash_uid index;
77357 +
77358 + for (i = 1; i < uid_used; i++) {
77359 + index = uid_set[i];
77360 + j = i;
77361 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
77362 + uid_set[j] = uid_set[j - 1];
77363 + j--;
77364 + }
77365 + uid_set[j] = index;
77366 + }
77367 +
77368 + return;
77369 +}
77370 +
77371 +static __inline__ void
77372 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
77373 +{
77374 + int loc;
77375 + uid_t uid = GR_GLOBAL_UID(kuid);
77376 +
77377 + if (uid_used == GR_UIDTABLE_MAX)
77378 + return;
77379 +
77380 + loc = gr_find_uid(uid);
77381 +
77382 + if (loc >= 0) {
77383 + uid_set[loc].expires = expires;
77384 + return;
77385 + }
77386 +
77387 + uid_set[uid_used].uid = uid;
77388 + uid_set[uid_used].expires = expires;
77389 + uid_used++;
77390 +
77391 + gr_insertsort();
77392 +
77393 + return;
77394 +}
77395 +
77396 +void
77397 +gr_remove_uid(const unsigned short loc)
77398 +{
77399 + unsigned short i;
77400 +
77401 + for (i = loc + 1; i < uid_used; i++)
77402 + uid_set[i - 1] = uid_set[i];
77403 +
77404 + uid_used--;
77405 +
77406 + return;
77407 +}
77408 +
77409 +int
77410 +gr_check_crash_uid(const kuid_t kuid)
77411 +{
77412 + int loc;
77413 + int ret = 0;
77414 + uid_t uid;
77415 +
77416 + if (unlikely(!gr_acl_is_enabled()))
77417 + return 0;
77418 +
77419 + uid = GR_GLOBAL_UID(kuid);
77420 +
77421 + spin_lock(&gr_uid_lock);
77422 + loc = gr_find_uid(uid);
77423 +
77424 + if (loc < 0)
77425 + goto out_unlock;
77426 +
77427 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
77428 + gr_remove_uid(loc);
77429 + else
77430 + ret = 1;
77431 +
77432 +out_unlock:
77433 + spin_unlock(&gr_uid_lock);
77434 + return ret;
77435 +}
77436 +
77437 +static __inline__ int
77438 +proc_is_setxid(const struct cred *cred)
77439 +{
77440 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
77441 + !uid_eq(cred->uid, cred->fsuid))
77442 + return 1;
77443 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
77444 + !gid_eq(cred->gid, cred->fsgid))
77445 + return 1;
77446 +
77447 + return 0;
77448 +}
77449 +
77450 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
77451 +
77452 +void
77453 +gr_handle_crash(struct task_struct *task, const int sig)
77454 +{
77455 + struct acl_subject_label *curr;
77456 + struct task_struct *tsk, *tsk2;
77457 + const struct cred *cred;
77458 + const struct cred *cred2;
77459 +
77460 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
77461 + return;
77462 +
77463 + if (unlikely(!gr_acl_is_enabled()))
77464 + return;
77465 +
77466 + curr = task->acl;
77467 +
77468 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
77469 + return;
77470 +
77471 + if (time_before_eq(curr->expires, get_seconds())) {
77472 + curr->expires = 0;
77473 + curr->crashes = 0;
77474 + }
77475 +
77476 + curr->crashes++;
77477 +
77478 + if (!curr->expires)
77479 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
77480 +
77481 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
77482 + time_after(curr->expires, get_seconds())) {
77483 + rcu_read_lock();
77484 + cred = __task_cred(task);
77485 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
77486 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
77487 + spin_lock(&gr_uid_lock);
77488 + gr_insert_uid(cred->uid, curr->expires);
77489 + spin_unlock(&gr_uid_lock);
77490 + curr->expires = 0;
77491 + curr->crashes = 0;
77492 + read_lock(&tasklist_lock);
77493 + do_each_thread(tsk2, tsk) {
77494 + cred2 = __task_cred(tsk);
77495 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
77496 + gr_fake_force_sig(SIGKILL, tsk);
77497 + } while_each_thread(tsk2, tsk);
77498 + read_unlock(&tasklist_lock);
77499 + } else {
77500 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
77501 + read_lock(&tasklist_lock);
77502 + read_lock(&grsec_exec_file_lock);
77503 + do_each_thread(tsk2, tsk) {
77504 + if (likely(tsk != task)) {
77505 + // if this thread has the same subject as the one that triggered
77506 + // RES_CRASH and it's the same binary, kill it
77507 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
77508 + gr_fake_force_sig(SIGKILL, tsk);
77509 + }
77510 + } while_each_thread(tsk2, tsk);
77511 + read_unlock(&grsec_exec_file_lock);
77512 + read_unlock(&tasklist_lock);
77513 + }
77514 + rcu_read_unlock();
77515 + }
77516 +
77517 + return;
77518 +}
77519 +
77520 +int
77521 +gr_check_crash_exec(const struct file *filp)
77522 +{
77523 + struct acl_subject_label *curr;
77524 +
77525 + if (unlikely(!gr_acl_is_enabled()))
77526 + return 0;
77527 +
77528 + read_lock(&gr_inode_lock);
77529 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
77530 + __get_dev(filp->f_path.dentry),
77531 + current->role);
77532 + read_unlock(&gr_inode_lock);
77533 +
77534 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
77535 + (!curr->crashes && !curr->expires))
77536 + return 0;
77537 +
77538 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
77539 + time_after(curr->expires, get_seconds()))
77540 + return 1;
77541 + else if (time_before_eq(curr->expires, get_seconds())) {
77542 + curr->crashes = 0;
77543 + curr->expires = 0;
77544 + }
77545 +
77546 + return 0;
77547 +}
77548 +
77549 +void
77550 +gr_handle_alertkill(struct task_struct *task)
77551 +{
77552 + struct acl_subject_label *curracl;
77553 + __u32 curr_ip;
77554 + struct task_struct *p, *p2;
77555 +
77556 + if (unlikely(!gr_acl_is_enabled()))
77557 + return;
77558 +
77559 + curracl = task->acl;
77560 + curr_ip = task->signal->curr_ip;
77561 +
77562 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
77563 + read_lock(&tasklist_lock);
77564 + do_each_thread(p2, p) {
77565 + if (p->signal->curr_ip == curr_ip)
77566 + gr_fake_force_sig(SIGKILL, p);
77567 + } while_each_thread(p2, p);
77568 + read_unlock(&tasklist_lock);
77569 + } else if (curracl->mode & GR_KILLPROC)
77570 + gr_fake_force_sig(SIGKILL, task);
77571 +
77572 + return;
77573 +}
77574 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
77575 new file mode 100644
77576 index 0000000..98011b0
77577 --- /dev/null
77578 +++ b/grsecurity/gracl_shm.c
77579 @@ -0,0 +1,40 @@
77580 +#include <linux/kernel.h>
77581 +#include <linux/mm.h>
77582 +#include <linux/sched.h>
77583 +#include <linux/file.h>
77584 +#include <linux/ipc.h>
77585 +#include <linux/gracl.h>
77586 +#include <linux/grsecurity.h>
77587 +#include <linux/grinternal.h>
77588 +
77589 +int
77590 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77591 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
77592 +{
77593 + struct task_struct *task;
77594 +
77595 + if (!gr_acl_is_enabled())
77596 + return 1;
77597 +
77598 + rcu_read_lock();
77599 + read_lock(&tasklist_lock);
77600 +
77601 + task = find_task_by_vpid(shm_cprid);
77602 +
77603 + if (unlikely(!task))
77604 + task = find_task_by_vpid(shm_lapid);
77605 +
77606 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
77607 + (task_pid_nr(task) == shm_lapid)) &&
77608 + (task->acl->mode & GR_PROTSHM) &&
77609 + (task->acl != current->acl))) {
77610 + read_unlock(&tasklist_lock);
77611 + rcu_read_unlock();
77612 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
77613 + return 0;
77614 + }
77615 + read_unlock(&tasklist_lock);
77616 + rcu_read_unlock();
77617 +
77618 + return 1;
77619 +}
77620 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
77621 new file mode 100644
77622 index 0000000..bc0be01
77623 --- /dev/null
77624 +++ b/grsecurity/grsec_chdir.c
77625 @@ -0,0 +1,19 @@
77626 +#include <linux/kernel.h>
77627 +#include <linux/sched.h>
77628 +#include <linux/fs.h>
77629 +#include <linux/file.h>
77630 +#include <linux/grsecurity.h>
77631 +#include <linux/grinternal.h>
77632 +
77633 +void
77634 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
77635 +{
77636 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77637 + if ((grsec_enable_chdir && grsec_enable_group &&
77638 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
77639 + !grsec_enable_group)) {
77640 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
77641 + }
77642 +#endif
77643 + return;
77644 +}
77645 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
77646 new file mode 100644
77647 index 0000000..baa635c
77648 --- /dev/null
77649 +++ b/grsecurity/grsec_chroot.c
77650 @@ -0,0 +1,387 @@
77651 +#include <linux/kernel.h>
77652 +#include <linux/module.h>
77653 +#include <linux/sched.h>
77654 +#include <linux/file.h>
77655 +#include <linux/fs.h>
77656 +#include <linux/mount.h>
77657 +#include <linux/types.h>
77658 +#include "../fs/mount.h"
77659 +#include <linux/grsecurity.h>
77660 +#include <linux/grinternal.h>
77661 +
77662 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
77663 +int gr_init_ran;
77664 +#endif
77665 +
77666 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
77667 +{
77668 +#ifdef CONFIG_GRKERNSEC
77669 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
77670 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
77671 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
77672 + && gr_init_ran
77673 +#endif
77674 + )
77675 + task->gr_is_chrooted = 1;
77676 + else {
77677 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
77678 + if (task_pid_nr(task) == 1 && !gr_init_ran)
77679 + gr_init_ran = 1;
77680 +#endif
77681 + task->gr_is_chrooted = 0;
77682 + }
77683 +
77684 + task->gr_chroot_dentry = path->dentry;
77685 +#endif
77686 + return;
77687 +}
77688 +
77689 +void gr_clear_chroot_entries(struct task_struct *task)
77690 +{
77691 +#ifdef CONFIG_GRKERNSEC
77692 + task->gr_is_chrooted = 0;
77693 + task->gr_chroot_dentry = NULL;
77694 +#endif
77695 + return;
77696 +}
77697 +
77698 +int
77699 +gr_handle_chroot_unix(const pid_t pid)
77700 +{
77701 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77702 + struct task_struct *p;
77703 +
77704 + if (unlikely(!grsec_enable_chroot_unix))
77705 + return 1;
77706 +
77707 + if (likely(!proc_is_chrooted(current)))
77708 + return 1;
77709 +
77710 + rcu_read_lock();
77711 + read_lock(&tasklist_lock);
77712 + p = find_task_by_vpid_unrestricted(pid);
77713 + if (unlikely(p && !have_same_root(current, p))) {
77714 + read_unlock(&tasklist_lock);
77715 + rcu_read_unlock();
77716 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
77717 + return 0;
77718 + }
77719 + read_unlock(&tasklist_lock);
77720 + rcu_read_unlock();
77721 +#endif
77722 + return 1;
77723 +}
77724 +
77725 +int
77726 +gr_handle_chroot_nice(void)
77727 +{
77728 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77729 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
77730 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
77731 + return -EPERM;
77732 + }
77733 +#endif
77734 + return 0;
77735 +}
77736 +
77737 +int
77738 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
77739 +{
77740 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77741 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
77742 + && proc_is_chrooted(current)) {
77743 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
77744 + return -EACCES;
77745 + }
77746 +#endif
77747 + return 0;
77748 +}
77749 +
77750 +int
77751 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
77752 +{
77753 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77754 + struct task_struct *p;
77755 + int ret = 0;
77756 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
77757 + return ret;
77758 +
77759 + read_lock(&tasklist_lock);
77760 + do_each_pid_task(pid, type, p) {
77761 + if (!have_same_root(current, p)) {
77762 + ret = 1;
77763 + goto out;
77764 + }
77765 + } while_each_pid_task(pid, type, p);
77766 +out:
77767 + read_unlock(&tasklist_lock);
77768 + return ret;
77769 +#endif
77770 + return 0;
77771 +}
77772 +
77773 +int
77774 +gr_pid_is_chrooted(struct task_struct *p)
77775 +{
77776 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77777 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
77778 + return 0;
77779 +
77780 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
77781 + !have_same_root(current, p)) {
77782 + return 1;
77783 + }
77784 +#endif
77785 + return 0;
77786 +}
77787 +
77788 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
77789 +
77790 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
77791 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
77792 +{
77793 + struct path path, currentroot;
77794 + int ret = 0;
77795 +
77796 + path.dentry = (struct dentry *)u_dentry;
77797 + path.mnt = (struct vfsmount *)u_mnt;
77798 + get_fs_root(current->fs, &currentroot);
77799 + if (path_is_under(&path, &currentroot))
77800 + ret = 1;
77801 + path_put(&currentroot);
77802 +
77803 + return ret;
77804 +}
77805 +#endif
77806 +
77807 +int
77808 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
77809 +{
77810 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77811 + if (!grsec_enable_chroot_fchdir)
77812 + return 1;
77813 +
77814 + if (!proc_is_chrooted(current))
77815 + return 1;
77816 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
77817 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
77818 + return 0;
77819 + }
77820 +#endif
77821 + return 1;
77822 +}
77823 +
77824 +int
77825 +gr_chroot_fhandle(void)
77826 +{
77827 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77828 + if (!grsec_enable_chroot_fchdir)
77829 + return 1;
77830 +
77831 + if (!proc_is_chrooted(current))
77832 + return 1;
77833 + else {
77834 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
77835 + return 0;
77836 + }
77837 +#endif
77838 + return 1;
77839 +}
77840 +
77841 +int
77842 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77843 + const time_t shm_createtime)
77844 +{
77845 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77846 + struct task_struct *p;
77847 + time_t starttime;
77848 +
77849 + if (unlikely(!grsec_enable_chroot_shmat))
77850 + return 1;
77851 +
77852 + if (likely(!proc_is_chrooted(current)))
77853 + return 1;
77854 +
77855 + rcu_read_lock();
77856 + read_lock(&tasklist_lock);
77857 +
77858 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
77859 + starttime = p->start_time.tv_sec;
77860 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
77861 + if (have_same_root(current, p)) {
77862 + goto allow;
77863 + } else {
77864 + read_unlock(&tasklist_lock);
77865 + rcu_read_unlock();
77866 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77867 + return 0;
77868 + }
77869 + }
77870 + /* creator exited, pid reuse, fall through to next check */
77871 + }
77872 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
77873 + if (unlikely(!have_same_root(current, p))) {
77874 + read_unlock(&tasklist_lock);
77875 + rcu_read_unlock();
77876 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
77877 + return 0;
77878 + }
77879 + }
77880 +
77881 +allow:
77882 + read_unlock(&tasklist_lock);
77883 + rcu_read_unlock();
77884 +#endif
77885 + return 1;
77886 +}
77887 +
77888 +void
77889 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
77890 +{
77891 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77892 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
77893 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
77894 +#endif
77895 + return;
77896 +}
77897 +
77898 +int
77899 +gr_handle_chroot_mknod(const struct dentry *dentry,
77900 + const struct vfsmount *mnt, const int mode)
77901 +{
77902 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77903 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
77904 + proc_is_chrooted(current)) {
77905 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
77906 + return -EPERM;
77907 + }
77908 +#endif
77909 + return 0;
77910 +}
77911 +
77912 +int
77913 +gr_handle_chroot_mount(const struct dentry *dentry,
77914 + const struct vfsmount *mnt, const char *dev_name)
77915 +{
77916 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77917 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
77918 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
77919 + return -EPERM;
77920 + }
77921 +#endif
77922 + return 0;
77923 +}
77924 +
77925 +int
77926 +gr_handle_chroot_pivot(void)
77927 +{
77928 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77929 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
77930 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
77931 + return -EPERM;
77932 + }
77933 +#endif
77934 + return 0;
77935 +}
77936 +
77937 +int
77938 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
77939 +{
77940 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77941 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
77942 + !gr_is_outside_chroot(dentry, mnt)) {
77943 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
77944 + return -EPERM;
77945 + }
77946 +#endif
77947 + return 0;
77948 +}
77949 +
77950 +extern const char *captab_log[];
77951 +extern int captab_log_entries;
77952 +
77953 +int
77954 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77955 +{
77956 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77957 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77958 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77959 + if (cap_raised(chroot_caps, cap)) {
77960 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
77961 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
77962 + }
77963 + return 0;
77964 + }
77965 + }
77966 +#endif
77967 + return 1;
77968 +}
77969 +
77970 +int
77971 +gr_chroot_is_capable(const int cap)
77972 +{
77973 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77974 + return gr_task_chroot_is_capable(current, current_cred(), cap);
77975 +#endif
77976 + return 1;
77977 +}
77978 +
77979 +int
77980 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
77981 +{
77982 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77983 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
77984 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
77985 + if (cap_raised(chroot_caps, cap)) {
77986 + return 0;
77987 + }
77988 + }
77989 +#endif
77990 + return 1;
77991 +}
77992 +
77993 +int
77994 +gr_chroot_is_capable_nolog(const int cap)
77995 +{
77996 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77997 + return gr_task_chroot_is_capable_nolog(current, cap);
77998 +#endif
77999 + return 1;
78000 +}
78001 +
78002 +int
78003 +gr_handle_chroot_sysctl(const int op)
78004 +{
78005 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78006 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
78007 + proc_is_chrooted(current))
78008 + return -EACCES;
78009 +#endif
78010 + return 0;
78011 +}
78012 +
78013 +void
78014 +gr_handle_chroot_chdir(const struct path *path)
78015 +{
78016 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78017 + if (grsec_enable_chroot_chdir)
78018 + set_fs_pwd(current->fs, path);
78019 +#endif
78020 + return;
78021 +}
78022 +
78023 +int
78024 +gr_handle_chroot_chmod(const struct dentry *dentry,
78025 + const struct vfsmount *mnt, const int mode)
78026 +{
78027 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78028 + /* allow chmod +s on directories, but not files */
78029 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
78030 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
78031 + proc_is_chrooted(current)) {
78032 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
78033 + return -EPERM;
78034 + }
78035 +#endif
78036 + return 0;
78037 +}
78038 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
78039 new file mode 100644
78040 index 0000000..2d3bcb7
78041 --- /dev/null
78042 +++ b/grsecurity/grsec_disabled.c
78043 @@ -0,0 +1,440 @@
78044 +#include <linux/kernel.h>
78045 +#include <linux/module.h>
78046 +#include <linux/sched.h>
78047 +#include <linux/file.h>
78048 +#include <linux/fs.h>
78049 +#include <linux/kdev_t.h>
78050 +#include <linux/net.h>
78051 +#include <linux/in.h>
78052 +#include <linux/ip.h>
78053 +#include <linux/skbuff.h>
78054 +#include <linux/sysctl.h>
78055 +
78056 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
78057 +void
78058 +pax_set_initial_flags(struct linux_binprm *bprm)
78059 +{
78060 + return;
78061 +}
78062 +#endif
78063 +
78064 +#ifdef CONFIG_SYSCTL
78065 +__u32
78066 +gr_handle_sysctl(const struct ctl_table * table, const int op)
78067 +{
78068 + return 0;
78069 +}
78070 +#endif
78071 +
78072 +#ifdef CONFIG_TASKSTATS
78073 +int gr_is_taskstats_denied(int pid)
78074 +{
78075 + return 0;
78076 +}
78077 +#endif
78078 +
78079 +int
78080 +gr_acl_is_enabled(void)
78081 +{
78082 + return 0;
78083 +}
78084 +
78085 +int
78086 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
78087 +{
78088 + return 0;
78089 +}
78090 +
78091 +void
78092 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
78093 +{
78094 + return;
78095 +}
78096 +
78097 +int
78098 +gr_handle_rawio(const struct inode *inode)
78099 +{
78100 + return 0;
78101 +}
78102 +
78103 +void
78104 +gr_acl_handle_psacct(struct task_struct *task, const long code)
78105 +{
78106 + return;
78107 +}
78108 +
78109 +int
78110 +gr_handle_ptrace(struct task_struct *task, const long request)
78111 +{
78112 + return 0;
78113 +}
78114 +
78115 +int
78116 +gr_handle_proc_ptrace(struct task_struct *task)
78117 +{
78118 + return 0;
78119 +}
78120 +
78121 +int
78122 +gr_set_acls(const int type)
78123 +{
78124 + return 0;
78125 +}
78126 +
78127 +int
78128 +gr_check_hidden_task(const struct task_struct *tsk)
78129 +{
78130 + return 0;
78131 +}
78132 +
78133 +int
78134 +gr_check_protected_task(const struct task_struct *task)
78135 +{
78136 + return 0;
78137 +}
78138 +
78139 +int
78140 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
78141 +{
78142 + return 0;
78143 +}
78144 +
78145 +void
78146 +gr_copy_label(struct task_struct *tsk)
78147 +{
78148 + return;
78149 +}
78150 +
78151 +void
78152 +gr_set_pax_flags(struct task_struct *task)
78153 +{
78154 + return;
78155 +}
78156 +
78157 +int
78158 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
78159 + const int unsafe_share)
78160 +{
78161 + return 0;
78162 +}
78163 +
78164 +void
78165 +gr_handle_delete(const ino_t ino, const dev_t dev)
78166 +{
78167 + return;
78168 +}
78169 +
78170 +void
78171 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
78172 +{
78173 + return;
78174 +}
78175 +
78176 +void
78177 +gr_handle_crash(struct task_struct *task, const int sig)
78178 +{
78179 + return;
78180 +}
78181 +
78182 +int
78183 +gr_check_crash_exec(const struct file *filp)
78184 +{
78185 + return 0;
78186 +}
78187 +
78188 +int
78189 +gr_check_crash_uid(const kuid_t uid)
78190 +{
78191 + return 0;
78192 +}
78193 +
78194 +void
78195 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78196 + struct dentry *old_dentry,
78197 + struct dentry *new_dentry,
78198 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
78199 +{
78200 + return;
78201 +}
78202 +
78203 +int
78204 +gr_search_socket(const int family, const int type, const int protocol)
78205 +{
78206 + return 1;
78207 +}
78208 +
78209 +int
78210 +gr_search_connectbind(const int mode, const struct socket *sock,
78211 + const struct sockaddr_in *addr)
78212 +{
78213 + return 0;
78214 +}
78215 +
78216 +void
78217 +gr_handle_alertkill(struct task_struct *task)
78218 +{
78219 + return;
78220 +}
78221 +
78222 +__u32
78223 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
78224 +{
78225 + return 1;
78226 +}
78227 +
78228 +__u32
78229 +gr_acl_handle_hidden_file(const struct dentry * dentry,
78230 + const struct vfsmount * mnt)
78231 +{
78232 + return 1;
78233 +}
78234 +
78235 +__u32
78236 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
78237 + int acc_mode)
78238 +{
78239 + return 1;
78240 +}
78241 +
78242 +__u32
78243 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
78244 +{
78245 + return 1;
78246 +}
78247 +
78248 +__u32
78249 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
78250 +{
78251 + return 1;
78252 +}
78253 +
78254 +int
78255 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
78256 + unsigned int *vm_flags)
78257 +{
78258 + return 1;
78259 +}
78260 +
78261 +__u32
78262 +gr_acl_handle_truncate(const struct dentry * dentry,
78263 + const struct vfsmount * mnt)
78264 +{
78265 + return 1;
78266 +}
78267 +
78268 +__u32
78269 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
78270 +{
78271 + return 1;
78272 +}
78273 +
78274 +__u32
78275 +gr_acl_handle_access(const struct dentry * dentry,
78276 + const struct vfsmount * mnt, const int fmode)
78277 +{
78278 + return 1;
78279 +}
78280 +
78281 +__u32
78282 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
78283 + umode_t *mode)
78284 +{
78285 + return 1;
78286 +}
78287 +
78288 +__u32
78289 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
78290 +{
78291 + return 1;
78292 +}
78293 +
78294 +__u32
78295 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
78296 +{
78297 + return 1;
78298 +}
78299 +
78300 +__u32
78301 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
78302 +{
78303 + return 1;
78304 +}
78305 +
78306 +void
78307 +grsecurity_init(void)
78308 +{
78309 + return;
78310 +}
78311 +
78312 +umode_t gr_acl_umask(void)
78313 +{
78314 + return 0;
78315 +}
78316 +
78317 +__u32
78318 +gr_acl_handle_mknod(const struct dentry * new_dentry,
78319 + const struct dentry * parent_dentry,
78320 + const struct vfsmount * parent_mnt,
78321 + const int mode)
78322 +{
78323 + return 1;
78324 +}
78325 +
78326 +__u32
78327 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
78328 + const struct dentry * parent_dentry,
78329 + const struct vfsmount * parent_mnt)
78330 +{
78331 + return 1;
78332 +}
78333 +
78334 +__u32
78335 +gr_acl_handle_symlink(const struct dentry * new_dentry,
78336 + const struct dentry * parent_dentry,
78337 + const struct vfsmount * parent_mnt, const struct filename *from)
78338 +{
78339 + return 1;
78340 +}
78341 +
78342 +__u32
78343 +gr_acl_handle_link(const struct dentry * new_dentry,
78344 + const struct dentry * parent_dentry,
78345 + const struct vfsmount * parent_mnt,
78346 + const struct dentry * old_dentry,
78347 + const struct vfsmount * old_mnt, const struct filename *to)
78348 +{
78349 + return 1;
78350 +}
78351 +
78352 +int
78353 +gr_acl_handle_rename(const struct dentry *new_dentry,
78354 + const struct dentry *parent_dentry,
78355 + const struct vfsmount *parent_mnt,
78356 + const struct dentry *old_dentry,
78357 + const struct inode *old_parent_inode,
78358 + const struct vfsmount *old_mnt, const struct filename *newname,
78359 + unsigned int flags)
78360 +{
78361 + return 0;
78362 +}
78363 +
78364 +int
78365 +gr_acl_handle_filldir(const struct file *file, const char *name,
78366 + const int namelen, const ino_t ino)
78367 +{
78368 + return 1;
78369 +}
78370 +
78371 +int
78372 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
78373 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
78374 +{
78375 + return 1;
78376 +}
78377 +
78378 +int
78379 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
78380 +{
78381 + return 0;
78382 +}
78383 +
78384 +int
78385 +gr_search_accept(const struct socket *sock)
78386 +{
78387 + return 0;
78388 +}
78389 +
78390 +int
78391 +gr_search_listen(const struct socket *sock)
78392 +{
78393 + return 0;
78394 +}
78395 +
78396 +int
78397 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
78398 +{
78399 + return 0;
78400 +}
78401 +
78402 +__u32
78403 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
78404 +{
78405 + return 1;
78406 +}
78407 +
78408 +__u32
78409 +gr_acl_handle_creat(const struct dentry * dentry,
78410 + const struct dentry * p_dentry,
78411 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
78412 + const int imode)
78413 +{
78414 + return 1;
78415 +}
78416 +
78417 +void
78418 +gr_acl_handle_exit(void)
78419 +{
78420 + return;
78421 +}
78422 +
78423 +int
78424 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
78425 +{
78426 + return 1;
78427 +}
78428 +
78429 +void
78430 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
78431 +{
78432 + return;
78433 +}
78434 +
78435 +int
78436 +gr_acl_handle_procpidmem(const struct task_struct *task)
78437 +{
78438 + return 0;
78439 +}
78440 +
78441 +int
78442 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
78443 +{
78444 + return 0;
78445 +}
78446 +
78447 +int
78448 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
78449 +{
78450 + return 0;
78451 +}
78452 +
78453 +int
78454 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
78455 +{
78456 + return 0;
78457 +}
78458 +
78459 +int
78460 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
78461 +{
78462 + return 0;
78463 +}
78464 +
78465 +int gr_acl_enable_at_secure(void)
78466 +{
78467 + return 0;
78468 +}
78469 +
78470 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
78471 +{
78472 + return dentry->d_sb->s_dev;
78473 +}
78474 +
78475 +void gr_put_exec_file(struct task_struct *task)
78476 +{
78477 + return;
78478 +}
78479 +
78480 +#ifdef CONFIG_SECURITY
78481 +EXPORT_SYMBOL_GPL(gr_check_user_change);
78482 +EXPORT_SYMBOL_GPL(gr_check_group_change);
78483 +#endif
78484 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
78485 new file mode 100644
78486 index 0000000..14638ff
78487 --- /dev/null
78488 +++ b/grsecurity/grsec_exec.c
78489 @@ -0,0 +1,188 @@
78490 +#include <linux/kernel.h>
78491 +#include <linux/sched.h>
78492 +#include <linux/file.h>
78493 +#include <linux/binfmts.h>
78494 +#include <linux/fs.h>
78495 +#include <linux/types.h>
78496 +#include <linux/grdefs.h>
78497 +#include <linux/grsecurity.h>
78498 +#include <linux/grinternal.h>
78499 +#include <linux/capability.h>
78500 +#include <linux/module.h>
78501 +#include <linux/compat.h>
78502 +
78503 +#include <asm/uaccess.h>
78504 +
78505 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78506 +static char gr_exec_arg_buf[132];
78507 +static DEFINE_MUTEX(gr_exec_arg_mutex);
78508 +#endif
78509 +
78510 +struct user_arg_ptr {
78511 +#ifdef CONFIG_COMPAT
78512 + bool is_compat;
78513 +#endif
78514 + union {
78515 + const char __user *const __user *native;
78516 +#ifdef CONFIG_COMPAT
78517 + const compat_uptr_t __user *compat;
78518 +#endif
78519 + } ptr;
78520 +};
78521 +
78522 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
78523 +
78524 +void
78525 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
78526 +{
78527 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78528 + char *grarg = gr_exec_arg_buf;
78529 + unsigned int i, x, execlen = 0;
78530 + char c;
78531 +
78532 + if (!((grsec_enable_execlog && grsec_enable_group &&
78533 + in_group_p(grsec_audit_gid))
78534 + || (grsec_enable_execlog && !grsec_enable_group)))
78535 + return;
78536 +
78537 + mutex_lock(&gr_exec_arg_mutex);
78538 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
78539 +
78540 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
78541 + const char __user *p;
78542 + unsigned int len;
78543 +
78544 + p = get_user_arg_ptr(argv, i);
78545 + if (IS_ERR(p))
78546 + goto log;
78547 +
78548 + len = strnlen_user(p, 128 - execlen);
78549 + if (len > 128 - execlen)
78550 + len = 128 - execlen;
78551 + else if (len > 0)
78552 + len--;
78553 + if (copy_from_user(grarg + execlen, p, len))
78554 + goto log;
78555 +
78556 + /* rewrite unprintable characters */
78557 + for (x = 0; x < len; x++) {
78558 + c = *(grarg + execlen + x);
78559 + if (c < 32 || c > 126)
78560 + *(grarg + execlen + x) = ' ';
78561 + }
78562 +
78563 + execlen += len;
78564 + *(grarg + execlen) = ' ';
78565 + *(grarg + execlen + 1) = '\0';
78566 + execlen++;
78567 + }
78568 +
78569 + log:
78570 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
78571 + bprm->file->f_path.mnt, grarg);
78572 + mutex_unlock(&gr_exec_arg_mutex);
78573 +#endif
78574 + return;
78575 +}
78576 +
78577 +#ifdef CONFIG_GRKERNSEC
78578 +extern int gr_acl_is_capable(const int cap);
78579 +extern int gr_acl_is_capable_nolog(const int cap);
78580 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78581 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
78582 +extern int gr_chroot_is_capable(const int cap);
78583 +extern int gr_chroot_is_capable_nolog(const int cap);
78584 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78585 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
78586 +#endif
78587 +
78588 +const char *captab_log[] = {
78589 + "CAP_CHOWN",
78590 + "CAP_DAC_OVERRIDE",
78591 + "CAP_DAC_READ_SEARCH",
78592 + "CAP_FOWNER",
78593 + "CAP_FSETID",
78594 + "CAP_KILL",
78595 + "CAP_SETGID",
78596 + "CAP_SETUID",
78597 + "CAP_SETPCAP",
78598 + "CAP_LINUX_IMMUTABLE",
78599 + "CAP_NET_BIND_SERVICE",
78600 + "CAP_NET_BROADCAST",
78601 + "CAP_NET_ADMIN",
78602 + "CAP_NET_RAW",
78603 + "CAP_IPC_LOCK",
78604 + "CAP_IPC_OWNER",
78605 + "CAP_SYS_MODULE",
78606 + "CAP_SYS_RAWIO",
78607 + "CAP_SYS_CHROOT",
78608 + "CAP_SYS_PTRACE",
78609 + "CAP_SYS_PACCT",
78610 + "CAP_SYS_ADMIN",
78611 + "CAP_SYS_BOOT",
78612 + "CAP_SYS_NICE",
78613 + "CAP_SYS_RESOURCE",
78614 + "CAP_SYS_TIME",
78615 + "CAP_SYS_TTY_CONFIG",
78616 + "CAP_MKNOD",
78617 + "CAP_LEASE",
78618 + "CAP_AUDIT_WRITE",
78619 + "CAP_AUDIT_CONTROL",
78620 + "CAP_SETFCAP",
78621 + "CAP_MAC_OVERRIDE",
78622 + "CAP_MAC_ADMIN",
78623 + "CAP_SYSLOG",
78624 + "CAP_WAKE_ALARM",
78625 + "CAP_BLOCK_SUSPEND"
78626 +};
78627 +
78628 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
78629 +
78630 +int gr_is_capable(const int cap)
78631 +{
78632 +#ifdef CONFIG_GRKERNSEC
78633 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
78634 + return 1;
78635 + return 0;
78636 +#else
78637 + return 1;
78638 +#endif
78639 +}
78640 +
78641 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
78642 +{
78643 +#ifdef CONFIG_GRKERNSEC
78644 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
78645 + return 1;
78646 + return 0;
78647 +#else
78648 + return 1;
78649 +#endif
78650 +}
78651 +
78652 +int gr_is_capable_nolog(const int cap)
78653 +{
78654 +#ifdef CONFIG_GRKERNSEC
78655 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
78656 + return 1;
78657 + return 0;
78658 +#else
78659 + return 1;
78660 +#endif
78661 +}
78662 +
78663 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
78664 +{
78665 +#ifdef CONFIG_GRKERNSEC
78666 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
78667 + return 1;
78668 + return 0;
78669 +#else
78670 + return 1;
78671 +#endif
78672 +}
78673 +
78674 +EXPORT_SYMBOL_GPL(gr_is_capable);
78675 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
78676 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
78677 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
78678 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
78679 new file mode 100644
78680 index 0000000..06cc6ea
78681 --- /dev/null
78682 +++ b/grsecurity/grsec_fifo.c
78683 @@ -0,0 +1,24 @@
78684 +#include <linux/kernel.h>
78685 +#include <linux/sched.h>
78686 +#include <linux/fs.h>
78687 +#include <linux/file.h>
78688 +#include <linux/grinternal.h>
78689 +
78690 +int
78691 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
78692 + const struct dentry *dir, const int flag, const int acc_mode)
78693 +{
78694 +#ifdef CONFIG_GRKERNSEC_FIFO
78695 + const struct cred *cred = current_cred();
78696 +
78697 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
78698 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
78699 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
78700 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
78701 + if (!inode_permission(dentry->d_inode, acc_mode))
78702 + 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));
78703 + return -EACCES;
78704 + }
78705 +#endif
78706 + return 0;
78707 +}
78708 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
78709 new file mode 100644
78710 index 0000000..8ca18bf
78711 --- /dev/null
78712 +++ b/grsecurity/grsec_fork.c
78713 @@ -0,0 +1,23 @@
78714 +#include <linux/kernel.h>
78715 +#include <linux/sched.h>
78716 +#include <linux/grsecurity.h>
78717 +#include <linux/grinternal.h>
78718 +#include <linux/errno.h>
78719 +
78720 +void
78721 +gr_log_forkfail(const int retval)
78722 +{
78723 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78724 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
78725 + switch (retval) {
78726 + case -EAGAIN:
78727 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
78728 + break;
78729 + case -ENOMEM:
78730 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
78731 + break;
78732 + }
78733 + }
78734 +#endif
78735 + return;
78736 +}
78737 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
78738 new file mode 100644
78739 index 0000000..b7cb191
78740 --- /dev/null
78741 +++ b/grsecurity/grsec_init.c
78742 @@ -0,0 +1,286 @@
78743 +#include <linux/kernel.h>
78744 +#include <linux/sched.h>
78745 +#include <linux/mm.h>
78746 +#include <linux/gracl.h>
78747 +#include <linux/slab.h>
78748 +#include <linux/vmalloc.h>
78749 +#include <linux/percpu.h>
78750 +#include <linux/module.h>
78751 +
78752 +int grsec_enable_ptrace_readexec;
78753 +int grsec_enable_setxid;
78754 +int grsec_enable_symlinkown;
78755 +kgid_t grsec_symlinkown_gid;
78756 +int grsec_enable_brute;
78757 +int grsec_enable_link;
78758 +int grsec_enable_dmesg;
78759 +int grsec_enable_harden_ptrace;
78760 +int grsec_enable_harden_ipc;
78761 +int grsec_enable_fifo;
78762 +int grsec_enable_execlog;
78763 +int grsec_enable_signal;
78764 +int grsec_enable_forkfail;
78765 +int grsec_enable_audit_ptrace;
78766 +int grsec_enable_time;
78767 +int grsec_enable_group;
78768 +kgid_t grsec_audit_gid;
78769 +int grsec_enable_chdir;
78770 +int grsec_enable_mount;
78771 +int grsec_enable_rofs;
78772 +int grsec_deny_new_usb;
78773 +int grsec_enable_chroot_findtask;
78774 +int grsec_enable_chroot_mount;
78775 +int grsec_enable_chroot_shmat;
78776 +int grsec_enable_chroot_fchdir;
78777 +int grsec_enable_chroot_double;
78778 +int grsec_enable_chroot_pivot;
78779 +int grsec_enable_chroot_chdir;
78780 +int grsec_enable_chroot_chmod;
78781 +int grsec_enable_chroot_mknod;
78782 +int grsec_enable_chroot_nice;
78783 +int grsec_enable_chroot_execlog;
78784 +int grsec_enable_chroot_caps;
78785 +int grsec_enable_chroot_sysctl;
78786 +int grsec_enable_chroot_unix;
78787 +int grsec_enable_tpe;
78788 +kgid_t grsec_tpe_gid;
78789 +int grsec_enable_blackhole;
78790 +#ifdef CONFIG_IPV6_MODULE
78791 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
78792 +#endif
78793 +int grsec_lastack_retries;
78794 +int grsec_enable_tpe_all;
78795 +int grsec_enable_tpe_invert;
78796 +int grsec_enable_socket_all;
78797 +kgid_t grsec_socket_all_gid;
78798 +int grsec_enable_socket_client;
78799 +kgid_t grsec_socket_client_gid;
78800 +int grsec_enable_socket_server;
78801 +kgid_t grsec_socket_server_gid;
78802 +int grsec_resource_logging;
78803 +int grsec_disable_privio;
78804 +int grsec_enable_log_rwxmaps;
78805 +int grsec_lock;
78806 +
78807 +DEFINE_SPINLOCK(grsec_alert_lock);
78808 +unsigned long grsec_alert_wtime = 0;
78809 +unsigned long grsec_alert_fyet = 0;
78810 +
78811 +DEFINE_SPINLOCK(grsec_audit_lock);
78812 +
78813 +DEFINE_RWLOCK(grsec_exec_file_lock);
78814 +
78815 +char *gr_shared_page[4];
78816 +
78817 +char *gr_alert_log_fmt;
78818 +char *gr_audit_log_fmt;
78819 +char *gr_alert_log_buf;
78820 +char *gr_audit_log_buf;
78821 +
78822 +extern struct gr_arg *gr_usermode;
78823 +extern unsigned char *gr_system_salt;
78824 +extern unsigned char *gr_system_sum;
78825 +
78826 +void __init
78827 +grsecurity_init(void)
78828 +{
78829 + int j;
78830 + /* create the per-cpu shared pages */
78831 +
78832 +#ifdef CONFIG_X86
78833 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
78834 +#endif
78835 +
78836 + for (j = 0; j < 4; j++) {
78837 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
78838 + if (gr_shared_page[j] == NULL) {
78839 + panic("Unable to allocate grsecurity shared page");
78840 + return;
78841 + }
78842 + }
78843 +
78844 + /* allocate log buffers */
78845 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
78846 + if (!gr_alert_log_fmt) {
78847 + panic("Unable to allocate grsecurity alert log format buffer");
78848 + return;
78849 + }
78850 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
78851 + if (!gr_audit_log_fmt) {
78852 + panic("Unable to allocate grsecurity audit log format buffer");
78853 + return;
78854 + }
78855 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78856 + if (!gr_alert_log_buf) {
78857 + panic("Unable to allocate grsecurity alert log buffer");
78858 + return;
78859 + }
78860 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
78861 + if (!gr_audit_log_buf) {
78862 + panic("Unable to allocate grsecurity audit log buffer");
78863 + return;
78864 + }
78865 +
78866 + /* allocate memory for authentication structure */
78867 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
78868 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
78869 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
78870 +
78871 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
78872 + panic("Unable to allocate grsecurity authentication structure");
78873 + return;
78874 + }
78875 +
78876 +#ifdef CONFIG_GRKERNSEC_IO
78877 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
78878 + grsec_disable_privio = 1;
78879 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78880 + grsec_disable_privio = 1;
78881 +#else
78882 + grsec_disable_privio = 0;
78883 +#endif
78884 +#endif
78885 +
78886 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78887 + /* for backward compatibility, tpe_invert always defaults to on if
78888 + enabled in the kernel
78889 + */
78890 + grsec_enable_tpe_invert = 1;
78891 +#endif
78892 +
78893 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
78894 +#ifndef CONFIG_GRKERNSEC_SYSCTL
78895 + grsec_lock = 1;
78896 +#endif
78897 +
78898 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78899 + grsec_enable_log_rwxmaps = 1;
78900 +#endif
78901 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78902 + grsec_enable_group = 1;
78903 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
78904 +#endif
78905 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78906 + grsec_enable_ptrace_readexec = 1;
78907 +#endif
78908 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78909 + grsec_enable_chdir = 1;
78910 +#endif
78911 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78912 + grsec_enable_harden_ptrace = 1;
78913 +#endif
78914 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78915 + grsec_enable_harden_ipc = 1;
78916 +#endif
78917 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78918 + grsec_enable_mount = 1;
78919 +#endif
78920 +#ifdef CONFIG_GRKERNSEC_LINK
78921 + grsec_enable_link = 1;
78922 +#endif
78923 +#ifdef CONFIG_GRKERNSEC_BRUTE
78924 + grsec_enable_brute = 1;
78925 +#endif
78926 +#ifdef CONFIG_GRKERNSEC_DMESG
78927 + grsec_enable_dmesg = 1;
78928 +#endif
78929 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78930 + grsec_enable_blackhole = 1;
78931 + grsec_lastack_retries = 4;
78932 +#endif
78933 +#ifdef CONFIG_GRKERNSEC_FIFO
78934 + grsec_enable_fifo = 1;
78935 +#endif
78936 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78937 + grsec_enable_execlog = 1;
78938 +#endif
78939 +#ifdef CONFIG_GRKERNSEC_SETXID
78940 + grsec_enable_setxid = 1;
78941 +#endif
78942 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78943 + grsec_enable_signal = 1;
78944 +#endif
78945 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78946 + grsec_enable_forkfail = 1;
78947 +#endif
78948 +#ifdef CONFIG_GRKERNSEC_TIME
78949 + grsec_enable_time = 1;
78950 +#endif
78951 +#ifdef CONFIG_GRKERNSEC_RESLOG
78952 + grsec_resource_logging = 1;
78953 +#endif
78954 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78955 + grsec_enable_chroot_findtask = 1;
78956 +#endif
78957 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78958 + grsec_enable_chroot_unix = 1;
78959 +#endif
78960 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78961 + grsec_enable_chroot_mount = 1;
78962 +#endif
78963 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78964 + grsec_enable_chroot_fchdir = 1;
78965 +#endif
78966 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78967 + grsec_enable_chroot_shmat = 1;
78968 +#endif
78969 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78970 + grsec_enable_audit_ptrace = 1;
78971 +#endif
78972 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78973 + grsec_enable_chroot_double = 1;
78974 +#endif
78975 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78976 + grsec_enable_chroot_pivot = 1;
78977 +#endif
78978 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78979 + grsec_enable_chroot_chdir = 1;
78980 +#endif
78981 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78982 + grsec_enable_chroot_chmod = 1;
78983 +#endif
78984 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78985 + grsec_enable_chroot_mknod = 1;
78986 +#endif
78987 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78988 + grsec_enable_chroot_nice = 1;
78989 +#endif
78990 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78991 + grsec_enable_chroot_execlog = 1;
78992 +#endif
78993 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78994 + grsec_enable_chroot_caps = 1;
78995 +#endif
78996 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78997 + grsec_enable_chroot_sysctl = 1;
78998 +#endif
78999 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79000 + grsec_enable_symlinkown = 1;
79001 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
79002 +#endif
79003 +#ifdef CONFIG_GRKERNSEC_TPE
79004 + grsec_enable_tpe = 1;
79005 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
79006 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79007 + grsec_enable_tpe_all = 1;
79008 +#endif
79009 +#endif
79010 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79011 + grsec_enable_socket_all = 1;
79012 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
79013 +#endif
79014 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79015 + grsec_enable_socket_client = 1;
79016 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
79017 +#endif
79018 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79019 + grsec_enable_socket_server = 1;
79020 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
79021 +#endif
79022 +#endif
79023 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
79024 + grsec_deny_new_usb = 1;
79025 +#endif
79026 +
79027 + return;
79028 +}
79029 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
79030 new file mode 100644
79031 index 0000000..1773300
79032 --- /dev/null
79033 +++ b/grsecurity/grsec_ipc.c
79034 @@ -0,0 +1,48 @@
79035 +#include <linux/kernel.h>
79036 +#include <linux/mm.h>
79037 +#include <linux/sched.h>
79038 +#include <linux/file.h>
79039 +#include <linux/ipc.h>
79040 +#include <linux/ipc_namespace.h>
79041 +#include <linux/grsecurity.h>
79042 +#include <linux/grinternal.h>
79043 +
79044 +int
79045 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
79046 +{
79047 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79048 + int write;
79049 + int orig_granted_mode;
79050 + kuid_t euid;
79051 + kgid_t egid;
79052 +
79053 + if (!grsec_enable_harden_ipc)
79054 + return 1;
79055 +
79056 + euid = current_euid();
79057 + egid = current_egid();
79058 +
79059 + write = requested_mode & 00002;
79060 + orig_granted_mode = ipcp->mode;
79061 +
79062 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
79063 + orig_granted_mode >>= 6;
79064 + else {
79065 + /* if likely wrong permissions, lock to user */
79066 + if (orig_granted_mode & 0007)
79067 + orig_granted_mode = 0;
79068 + /* otherwise do a egid-only check */
79069 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
79070 + orig_granted_mode >>= 3;
79071 + /* otherwise, no access */
79072 + else
79073 + orig_granted_mode = 0;
79074 + }
79075 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
79076 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
79077 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
79078 + return 0;
79079 + }
79080 +#endif
79081 + return 1;
79082 +}
79083 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
79084 new file mode 100644
79085 index 0000000..5e05e20
79086 --- /dev/null
79087 +++ b/grsecurity/grsec_link.c
79088 @@ -0,0 +1,58 @@
79089 +#include <linux/kernel.h>
79090 +#include <linux/sched.h>
79091 +#include <linux/fs.h>
79092 +#include <linux/file.h>
79093 +#include <linux/grinternal.h>
79094 +
79095 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
79096 +{
79097 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79098 + const struct inode *link_inode = link->dentry->d_inode;
79099 +
79100 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
79101 + /* ignore root-owned links, e.g. /proc/self */
79102 + gr_is_global_nonroot(link_inode->i_uid) && target &&
79103 + !uid_eq(link_inode->i_uid, target->i_uid)) {
79104 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
79105 + return 1;
79106 + }
79107 +#endif
79108 + return 0;
79109 +}
79110 +
79111 +int
79112 +gr_handle_follow_link(const struct inode *parent,
79113 + const struct inode *inode,
79114 + const struct dentry *dentry, const struct vfsmount *mnt)
79115 +{
79116 +#ifdef CONFIG_GRKERNSEC_LINK
79117 + const struct cred *cred = current_cred();
79118 +
79119 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
79120 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
79121 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
79122 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
79123 + return -EACCES;
79124 + }
79125 +#endif
79126 + return 0;
79127 +}
79128 +
79129 +int
79130 +gr_handle_hardlink(const struct dentry *dentry,
79131 + const struct vfsmount *mnt,
79132 + struct inode *inode, const int mode, const struct filename *to)
79133 +{
79134 +#ifdef CONFIG_GRKERNSEC_LINK
79135 + const struct cred *cred = current_cred();
79136 +
79137 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
79138 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
79139 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
79140 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
79141 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
79142 + return -EPERM;
79143 + }
79144 +#endif
79145 + return 0;
79146 +}
79147 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
79148 new file mode 100644
79149 index 0000000..dbe0a6b
79150 --- /dev/null
79151 +++ b/grsecurity/grsec_log.c
79152 @@ -0,0 +1,341 @@
79153 +#include <linux/kernel.h>
79154 +#include <linux/sched.h>
79155 +#include <linux/file.h>
79156 +#include <linux/tty.h>
79157 +#include <linux/fs.h>
79158 +#include <linux/mm.h>
79159 +#include <linux/grinternal.h>
79160 +
79161 +#ifdef CONFIG_TREE_PREEMPT_RCU
79162 +#define DISABLE_PREEMPT() preempt_disable()
79163 +#define ENABLE_PREEMPT() preempt_enable()
79164 +#else
79165 +#define DISABLE_PREEMPT()
79166 +#define ENABLE_PREEMPT()
79167 +#endif
79168 +
79169 +#define BEGIN_LOCKS(x) \
79170 + DISABLE_PREEMPT(); \
79171 + rcu_read_lock(); \
79172 + read_lock(&tasklist_lock); \
79173 + read_lock(&grsec_exec_file_lock); \
79174 + if (x != GR_DO_AUDIT) \
79175 + spin_lock(&grsec_alert_lock); \
79176 + else \
79177 + spin_lock(&grsec_audit_lock)
79178 +
79179 +#define END_LOCKS(x) \
79180 + if (x != GR_DO_AUDIT) \
79181 + spin_unlock(&grsec_alert_lock); \
79182 + else \
79183 + spin_unlock(&grsec_audit_lock); \
79184 + read_unlock(&grsec_exec_file_lock); \
79185 + read_unlock(&tasklist_lock); \
79186 + rcu_read_unlock(); \
79187 + ENABLE_PREEMPT(); \
79188 + if (x == GR_DONT_AUDIT) \
79189 + gr_handle_alertkill(current)
79190 +
79191 +enum {
79192 + FLOODING,
79193 + NO_FLOODING
79194 +};
79195 +
79196 +extern char *gr_alert_log_fmt;
79197 +extern char *gr_audit_log_fmt;
79198 +extern char *gr_alert_log_buf;
79199 +extern char *gr_audit_log_buf;
79200 +
79201 +static int gr_log_start(int audit)
79202 +{
79203 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
79204 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
79205 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
79206 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
79207 + unsigned long curr_secs = get_seconds();
79208 +
79209 + if (audit == GR_DO_AUDIT)
79210 + goto set_fmt;
79211 +
79212 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
79213 + grsec_alert_wtime = curr_secs;
79214 + grsec_alert_fyet = 0;
79215 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
79216 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
79217 + grsec_alert_fyet++;
79218 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
79219 + grsec_alert_wtime = curr_secs;
79220 + grsec_alert_fyet++;
79221 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
79222 + return FLOODING;
79223 + }
79224 + else return FLOODING;
79225 +
79226 +set_fmt:
79227 +#endif
79228 + memset(buf, 0, PAGE_SIZE);
79229 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
79230 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
79231 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
79232 + } else if (current->signal->curr_ip) {
79233 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
79234 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
79235 + } else if (gr_acl_is_enabled()) {
79236 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
79237 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
79238 + } else {
79239 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
79240 + strcpy(buf, fmt);
79241 + }
79242 +
79243 + return NO_FLOODING;
79244 +}
79245 +
79246 +static void gr_log_middle(int audit, const char *msg, va_list ap)
79247 + __attribute__ ((format (printf, 2, 0)));
79248 +
79249 +static void gr_log_middle(int audit, const char *msg, va_list ap)
79250 +{
79251 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
79252 + unsigned int len = strlen(buf);
79253 +
79254 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
79255 +
79256 + return;
79257 +}
79258 +
79259 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
79260 + __attribute__ ((format (printf, 2, 3)));
79261 +
79262 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
79263 +{
79264 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
79265 + unsigned int len = strlen(buf);
79266 + va_list ap;
79267 +
79268 + va_start(ap, msg);
79269 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
79270 + va_end(ap);
79271 +
79272 + return;
79273 +}
79274 +
79275 +static void gr_log_end(int audit, int append_default)
79276 +{
79277 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
79278 + if (append_default) {
79279 + struct task_struct *task = current;
79280 + struct task_struct *parent = task->real_parent;
79281 + const struct cred *cred = __task_cred(task);
79282 + const struct cred *pcred = __task_cred(parent);
79283 + unsigned int len = strlen(buf);
79284 +
79285 + 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));
79286 + }
79287 +
79288 + printk("%s\n", buf);
79289 +
79290 + return;
79291 +}
79292 +
79293 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
79294 +{
79295 + int logtype;
79296 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
79297 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
79298 + void *voidptr = NULL;
79299 + int num1 = 0, num2 = 0;
79300 + unsigned long ulong1 = 0, ulong2 = 0;
79301 + struct dentry *dentry = NULL;
79302 + struct vfsmount *mnt = NULL;
79303 + struct file *file = NULL;
79304 + struct task_struct *task = NULL;
79305 + struct vm_area_struct *vma = NULL;
79306 + const struct cred *cred, *pcred;
79307 + va_list ap;
79308 +
79309 + BEGIN_LOCKS(audit);
79310 + logtype = gr_log_start(audit);
79311 + if (logtype == FLOODING) {
79312 + END_LOCKS(audit);
79313 + return;
79314 + }
79315 + va_start(ap, argtypes);
79316 + switch (argtypes) {
79317 + case GR_TTYSNIFF:
79318 + task = va_arg(ap, struct task_struct *);
79319 + 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));
79320 + break;
79321 + case GR_SYSCTL_HIDDEN:
79322 + str1 = va_arg(ap, char *);
79323 + gr_log_middle_varargs(audit, msg, result, str1);
79324 + break;
79325 + case GR_RBAC:
79326 + dentry = va_arg(ap, struct dentry *);
79327 + mnt = va_arg(ap, struct vfsmount *);
79328 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
79329 + break;
79330 + case GR_RBAC_STR:
79331 + dentry = va_arg(ap, struct dentry *);
79332 + mnt = va_arg(ap, struct vfsmount *);
79333 + str1 = va_arg(ap, char *);
79334 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
79335 + break;
79336 + case GR_STR_RBAC:
79337 + str1 = va_arg(ap, char *);
79338 + dentry = va_arg(ap, struct dentry *);
79339 + mnt = va_arg(ap, struct vfsmount *);
79340 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
79341 + break;
79342 + case GR_RBAC_MODE2:
79343 + dentry = va_arg(ap, struct dentry *);
79344 + mnt = va_arg(ap, struct vfsmount *);
79345 + str1 = va_arg(ap, char *);
79346 + str2 = va_arg(ap, char *);
79347 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
79348 + break;
79349 + case GR_RBAC_MODE3:
79350 + dentry = va_arg(ap, struct dentry *);
79351 + mnt = va_arg(ap, struct vfsmount *);
79352 + str1 = va_arg(ap, char *);
79353 + str2 = va_arg(ap, char *);
79354 + str3 = va_arg(ap, char *);
79355 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
79356 + break;
79357 + case GR_FILENAME:
79358 + dentry = va_arg(ap, struct dentry *);
79359 + mnt = va_arg(ap, struct vfsmount *);
79360 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
79361 + break;
79362 + case GR_STR_FILENAME:
79363 + str1 = va_arg(ap, char *);
79364 + dentry = va_arg(ap, struct dentry *);
79365 + mnt = va_arg(ap, struct vfsmount *);
79366 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
79367 + break;
79368 + case GR_FILENAME_STR:
79369 + dentry = va_arg(ap, struct dentry *);
79370 + mnt = va_arg(ap, struct vfsmount *);
79371 + str1 = va_arg(ap, char *);
79372 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
79373 + break;
79374 + case GR_FILENAME_TWO_INT:
79375 + dentry = va_arg(ap, struct dentry *);
79376 + mnt = va_arg(ap, struct vfsmount *);
79377 + num1 = va_arg(ap, int);
79378 + num2 = va_arg(ap, int);
79379 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
79380 + break;
79381 + case GR_FILENAME_TWO_INT_STR:
79382 + dentry = va_arg(ap, struct dentry *);
79383 + mnt = va_arg(ap, struct vfsmount *);
79384 + num1 = va_arg(ap, int);
79385 + num2 = va_arg(ap, int);
79386 + str1 = va_arg(ap, char *);
79387 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
79388 + break;
79389 + case GR_TEXTREL:
79390 + file = va_arg(ap, struct file *);
79391 + ulong1 = va_arg(ap, unsigned long);
79392 + ulong2 = va_arg(ap, unsigned long);
79393 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
79394 + break;
79395 + case GR_PTRACE:
79396 + task = va_arg(ap, struct task_struct *);
79397 + 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));
79398 + break;
79399 + case GR_RESOURCE:
79400 + task = va_arg(ap, struct task_struct *);
79401 + cred = __task_cred(task);
79402 + pcred = __task_cred(task->real_parent);
79403 + ulong1 = va_arg(ap, unsigned long);
79404 + str1 = va_arg(ap, char *);
79405 + ulong2 = va_arg(ap, unsigned long);
79406 + 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));
79407 + break;
79408 + case GR_CAP:
79409 + task = va_arg(ap, struct task_struct *);
79410 + cred = __task_cred(task);
79411 + pcred = __task_cred(task->real_parent);
79412 + str1 = va_arg(ap, char *);
79413 + 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));
79414 + break;
79415 + case GR_SIG:
79416 + str1 = va_arg(ap, char *);
79417 + voidptr = va_arg(ap, void *);
79418 + gr_log_middle_varargs(audit, msg, str1, voidptr);
79419 + break;
79420 + case GR_SIG2:
79421 + task = va_arg(ap, struct task_struct *);
79422 + cred = __task_cred(task);
79423 + pcred = __task_cred(task->real_parent);
79424 + num1 = va_arg(ap, int);
79425 + 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));
79426 + break;
79427 + case GR_CRASH1:
79428 + task = va_arg(ap, struct task_struct *);
79429 + cred = __task_cred(task);
79430 + pcred = __task_cred(task->real_parent);
79431 + ulong1 = va_arg(ap, unsigned long);
79432 + 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);
79433 + break;
79434 + case GR_CRASH2:
79435 + task = va_arg(ap, struct task_struct *);
79436 + cred = __task_cred(task);
79437 + pcred = __task_cred(task->real_parent);
79438 + ulong1 = va_arg(ap, unsigned long);
79439 + 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);
79440 + break;
79441 + case GR_RWXMAP:
79442 + file = va_arg(ap, struct file *);
79443 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
79444 + break;
79445 + case GR_RWXMAPVMA:
79446 + vma = va_arg(ap, struct vm_area_struct *);
79447 + if (vma->vm_file)
79448 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
79449 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
79450 + str1 = "<stack>";
79451 + else if (vma->vm_start <= current->mm->brk &&
79452 + vma->vm_end >= current->mm->start_brk)
79453 + str1 = "<heap>";
79454 + else
79455 + str1 = "<anonymous mapping>";
79456 + gr_log_middle_varargs(audit, msg, str1);
79457 + break;
79458 + case GR_PSACCT:
79459 + {
79460 + unsigned int wday, cday;
79461 + __u8 whr, chr;
79462 + __u8 wmin, cmin;
79463 + __u8 wsec, csec;
79464 + char cur_tty[64] = { 0 };
79465 + char parent_tty[64] = { 0 };
79466 +
79467 + task = va_arg(ap, struct task_struct *);
79468 + wday = va_arg(ap, unsigned int);
79469 + cday = va_arg(ap, unsigned int);
79470 + whr = va_arg(ap, int);
79471 + chr = va_arg(ap, int);
79472 + wmin = va_arg(ap, int);
79473 + cmin = va_arg(ap, int);
79474 + wsec = va_arg(ap, int);
79475 + csec = va_arg(ap, int);
79476 + ulong1 = va_arg(ap, unsigned long);
79477 + cred = __task_cred(task);
79478 + pcred = __task_cred(task->real_parent);
79479 +
79480 + 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));
79481 + }
79482 + break;
79483 + default:
79484 + gr_log_middle(audit, msg, ap);
79485 + }
79486 + va_end(ap);
79487 + // these don't need DEFAULTSECARGS printed on the end
79488 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
79489 + gr_log_end(audit, 0);
79490 + else
79491 + gr_log_end(audit, 1);
79492 + END_LOCKS(audit);
79493 +}
79494 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
79495 new file mode 100644
79496 index 0000000..0e39d8c
79497 --- /dev/null
79498 +++ b/grsecurity/grsec_mem.c
79499 @@ -0,0 +1,48 @@
79500 +#include <linux/kernel.h>
79501 +#include <linux/sched.h>
79502 +#include <linux/mm.h>
79503 +#include <linux/mman.h>
79504 +#include <linux/module.h>
79505 +#include <linux/grinternal.h>
79506 +
79507 +void gr_handle_msr_write(void)
79508 +{
79509 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
79510 + return;
79511 +}
79512 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
79513 +
79514 +void
79515 +gr_handle_ioperm(void)
79516 +{
79517 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
79518 + return;
79519 +}
79520 +
79521 +void
79522 +gr_handle_iopl(void)
79523 +{
79524 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
79525 + return;
79526 +}
79527 +
79528 +void
79529 +gr_handle_mem_readwrite(u64 from, u64 to)
79530 +{
79531 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
79532 + return;
79533 +}
79534 +
79535 +void
79536 +gr_handle_vm86(void)
79537 +{
79538 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
79539 + return;
79540 +}
79541 +
79542 +void
79543 +gr_log_badprocpid(const char *entry)
79544 +{
79545 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
79546 + return;
79547 +}
79548 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
79549 new file mode 100644
79550 index 0000000..cd9e124
79551 --- /dev/null
79552 +++ b/grsecurity/grsec_mount.c
79553 @@ -0,0 +1,65 @@
79554 +#include <linux/kernel.h>
79555 +#include <linux/sched.h>
79556 +#include <linux/mount.h>
79557 +#include <linux/major.h>
79558 +#include <linux/grsecurity.h>
79559 +#include <linux/grinternal.h>
79560 +
79561 +void
79562 +gr_log_remount(const char *devname, const int retval)
79563 +{
79564 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79565 + if (grsec_enable_mount && (retval >= 0))
79566 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
79567 +#endif
79568 + return;
79569 +}
79570 +
79571 +void
79572 +gr_log_unmount(const char *devname, const int retval)
79573 +{
79574 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79575 + if (grsec_enable_mount && (retval >= 0))
79576 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
79577 +#endif
79578 + return;
79579 +}
79580 +
79581 +void
79582 +gr_log_mount(const char *from, const char *to, const int retval)
79583 +{
79584 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79585 + if (grsec_enable_mount && (retval >= 0))
79586 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
79587 +#endif
79588 + return;
79589 +}
79590 +
79591 +int
79592 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
79593 +{
79594 +#ifdef CONFIG_GRKERNSEC_ROFS
79595 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
79596 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
79597 + return -EPERM;
79598 + } else
79599 + return 0;
79600 +#endif
79601 + return 0;
79602 +}
79603 +
79604 +int
79605 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
79606 +{
79607 +#ifdef CONFIG_GRKERNSEC_ROFS
79608 + struct inode *inode = dentry->d_inode;
79609 +
79610 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
79611 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
79612 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
79613 + return -EPERM;
79614 + } else
79615 + return 0;
79616 +#endif
79617 + return 0;
79618 +}
79619 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
79620 new file mode 100644
79621 index 0000000..6ee9d50
79622 --- /dev/null
79623 +++ b/grsecurity/grsec_pax.c
79624 @@ -0,0 +1,45 @@
79625 +#include <linux/kernel.h>
79626 +#include <linux/sched.h>
79627 +#include <linux/mm.h>
79628 +#include <linux/file.h>
79629 +#include <linux/grinternal.h>
79630 +#include <linux/grsecurity.h>
79631 +
79632 +void
79633 +gr_log_textrel(struct vm_area_struct * vma)
79634 +{
79635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79636 + if (grsec_enable_log_rwxmaps)
79637 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
79638 +#endif
79639 + return;
79640 +}
79641 +
79642 +void gr_log_ptgnustack(struct file *file)
79643 +{
79644 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79645 + if (grsec_enable_log_rwxmaps)
79646 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
79647 +#endif
79648 + return;
79649 +}
79650 +
79651 +void
79652 +gr_log_rwxmmap(struct file *file)
79653 +{
79654 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79655 + if (grsec_enable_log_rwxmaps)
79656 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
79657 +#endif
79658 + return;
79659 +}
79660 +
79661 +void
79662 +gr_log_rwxmprotect(struct vm_area_struct *vma)
79663 +{
79664 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79665 + if (grsec_enable_log_rwxmaps)
79666 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
79667 +#endif
79668 + return;
79669 +}
79670 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
79671 new file mode 100644
79672 index 0000000..2005a3a
79673 --- /dev/null
79674 +++ b/grsecurity/grsec_proc.c
79675 @@ -0,0 +1,20 @@
79676 +#include <linux/kernel.h>
79677 +#include <linux/sched.h>
79678 +#include <linux/grsecurity.h>
79679 +#include <linux/grinternal.h>
79680 +
79681 +int gr_proc_is_restricted(void)
79682 +{
79683 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79684 + const struct cred *cred = current_cred();
79685 +#endif
79686 +
79687 +#ifdef CONFIG_GRKERNSEC_PROC_USER
79688 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
79689 + return -EACCES;
79690 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79691 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
79692 + return -EACCES;
79693 +#endif
79694 + return 0;
79695 +}
79696 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
79697 new file mode 100644
79698 index 0000000..f7f29aa
79699 --- /dev/null
79700 +++ b/grsecurity/grsec_ptrace.c
79701 @@ -0,0 +1,30 @@
79702 +#include <linux/kernel.h>
79703 +#include <linux/sched.h>
79704 +#include <linux/grinternal.h>
79705 +#include <linux/security.h>
79706 +
79707 +void
79708 +gr_audit_ptrace(struct task_struct *task)
79709 +{
79710 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79711 + if (grsec_enable_audit_ptrace)
79712 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
79713 +#endif
79714 + return;
79715 +}
79716 +
79717 +int
79718 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
79719 +{
79720 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79721 + const struct dentry *dentry = file->f_path.dentry;
79722 + const struct vfsmount *mnt = file->f_path.mnt;
79723 +
79724 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
79725 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
79726 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
79727 + return -EACCES;
79728 + }
79729 +#endif
79730 + return 0;
79731 +}
79732 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
79733 new file mode 100644
79734 index 0000000..3860c7e
79735 --- /dev/null
79736 +++ b/grsecurity/grsec_sig.c
79737 @@ -0,0 +1,236 @@
79738 +#include <linux/kernel.h>
79739 +#include <linux/sched.h>
79740 +#include <linux/fs.h>
79741 +#include <linux/delay.h>
79742 +#include <linux/grsecurity.h>
79743 +#include <linux/grinternal.h>
79744 +#include <linux/hardirq.h>
79745 +
79746 +char *signames[] = {
79747 + [SIGSEGV] = "Segmentation fault",
79748 + [SIGILL] = "Illegal instruction",
79749 + [SIGABRT] = "Abort",
79750 + [SIGBUS] = "Invalid alignment/Bus error"
79751 +};
79752 +
79753 +void
79754 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
79755 +{
79756 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79757 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
79758 + (sig == SIGABRT) || (sig == SIGBUS))) {
79759 + if (task_pid_nr(t) == task_pid_nr(current)) {
79760 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
79761 + } else {
79762 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
79763 + }
79764 + }
79765 +#endif
79766 + return;
79767 +}
79768 +
79769 +int
79770 +gr_handle_signal(const struct task_struct *p, const int sig)
79771 +{
79772 +#ifdef CONFIG_GRKERNSEC
79773 + /* ignore the 0 signal for protected task checks */
79774 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
79775 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
79776 + return -EPERM;
79777 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
79778 + return -EPERM;
79779 + }
79780 +#endif
79781 + return 0;
79782 +}
79783 +
79784 +#ifdef CONFIG_GRKERNSEC
79785 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
79786 +
79787 +int gr_fake_force_sig(int sig, struct task_struct *t)
79788 +{
79789 + unsigned long int flags;
79790 + int ret, blocked, ignored;
79791 + struct k_sigaction *action;
79792 +
79793 + spin_lock_irqsave(&t->sighand->siglock, flags);
79794 + action = &t->sighand->action[sig-1];
79795 + ignored = action->sa.sa_handler == SIG_IGN;
79796 + blocked = sigismember(&t->blocked, sig);
79797 + if (blocked || ignored) {
79798 + action->sa.sa_handler = SIG_DFL;
79799 + if (blocked) {
79800 + sigdelset(&t->blocked, sig);
79801 + recalc_sigpending_and_wake(t);
79802 + }
79803 + }
79804 + if (action->sa.sa_handler == SIG_DFL)
79805 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
79806 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
79807 +
79808 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
79809 +
79810 + return ret;
79811 +}
79812 +#endif
79813 +
79814 +#define GR_USER_BAN_TIME (15 * 60)
79815 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
79816 +
79817 +void gr_handle_brute_attach(int dumpable)
79818 +{
79819 +#ifdef CONFIG_GRKERNSEC_BRUTE
79820 + struct task_struct *p = current;
79821 + kuid_t uid = GLOBAL_ROOT_UID;
79822 + int daemon = 0;
79823 +
79824 + if (!grsec_enable_brute)
79825 + return;
79826 +
79827 + rcu_read_lock();
79828 + read_lock(&tasklist_lock);
79829 + read_lock(&grsec_exec_file_lock);
79830 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
79831 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
79832 + p->real_parent->brute = 1;
79833 + daemon = 1;
79834 + } else {
79835 + const struct cred *cred = __task_cred(p), *cred2;
79836 + struct task_struct *tsk, *tsk2;
79837 +
79838 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
79839 + struct user_struct *user;
79840 +
79841 + uid = cred->uid;
79842 +
79843 + /* this is put upon execution past expiration */
79844 + user = find_user(uid);
79845 + if (user == NULL)
79846 + goto unlock;
79847 + user->suid_banned = 1;
79848 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
79849 + if (user->suid_ban_expires == ~0UL)
79850 + user->suid_ban_expires--;
79851 +
79852 + /* only kill other threads of the same binary, from the same user */
79853 + do_each_thread(tsk2, tsk) {
79854 + cred2 = __task_cred(tsk);
79855 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
79856 + gr_fake_force_sig(SIGKILL, tsk);
79857 + } while_each_thread(tsk2, tsk);
79858 + }
79859 + }
79860 +unlock:
79861 + read_unlock(&grsec_exec_file_lock);
79862 + read_unlock(&tasklist_lock);
79863 + rcu_read_unlock();
79864 +
79865 + if (gr_is_global_nonroot(uid))
79866 + 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);
79867 + else if (daemon)
79868 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
79869 +
79870 +#endif
79871 + return;
79872 +}
79873 +
79874 +void gr_handle_brute_check(void)
79875 +{
79876 +#ifdef CONFIG_GRKERNSEC_BRUTE
79877 + struct task_struct *p = current;
79878 +
79879 + if (unlikely(p->brute)) {
79880 + if (!grsec_enable_brute)
79881 + p->brute = 0;
79882 + else if (time_before(get_seconds(), p->brute_expires))
79883 + msleep(30 * 1000);
79884 + }
79885 +#endif
79886 + return;
79887 +}
79888 +
79889 +void gr_handle_kernel_exploit(void)
79890 +{
79891 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79892 + const struct cred *cred;
79893 + struct task_struct *tsk, *tsk2;
79894 + struct user_struct *user;
79895 + kuid_t uid;
79896 +
79897 + if (in_irq() || in_serving_softirq() || in_nmi())
79898 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
79899 +
79900 + uid = current_uid();
79901 +
79902 + if (gr_is_global_root(uid))
79903 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
79904 + else {
79905 + /* kill all the processes of this user, hold a reference
79906 + to their creds struct, and prevent them from creating
79907 + another process until system reset
79908 + */
79909 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
79910 + GR_GLOBAL_UID(uid));
79911 + /* we intentionally leak this ref */
79912 + user = get_uid(current->cred->user);
79913 + if (user)
79914 + user->kernel_banned = 1;
79915 +
79916 + /* kill all processes of this user */
79917 + read_lock(&tasklist_lock);
79918 + do_each_thread(tsk2, tsk) {
79919 + cred = __task_cred(tsk);
79920 + if (uid_eq(cred->uid, uid))
79921 + gr_fake_force_sig(SIGKILL, tsk);
79922 + } while_each_thread(tsk2, tsk);
79923 + read_unlock(&tasklist_lock);
79924 + }
79925 +#endif
79926 +}
79927 +
79928 +#ifdef CONFIG_GRKERNSEC_BRUTE
79929 +static bool suid_ban_expired(struct user_struct *user)
79930 +{
79931 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
79932 + user->suid_banned = 0;
79933 + user->suid_ban_expires = 0;
79934 + free_uid(user);
79935 + return true;
79936 + }
79937 +
79938 + return false;
79939 +}
79940 +#endif
79941 +
79942 +int gr_process_kernel_exec_ban(void)
79943 +{
79944 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79945 + if (unlikely(current->cred->user->kernel_banned))
79946 + return -EPERM;
79947 +#endif
79948 + return 0;
79949 +}
79950 +
79951 +int gr_process_kernel_setuid_ban(struct user_struct *user)
79952 +{
79953 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
79954 + if (unlikely(user->kernel_banned))
79955 + gr_fake_force_sig(SIGKILL, current);
79956 +#endif
79957 + return 0;
79958 +}
79959 +
79960 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
79961 +{
79962 +#ifdef CONFIG_GRKERNSEC_BRUTE
79963 + struct user_struct *user = current->cred->user;
79964 + if (unlikely(user->suid_banned)) {
79965 + if (suid_ban_expired(user))
79966 + return 0;
79967 + /* disallow execution of suid binaries only */
79968 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
79969 + return -EPERM;
79970 + }
79971 +#endif
79972 + return 0;
79973 +}
79974 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
79975 new file mode 100644
79976 index 0000000..c0aef3a
79977 --- /dev/null
79978 +++ b/grsecurity/grsec_sock.c
79979 @@ -0,0 +1,244 @@
79980 +#include <linux/kernel.h>
79981 +#include <linux/module.h>
79982 +#include <linux/sched.h>
79983 +#include <linux/file.h>
79984 +#include <linux/net.h>
79985 +#include <linux/in.h>
79986 +#include <linux/ip.h>
79987 +#include <net/sock.h>
79988 +#include <net/inet_sock.h>
79989 +#include <linux/grsecurity.h>
79990 +#include <linux/grinternal.h>
79991 +#include <linux/gracl.h>
79992 +
79993 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
79994 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
79995 +
79996 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
79997 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
79998 +
79999 +#ifdef CONFIG_UNIX_MODULE
80000 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
80001 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
80002 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
80003 +EXPORT_SYMBOL_GPL(gr_handle_create);
80004 +#endif
80005 +
80006 +#ifdef CONFIG_GRKERNSEC
80007 +#define gr_conn_table_size 32749
80008 +struct conn_table_entry {
80009 + struct conn_table_entry *next;
80010 + struct signal_struct *sig;
80011 +};
80012 +
80013 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
80014 +DEFINE_SPINLOCK(gr_conn_table_lock);
80015 +
80016 +extern const char * gr_socktype_to_name(unsigned char type);
80017 +extern const char * gr_proto_to_name(unsigned char proto);
80018 +extern const char * gr_sockfamily_to_name(unsigned char family);
80019 +
80020 +static __inline__ int
80021 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
80022 +{
80023 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
80024 +}
80025 +
80026 +static __inline__ int
80027 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
80028 + __u16 sport, __u16 dport)
80029 +{
80030 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
80031 + sig->gr_sport == sport && sig->gr_dport == dport))
80032 + return 1;
80033 + else
80034 + return 0;
80035 +}
80036 +
80037 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
80038 +{
80039 + struct conn_table_entry **match;
80040 + unsigned int index;
80041 +
80042 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
80043 + sig->gr_sport, sig->gr_dport,
80044 + gr_conn_table_size);
80045 +
80046 + newent->sig = sig;
80047 +
80048 + match = &gr_conn_table[index];
80049 + newent->next = *match;
80050 + *match = newent;
80051 +
80052 + return;
80053 +}
80054 +
80055 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
80056 +{
80057 + struct conn_table_entry *match, *last = NULL;
80058 + unsigned int index;
80059 +
80060 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
80061 + sig->gr_sport, sig->gr_dport,
80062 + gr_conn_table_size);
80063 +
80064 + match = gr_conn_table[index];
80065 + while (match && !conn_match(match->sig,
80066 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
80067 + sig->gr_dport)) {
80068 + last = match;
80069 + match = match->next;
80070 + }
80071 +
80072 + if (match) {
80073 + if (last)
80074 + last->next = match->next;
80075 + else
80076 + gr_conn_table[index] = NULL;
80077 + kfree(match);
80078 + }
80079 +
80080 + return;
80081 +}
80082 +
80083 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
80084 + __u16 sport, __u16 dport)
80085 +{
80086 + struct conn_table_entry *match;
80087 + unsigned int index;
80088 +
80089 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
80090 +
80091 + match = gr_conn_table[index];
80092 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
80093 + match = match->next;
80094 +
80095 + if (match)
80096 + return match->sig;
80097 + else
80098 + return NULL;
80099 +}
80100 +
80101 +#endif
80102 +
80103 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
80104 +{
80105 +#ifdef CONFIG_GRKERNSEC
80106 + struct signal_struct *sig = task->signal;
80107 + struct conn_table_entry *newent;
80108 +
80109 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
80110 + if (newent == NULL)
80111 + return;
80112 + /* no bh lock needed since we are called with bh disabled */
80113 + spin_lock(&gr_conn_table_lock);
80114 + gr_del_task_from_ip_table_nolock(sig);
80115 + sig->gr_saddr = inet->inet_rcv_saddr;
80116 + sig->gr_daddr = inet->inet_daddr;
80117 + sig->gr_sport = inet->inet_sport;
80118 + sig->gr_dport = inet->inet_dport;
80119 + gr_add_to_task_ip_table_nolock(sig, newent);
80120 + spin_unlock(&gr_conn_table_lock);
80121 +#endif
80122 + return;
80123 +}
80124 +
80125 +void gr_del_task_from_ip_table(struct task_struct *task)
80126 +{
80127 +#ifdef CONFIG_GRKERNSEC
80128 + spin_lock_bh(&gr_conn_table_lock);
80129 + gr_del_task_from_ip_table_nolock(task->signal);
80130 + spin_unlock_bh(&gr_conn_table_lock);
80131 +#endif
80132 + return;
80133 +}
80134 +
80135 +void
80136 +gr_attach_curr_ip(const struct sock *sk)
80137 +{
80138 +#ifdef CONFIG_GRKERNSEC
80139 + struct signal_struct *p, *set;
80140 + const struct inet_sock *inet = inet_sk(sk);
80141 +
80142 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
80143 + return;
80144 +
80145 + set = current->signal;
80146 +
80147 + spin_lock_bh(&gr_conn_table_lock);
80148 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
80149 + inet->inet_dport, inet->inet_sport);
80150 + if (unlikely(p != NULL)) {
80151 + set->curr_ip = p->curr_ip;
80152 + set->used_accept = 1;
80153 + gr_del_task_from_ip_table_nolock(p);
80154 + spin_unlock_bh(&gr_conn_table_lock);
80155 + return;
80156 + }
80157 + spin_unlock_bh(&gr_conn_table_lock);
80158 +
80159 + set->curr_ip = inet->inet_daddr;
80160 + set->used_accept = 1;
80161 +#endif
80162 + return;
80163 +}
80164 +
80165 +int
80166 +gr_handle_sock_all(const int family, const int type, const int protocol)
80167 +{
80168 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
80169 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
80170 + (family != AF_UNIX)) {
80171 + if (family == AF_INET)
80172 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
80173 + else
80174 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
80175 + return -EACCES;
80176 + }
80177 +#endif
80178 + return 0;
80179 +}
80180 +
80181 +int
80182 +gr_handle_sock_server(const struct sockaddr *sck)
80183 +{
80184 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
80185 + if (grsec_enable_socket_server &&
80186 + in_group_p(grsec_socket_server_gid) &&
80187 + sck && (sck->sa_family != AF_UNIX) &&
80188 + (sck->sa_family != AF_LOCAL)) {
80189 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
80190 + return -EACCES;
80191 + }
80192 +#endif
80193 + return 0;
80194 +}
80195 +
80196 +int
80197 +gr_handle_sock_server_other(const struct sock *sck)
80198 +{
80199 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
80200 + if (grsec_enable_socket_server &&
80201 + in_group_p(grsec_socket_server_gid) &&
80202 + sck && (sck->sk_family != AF_UNIX) &&
80203 + (sck->sk_family != AF_LOCAL)) {
80204 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
80205 + return -EACCES;
80206 + }
80207 +#endif
80208 + return 0;
80209 +}
80210 +
80211 +int
80212 +gr_handle_sock_client(const struct sockaddr *sck)
80213 +{
80214 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
80215 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
80216 + sck && (sck->sa_family != AF_UNIX) &&
80217 + (sck->sa_family != AF_LOCAL)) {
80218 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
80219 + return -EACCES;
80220 + }
80221 +#endif
80222 + return 0;
80223 +}
80224 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
80225 new file mode 100644
80226 index 0000000..8159888
80227 --- /dev/null
80228 +++ b/grsecurity/grsec_sysctl.c
80229 @@ -0,0 +1,479 @@
80230 +#include <linux/kernel.h>
80231 +#include <linux/sched.h>
80232 +#include <linux/sysctl.h>
80233 +#include <linux/grsecurity.h>
80234 +#include <linux/grinternal.h>
80235 +
80236 +int
80237 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
80238 +{
80239 +#ifdef CONFIG_GRKERNSEC_SYSCTL
80240 + if (dirname == NULL || name == NULL)
80241 + return 0;
80242 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
80243 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
80244 + return -EACCES;
80245 + }
80246 +#endif
80247 + return 0;
80248 +}
80249 +
80250 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
80251 +static int __maybe_unused __read_only one = 1;
80252 +#endif
80253 +
80254 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
80255 + defined(CONFIG_GRKERNSEC_DENYUSB)
80256 +struct ctl_table grsecurity_table[] = {
80257 +#ifdef CONFIG_GRKERNSEC_SYSCTL
80258 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
80259 +#ifdef CONFIG_GRKERNSEC_IO
80260 + {
80261 + .procname = "disable_priv_io",
80262 + .data = &grsec_disable_privio,
80263 + .maxlen = sizeof(int),
80264 + .mode = 0600,
80265 + .proc_handler = &proc_dointvec,
80266 + },
80267 +#endif
80268 +#endif
80269 +#ifdef CONFIG_GRKERNSEC_LINK
80270 + {
80271 + .procname = "linking_restrictions",
80272 + .data = &grsec_enable_link,
80273 + .maxlen = sizeof(int),
80274 + .mode = 0600,
80275 + .proc_handler = &proc_dointvec,
80276 + },
80277 +#endif
80278 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
80279 + {
80280 + .procname = "enforce_symlinksifowner",
80281 + .data = &grsec_enable_symlinkown,
80282 + .maxlen = sizeof(int),
80283 + .mode = 0600,
80284 + .proc_handler = &proc_dointvec,
80285 + },
80286 + {
80287 + .procname = "symlinkown_gid",
80288 + .data = &grsec_symlinkown_gid,
80289 + .maxlen = sizeof(int),
80290 + .mode = 0600,
80291 + .proc_handler = &proc_dointvec,
80292 + },
80293 +#endif
80294 +#ifdef CONFIG_GRKERNSEC_BRUTE
80295 + {
80296 + .procname = "deter_bruteforce",
80297 + .data = &grsec_enable_brute,
80298 + .maxlen = sizeof(int),
80299 + .mode = 0600,
80300 + .proc_handler = &proc_dointvec,
80301 + },
80302 +#endif
80303 +#ifdef CONFIG_GRKERNSEC_FIFO
80304 + {
80305 + .procname = "fifo_restrictions",
80306 + .data = &grsec_enable_fifo,
80307 + .maxlen = sizeof(int),
80308 + .mode = 0600,
80309 + .proc_handler = &proc_dointvec,
80310 + },
80311 +#endif
80312 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
80313 + {
80314 + .procname = "ptrace_readexec",
80315 + .data = &grsec_enable_ptrace_readexec,
80316 + .maxlen = sizeof(int),
80317 + .mode = 0600,
80318 + .proc_handler = &proc_dointvec,
80319 + },
80320 +#endif
80321 +#ifdef CONFIG_GRKERNSEC_SETXID
80322 + {
80323 + .procname = "consistent_setxid",
80324 + .data = &grsec_enable_setxid,
80325 + .maxlen = sizeof(int),
80326 + .mode = 0600,
80327 + .proc_handler = &proc_dointvec,
80328 + },
80329 +#endif
80330 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80331 + {
80332 + .procname = "ip_blackhole",
80333 + .data = &grsec_enable_blackhole,
80334 + .maxlen = sizeof(int),
80335 + .mode = 0600,
80336 + .proc_handler = &proc_dointvec,
80337 + },
80338 + {
80339 + .procname = "lastack_retries",
80340 + .data = &grsec_lastack_retries,
80341 + .maxlen = sizeof(int),
80342 + .mode = 0600,
80343 + .proc_handler = &proc_dointvec,
80344 + },
80345 +#endif
80346 +#ifdef CONFIG_GRKERNSEC_EXECLOG
80347 + {
80348 + .procname = "exec_logging",
80349 + .data = &grsec_enable_execlog,
80350 + .maxlen = sizeof(int),
80351 + .mode = 0600,
80352 + .proc_handler = &proc_dointvec,
80353 + },
80354 +#endif
80355 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
80356 + {
80357 + .procname = "rwxmap_logging",
80358 + .data = &grsec_enable_log_rwxmaps,
80359 + .maxlen = sizeof(int),
80360 + .mode = 0600,
80361 + .proc_handler = &proc_dointvec,
80362 + },
80363 +#endif
80364 +#ifdef CONFIG_GRKERNSEC_SIGNAL
80365 + {
80366 + .procname = "signal_logging",
80367 + .data = &grsec_enable_signal,
80368 + .maxlen = sizeof(int),
80369 + .mode = 0600,
80370 + .proc_handler = &proc_dointvec,
80371 + },
80372 +#endif
80373 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
80374 + {
80375 + .procname = "forkfail_logging",
80376 + .data = &grsec_enable_forkfail,
80377 + .maxlen = sizeof(int),
80378 + .mode = 0600,
80379 + .proc_handler = &proc_dointvec,
80380 + },
80381 +#endif
80382 +#ifdef CONFIG_GRKERNSEC_TIME
80383 + {
80384 + .procname = "timechange_logging",
80385 + .data = &grsec_enable_time,
80386 + .maxlen = sizeof(int),
80387 + .mode = 0600,
80388 + .proc_handler = &proc_dointvec,
80389 + },
80390 +#endif
80391 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
80392 + {
80393 + .procname = "chroot_deny_shmat",
80394 + .data = &grsec_enable_chroot_shmat,
80395 + .maxlen = sizeof(int),
80396 + .mode = 0600,
80397 + .proc_handler = &proc_dointvec,
80398 + },
80399 +#endif
80400 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
80401 + {
80402 + .procname = "chroot_deny_unix",
80403 + .data = &grsec_enable_chroot_unix,
80404 + .maxlen = sizeof(int),
80405 + .mode = 0600,
80406 + .proc_handler = &proc_dointvec,
80407 + },
80408 +#endif
80409 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
80410 + {
80411 + .procname = "chroot_deny_mount",
80412 + .data = &grsec_enable_chroot_mount,
80413 + .maxlen = sizeof(int),
80414 + .mode = 0600,
80415 + .proc_handler = &proc_dointvec,
80416 + },
80417 +#endif
80418 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
80419 + {
80420 + .procname = "chroot_deny_fchdir",
80421 + .data = &grsec_enable_chroot_fchdir,
80422 + .maxlen = sizeof(int),
80423 + .mode = 0600,
80424 + .proc_handler = &proc_dointvec,
80425 + },
80426 +#endif
80427 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
80428 + {
80429 + .procname = "chroot_deny_chroot",
80430 + .data = &grsec_enable_chroot_double,
80431 + .maxlen = sizeof(int),
80432 + .mode = 0600,
80433 + .proc_handler = &proc_dointvec,
80434 + },
80435 +#endif
80436 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
80437 + {
80438 + .procname = "chroot_deny_pivot",
80439 + .data = &grsec_enable_chroot_pivot,
80440 + .maxlen = sizeof(int),
80441 + .mode = 0600,
80442 + .proc_handler = &proc_dointvec,
80443 + },
80444 +#endif
80445 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
80446 + {
80447 + .procname = "chroot_enforce_chdir",
80448 + .data = &grsec_enable_chroot_chdir,
80449 + .maxlen = sizeof(int),
80450 + .mode = 0600,
80451 + .proc_handler = &proc_dointvec,
80452 + },
80453 +#endif
80454 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
80455 + {
80456 + .procname = "chroot_deny_chmod",
80457 + .data = &grsec_enable_chroot_chmod,
80458 + .maxlen = sizeof(int),
80459 + .mode = 0600,
80460 + .proc_handler = &proc_dointvec,
80461 + },
80462 +#endif
80463 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
80464 + {
80465 + .procname = "chroot_deny_mknod",
80466 + .data = &grsec_enable_chroot_mknod,
80467 + .maxlen = sizeof(int),
80468 + .mode = 0600,
80469 + .proc_handler = &proc_dointvec,
80470 + },
80471 +#endif
80472 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
80473 + {
80474 + .procname = "chroot_restrict_nice",
80475 + .data = &grsec_enable_chroot_nice,
80476 + .maxlen = sizeof(int),
80477 + .mode = 0600,
80478 + .proc_handler = &proc_dointvec,
80479 + },
80480 +#endif
80481 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
80482 + {
80483 + .procname = "chroot_execlog",
80484 + .data = &grsec_enable_chroot_execlog,
80485 + .maxlen = sizeof(int),
80486 + .mode = 0600,
80487 + .proc_handler = &proc_dointvec,
80488 + },
80489 +#endif
80490 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
80491 + {
80492 + .procname = "chroot_caps",
80493 + .data = &grsec_enable_chroot_caps,
80494 + .maxlen = sizeof(int),
80495 + .mode = 0600,
80496 + .proc_handler = &proc_dointvec,
80497 + },
80498 +#endif
80499 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
80500 + {
80501 + .procname = "chroot_deny_sysctl",
80502 + .data = &grsec_enable_chroot_sysctl,
80503 + .maxlen = sizeof(int),
80504 + .mode = 0600,
80505 + .proc_handler = &proc_dointvec,
80506 + },
80507 +#endif
80508 +#ifdef CONFIG_GRKERNSEC_TPE
80509 + {
80510 + .procname = "tpe",
80511 + .data = &grsec_enable_tpe,
80512 + .maxlen = sizeof(int),
80513 + .mode = 0600,
80514 + .proc_handler = &proc_dointvec,
80515 + },
80516 + {
80517 + .procname = "tpe_gid",
80518 + .data = &grsec_tpe_gid,
80519 + .maxlen = sizeof(int),
80520 + .mode = 0600,
80521 + .proc_handler = &proc_dointvec,
80522 + },
80523 +#endif
80524 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
80525 + {
80526 + .procname = "tpe_invert",
80527 + .data = &grsec_enable_tpe_invert,
80528 + .maxlen = sizeof(int),
80529 + .mode = 0600,
80530 + .proc_handler = &proc_dointvec,
80531 + },
80532 +#endif
80533 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
80534 + {
80535 + .procname = "tpe_restrict_all",
80536 + .data = &grsec_enable_tpe_all,
80537 + .maxlen = sizeof(int),
80538 + .mode = 0600,
80539 + .proc_handler = &proc_dointvec,
80540 + },
80541 +#endif
80542 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
80543 + {
80544 + .procname = "socket_all",
80545 + .data = &grsec_enable_socket_all,
80546 + .maxlen = sizeof(int),
80547 + .mode = 0600,
80548 + .proc_handler = &proc_dointvec,
80549 + },
80550 + {
80551 + .procname = "socket_all_gid",
80552 + .data = &grsec_socket_all_gid,
80553 + .maxlen = sizeof(int),
80554 + .mode = 0600,
80555 + .proc_handler = &proc_dointvec,
80556 + },
80557 +#endif
80558 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
80559 + {
80560 + .procname = "socket_client",
80561 + .data = &grsec_enable_socket_client,
80562 + .maxlen = sizeof(int),
80563 + .mode = 0600,
80564 + .proc_handler = &proc_dointvec,
80565 + },
80566 + {
80567 + .procname = "socket_client_gid",
80568 + .data = &grsec_socket_client_gid,
80569 + .maxlen = sizeof(int),
80570 + .mode = 0600,
80571 + .proc_handler = &proc_dointvec,
80572 + },
80573 +#endif
80574 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
80575 + {
80576 + .procname = "socket_server",
80577 + .data = &grsec_enable_socket_server,
80578 + .maxlen = sizeof(int),
80579 + .mode = 0600,
80580 + .proc_handler = &proc_dointvec,
80581 + },
80582 + {
80583 + .procname = "socket_server_gid",
80584 + .data = &grsec_socket_server_gid,
80585 + .maxlen = sizeof(int),
80586 + .mode = 0600,
80587 + .proc_handler = &proc_dointvec,
80588 + },
80589 +#endif
80590 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
80591 + {
80592 + .procname = "audit_group",
80593 + .data = &grsec_enable_group,
80594 + .maxlen = sizeof(int),
80595 + .mode = 0600,
80596 + .proc_handler = &proc_dointvec,
80597 + },
80598 + {
80599 + .procname = "audit_gid",
80600 + .data = &grsec_audit_gid,
80601 + .maxlen = sizeof(int),
80602 + .mode = 0600,
80603 + .proc_handler = &proc_dointvec,
80604 + },
80605 +#endif
80606 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
80607 + {
80608 + .procname = "audit_chdir",
80609 + .data = &grsec_enable_chdir,
80610 + .maxlen = sizeof(int),
80611 + .mode = 0600,
80612 + .proc_handler = &proc_dointvec,
80613 + },
80614 +#endif
80615 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
80616 + {
80617 + .procname = "audit_mount",
80618 + .data = &grsec_enable_mount,
80619 + .maxlen = sizeof(int),
80620 + .mode = 0600,
80621 + .proc_handler = &proc_dointvec,
80622 + },
80623 +#endif
80624 +#ifdef CONFIG_GRKERNSEC_DMESG
80625 + {
80626 + .procname = "dmesg",
80627 + .data = &grsec_enable_dmesg,
80628 + .maxlen = sizeof(int),
80629 + .mode = 0600,
80630 + .proc_handler = &proc_dointvec,
80631 + },
80632 +#endif
80633 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80634 + {
80635 + .procname = "chroot_findtask",
80636 + .data = &grsec_enable_chroot_findtask,
80637 + .maxlen = sizeof(int),
80638 + .mode = 0600,
80639 + .proc_handler = &proc_dointvec,
80640 + },
80641 +#endif
80642 +#ifdef CONFIG_GRKERNSEC_RESLOG
80643 + {
80644 + .procname = "resource_logging",
80645 + .data = &grsec_resource_logging,
80646 + .maxlen = sizeof(int),
80647 + .mode = 0600,
80648 + .proc_handler = &proc_dointvec,
80649 + },
80650 +#endif
80651 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
80652 + {
80653 + .procname = "audit_ptrace",
80654 + .data = &grsec_enable_audit_ptrace,
80655 + .maxlen = sizeof(int),
80656 + .mode = 0600,
80657 + .proc_handler = &proc_dointvec,
80658 + },
80659 +#endif
80660 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
80661 + {
80662 + .procname = "harden_ptrace",
80663 + .data = &grsec_enable_harden_ptrace,
80664 + .maxlen = sizeof(int),
80665 + .mode = 0600,
80666 + .proc_handler = &proc_dointvec,
80667 + },
80668 +#endif
80669 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
80670 + {
80671 + .procname = "harden_ipc",
80672 + .data = &grsec_enable_harden_ipc,
80673 + .maxlen = sizeof(int),
80674 + .mode = 0600,
80675 + .proc_handler = &proc_dointvec,
80676 + },
80677 +#endif
80678 + {
80679 + .procname = "grsec_lock",
80680 + .data = &grsec_lock,
80681 + .maxlen = sizeof(int),
80682 + .mode = 0600,
80683 + .proc_handler = &proc_dointvec,
80684 + },
80685 +#endif
80686 +#ifdef CONFIG_GRKERNSEC_ROFS
80687 + {
80688 + .procname = "romount_protect",
80689 + .data = &grsec_enable_rofs,
80690 + .maxlen = sizeof(int),
80691 + .mode = 0600,
80692 + .proc_handler = &proc_dointvec_minmax,
80693 + .extra1 = &one,
80694 + .extra2 = &one,
80695 + },
80696 +#endif
80697 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
80698 + {
80699 + .procname = "deny_new_usb",
80700 + .data = &grsec_deny_new_usb,
80701 + .maxlen = sizeof(int),
80702 + .mode = 0600,
80703 + .proc_handler = &proc_dointvec,
80704 + },
80705 +#endif
80706 + { }
80707 +};
80708 +#endif
80709 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
80710 new file mode 100644
80711 index 0000000..61b514e
80712 --- /dev/null
80713 +++ b/grsecurity/grsec_time.c
80714 @@ -0,0 +1,16 @@
80715 +#include <linux/kernel.h>
80716 +#include <linux/sched.h>
80717 +#include <linux/grinternal.h>
80718 +#include <linux/module.h>
80719 +
80720 +void
80721 +gr_log_timechange(void)
80722 +{
80723 +#ifdef CONFIG_GRKERNSEC_TIME
80724 + if (grsec_enable_time)
80725 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
80726 +#endif
80727 + return;
80728 +}
80729 +
80730 +EXPORT_SYMBOL_GPL(gr_log_timechange);
80731 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
80732 new file mode 100644
80733 index 0000000..d1953de
80734 --- /dev/null
80735 +++ b/grsecurity/grsec_tpe.c
80736 @@ -0,0 +1,78 @@
80737 +#include <linux/kernel.h>
80738 +#include <linux/sched.h>
80739 +#include <linux/file.h>
80740 +#include <linux/fs.h>
80741 +#include <linux/grinternal.h>
80742 +
80743 +extern int gr_acl_tpe_check(void);
80744 +
80745 +int
80746 +gr_tpe_allow(const struct file *file)
80747 +{
80748 +#ifdef CONFIG_GRKERNSEC
80749 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
80750 + struct inode *file_inode = file->f_path.dentry->d_inode;
80751 + const struct cred *cred = current_cred();
80752 + char *msg = NULL;
80753 + char *msg2 = NULL;
80754 +
80755 + // never restrict root
80756 + if (gr_is_global_root(cred->uid))
80757 + return 1;
80758 +
80759 + if (grsec_enable_tpe) {
80760 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
80761 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
80762 + msg = "not being in trusted group";
80763 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
80764 + msg = "being in untrusted group";
80765 +#else
80766 + if (in_group_p(grsec_tpe_gid))
80767 + msg = "being in untrusted group";
80768 +#endif
80769 + }
80770 + if (!msg && gr_acl_tpe_check())
80771 + msg = "being in untrusted role";
80772 +
80773 + // not in any affected group/role
80774 + if (!msg)
80775 + goto next_check;
80776 +
80777 + if (gr_is_global_nonroot(inode->i_uid))
80778 + msg2 = "file in non-root-owned directory";
80779 + else if (inode->i_mode & S_IWOTH)
80780 + msg2 = "file in world-writable directory";
80781 + else if (inode->i_mode & S_IWGRP)
80782 + msg2 = "file in group-writable directory";
80783 + else if (file_inode->i_mode & S_IWOTH)
80784 + msg2 = "file is world-writable";
80785 +
80786 + if (msg && msg2) {
80787 + char fullmsg[70] = {0};
80788 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
80789 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
80790 + return 0;
80791 + }
80792 + msg = NULL;
80793 +next_check:
80794 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
80795 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
80796 + return 1;
80797 +
80798 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
80799 + msg = "directory not owned by user";
80800 + else if (inode->i_mode & S_IWOTH)
80801 + msg = "file in world-writable directory";
80802 + else if (inode->i_mode & S_IWGRP)
80803 + msg = "file in group-writable directory";
80804 + else if (file_inode->i_mode & S_IWOTH)
80805 + msg = "file is world-writable";
80806 +
80807 + if (msg) {
80808 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
80809 + return 0;
80810 + }
80811 +#endif
80812 +#endif
80813 + return 1;
80814 +}
80815 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
80816 new file mode 100644
80817 index 0000000..ae02d8e
80818 --- /dev/null
80819 +++ b/grsecurity/grsec_usb.c
80820 @@ -0,0 +1,15 @@
80821 +#include <linux/kernel.h>
80822 +#include <linux/grinternal.h>
80823 +#include <linux/module.h>
80824 +
80825 +int gr_handle_new_usb(void)
80826 +{
80827 +#ifdef CONFIG_GRKERNSEC_DENYUSB
80828 + if (grsec_deny_new_usb) {
80829 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
80830 + return 1;
80831 + }
80832 +#endif
80833 + return 0;
80834 +}
80835 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
80836 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
80837 new file mode 100644
80838 index 0000000..158b330
80839 --- /dev/null
80840 +++ b/grsecurity/grsum.c
80841 @@ -0,0 +1,64 @@
80842 +#include <linux/err.h>
80843 +#include <linux/kernel.h>
80844 +#include <linux/sched.h>
80845 +#include <linux/mm.h>
80846 +#include <linux/scatterlist.h>
80847 +#include <linux/crypto.h>
80848 +#include <linux/gracl.h>
80849 +
80850 +
80851 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
80852 +#error "crypto and sha256 must be built into the kernel"
80853 +#endif
80854 +
80855 +int
80856 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
80857 +{
80858 + struct crypto_hash *tfm;
80859 + struct hash_desc desc;
80860 + struct scatterlist sg[2];
80861 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
80862 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
80863 + unsigned long *sumptr = (unsigned long *)sum;
80864 + int cryptres;
80865 + int retval = 1;
80866 + volatile int mismatched = 0;
80867 + volatile int dummy = 0;
80868 + unsigned int i;
80869 +
80870 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
80871 + if (IS_ERR(tfm)) {
80872 + /* should never happen, since sha256 should be built in */
80873 + memset(entry->pw, 0, GR_PW_LEN);
80874 + return 1;
80875 + }
80876 +
80877 + sg_init_table(sg, 2);
80878 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
80879 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
80880 +
80881 + desc.tfm = tfm;
80882 + desc.flags = 0;
80883 +
80884 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
80885 + temp_sum);
80886 +
80887 + memset(entry->pw, 0, GR_PW_LEN);
80888 +
80889 + if (cryptres)
80890 + goto out;
80891 +
80892 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
80893 + if (sumptr[i] != tmpsumptr[i])
80894 + mismatched = 1;
80895 + else
80896 + dummy = 1; // waste a cycle
80897 +
80898 + if (!mismatched)
80899 + retval = dummy - 1;
80900 +
80901 +out:
80902 + crypto_free_hash(tfm);
80903 +
80904 + return retval;
80905 +}
80906 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
80907 index 77ff547..181834f 100644
80908 --- a/include/asm-generic/4level-fixup.h
80909 +++ b/include/asm-generic/4level-fixup.h
80910 @@ -13,8 +13,10 @@
80911 #define pmd_alloc(mm, pud, address) \
80912 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
80913 NULL: pmd_offset(pud, address))
80914 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
80915
80916 #define pud_alloc(mm, pgd, address) (pgd)
80917 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
80918 #define pud_offset(pgd, start) (pgd)
80919 #define pud_none(pud) 0
80920 #define pud_bad(pud) 0
80921 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
80922 index b7babf0..97f4c4f 100644
80923 --- a/include/asm-generic/atomic-long.h
80924 +++ b/include/asm-generic/atomic-long.h
80925 @@ -22,6 +22,12 @@
80926
80927 typedef atomic64_t atomic_long_t;
80928
80929 +#ifdef CONFIG_PAX_REFCOUNT
80930 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
80931 +#else
80932 +typedef atomic64_t atomic_long_unchecked_t;
80933 +#endif
80934 +
80935 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
80936
80937 static inline long atomic_long_read(atomic_long_t *l)
80938 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
80939 return (long)atomic64_read(v);
80940 }
80941
80942 +#ifdef CONFIG_PAX_REFCOUNT
80943 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
80944 +{
80945 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80946 +
80947 + return (long)atomic64_read_unchecked(v);
80948 +}
80949 +#endif
80950 +
80951 static inline void atomic_long_set(atomic_long_t *l, long i)
80952 {
80953 atomic64_t *v = (atomic64_t *)l;
80954 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
80955 atomic64_set(v, i);
80956 }
80957
80958 +#ifdef CONFIG_PAX_REFCOUNT
80959 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
80960 +{
80961 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80962 +
80963 + atomic64_set_unchecked(v, i);
80964 +}
80965 +#endif
80966 +
80967 static inline void atomic_long_inc(atomic_long_t *l)
80968 {
80969 atomic64_t *v = (atomic64_t *)l;
80970 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
80971 atomic64_inc(v);
80972 }
80973
80974 +#ifdef CONFIG_PAX_REFCOUNT
80975 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
80976 +{
80977 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80978 +
80979 + atomic64_inc_unchecked(v);
80980 +}
80981 +#endif
80982 +
80983 static inline void atomic_long_dec(atomic_long_t *l)
80984 {
80985 atomic64_t *v = (atomic64_t *)l;
80986 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
80987 atomic64_dec(v);
80988 }
80989
80990 +#ifdef CONFIG_PAX_REFCOUNT
80991 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
80992 +{
80993 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
80994 +
80995 + atomic64_dec_unchecked(v);
80996 +}
80997 +#endif
80998 +
80999 static inline void atomic_long_add(long i, atomic_long_t *l)
81000 {
81001 atomic64_t *v = (atomic64_t *)l;
81002 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
81003 atomic64_add(i, v);
81004 }
81005
81006 +#ifdef CONFIG_PAX_REFCOUNT
81007 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
81008 +{
81009 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
81010 +
81011 + atomic64_add_unchecked(i, v);
81012 +}
81013 +#endif
81014 +
81015 static inline void atomic_long_sub(long i, atomic_long_t *l)
81016 {
81017 atomic64_t *v = (atomic64_t *)l;
81018 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
81019 atomic64_sub(i, v);
81020 }
81021
81022 +#ifdef CONFIG_PAX_REFCOUNT
81023 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
81024 +{
81025 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
81026 +
81027 + atomic64_sub_unchecked(i, v);
81028 +}
81029 +#endif
81030 +
81031 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
81032 {
81033 atomic64_t *v = (atomic64_t *)l;
81034 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
81035 return atomic64_add_negative(i, v);
81036 }
81037
81038 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
81039 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
81040 {
81041 atomic64_t *v = (atomic64_t *)l;
81042
81043 return (long)atomic64_add_return(i, v);
81044 }
81045
81046 +#ifdef CONFIG_PAX_REFCOUNT
81047 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
81048 +{
81049 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
81050 +
81051 + return (long)atomic64_add_return_unchecked(i, v);
81052 +}
81053 +#endif
81054 +
81055 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
81056 {
81057 atomic64_t *v = (atomic64_t *)l;
81058 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
81059 return (long)atomic64_inc_return(v);
81060 }
81061
81062 +#ifdef CONFIG_PAX_REFCOUNT
81063 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
81064 +{
81065 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
81066 +
81067 + return (long)atomic64_inc_return_unchecked(v);
81068 +}
81069 +#endif
81070 +
81071 static inline long atomic_long_dec_return(atomic_long_t *l)
81072 {
81073 atomic64_t *v = (atomic64_t *)l;
81074 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
81075
81076 typedef atomic_t atomic_long_t;
81077
81078 +#ifdef CONFIG_PAX_REFCOUNT
81079 +typedef atomic_unchecked_t atomic_long_unchecked_t;
81080 +#else
81081 +typedef atomic_t atomic_long_unchecked_t;
81082 +#endif
81083 +
81084 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
81085 static inline long atomic_long_read(atomic_long_t *l)
81086 {
81087 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
81088 return (long)atomic_read(v);
81089 }
81090
81091 +#ifdef CONFIG_PAX_REFCOUNT
81092 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
81093 +{
81094 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81095 +
81096 + return (long)atomic_read_unchecked(v);
81097 +}
81098 +#endif
81099 +
81100 static inline void atomic_long_set(atomic_long_t *l, long i)
81101 {
81102 atomic_t *v = (atomic_t *)l;
81103 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
81104 atomic_set(v, i);
81105 }
81106
81107 +#ifdef CONFIG_PAX_REFCOUNT
81108 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
81109 +{
81110 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81111 +
81112 + atomic_set_unchecked(v, i);
81113 +}
81114 +#endif
81115 +
81116 static inline void atomic_long_inc(atomic_long_t *l)
81117 {
81118 atomic_t *v = (atomic_t *)l;
81119 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
81120 atomic_inc(v);
81121 }
81122
81123 +#ifdef CONFIG_PAX_REFCOUNT
81124 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
81125 +{
81126 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81127 +
81128 + atomic_inc_unchecked(v);
81129 +}
81130 +#endif
81131 +
81132 static inline void atomic_long_dec(atomic_long_t *l)
81133 {
81134 atomic_t *v = (atomic_t *)l;
81135 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
81136 atomic_dec(v);
81137 }
81138
81139 +#ifdef CONFIG_PAX_REFCOUNT
81140 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
81141 +{
81142 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81143 +
81144 + atomic_dec_unchecked(v);
81145 +}
81146 +#endif
81147 +
81148 static inline void atomic_long_add(long i, atomic_long_t *l)
81149 {
81150 atomic_t *v = (atomic_t *)l;
81151 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
81152 atomic_add(i, v);
81153 }
81154
81155 +#ifdef CONFIG_PAX_REFCOUNT
81156 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
81157 +{
81158 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81159 +
81160 + atomic_add_unchecked(i, v);
81161 +}
81162 +#endif
81163 +
81164 static inline void atomic_long_sub(long i, atomic_long_t *l)
81165 {
81166 atomic_t *v = (atomic_t *)l;
81167 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
81168 atomic_sub(i, v);
81169 }
81170
81171 +#ifdef CONFIG_PAX_REFCOUNT
81172 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
81173 +{
81174 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81175 +
81176 + atomic_sub_unchecked(i, v);
81177 +}
81178 +#endif
81179 +
81180 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
81181 {
81182 atomic_t *v = (atomic_t *)l;
81183 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
81184 return (long)atomic_add_return(i, v);
81185 }
81186
81187 +#ifdef CONFIG_PAX_REFCOUNT
81188 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
81189 +{
81190 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81191 +
81192 + return (long)atomic_add_return_unchecked(i, v);
81193 +}
81194 +
81195 +#endif
81196 +
81197 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
81198 {
81199 atomic_t *v = (atomic_t *)l;
81200 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
81201 return (long)atomic_inc_return(v);
81202 }
81203
81204 +#ifdef CONFIG_PAX_REFCOUNT
81205 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
81206 +{
81207 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
81208 +
81209 + return (long)atomic_inc_return_unchecked(v);
81210 +}
81211 +#endif
81212 +
81213 static inline long atomic_long_dec_return(atomic_long_t *l)
81214 {
81215 atomic_t *v = (atomic_t *)l;
81216 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
81217
81218 #endif /* BITS_PER_LONG == 64 */
81219
81220 +#ifdef CONFIG_PAX_REFCOUNT
81221 +static inline void pax_refcount_needs_these_functions(void)
81222 +{
81223 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
81224 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
81225 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
81226 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
81227 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
81228 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
81229 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
81230 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
81231 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
81232 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
81233 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
81234 +#ifdef CONFIG_X86
81235 + atomic_clear_mask_unchecked(0, NULL);
81236 + atomic_set_mask_unchecked(0, NULL);
81237 +#endif
81238 +
81239 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
81240 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
81241 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
81242 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
81243 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
81244 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
81245 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
81246 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
81247 +}
81248 +#else
81249 +#define atomic_read_unchecked(v) atomic_read(v)
81250 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
81251 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
81252 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
81253 +#define atomic_inc_unchecked(v) atomic_inc(v)
81254 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
81255 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
81256 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
81257 +#define atomic_dec_unchecked(v) atomic_dec(v)
81258 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
81259 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
81260 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
81261 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
81262 +
81263 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
81264 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
81265 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
81266 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
81267 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
81268 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
81269 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
81270 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
81271 +#endif
81272 +
81273 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
81274 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
81275 index 9c79e76..9f7827d 100644
81276 --- a/include/asm-generic/atomic.h
81277 +++ b/include/asm-generic/atomic.h
81278 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
81279 * Atomically clears the bits set in @mask from @v
81280 */
81281 #ifndef atomic_clear_mask
81282 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
81283 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
81284 {
81285 unsigned long flags;
81286
81287 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
81288 index b18ce4f..2ee2843 100644
81289 --- a/include/asm-generic/atomic64.h
81290 +++ b/include/asm-generic/atomic64.h
81291 @@ -16,6 +16,8 @@ typedef struct {
81292 long long counter;
81293 } atomic64_t;
81294
81295 +typedef atomic64_t atomic64_unchecked_t;
81296 +
81297 #define ATOMIC64_INIT(i) { (i) }
81298
81299 extern long long atomic64_read(const atomic64_t *v);
81300 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
81301 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
81302 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
81303
81304 +#define atomic64_read_unchecked(v) atomic64_read(v)
81305 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
81306 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
81307 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
81308 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
81309 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
81310 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
81311 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
81312 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
81313 +
81314 #endif /* _ASM_GENERIC_ATOMIC64_H */
81315 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
81316 index 1402fa8..025a736 100644
81317 --- a/include/asm-generic/barrier.h
81318 +++ b/include/asm-generic/barrier.h
81319 @@ -74,7 +74,7 @@
81320 do { \
81321 compiletime_assert_atomic_type(*p); \
81322 smp_mb(); \
81323 - ACCESS_ONCE(*p) = (v); \
81324 + ACCESS_ONCE_RW(*p) = (v); \
81325 } while (0)
81326
81327 #define smp_load_acquire(p) \
81328 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
81329 index a60a7cc..0fe12f2 100644
81330 --- a/include/asm-generic/bitops/__fls.h
81331 +++ b/include/asm-generic/bitops/__fls.h
81332 @@ -9,7 +9,7 @@
81333 *
81334 * Undefined if no set bit exists, so code should check against 0 first.
81335 */
81336 -static __always_inline unsigned long __fls(unsigned long word)
81337 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
81338 {
81339 int num = BITS_PER_LONG - 1;
81340
81341 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
81342 index 0576d1f..dad6c71 100644
81343 --- a/include/asm-generic/bitops/fls.h
81344 +++ b/include/asm-generic/bitops/fls.h
81345 @@ -9,7 +9,7 @@
81346 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
81347 */
81348
81349 -static __always_inline int fls(int x)
81350 +static __always_inline int __intentional_overflow(-1) fls(int x)
81351 {
81352 int r = 32;
81353
81354 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
81355 index b097cf8..3d40e14 100644
81356 --- a/include/asm-generic/bitops/fls64.h
81357 +++ b/include/asm-generic/bitops/fls64.h
81358 @@ -15,7 +15,7 @@
81359 * at position 64.
81360 */
81361 #if BITS_PER_LONG == 32
81362 -static __always_inline int fls64(__u64 x)
81363 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
81364 {
81365 __u32 h = x >> 32;
81366 if (h)
81367 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
81368 return fls(x);
81369 }
81370 #elif BITS_PER_LONG == 64
81371 -static __always_inline int fls64(__u64 x)
81372 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
81373 {
81374 if (x == 0)
81375 return 0;
81376 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
81377 index 1bfcfe5..e04c5c9 100644
81378 --- a/include/asm-generic/cache.h
81379 +++ b/include/asm-generic/cache.h
81380 @@ -6,7 +6,7 @@
81381 * cache lines need to provide their own cache.h.
81382 */
81383
81384 -#define L1_CACHE_SHIFT 5
81385 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
81386 +#define L1_CACHE_SHIFT 5UL
81387 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
81388
81389 #endif /* __ASM_GENERIC_CACHE_H */
81390 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
81391 index 0d68a1e..b74a761 100644
81392 --- a/include/asm-generic/emergency-restart.h
81393 +++ b/include/asm-generic/emergency-restart.h
81394 @@ -1,7 +1,7 @@
81395 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
81396 #define _ASM_GENERIC_EMERGENCY_RESTART_H
81397
81398 -static inline void machine_emergency_restart(void)
81399 +static inline __noreturn void machine_emergency_restart(void)
81400 {
81401 machine_restart(NULL);
81402 }
81403 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
81404 index 975e1cc..0b8a083 100644
81405 --- a/include/asm-generic/io.h
81406 +++ b/include/asm-generic/io.h
81407 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
81408 * These are pretty trivial
81409 */
81410 #ifndef virt_to_phys
81411 -static inline unsigned long virt_to_phys(volatile void *address)
81412 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
81413 {
81414 return __pa((unsigned long)address);
81415 }
81416 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
81417 index 90f99c7..00ce236 100644
81418 --- a/include/asm-generic/kmap_types.h
81419 +++ b/include/asm-generic/kmap_types.h
81420 @@ -2,9 +2,9 @@
81421 #define _ASM_GENERIC_KMAP_TYPES_H
81422
81423 #ifdef __WITH_KM_FENCE
81424 -# define KM_TYPE_NR 41
81425 +# define KM_TYPE_NR 42
81426 #else
81427 -# define KM_TYPE_NR 20
81428 +# define KM_TYPE_NR 21
81429 #endif
81430
81431 #endif
81432 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
81433 index 9ceb03b..62b0b8f 100644
81434 --- a/include/asm-generic/local.h
81435 +++ b/include/asm-generic/local.h
81436 @@ -23,24 +23,37 @@ typedef struct
81437 atomic_long_t a;
81438 } local_t;
81439
81440 +typedef struct {
81441 + atomic_long_unchecked_t a;
81442 +} local_unchecked_t;
81443 +
81444 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
81445
81446 #define local_read(l) atomic_long_read(&(l)->a)
81447 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
81448 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
81449 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
81450 #define local_inc(l) atomic_long_inc(&(l)->a)
81451 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
81452 #define local_dec(l) atomic_long_dec(&(l)->a)
81453 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
81454 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
81455 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
81456 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
81457 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
81458
81459 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
81460 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
81461 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
81462 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
81463 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
81464 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
81465 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
81466 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
81467 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
81468
81469 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
81470 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
81471 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
81472 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
81473 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
81474 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
81475 index 725612b..9cc513a 100644
81476 --- a/include/asm-generic/pgtable-nopmd.h
81477 +++ b/include/asm-generic/pgtable-nopmd.h
81478 @@ -1,14 +1,19 @@
81479 #ifndef _PGTABLE_NOPMD_H
81480 #define _PGTABLE_NOPMD_H
81481
81482 -#ifndef __ASSEMBLY__
81483 -
81484 #include <asm-generic/pgtable-nopud.h>
81485
81486 -struct mm_struct;
81487 -
81488 #define __PAGETABLE_PMD_FOLDED
81489
81490 +#define PMD_SHIFT PUD_SHIFT
81491 +#define PTRS_PER_PMD 1
81492 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
81493 +#define PMD_MASK (~(PMD_SIZE-1))
81494 +
81495 +#ifndef __ASSEMBLY__
81496 +
81497 +struct mm_struct;
81498 +
81499 /*
81500 * Having the pmd type consist of a pud gets the size right, and allows
81501 * us to conceptually access the pud entry that this pmd is folded into
81502 @@ -16,11 +21,6 @@ struct mm_struct;
81503 */
81504 typedef struct { pud_t pud; } pmd_t;
81505
81506 -#define PMD_SHIFT PUD_SHIFT
81507 -#define PTRS_PER_PMD 1
81508 -#define PMD_SIZE (1UL << PMD_SHIFT)
81509 -#define PMD_MASK (~(PMD_SIZE-1))
81510 -
81511 /*
81512 * The "pud_xxx()" functions here are trivial for a folded two-level
81513 * setup: the pmd is never bad, and a pmd always exists (as it's folded
81514 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
81515 index 810431d..0ec4804f 100644
81516 --- a/include/asm-generic/pgtable-nopud.h
81517 +++ b/include/asm-generic/pgtable-nopud.h
81518 @@ -1,10 +1,15 @@
81519 #ifndef _PGTABLE_NOPUD_H
81520 #define _PGTABLE_NOPUD_H
81521
81522 -#ifndef __ASSEMBLY__
81523 -
81524 #define __PAGETABLE_PUD_FOLDED
81525
81526 +#define PUD_SHIFT PGDIR_SHIFT
81527 +#define PTRS_PER_PUD 1
81528 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
81529 +#define PUD_MASK (~(PUD_SIZE-1))
81530 +
81531 +#ifndef __ASSEMBLY__
81532 +
81533 /*
81534 * Having the pud type consist of a pgd gets the size right, and allows
81535 * us to conceptually access the pgd entry that this pud is folded into
81536 @@ -12,11 +17,6 @@
81537 */
81538 typedef struct { pgd_t pgd; } pud_t;
81539
81540 -#define PUD_SHIFT PGDIR_SHIFT
81541 -#define PTRS_PER_PUD 1
81542 -#define PUD_SIZE (1UL << PUD_SHIFT)
81543 -#define PUD_MASK (~(PUD_SIZE-1))
81544 -
81545 /*
81546 * The "pgd_xxx()" functions here are trivial for a folded two-level
81547 * setup: the pud is never bad, and a pud always exists (as it's folded
81548 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
81549 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
81550
81551 #define pgd_populate(mm, pgd, pud) do { } while (0)
81552 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
81553 /*
81554 * (puds are folded into pgds so this doesn't get actually called,
81555 * but the define is needed for a generic inline function.)
81556 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
81557 index 53b2acc..f4568e7 100644
81558 --- a/include/asm-generic/pgtable.h
81559 +++ b/include/asm-generic/pgtable.h
81560 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
81561 }
81562 #endif /* CONFIG_NUMA_BALANCING */
81563
81564 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
81565 +#ifdef CONFIG_PAX_KERNEXEC
81566 +#error KERNEXEC requires pax_open_kernel
81567 +#else
81568 +static inline unsigned long pax_open_kernel(void) { return 0; }
81569 +#endif
81570 +#endif
81571 +
81572 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
81573 +#ifdef CONFIG_PAX_KERNEXEC
81574 +#error KERNEXEC requires pax_close_kernel
81575 +#else
81576 +static inline unsigned long pax_close_kernel(void) { return 0; }
81577 +#endif
81578 +#endif
81579 +
81580 #endif /* CONFIG_MMU */
81581
81582 #endif /* !__ASSEMBLY__ */
81583 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
81584 index 72d8803..cb9749c 100644
81585 --- a/include/asm-generic/uaccess.h
81586 +++ b/include/asm-generic/uaccess.h
81587 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
81588 return __clear_user(to, n);
81589 }
81590
81591 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
81592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
81593 +#error UDEREF requires pax_open_userland
81594 +#else
81595 +static inline unsigned long pax_open_userland(void) { return 0; }
81596 +#endif
81597 +#endif
81598 +
81599 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
81600 +#ifdef CONFIG_PAX_MEMORY_UDEREF
81601 +#error UDEREF requires pax_close_userland
81602 +#else
81603 +static inline unsigned long pax_close_userland(void) { return 0; }
81604 +#endif
81605 +#endif
81606 +
81607 #endif /* __ASM_GENERIC_UACCESS_H */
81608 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
81609 index c1c0b0c..05c9588 100644
81610 --- a/include/asm-generic/vmlinux.lds.h
81611 +++ b/include/asm-generic/vmlinux.lds.h
81612 @@ -231,6 +231,7 @@
81613 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
81614 VMLINUX_SYMBOL(__start_rodata) = .; \
81615 *(.rodata) *(.rodata.*) \
81616 + *(.data..read_only) \
81617 *(__vermagic) /* Kernel version magic */ \
81618 . = ALIGN(8); \
81619 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
81620 @@ -719,17 +720,18 @@
81621 * section in the linker script will go there too. @phdr should have
81622 * a leading colon.
81623 *
81624 - * Note that this macros defines __per_cpu_load as an absolute symbol.
81625 + * Note that this macros defines per_cpu_load as an absolute symbol.
81626 * If there is no need to put the percpu section at a predetermined
81627 * address, use PERCPU_SECTION.
81628 */
81629 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
81630 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
81631 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
81632 + per_cpu_load = .; \
81633 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
81634 - LOAD_OFFSET) { \
81635 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
81636 PERCPU_INPUT(cacheline) \
81637 } phdr \
81638 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
81639 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
81640
81641 /**
81642 * PERCPU_SECTION - define output section for percpu area, simple version
81643 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
81644 index 016c2f1..c4baa98 100644
81645 --- a/include/crypto/algapi.h
81646 +++ b/include/crypto/algapi.h
81647 @@ -34,7 +34,7 @@ struct crypto_type {
81648 unsigned int maskclear;
81649 unsigned int maskset;
81650 unsigned int tfmsize;
81651 -};
81652 +} __do_const;
81653
81654 struct crypto_instance {
81655 struct crypto_alg alg;
81656 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
81657 index 8af71a8..7fe6c19 100644
81658 --- a/include/drm/drmP.h
81659 +++ b/include/drm/drmP.h
81660 @@ -68,6 +68,7 @@
81661 #include <linux/workqueue.h>
81662 #include <linux/poll.h>
81663 #include <asm/pgalloc.h>
81664 +#include <asm/local.h>
81665 #include <drm/drm.h>
81666 #include <drm/drm_sarea.h>
81667 #include <drm/drm_vma_manager.h>
81668 @@ -261,10 +262,12 @@ do { \
81669 * \param cmd command.
81670 * \param arg argument.
81671 */
81672 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
81673 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
81674 + struct drm_file *file_priv);
81675 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
81676 struct drm_file *file_priv);
81677
81678 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
81679 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
81680 unsigned long arg);
81681
81682 #define DRM_IOCTL_NR(n) _IOC_NR(n)
81683 @@ -280,10 +283,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
81684 struct drm_ioctl_desc {
81685 unsigned int cmd;
81686 int flags;
81687 - drm_ioctl_t *func;
81688 + drm_ioctl_t func;
81689 unsigned int cmd_drv;
81690 const char *name;
81691 -};
81692 +} __do_const;
81693
81694 /**
81695 * Creates a driver or general drm_ioctl_desc array entry for the given
81696 @@ -983,7 +986,8 @@ struct drm_info_list {
81697 int (*show)(struct seq_file*, void*); /** show callback */
81698 u32 driver_features; /**< Required driver features for this entry */
81699 void *data;
81700 -};
81701 +} __do_const;
81702 +typedef struct drm_info_list __no_const drm_info_list_no_const;
81703
81704 /**
81705 * debugfs node structure. This structure represents a debugfs file.
81706 @@ -1067,7 +1071,7 @@ struct drm_device {
81707
81708 /** \name Usage Counters */
81709 /*@{ */
81710 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
81711 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
81712 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
81713 int buf_use; /**< Buffers in use -- cannot alloc */
81714 atomic_t buf_alloc; /**< Buffer allocation in progress */
81715 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
81716 index a3d75fe..6802f9c 100644
81717 --- a/include/drm/drm_crtc_helper.h
81718 +++ b/include/drm/drm_crtc_helper.h
81719 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
81720 struct drm_connector *connector);
81721 /* disable encoder when not in use - more explicit than dpms off */
81722 void (*disable)(struct drm_encoder *encoder);
81723 -};
81724 +} __no_const;
81725
81726 /**
81727 * drm_connector_helper_funcs - helper operations for connectors
81728 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
81729 index a70d456..6ea07cd 100644
81730 --- a/include/drm/i915_pciids.h
81731 +++ b/include/drm/i915_pciids.h
81732 @@ -37,7 +37,7 @@
81733 */
81734 #define INTEL_VGA_DEVICE(id, info) { \
81735 0x8086, id, \
81736 - ~0, ~0, \
81737 + PCI_ANY_ID, PCI_ANY_ID, \
81738 0x030000, 0xff0000, \
81739 (unsigned long) info }
81740
81741 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
81742 index 72dcbe8..8db58d7 100644
81743 --- a/include/drm/ttm/ttm_memory.h
81744 +++ b/include/drm/ttm/ttm_memory.h
81745 @@ -48,7 +48,7 @@
81746
81747 struct ttm_mem_shrink {
81748 int (*do_shrink) (struct ttm_mem_shrink *);
81749 -};
81750 +} __no_const;
81751
81752 /**
81753 * struct ttm_mem_global - Global memory accounting structure.
81754 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
81755 index 49a8284..9643967 100644
81756 --- a/include/drm/ttm/ttm_page_alloc.h
81757 +++ b/include/drm/ttm/ttm_page_alloc.h
81758 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
81759 */
81760 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
81761
81762 +struct device;
81763 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81764 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
81765
81766 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
81767 index 4b840e8..155d235 100644
81768 --- a/include/keys/asymmetric-subtype.h
81769 +++ b/include/keys/asymmetric-subtype.h
81770 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
81771 /* Verify the signature on a key of this subtype (optional) */
81772 int (*verify_signature)(const struct key *key,
81773 const struct public_key_signature *sig);
81774 -};
81775 +} __do_const;
81776
81777 /**
81778 * asymmetric_key_subtype - Get the subtype from an asymmetric key
81779 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
81780 index c1da539..1dcec55 100644
81781 --- a/include/linux/atmdev.h
81782 +++ b/include/linux/atmdev.h
81783 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
81784 #endif
81785
81786 struct k_atm_aal_stats {
81787 -#define __HANDLE_ITEM(i) atomic_t i
81788 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81789 __AAL_STAT_ITEMS
81790 #undef __HANDLE_ITEM
81791 };
81792 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
81793 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
81794 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
81795 struct module *owner;
81796 -};
81797 +} __do_const ;
81798
81799 struct atmphy_ops {
81800 int (*start)(struct atm_dev *dev);
81801 diff --git a/include/linux/audit.h b/include/linux/audit.h
81802 index 22cfddb..ab759e8 100644
81803 --- a/include/linux/audit.h
81804 +++ b/include/linux/audit.h
81805 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
81806 extern unsigned int audit_serial(void);
81807 extern int auditsc_get_stamp(struct audit_context *ctx,
81808 struct timespec *t, unsigned int *serial);
81809 -extern int audit_set_loginuid(kuid_t loginuid);
81810 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
81811
81812 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
81813 {
81814 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
81815 index 61f29e5..e67c658 100644
81816 --- a/include/linux/binfmts.h
81817 +++ b/include/linux/binfmts.h
81818 @@ -44,7 +44,7 @@ struct linux_binprm {
81819 unsigned interp_flags;
81820 unsigned interp_data;
81821 unsigned long loader, exec;
81822 -};
81823 +} __randomize_layout;
81824
81825 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
81826 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
81827 @@ -73,8 +73,10 @@ struct linux_binfmt {
81828 int (*load_binary)(struct linux_binprm *);
81829 int (*load_shlib)(struct file *);
81830 int (*core_dump)(struct coredump_params *cprm);
81831 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
81832 + void (*handle_mmap)(struct file *);
81833 unsigned long min_coredump; /* minimal dump size */
81834 -};
81835 +} __do_const __randomize_layout;
81836
81837 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
81838
81839 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
81840 index cbc5833..8123ebc 100644
81841 --- a/include/linux/bitops.h
81842 +++ b/include/linux/bitops.h
81843 @@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
81844 * @word: value to rotate
81845 * @shift: bits to roll
81846 */
81847 -static inline __u32 rol32(__u32 word, unsigned int shift)
81848 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
81849 {
81850 return (word << shift) | (word >> (32 - shift));
81851 }
81852 @@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
81853 * @word: value to rotate
81854 * @shift: bits to roll
81855 */
81856 -static inline __u32 ror32(__u32 word, unsigned int shift)
81857 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
81858 {
81859 return (word >> shift) | (word << (32 - shift));
81860 }
81861 @@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
81862 return (__s32)(value << shift) >> shift;
81863 }
81864
81865 -static inline unsigned fls_long(unsigned long l)
81866 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
81867 {
81868 if (sizeof(l) == 4)
81869 return fls(l);
81870 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
81871 index 8699bcf..279485d 100644
81872 --- a/include/linux/blkdev.h
81873 +++ b/include/linux/blkdev.h
81874 @@ -1625,7 +1625,7 @@ struct block_device_operations {
81875 /* this callback is with swap_lock and sometimes page table lock held */
81876 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
81877 struct module *owner;
81878 -};
81879 +} __do_const;
81880
81881 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
81882 unsigned long);
81883 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
81884 index afc1343..9735539 100644
81885 --- a/include/linux/blktrace_api.h
81886 +++ b/include/linux/blktrace_api.h
81887 @@ -25,7 +25,7 @@ struct blk_trace {
81888 struct dentry *dropped_file;
81889 struct dentry *msg_file;
81890 struct list_head running_list;
81891 - atomic_t dropped;
81892 + atomic_unchecked_t dropped;
81893 };
81894
81895 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
81896 diff --git a/include/linux/cache.h b/include/linux/cache.h
81897 index 17e7e82..1d7da26 100644
81898 --- a/include/linux/cache.h
81899 +++ b/include/linux/cache.h
81900 @@ -16,6 +16,14 @@
81901 #define __read_mostly
81902 #endif
81903
81904 +#ifndef __read_only
81905 +#ifdef CONFIG_PAX_KERNEXEC
81906 +#error KERNEXEC requires __read_only
81907 +#else
81908 +#define __read_only __read_mostly
81909 +#endif
81910 +#endif
81911 +
81912 #ifndef ____cacheline_aligned
81913 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
81914 #endif
81915 diff --git a/include/linux/capability.h b/include/linux/capability.h
81916 index 84b13ad..172cdee 100644
81917 --- a/include/linux/capability.h
81918 +++ b/include/linux/capability.h
81919 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
81920 extern bool capable(int cap);
81921 extern bool ns_capable(struct user_namespace *ns, int cap);
81922 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
81923 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
81924 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
81925 +extern bool capable_nolog(int cap);
81926 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
81927
81928 /* audit system wants to get cap info from files as well */
81929 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
81930
81931 +extern int is_privileged_binary(const struct dentry *dentry);
81932 +
81933 #endif /* !_LINUX_CAPABILITY_H */
81934 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
81935 index 8609d57..86e4d79 100644
81936 --- a/include/linux/cdrom.h
81937 +++ b/include/linux/cdrom.h
81938 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
81939
81940 /* driver specifications */
81941 const int capability; /* capability flags */
81942 - int n_minors; /* number of active minor devices */
81943 /* handle uniform packets for scsi type devices (scsi,atapi) */
81944 int (*generic_packet) (struct cdrom_device_info *,
81945 struct packet_command *);
81946 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
81947 index 4ce9056..86caac6 100644
81948 --- a/include/linux/cleancache.h
81949 +++ b/include/linux/cleancache.h
81950 @@ -31,7 +31,7 @@ struct cleancache_ops {
81951 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
81952 void (*invalidate_inode)(int, struct cleancache_filekey);
81953 void (*invalidate_fs)(int);
81954 -};
81955 +} __no_const;
81956
81957 extern struct cleancache_ops *
81958 cleancache_register_ops(struct cleancache_ops *ops);
81959 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
81960 index 0c287db..5efa775 100644
81961 --- a/include/linux/clk-provider.h
81962 +++ b/include/linux/clk-provider.h
81963 @@ -180,6 +180,7 @@ struct clk_ops {
81964 void (*init)(struct clk_hw *hw);
81965 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
81966 };
81967 +typedef struct clk_ops __no_const clk_ops_no_const;
81968
81969 /**
81970 * struct clk_init_data - holds init data that's common to all clocks and is
81971 diff --git a/include/linux/compat.h b/include/linux/compat.h
81972 index e649426..a74047b 100644
81973 --- a/include/linux/compat.h
81974 +++ b/include/linux/compat.h
81975 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
81976 compat_size_t __user *len_ptr);
81977
81978 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
81979 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
81980 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
81981 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
81982 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
81983 compat_ssize_t msgsz, int msgflg);
81984 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
81985 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
81986 compat_ulong_t addr, compat_ulong_t data);
81987 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
81988 - compat_long_t addr, compat_long_t data);
81989 + compat_ulong_t addr, compat_ulong_t data);
81990
81991 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
81992 /*
81993 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
81994 index 2507fd2..55203f8 100644
81995 --- a/include/linux/compiler-gcc4.h
81996 +++ b/include/linux/compiler-gcc4.h
81997 @@ -39,9 +39,34 @@
81998 # define __compiletime_warning(message) __attribute__((warning(message)))
81999 # define __compiletime_error(message) __attribute__((error(message)))
82000 #endif /* __CHECKER__ */
82001 +
82002 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
82003 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
82004 +#define __bos0(ptr) __bos((ptr), 0)
82005 +#define __bos1(ptr) __bos((ptr), 1)
82006 #endif /* GCC_VERSION >= 40300 */
82007
82008 #if GCC_VERSION >= 40500
82009 +
82010 +#ifdef RANDSTRUCT_PLUGIN
82011 +#define __randomize_layout __attribute__((randomize_layout))
82012 +#define __no_randomize_layout __attribute__((no_randomize_layout))
82013 +#endif
82014 +
82015 +#ifdef CONSTIFY_PLUGIN
82016 +#define __no_const __attribute__((no_const))
82017 +#define __do_const __attribute__((do_const))
82018 +#endif
82019 +
82020 +#ifdef SIZE_OVERFLOW_PLUGIN
82021 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
82022 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
82023 +#endif
82024 +
82025 +#ifdef LATENT_ENTROPY_PLUGIN
82026 +#define __latent_entropy __attribute__((latent_entropy))
82027 +#endif
82028 +
82029 /*
82030 * Mark a position in code as unreachable. This can be used to
82031 * suppress control flow warnings after asm blocks that transfer
82032 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
82033 index d5ad7b1..3b74638 100644
82034 --- a/include/linux/compiler.h
82035 +++ b/include/linux/compiler.h
82036 @@ -5,11 +5,14 @@
82037
82038 #ifdef __CHECKER__
82039 # define __user __attribute__((noderef, address_space(1)))
82040 +# define __force_user __force __user
82041 # define __kernel __attribute__((address_space(0)))
82042 +# define __force_kernel __force __kernel
82043 # define __safe __attribute__((safe))
82044 # define __force __attribute__((force))
82045 # define __nocast __attribute__((nocast))
82046 # define __iomem __attribute__((noderef, address_space(2)))
82047 +# define __force_iomem __force __iomem
82048 # define __must_hold(x) __attribute__((context(x,1,1)))
82049 # define __acquires(x) __attribute__((context(x,0,1)))
82050 # define __releases(x) __attribute__((context(x,1,0)))
82051 @@ -17,20 +20,37 @@
82052 # define __release(x) __context__(x,-1)
82053 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
82054 # define __percpu __attribute__((noderef, address_space(3)))
82055 +# define __force_percpu __force __percpu
82056 #ifdef CONFIG_SPARSE_RCU_POINTER
82057 # define __rcu __attribute__((noderef, address_space(4)))
82058 +# define __force_rcu __force __rcu
82059 #else
82060 # define __rcu
82061 +# define __force_rcu
82062 #endif
82063 extern void __chk_user_ptr(const volatile void __user *);
82064 extern void __chk_io_ptr(const volatile void __iomem *);
82065 #else
82066 -# define __user
82067 -# define __kernel
82068 +# ifdef CHECKER_PLUGIN
82069 +//# define __user
82070 +//# define __force_user
82071 +//# define __kernel
82072 +//# define __force_kernel
82073 +# else
82074 +# ifdef STRUCTLEAK_PLUGIN
82075 +# define __user __attribute__((user))
82076 +# else
82077 +# define __user
82078 +# endif
82079 +# define __force_user
82080 +# define __kernel
82081 +# define __force_kernel
82082 +# endif
82083 # define __safe
82084 # define __force
82085 # define __nocast
82086 # define __iomem
82087 +# define __force_iomem
82088 # define __chk_user_ptr(x) (void)0
82089 # define __chk_io_ptr(x) (void)0
82090 # define __builtin_warning(x, y...) (1)
82091 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
82092 # define __release(x) (void)0
82093 # define __cond_lock(x,c) (c)
82094 # define __percpu
82095 +# define __force_percpu
82096 # define __rcu
82097 +# define __force_rcu
82098 #endif
82099
82100 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
82101 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
82102 # define __attribute_const__ /* unimplemented */
82103 #endif
82104
82105 +#ifndef __randomize_layout
82106 +# define __randomize_layout
82107 +#endif
82108 +
82109 +#ifndef __no_randomize_layout
82110 +# define __no_randomize_layout
82111 +#endif
82112 +
82113 +#ifndef __no_const
82114 +# define __no_const
82115 +#endif
82116 +
82117 +#ifndef __do_const
82118 +# define __do_const
82119 +#endif
82120 +
82121 +#ifndef __size_overflow
82122 +# define __size_overflow(...)
82123 +#endif
82124 +
82125 +#ifndef __intentional_overflow
82126 +# define __intentional_overflow(...)
82127 +#endif
82128 +
82129 +#ifndef __latent_entropy
82130 +# define __latent_entropy
82131 +#endif
82132 +
82133 /*
82134 * Tell gcc if a function is cold. The compiler will assume any path
82135 * directly leading to the call is unlikely.
82136 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
82137 #define __cold
82138 #endif
82139
82140 +#ifndef __alloc_size
82141 +#define __alloc_size(...)
82142 +#endif
82143 +
82144 +#ifndef __bos
82145 +#define __bos(ptr, arg)
82146 +#endif
82147 +
82148 +#ifndef __bos0
82149 +#define __bos0(ptr)
82150 +#endif
82151 +
82152 +#ifndef __bos1
82153 +#define __bos1(ptr)
82154 +#endif
82155 +
82156 /* Simple shorthand for a section definition */
82157 #ifndef __section
82158 # define __section(S) __attribute__ ((__section__(#S)))
82159 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
82160 * use is to mediate communication between process-level code and irq/NMI
82161 * handlers, all running on the same CPU.
82162 */
82163 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
82164 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
82165 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
82166
82167 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
82168 #ifdef CONFIG_KPROBES
82169 diff --git a/include/linux/completion.h b/include/linux/completion.h
82170 index 5d5aaae..0ea9b84 100644
82171 --- a/include/linux/completion.h
82172 +++ b/include/linux/completion.h
82173 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
82174
82175 extern void wait_for_completion(struct completion *);
82176 extern void wait_for_completion_io(struct completion *);
82177 -extern int wait_for_completion_interruptible(struct completion *x);
82178 -extern int wait_for_completion_killable(struct completion *x);
82179 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
82180 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
82181 extern unsigned long wait_for_completion_timeout(struct completion *x,
82182 - unsigned long timeout);
82183 + unsigned long timeout) __intentional_overflow(-1);
82184 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
82185 - unsigned long timeout);
82186 + unsigned long timeout) __intentional_overflow(-1);
82187 extern long wait_for_completion_interruptible_timeout(
82188 - struct completion *x, unsigned long timeout);
82189 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
82190 extern long wait_for_completion_killable_timeout(
82191 - struct completion *x, unsigned long timeout);
82192 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
82193 extern bool try_wait_for_completion(struct completion *x);
82194 extern bool completion_done(struct completion *x);
82195
82196 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
82197 index 34025df..d94bbbc 100644
82198 --- a/include/linux/configfs.h
82199 +++ b/include/linux/configfs.h
82200 @@ -125,7 +125,7 @@ struct configfs_attribute {
82201 const char *ca_name;
82202 struct module *ca_owner;
82203 umode_t ca_mode;
82204 -};
82205 +} __do_const;
82206
82207 /*
82208 * Users often need to create attribute structures for their configurable
82209 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
82210 index 8f8ae95..b9b0e6d 100644
82211 --- a/include/linux/cpufreq.h
82212 +++ b/include/linux/cpufreq.h
82213 @@ -202,6 +202,7 @@ struct global_attr {
82214 ssize_t (*store)(struct kobject *a, struct attribute *b,
82215 const char *c, size_t count);
82216 };
82217 +typedef struct global_attr __no_const global_attr_no_const;
82218
82219 #define define_one_global_ro(_name) \
82220 static struct global_attr _name = \
82221 @@ -268,7 +269,7 @@ struct cpufreq_driver {
82222 bool boost_supported;
82223 bool boost_enabled;
82224 int (*set_boost) (int state);
82225 -};
82226 +} __do_const;
82227
82228 /* flags */
82229 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
82230 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
82231 index 25e0df6..952dffd 100644
82232 --- a/include/linux/cpuidle.h
82233 +++ b/include/linux/cpuidle.h
82234 @@ -50,7 +50,8 @@ struct cpuidle_state {
82235 int index);
82236
82237 int (*enter_dead) (struct cpuidle_device *dev, int index);
82238 -};
82239 +} __do_const;
82240 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
82241
82242 /* Idle State Flags */
82243 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
82244 @@ -209,7 +210,7 @@ struct cpuidle_governor {
82245 void (*reflect) (struct cpuidle_device *dev, int index);
82246
82247 struct module *owner;
82248 -};
82249 +} __do_const;
82250
82251 #ifdef CONFIG_CPU_IDLE
82252 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
82253 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
82254 index 2997af6..424ddc1 100644
82255 --- a/include/linux/cpumask.h
82256 +++ b/include/linux/cpumask.h
82257 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
82258 }
82259
82260 /* Valid inputs for n are -1 and 0. */
82261 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
82262 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
82263 {
82264 return n+1;
82265 }
82266
82267 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
82268 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
82269 {
82270 return n+1;
82271 }
82272
82273 -static inline unsigned int cpumask_next_and(int n,
82274 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
82275 const struct cpumask *srcp,
82276 const struct cpumask *andp)
82277 {
82278 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
82279 *
82280 * Returns >= nr_cpu_ids if no further cpus set.
82281 */
82282 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
82283 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
82284 {
82285 /* -1 is a legal arg here. */
82286 if (n != -1)
82287 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
82288 *
82289 * Returns >= nr_cpu_ids if no further cpus unset.
82290 */
82291 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
82292 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
82293 {
82294 /* -1 is a legal arg here. */
82295 if (n != -1)
82296 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
82297 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
82298 }
82299
82300 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
82301 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
82302 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
82303 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
82304
82305 diff --git a/include/linux/cred.h b/include/linux/cred.h
82306 index f61d6c8..d372d95 100644
82307 --- a/include/linux/cred.h
82308 +++ b/include/linux/cred.h
82309 @@ -35,7 +35,7 @@ struct group_info {
82310 int nblocks;
82311 kgid_t small_block[NGROUPS_SMALL];
82312 kgid_t *blocks[0];
82313 -};
82314 +} __randomize_layout;
82315
82316 /**
82317 * get_group_info - Get a reference to a group info structure
82318 @@ -136,7 +136,7 @@ struct cred {
82319 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
82320 struct group_info *group_info; /* supplementary groups for euid/fsgid */
82321 struct rcu_head rcu; /* RCU deletion hook */
82322 -};
82323 +} __randomize_layout;
82324
82325 extern void __put_cred(struct cred *);
82326 extern void exit_creds(struct task_struct *);
82327 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
82328 static inline void validate_process_creds(void)
82329 {
82330 }
82331 +static inline void validate_task_creds(struct task_struct *task)
82332 +{
82333 +}
82334 #endif
82335
82336 /**
82337 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
82338
82339 #define task_uid(task) (task_cred_xxx((task), uid))
82340 #define task_euid(task) (task_cred_xxx((task), euid))
82341 +#define task_securebits(task) (task_cred_xxx((task), securebits))
82342
82343 #define current_cred_xxx(xxx) \
82344 ({ \
82345 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
82346 index b92eadf..b4ecdc1 100644
82347 --- a/include/linux/crypto.h
82348 +++ b/include/linux/crypto.h
82349 @@ -373,7 +373,7 @@ struct cipher_tfm {
82350 const u8 *key, unsigned int keylen);
82351 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
82352 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
82353 -};
82354 +} __no_const;
82355
82356 struct hash_tfm {
82357 int (*init)(struct hash_desc *desc);
82358 @@ -394,13 +394,13 @@ struct compress_tfm {
82359 int (*cot_decompress)(struct crypto_tfm *tfm,
82360 const u8 *src, unsigned int slen,
82361 u8 *dst, unsigned int *dlen);
82362 -};
82363 +} __no_const;
82364
82365 struct rng_tfm {
82366 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
82367 unsigned int dlen);
82368 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
82369 -};
82370 +} __no_const;
82371
82372 #define crt_ablkcipher crt_u.ablkcipher
82373 #define crt_aead crt_u.aead
82374 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
82375 index 653589e..4ef254a 100644
82376 --- a/include/linux/ctype.h
82377 +++ b/include/linux/ctype.h
82378 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
82379 * Fast implementation of tolower() for internal usage. Do not use in your
82380 * code.
82381 */
82382 -static inline char _tolower(const char c)
82383 +static inline unsigned char _tolower(const unsigned char c)
82384 {
82385 return c | 0x20;
82386 }
82387 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
82388 index 3c7ec32..4ca97cc 100644
82389 --- a/include/linux/dcache.h
82390 +++ b/include/linux/dcache.h
82391 @@ -133,7 +133,7 @@ struct dentry {
82392 } d_u;
82393 struct list_head d_subdirs; /* our children */
82394 struct hlist_node d_alias; /* inode alias list */
82395 -};
82396 +} __randomize_layout;
82397
82398 /*
82399 * dentry->d_lock spinlock nesting subclasses:
82400 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
82401 index 7925bf0..d5143d2 100644
82402 --- a/include/linux/decompress/mm.h
82403 +++ b/include/linux/decompress/mm.h
82404 @@ -77,7 +77,7 @@ static void free(void *where)
82405 * warnings when not needed (indeed large_malloc / large_free are not
82406 * needed by inflate */
82407
82408 -#define malloc(a) kmalloc(a, GFP_KERNEL)
82409 +#define malloc(a) kmalloc((a), GFP_KERNEL)
82410 #define free(a) kfree(a)
82411
82412 #define large_malloc(a) vmalloc(a)
82413 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
82414 index f1863dc..5c26074 100644
82415 --- a/include/linux/devfreq.h
82416 +++ b/include/linux/devfreq.h
82417 @@ -114,7 +114,7 @@ struct devfreq_governor {
82418 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
82419 int (*event_handler)(struct devfreq *devfreq,
82420 unsigned int event, void *data);
82421 -};
82422 +} __do_const;
82423
82424 /**
82425 * struct devfreq - Device devfreq structure
82426 diff --git a/include/linux/device.h b/include/linux/device.h
82427 index af424ac..fd46ddf 100644
82428 --- a/include/linux/device.h
82429 +++ b/include/linux/device.h
82430 @@ -310,7 +310,7 @@ struct subsys_interface {
82431 struct list_head node;
82432 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
82433 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
82434 -};
82435 +} __do_const;
82436
82437 int subsys_interface_register(struct subsys_interface *sif);
82438 void subsys_interface_unregister(struct subsys_interface *sif);
82439 @@ -506,7 +506,7 @@ struct device_type {
82440 void (*release)(struct device *dev);
82441
82442 const struct dev_pm_ops *pm;
82443 -};
82444 +} __do_const;
82445
82446 /* interface for exporting device attributes */
82447 struct device_attribute {
82448 @@ -516,11 +516,12 @@ struct device_attribute {
82449 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
82450 const char *buf, size_t count);
82451 };
82452 +typedef struct device_attribute __no_const device_attribute_no_const;
82453
82454 struct dev_ext_attribute {
82455 struct device_attribute attr;
82456 void *var;
82457 -};
82458 +} __do_const;
82459
82460 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
82461 char *buf);
82462 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
82463 index 931b709..89b2d89 100644
82464 --- a/include/linux/dma-mapping.h
82465 +++ b/include/linux/dma-mapping.h
82466 @@ -60,7 +60,7 @@ struct dma_map_ops {
82467 u64 (*get_required_mask)(struct device *dev);
82468 #endif
82469 int is_phys;
82470 -};
82471 +} __do_const;
82472
82473 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
82474
82475 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
82476 index d2c5cc7..d193394 100644
82477 --- a/include/linux/dmaengine.h
82478 +++ b/include/linux/dmaengine.h
82479 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
82480 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
82481 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
82482
82483 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
82484 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
82485 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
82486 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
82487 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
82488 struct dma_pinned_list *pinned_list, struct page *page,
82489 unsigned int offset, size_t len);
82490
82491 diff --git a/include/linux/efi.h b/include/linux/efi.h
82492 index 41bbf8b..bd3a718 100644
82493 --- a/include/linux/efi.h
82494 +++ b/include/linux/efi.h
82495 @@ -1027,6 +1027,7 @@ struct efivar_operations {
82496 efi_set_variable_t *set_variable;
82497 efi_query_variable_store_t *query_variable_store;
82498 };
82499 +typedef struct efivar_operations __no_const efivar_operations_no_const;
82500
82501 struct efivars {
82502 /*
82503 diff --git a/include/linux/elf.h b/include/linux/elf.h
82504 index 67a5fa7..b817372 100644
82505 --- a/include/linux/elf.h
82506 +++ b/include/linux/elf.h
82507 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
82508 #define elf_note elf32_note
82509 #define elf_addr_t Elf32_Off
82510 #define Elf_Half Elf32_Half
82511 +#define elf_dyn Elf32_Dyn
82512
82513 #else
82514
82515 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
82516 #define elf_note elf64_note
82517 #define elf_addr_t Elf64_Off
82518 #define Elf_Half Elf64_Half
82519 +#define elf_dyn Elf64_Dyn
82520
82521 #endif
82522
82523 diff --git a/include/linux/err.h b/include/linux/err.h
82524 index a729120..6ede2c9 100644
82525 --- a/include/linux/err.h
82526 +++ b/include/linux/err.h
82527 @@ -20,12 +20,12 @@
82528
82529 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
82530
82531 -static inline void * __must_check ERR_PTR(long error)
82532 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
82533 {
82534 return (void *) error;
82535 }
82536
82537 -static inline long __must_check PTR_ERR(__force const void *ptr)
82538 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
82539 {
82540 return (long) ptr;
82541 }
82542 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
82543 index 36f49c4..a2a1f4c 100644
82544 --- a/include/linux/extcon.h
82545 +++ b/include/linux/extcon.h
82546 @@ -135,7 +135,7 @@ struct extcon_dev {
82547 /* /sys/class/extcon/.../mutually_exclusive/... */
82548 struct attribute_group attr_g_muex;
82549 struct attribute **attrs_muex;
82550 - struct device_attribute *d_attrs_muex;
82551 + device_attribute_no_const *d_attrs_muex;
82552 };
82553
82554 /**
82555 diff --git a/include/linux/fb.h b/include/linux/fb.h
82556 index b6bfda9..1f13487 100644
82557 --- a/include/linux/fb.h
82558 +++ b/include/linux/fb.h
82559 @@ -305,7 +305,7 @@ struct fb_ops {
82560 /* called at KDB enter and leave time to prepare the console */
82561 int (*fb_debug_enter)(struct fb_info *info);
82562 int (*fb_debug_leave)(struct fb_info *info);
82563 -};
82564 +} __do_const;
82565
82566 #ifdef CONFIG_FB_TILEBLITTING
82567 #define FB_TILE_CURSOR_NONE 0
82568 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
82569 index 230f87b..1fd0485 100644
82570 --- a/include/linux/fdtable.h
82571 +++ b/include/linux/fdtable.h
82572 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
82573 void put_files_struct(struct files_struct *fs);
82574 void reset_files_struct(struct files_struct *);
82575 int unshare_files(struct files_struct **);
82576 -struct files_struct *dup_fd(struct files_struct *, int *);
82577 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
82578 void do_close_on_exec(struct files_struct *);
82579 int iterate_fd(struct files_struct *, unsigned,
82580 int (*)(const void *, struct file *, unsigned),
82581 diff --git a/include/linux/filter.h b/include/linux/filter.h
82582 index a7e3c48..e568c8e 100644
82583 --- a/include/linux/filter.h
82584 +++ b/include/linux/filter.h
82585 @@ -9,330 +9,28 @@
82586 #include <linux/workqueue.h>
82587 #include <uapi/linux/filter.h>
82588
82589 -/* Internally used and optimized filter representation with extended
82590 - * instruction set based on top of classic BPF.
82591 - */
82592 -
82593 -/* instruction classes */
82594 -#define BPF_ALU64 0x07 /* alu mode in double word width */
82595 -
82596 -/* ld/ldx fields */
82597 -#define BPF_DW 0x18 /* double word */
82598 -#define BPF_XADD 0xc0 /* exclusive add */
82599 -
82600 -/* alu/jmp fields */
82601 -#define BPF_MOV 0xb0 /* mov reg to reg */
82602 -#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
82603 -
82604 -/* change endianness of a register */
82605 -#define BPF_END 0xd0 /* flags for endianness conversion: */
82606 -#define BPF_TO_LE 0x00 /* convert to little-endian */
82607 -#define BPF_TO_BE 0x08 /* convert to big-endian */
82608 -#define BPF_FROM_LE BPF_TO_LE
82609 -#define BPF_FROM_BE BPF_TO_BE
82610 -
82611 -#define BPF_JNE 0x50 /* jump != */
82612 -#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
82613 -#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
82614 -#define BPF_CALL 0x80 /* function call */
82615 -#define BPF_EXIT 0x90 /* function return */
82616 -
82617 -/* Register numbers */
82618 -enum {
82619 - BPF_REG_0 = 0,
82620 - BPF_REG_1,
82621 - BPF_REG_2,
82622 - BPF_REG_3,
82623 - BPF_REG_4,
82624 - BPF_REG_5,
82625 - BPF_REG_6,
82626 - BPF_REG_7,
82627 - BPF_REG_8,
82628 - BPF_REG_9,
82629 - BPF_REG_10,
82630 - __MAX_BPF_REG,
82631 -};
82632 -
82633 -/* BPF has 10 general purpose 64-bit registers and stack frame. */
82634 -#define MAX_BPF_REG __MAX_BPF_REG
82635 -
82636 -/* ArgX, context and stack frame pointer register positions. Note,
82637 - * Arg1, Arg2, Arg3, etc are used as argument mappings of function
82638 - * calls in BPF_CALL instruction.
82639 - */
82640 -#define BPF_REG_ARG1 BPF_REG_1
82641 -#define BPF_REG_ARG2 BPF_REG_2
82642 -#define BPF_REG_ARG3 BPF_REG_3
82643 -#define BPF_REG_ARG4 BPF_REG_4
82644 -#define BPF_REG_ARG5 BPF_REG_5
82645 -#define BPF_REG_CTX BPF_REG_6
82646 -#define BPF_REG_FP BPF_REG_10
82647 -
82648 -/* Additional register mappings for converted user programs. */
82649 -#define BPF_REG_A BPF_REG_0
82650 -#define BPF_REG_X BPF_REG_7
82651 -#define BPF_REG_TMP BPF_REG_8
82652 -
82653 -/* BPF program can access up to 512 bytes of stack space. */
82654 -#define MAX_BPF_STACK 512
82655 -
82656 -/* Helper macros for filter block array initializers. */
82657 -
82658 -/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
82659 -
82660 -#define BPF_ALU64_REG(OP, DST, SRC) \
82661 - ((struct sock_filter_int) { \
82662 - .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
82663 - .dst_reg = DST, \
82664 - .src_reg = SRC, \
82665 - .off = 0, \
82666 - .imm = 0 })
82667 -
82668 -#define BPF_ALU32_REG(OP, DST, SRC) \
82669 - ((struct sock_filter_int) { \
82670 - .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
82671 - .dst_reg = DST, \
82672 - .src_reg = SRC, \
82673 - .off = 0, \
82674 - .imm = 0 })
82675 -
82676 -/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
82677 -
82678 -#define BPF_ALU64_IMM(OP, DST, IMM) \
82679 - ((struct sock_filter_int) { \
82680 - .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
82681 - .dst_reg = DST, \
82682 - .src_reg = 0, \
82683 - .off = 0, \
82684 - .imm = IMM })
82685 -
82686 -#define BPF_ALU32_IMM(OP, DST, IMM) \
82687 - ((struct sock_filter_int) { \
82688 - .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
82689 - .dst_reg = DST, \
82690 - .src_reg = 0, \
82691 - .off = 0, \
82692 - .imm = IMM })
82693 -
82694 -/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
82695 -
82696 -#define BPF_ENDIAN(TYPE, DST, LEN) \
82697 - ((struct sock_filter_int) { \
82698 - .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \
82699 - .dst_reg = DST, \
82700 - .src_reg = 0, \
82701 - .off = 0, \
82702 - .imm = LEN })
82703 -
82704 -/* Short form of mov, dst_reg = src_reg */
82705 -
82706 -#define BPF_MOV64_REG(DST, SRC) \
82707 - ((struct sock_filter_int) { \
82708 - .code = BPF_ALU64 | BPF_MOV | BPF_X, \
82709 - .dst_reg = DST, \
82710 - .src_reg = SRC, \
82711 - .off = 0, \
82712 - .imm = 0 })
82713 -
82714 -#define BPF_MOV32_REG(DST, SRC) \
82715 - ((struct sock_filter_int) { \
82716 - .code = BPF_ALU | BPF_MOV | BPF_X, \
82717 - .dst_reg = DST, \
82718 - .src_reg = SRC, \
82719 - .off = 0, \
82720 - .imm = 0 })
82721 -
82722 -/* Short form of mov, dst_reg = imm32 */
82723 -
82724 -#define BPF_MOV64_IMM(DST, IMM) \
82725 - ((struct sock_filter_int) { \
82726 - .code = BPF_ALU64 | BPF_MOV | BPF_K, \
82727 - .dst_reg = DST, \
82728 - .src_reg = 0, \
82729 - .off = 0, \
82730 - .imm = IMM })
82731 -
82732 -#define BPF_MOV32_IMM(DST, IMM) \
82733 - ((struct sock_filter_int) { \
82734 - .code = BPF_ALU | BPF_MOV | BPF_K, \
82735 - .dst_reg = DST, \
82736 - .src_reg = 0, \
82737 - .off = 0, \
82738 - .imm = IMM })
82739 -
82740 -/* Short form of mov based on type, BPF_X: dst_reg = src_reg, BPF_K: dst_reg = imm32 */
82741 -
82742 -#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) \
82743 - ((struct sock_filter_int) { \
82744 - .code = BPF_ALU64 | BPF_MOV | BPF_SRC(TYPE), \
82745 - .dst_reg = DST, \
82746 - .src_reg = SRC, \
82747 - .off = 0, \
82748 - .imm = IMM })
82749 -
82750 -#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) \
82751 - ((struct sock_filter_int) { \
82752 - .code = BPF_ALU | BPF_MOV | BPF_SRC(TYPE), \
82753 - .dst_reg = DST, \
82754 - .src_reg = SRC, \
82755 - .off = 0, \
82756 - .imm = IMM })
82757 -
82758 -/* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
82759 -
82760 -#define BPF_LD_ABS(SIZE, IMM) \
82761 - ((struct sock_filter_int) { \
82762 - .code = BPF_LD | BPF_SIZE(SIZE) | BPF_ABS, \
82763 - .dst_reg = 0, \
82764 - .src_reg = 0, \
82765 - .off = 0, \
82766 - .imm = IMM })
82767 -
82768 -/* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */
82769 -
82770 -#define BPF_LD_IND(SIZE, SRC, IMM) \
82771 - ((struct sock_filter_int) { \
82772 - .code = BPF_LD | BPF_SIZE(SIZE) | BPF_IND, \
82773 - .dst_reg = 0, \
82774 - .src_reg = SRC, \
82775 - .off = 0, \
82776 - .imm = IMM })
82777 -
82778 -/* Memory load, dst_reg = *(uint *) (src_reg + off16) */
82779 -
82780 -#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
82781 - ((struct sock_filter_int) { \
82782 - .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
82783 - .dst_reg = DST, \
82784 - .src_reg = SRC, \
82785 - .off = OFF, \
82786 - .imm = 0 })
82787 -
82788 -/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
82789 -
82790 -#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
82791 - ((struct sock_filter_int) { \
82792 - .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
82793 - .dst_reg = DST, \
82794 - .src_reg = SRC, \
82795 - .off = OFF, \
82796 - .imm = 0 })
82797 -
82798 -/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
82799 -
82800 -#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
82801 - ((struct sock_filter_int) { \
82802 - .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
82803 - .dst_reg = DST, \
82804 - .src_reg = 0, \
82805 - .off = OFF, \
82806 - .imm = IMM })
82807 -
82808 -/* Conditional jumps against registers, if (dst_reg 'op' src_reg) goto pc + off16 */
82809 -
82810 -#define BPF_JMP_REG(OP, DST, SRC, OFF) \
82811 - ((struct sock_filter_int) { \
82812 - .code = BPF_JMP | BPF_OP(OP) | BPF_X, \
82813 - .dst_reg = DST, \
82814 - .src_reg = SRC, \
82815 - .off = OFF, \
82816 - .imm = 0 })
82817 -
82818 -/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
82819 -
82820 -#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
82821 - ((struct sock_filter_int) { \
82822 - .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
82823 - .dst_reg = DST, \
82824 - .src_reg = 0, \
82825 - .off = OFF, \
82826 - .imm = IMM })
82827 -
82828 -/* Function call */
82829 -
82830 -#define BPF_EMIT_CALL(FUNC) \
82831 - ((struct sock_filter_int) { \
82832 - .code = BPF_JMP | BPF_CALL, \
82833 - .dst_reg = 0, \
82834 - .src_reg = 0, \
82835 - .off = 0, \
82836 - .imm = ((FUNC) - __bpf_call_base) })
82837 -
82838 -/* Raw code statement block */
82839 -
82840 -#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \
82841 - ((struct sock_filter_int) { \
82842 - .code = CODE, \
82843 - .dst_reg = DST, \
82844 - .src_reg = SRC, \
82845 - .off = OFF, \
82846 - .imm = IMM })
82847 -
82848 -/* Program exit */
82849 -
82850 -#define BPF_EXIT_INSN() \
82851 - ((struct sock_filter_int) { \
82852 - .code = BPF_JMP | BPF_EXIT, \
82853 - .dst_reg = 0, \
82854 - .src_reg = 0, \
82855 - .off = 0, \
82856 - .imm = 0 })
82857 -
82858 -#define bytes_to_bpf_size(bytes) \
82859 -({ \
82860 - int bpf_size = -EINVAL; \
82861 - \
82862 - if (bytes == sizeof(u8)) \
82863 - bpf_size = BPF_B; \
82864 - else if (bytes == sizeof(u16)) \
82865 - bpf_size = BPF_H; \
82866 - else if (bytes == sizeof(u32)) \
82867 - bpf_size = BPF_W; \
82868 - else if (bytes == sizeof(u64)) \
82869 - bpf_size = BPF_DW; \
82870 - \
82871 - bpf_size; \
82872 -})
82873 -
82874 -/* Macro to invoke filter function. */
82875 -#define SK_RUN_FILTER(filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi)
82876 -
82877 -struct sock_filter_int {
82878 - __u8 code; /* opcode */
82879 - __u8 dst_reg:4; /* dest register */
82880 - __u8 src_reg:4; /* source register */
82881 - __s16 off; /* signed offset */
82882 - __s32 imm; /* signed immediate constant */
82883 -};
82884 -
82885 #ifdef CONFIG_COMPAT
82886 -/* A struct sock_filter is architecture independent. */
82887 +/*
82888 + * A struct sock_filter is architecture independent.
82889 + */
82890 struct compat_sock_fprog {
82891 u16 len;
82892 - compat_uptr_t filter; /* struct sock_filter * */
82893 + compat_uptr_t filter; /* struct sock_filter * */
82894 };
82895 #endif
82896
82897 -struct sock_fprog_kern {
82898 - u16 len;
82899 - struct sock_filter *filter;
82900 -};
82901 -
82902 struct sk_buff;
82903 struct sock;
82904 -struct seccomp_data;
82905
82906 -struct sk_filter {
82907 +struct sk_filter
82908 +{
82909 atomic_t refcnt;
82910 - u32 jited:1, /* Is our filter JIT'ed? */
82911 - len:31; /* Number of filter blocks */
82912 - struct sock_fprog_kern *orig_prog; /* Original BPF program */
82913 + unsigned int len; /* Number of filter blocks */
82914 struct rcu_head rcu;
82915 unsigned int (*bpf_func)(const struct sk_buff *skb,
82916 - const struct sock_filter_int *filter);
82917 + const struct sock_filter *filter);
82918 union {
82919 - struct sock_filter insns[0];
82920 - struct sock_filter_int insnsi[0];
82921 + struct sock_filter insns[0];
82922 struct work_struct work;
82923 };
82924 };
82925 @@ -343,76 +41,25 @@ static inline unsigned int sk_filter_size(unsigned int proglen)
82926 offsetof(struct sk_filter, insns[proglen]));
82927 }
82928
82929 -#define sk_filter_proglen(fprog) \
82930 - (fprog->len * sizeof(fprog->filter[0]))
82931 -
82932 -int sk_filter(struct sock *sk, struct sk_buff *skb);
82933 -
82934 -void sk_filter_select_runtime(struct sk_filter *fp);
82935 -void sk_filter_free(struct sk_filter *fp);
82936 -
82937 -int sk_convert_filter(struct sock_filter *prog, int len,
82938 - struct sock_filter_int *new_prog, int *new_len);
82939 -
82940 -int sk_unattached_filter_create(struct sk_filter **pfp,
82941 - struct sock_fprog_kern *fprog);
82942 -void sk_unattached_filter_destroy(struct sk_filter *fp);
82943 -
82944 -int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
82945 -int sk_detach_filter(struct sock *sk);
82946 -
82947 -int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
82948 -int sk_get_filter(struct sock *sk, struct sock_filter __user *filter,
82949 - unsigned int len);
82950 -
82951 -void sk_filter_charge(struct sock *sk, struct sk_filter *fp);
82952 -void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
82953 -
82954 -u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
82955 -void bpf_int_jit_compile(struct sk_filter *fp);
82956 -
82957 -#define BPF_ANC BIT(15)
82958 -
82959 -static inline u16 bpf_anc_helper(const struct sock_filter *ftest)
82960 -{
82961 - BUG_ON(ftest->code & BPF_ANC);
82962 -
82963 - switch (ftest->code) {
82964 - case BPF_LD | BPF_W | BPF_ABS:
82965 - case BPF_LD | BPF_H | BPF_ABS:
82966 - case BPF_LD | BPF_B | BPF_ABS:
82967 -#define BPF_ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
82968 - return BPF_ANC | SKF_AD_##CODE
82969 - switch (ftest->k) {
82970 - BPF_ANCILLARY(PROTOCOL);
82971 - BPF_ANCILLARY(PKTTYPE);
82972 - BPF_ANCILLARY(IFINDEX);
82973 - BPF_ANCILLARY(NLATTR);
82974 - BPF_ANCILLARY(NLATTR_NEST);
82975 - BPF_ANCILLARY(MARK);
82976 - BPF_ANCILLARY(QUEUE);
82977 - BPF_ANCILLARY(HATYPE);
82978 - BPF_ANCILLARY(RXHASH);
82979 - BPF_ANCILLARY(CPU);
82980 - BPF_ANCILLARY(ALU_XOR_X);
82981 - BPF_ANCILLARY(VLAN_TAG);
82982 - BPF_ANCILLARY(VLAN_TAG_PRESENT);
82983 - BPF_ANCILLARY(PAY_OFFSET);
82984 - BPF_ANCILLARY(RANDOM);
82985 - }
82986 - /* Fallthrough. */
82987 - default:
82988 - return ftest->code;
82989 - }
82990 -}
82991 +extern int sk_filter(struct sock *sk, struct sk_buff *skb);
82992 +extern unsigned int sk_run_filter(const struct sk_buff *skb,
82993 + const struct sock_filter *filter);
82994 +extern int sk_unattached_filter_create(struct sk_filter **pfp,
82995 + struct sock_fprog *fprog);
82996 +extern void sk_unattached_filter_destroy(struct sk_filter *fp);
82997 +extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
82998 +extern int sk_detach_filter(struct sock *sk);
82999 +extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
83000 +extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len);
83001 +extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
83002
83003 #ifdef CONFIG_BPF_JIT
83004 #include <stdarg.h>
83005 #include <linux/linkage.h>
83006 #include <linux/printk.h>
83007
83008 -void bpf_jit_compile(struct sk_filter *fp);
83009 -void bpf_jit_free(struct sk_filter *fp);
83010 +extern void bpf_jit_compile(struct sk_filter *fp);
83011 +extern void bpf_jit_free(struct sk_filter *fp);
83012
83013 static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
83014 u32 pass, void *image)
83015 @@ -423,22 +70,90 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
83016 print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
83017 16, 1, image, proglen, false);
83018 }
83019 +#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
83020 #else
83021 #include <linux/slab.h>
83022 -
83023 static inline void bpf_jit_compile(struct sk_filter *fp)
83024 {
83025 }
83026 -
83027 static inline void bpf_jit_free(struct sk_filter *fp)
83028 {
83029 kfree(fp);
83030 }
83031 -#endif /* CONFIG_BPF_JIT */
83032 +#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
83033 +#endif
83034
83035 static inline int bpf_tell_extensions(void)
83036 {
83037 return SKF_AD_MAX;
83038 }
83039
83040 +enum {
83041 + BPF_S_RET_K = 1,
83042 + BPF_S_RET_A,
83043 + BPF_S_ALU_ADD_K,
83044 + BPF_S_ALU_ADD_X,
83045 + BPF_S_ALU_SUB_K,
83046 + BPF_S_ALU_SUB_X,
83047 + BPF_S_ALU_MUL_K,
83048 + BPF_S_ALU_MUL_X,
83049 + BPF_S_ALU_DIV_X,
83050 + BPF_S_ALU_MOD_K,
83051 + BPF_S_ALU_MOD_X,
83052 + BPF_S_ALU_AND_K,
83053 + BPF_S_ALU_AND_X,
83054 + BPF_S_ALU_OR_K,
83055 + BPF_S_ALU_OR_X,
83056 + BPF_S_ALU_XOR_K,
83057 + BPF_S_ALU_XOR_X,
83058 + BPF_S_ALU_LSH_K,
83059 + BPF_S_ALU_LSH_X,
83060 + BPF_S_ALU_RSH_K,
83061 + BPF_S_ALU_RSH_X,
83062 + BPF_S_ALU_NEG,
83063 + BPF_S_LD_W_ABS,
83064 + BPF_S_LD_H_ABS,
83065 + BPF_S_LD_B_ABS,
83066 + BPF_S_LD_W_LEN,
83067 + BPF_S_LD_W_IND,
83068 + BPF_S_LD_H_IND,
83069 + BPF_S_LD_B_IND,
83070 + BPF_S_LD_IMM,
83071 + BPF_S_LDX_W_LEN,
83072 + BPF_S_LDX_B_MSH,
83073 + BPF_S_LDX_IMM,
83074 + BPF_S_MISC_TAX,
83075 + BPF_S_MISC_TXA,
83076 + BPF_S_ALU_DIV_K,
83077 + BPF_S_LD_MEM,
83078 + BPF_S_LDX_MEM,
83079 + BPF_S_ST,
83080 + BPF_S_STX,
83081 + BPF_S_JMP_JA,
83082 + BPF_S_JMP_JEQ_K,
83083 + BPF_S_JMP_JEQ_X,
83084 + BPF_S_JMP_JGE_K,
83085 + BPF_S_JMP_JGE_X,
83086 + BPF_S_JMP_JGT_K,
83087 + BPF_S_JMP_JGT_X,
83088 + BPF_S_JMP_JSET_K,
83089 + BPF_S_JMP_JSET_X,
83090 + /* Ancillary data */
83091 + BPF_S_ANC_PROTOCOL,
83092 + BPF_S_ANC_PKTTYPE,
83093 + BPF_S_ANC_IFINDEX,
83094 + BPF_S_ANC_NLATTR,
83095 + BPF_S_ANC_NLATTR_NEST,
83096 + BPF_S_ANC_MARK,
83097 + BPF_S_ANC_QUEUE,
83098 + BPF_S_ANC_HATYPE,
83099 + BPF_S_ANC_RXHASH,
83100 + BPF_S_ANC_CPU,
83101 + BPF_S_ANC_ALU_XOR_X,
83102 + BPF_S_ANC_SECCOMP_LD_W,
83103 + BPF_S_ANC_VLAN_TAG,
83104 + BPF_S_ANC_VLAN_TAG_PRESENT,
83105 + BPF_S_ANC_PAY_OFFSET,
83106 +};
83107 +
83108 #endif /* __LINUX_FILTER_H__ */
83109 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
83110 index 8293262..2b3b8bd 100644
83111 --- a/include/linux/frontswap.h
83112 +++ b/include/linux/frontswap.h
83113 @@ -11,7 +11,7 @@ struct frontswap_ops {
83114 int (*load)(unsigned, pgoff_t, struct page *);
83115 void (*invalidate_page)(unsigned, pgoff_t);
83116 void (*invalidate_area)(unsigned);
83117 -};
83118 +} __no_const;
83119
83120 extern bool frontswap_enabled;
83121 extern struct frontswap_ops *
83122 diff --git a/include/linux/fs.h b/include/linux/fs.h
83123 index e11d60c..901317a 100644
83124 --- a/include/linux/fs.h
83125 +++ b/include/linux/fs.h
83126 @@ -401,7 +401,7 @@ struct address_space {
83127 spinlock_t private_lock; /* for use by the address_space */
83128 struct list_head private_list; /* ditto */
83129 void *private_data; /* ditto */
83130 -} __attribute__((aligned(sizeof(long))));
83131 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
83132 /*
83133 * On most architectures that alignment is already the case; but
83134 * must be enforced here for CRIS, to let the least significant bit
83135 @@ -444,7 +444,7 @@ struct block_device {
83136 int bd_fsfreeze_count;
83137 /* Mutex for freeze */
83138 struct mutex bd_fsfreeze_mutex;
83139 -};
83140 +} __randomize_layout;
83141
83142 /*
83143 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
83144 @@ -588,7 +588,7 @@ struct inode {
83145 #endif
83146
83147 void *i_private; /* fs or device private pointer */
83148 -};
83149 +} __randomize_layout;
83150
83151 static inline int inode_unhashed(struct inode *inode)
83152 {
83153 @@ -781,7 +781,7 @@ struct file {
83154 struct list_head f_tfile_llink;
83155 #endif /* #ifdef CONFIG_EPOLL */
83156 struct address_space *f_mapping;
83157 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
83158 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
83159
83160 struct file_handle {
83161 __u32 handle_bytes;
83162 @@ -909,7 +909,7 @@ struct file_lock {
83163 int state; /* state of grant or error if -ve */
83164 } afs;
83165 } fl_u;
83166 -};
83167 +} __randomize_layout;
83168
83169 /* The following constant reflects the upper bound of the file/locking space */
83170 #ifndef OFFSET_MAX
83171 @@ -1258,7 +1258,7 @@ struct super_block {
83172 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
83173 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
83174 struct rcu_head rcu;
83175 -};
83176 +} __randomize_layout;
83177
83178 extern struct timespec current_fs_time(struct super_block *sb);
83179
83180 @@ -1484,7 +1484,8 @@ struct file_operations {
83181 long (*fallocate)(struct file *file, int mode, loff_t offset,
83182 loff_t len);
83183 int (*show_fdinfo)(struct seq_file *m, struct file *f);
83184 -};
83185 +} __do_const __randomize_layout;
83186 +typedef struct file_operations __no_const file_operations_no_const;
83187
83188 struct inode_operations {
83189 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
83190 @@ -2769,4 +2770,14 @@ static inline bool dir_relax(struct inode *inode)
83191 return !IS_DEADDIR(inode);
83192 }
83193
83194 +static inline bool is_sidechannel_device(const struct inode *inode)
83195 +{
83196 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
83197 + umode_t mode = inode->i_mode;
83198 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
83199 +#else
83200 + return false;
83201 +#endif
83202 +}
83203 +
83204 #endif /* _LINUX_FS_H */
83205 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
83206 index 0efc3e6..fd23610 100644
83207 --- a/include/linux/fs_struct.h
83208 +++ b/include/linux/fs_struct.h
83209 @@ -6,13 +6,13 @@
83210 #include <linux/seqlock.h>
83211
83212 struct fs_struct {
83213 - int users;
83214 + atomic_t users;
83215 spinlock_t lock;
83216 seqcount_t seq;
83217 int umask;
83218 int in_exec;
83219 struct path root, pwd;
83220 -};
83221 +} __randomize_layout;
83222
83223 extern struct kmem_cache *fs_cachep;
83224
83225 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
83226 index 7714849..a4a5c7a 100644
83227 --- a/include/linux/fscache-cache.h
83228 +++ b/include/linux/fscache-cache.h
83229 @@ -113,7 +113,7 @@ struct fscache_operation {
83230 fscache_operation_release_t release;
83231 };
83232
83233 -extern atomic_t fscache_op_debug_id;
83234 +extern atomic_unchecked_t fscache_op_debug_id;
83235 extern void fscache_op_work_func(struct work_struct *work);
83236
83237 extern void fscache_enqueue_operation(struct fscache_operation *);
83238 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
83239 INIT_WORK(&op->work, fscache_op_work_func);
83240 atomic_set(&op->usage, 1);
83241 op->state = FSCACHE_OP_ST_INITIALISED;
83242 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
83243 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
83244 op->processor = processor;
83245 op->release = release;
83246 INIT_LIST_HEAD(&op->pend_link);
83247 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
83248 index 115bb81..e7b812b 100644
83249 --- a/include/linux/fscache.h
83250 +++ b/include/linux/fscache.h
83251 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
83252 * - this is mandatory for any object that may have data
83253 */
83254 void (*now_uncached)(void *cookie_netfs_data);
83255 -};
83256 +} __do_const;
83257
83258 /*
83259 * fscache cached network filesystem type
83260 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
83261 index 1c804b0..1432c2b 100644
83262 --- a/include/linux/fsnotify.h
83263 +++ b/include/linux/fsnotify.h
83264 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
83265 struct inode *inode = file_inode(file);
83266 __u32 mask = FS_ACCESS;
83267
83268 + if (is_sidechannel_device(inode))
83269 + return;
83270 +
83271 if (S_ISDIR(inode->i_mode))
83272 mask |= FS_ISDIR;
83273
83274 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
83275 struct inode *inode = file_inode(file);
83276 __u32 mask = FS_MODIFY;
83277
83278 + if (is_sidechannel_device(inode))
83279 + return;
83280 +
83281 if (S_ISDIR(inode->i_mode))
83282 mask |= FS_ISDIR;
83283
83284 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
83285 */
83286 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
83287 {
83288 - return kstrdup(name, GFP_KERNEL);
83289 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
83290 }
83291
83292 /*
83293 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
83294 index ec274e0..e678159 100644
83295 --- a/include/linux/genhd.h
83296 +++ b/include/linux/genhd.h
83297 @@ -194,7 +194,7 @@ struct gendisk {
83298 struct kobject *slave_dir;
83299
83300 struct timer_rand_state *random;
83301 - atomic_t sync_io; /* RAID */
83302 + atomic_unchecked_t sync_io; /* RAID */
83303 struct disk_events *ev;
83304 #ifdef CONFIG_BLK_DEV_INTEGRITY
83305 struct blk_integrity *integrity;
83306 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
83307 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
83308
83309 /* drivers/char/random.c */
83310 -extern void add_disk_randomness(struct gendisk *disk);
83311 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
83312 extern void rand_initialize_disk(struct gendisk *disk);
83313
83314 static inline sector_t get_start_sect(struct block_device *bdev)
83315 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
83316 index c0894dd..2fbf10c 100644
83317 --- a/include/linux/genl_magic_func.h
83318 +++ b/include/linux/genl_magic_func.h
83319 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
83320 },
83321
83322 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
83323 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
83324 +static struct genl_ops ZZZ_genl_ops[] = {
83325 #include GENL_MAGIC_INCLUDE_FILE
83326 };
83327
83328 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
83329 index 6eb1fb3..30fe7e4 100644
83330 --- a/include/linux/gfp.h
83331 +++ b/include/linux/gfp.h
83332 @@ -34,6 +34,13 @@ struct vm_area_struct;
83333 #define ___GFP_NO_KSWAPD 0x400000u
83334 #define ___GFP_OTHER_NODE 0x800000u
83335 #define ___GFP_WRITE 0x1000000u
83336 +
83337 +#ifdef CONFIG_PAX_USERCOPY_SLABS
83338 +#define ___GFP_USERCOPY 0x2000000u
83339 +#else
83340 +#define ___GFP_USERCOPY 0
83341 +#endif
83342 +
83343 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
83344
83345 /*
83346 @@ -90,6 +97,7 @@ struct vm_area_struct;
83347 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
83348 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
83349 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
83350 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
83351
83352 /*
83353 * This may seem redundant, but it's a way of annotating false positives vs.
83354 @@ -97,7 +105,7 @@ struct vm_area_struct;
83355 */
83356 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
83357
83358 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
83359 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
83360 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
83361
83362 /* This equals 0, but use constants in case they ever change */
83363 @@ -155,6 +163,8 @@ struct vm_area_struct;
83364 /* 4GB DMA on some platforms */
83365 #define GFP_DMA32 __GFP_DMA32
83366
83367 +#define GFP_USERCOPY __GFP_USERCOPY
83368 +
83369 /* Convert GFP flags to their corresponding migrate type */
83370 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
83371 {
83372 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
83373 new file mode 100644
83374 index 0000000..edb2cb6
83375 --- /dev/null
83376 +++ b/include/linux/gracl.h
83377 @@ -0,0 +1,340 @@
83378 +#ifndef GR_ACL_H
83379 +#define GR_ACL_H
83380 +
83381 +#include <linux/grdefs.h>
83382 +#include <linux/resource.h>
83383 +#include <linux/capability.h>
83384 +#include <linux/dcache.h>
83385 +#include <asm/resource.h>
83386 +
83387 +/* Major status information */
83388 +
83389 +#define GR_VERSION "grsecurity 3.0"
83390 +#define GRSECURITY_VERSION 0x3000
83391 +
83392 +enum {
83393 + GR_SHUTDOWN = 0,
83394 + GR_ENABLE = 1,
83395 + GR_SPROLE = 2,
83396 + GR_OLDRELOAD = 3,
83397 + GR_SEGVMOD = 4,
83398 + GR_STATUS = 5,
83399 + GR_UNSPROLE = 6,
83400 + GR_PASSSET = 7,
83401 + GR_SPROLEPAM = 8,
83402 + GR_RELOAD = 9,
83403 +};
83404 +
83405 +/* Password setup definitions
83406 + * kernel/grhash.c */
83407 +enum {
83408 + GR_PW_LEN = 128,
83409 + GR_SALT_LEN = 16,
83410 + GR_SHA_LEN = 32,
83411 +};
83412 +
83413 +enum {
83414 + GR_SPROLE_LEN = 64,
83415 +};
83416 +
83417 +enum {
83418 + GR_NO_GLOB = 0,
83419 + GR_REG_GLOB,
83420 + GR_CREATE_GLOB
83421 +};
83422 +
83423 +#define GR_NLIMITS 32
83424 +
83425 +/* Begin Data Structures */
83426 +
83427 +struct sprole_pw {
83428 + unsigned char *rolename;
83429 + unsigned char salt[GR_SALT_LEN];
83430 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
83431 +};
83432 +
83433 +struct name_entry {
83434 + __u32 key;
83435 + ino_t inode;
83436 + dev_t device;
83437 + char *name;
83438 + __u16 len;
83439 + __u8 deleted;
83440 + struct name_entry *prev;
83441 + struct name_entry *next;
83442 +};
83443 +
83444 +struct inodev_entry {
83445 + struct name_entry *nentry;
83446 + struct inodev_entry *prev;
83447 + struct inodev_entry *next;
83448 +};
83449 +
83450 +struct acl_role_db {
83451 + struct acl_role_label **r_hash;
83452 + __u32 r_size;
83453 +};
83454 +
83455 +struct inodev_db {
83456 + struct inodev_entry **i_hash;
83457 + __u32 i_size;
83458 +};
83459 +
83460 +struct name_db {
83461 + struct name_entry **n_hash;
83462 + __u32 n_size;
83463 +};
83464 +
83465 +struct crash_uid {
83466 + uid_t uid;
83467 + unsigned long expires;
83468 +};
83469 +
83470 +struct gr_hash_struct {
83471 + void **table;
83472 + void **nametable;
83473 + void *first;
83474 + __u32 table_size;
83475 + __u32 used_size;
83476 + int type;
83477 +};
83478 +
83479 +/* Userspace Grsecurity ACL data structures */
83480 +
83481 +struct acl_subject_label {
83482 + char *filename;
83483 + ino_t inode;
83484 + dev_t device;
83485 + __u32 mode;
83486 + kernel_cap_t cap_mask;
83487 + kernel_cap_t cap_lower;
83488 + kernel_cap_t cap_invert_audit;
83489 +
83490 + struct rlimit res[GR_NLIMITS];
83491 + __u32 resmask;
83492 +
83493 + __u8 user_trans_type;
83494 + __u8 group_trans_type;
83495 + uid_t *user_transitions;
83496 + gid_t *group_transitions;
83497 + __u16 user_trans_num;
83498 + __u16 group_trans_num;
83499 +
83500 + __u32 sock_families[2];
83501 + __u32 ip_proto[8];
83502 + __u32 ip_type;
83503 + struct acl_ip_label **ips;
83504 + __u32 ip_num;
83505 + __u32 inaddr_any_override;
83506 +
83507 + __u32 crashes;
83508 + unsigned long expires;
83509 +
83510 + struct acl_subject_label *parent_subject;
83511 + struct gr_hash_struct *hash;
83512 + struct acl_subject_label *prev;
83513 + struct acl_subject_label *next;
83514 +
83515 + struct acl_object_label **obj_hash;
83516 + __u32 obj_hash_size;
83517 + __u16 pax_flags;
83518 +};
83519 +
83520 +struct role_allowed_ip {
83521 + __u32 addr;
83522 + __u32 netmask;
83523 +
83524 + struct role_allowed_ip *prev;
83525 + struct role_allowed_ip *next;
83526 +};
83527 +
83528 +struct role_transition {
83529 + char *rolename;
83530 +
83531 + struct role_transition *prev;
83532 + struct role_transition *next;
83533 +};
83534 +
83535 +struct acl_role_label {
83536 + char *rolename;
83537 + uid_t uidgid;
83538 + __u16 roletype;
83539 +
83540 + __u16 auth_attempts;
83541 + unsigned long expires;
83542 +
83543 + struct acl_subject_label *root_label;
83544 + struct gr_hash_struct *hash;
83545 +
83546 + struct acl_role_label *prev;
83547 + struct acl_role_label *next;
83548 +
83549 + struct role_transition *transitions;
83550 + struct role_allowed_ip *allowed_ips;
83551 + uid_t *domain_children;
83552 + __u16 domain_child_num;
83553 +
83554 + umode_t umask;
83555 +
83556 + struct acl_subject_label **subj_hash;
83557 + __u32 subj_hash_size;
83558 +};
83559 +
83560 +struct user_acl_role_db {
83561 + struct acl_role_label **r_table;
83562 + __u32 num_pointers; /* Number of allocations to track */
83563 + __u32 num_roles; /* Number of roles */
83564 + __u32 num_domain_children; /* Number of domain children */
83565 + __u32 num_subjects; /* Number of subjects */
83566 + __u32 num_objects; /* Number of objects */
83567 +};
83568 +
83569 +struct acl_object_label {
83570 + char *filename;
83571 + ino_t inode;
83572 + dev_t device;
83573 + __u32 mode;
83574 +
83575 + struct acl_subject_label *nested;
83576 + struct acl_object_label *globbed;
83577 +
83578 + /* next two structures not used */
83579 +
83580 + struct acl_object_label *prev;
83581 + struct acl_object_label *next;
83582 +};
83583 +
83584 +struct acl_ip_label {
83585 + char *iface;
83586 + __u32 addr;
83587 + __u32 netmask;
83588 + __u16 low, high;
83589 + __u8 mode;
83590 + __u32 type;
83591 + __u32 proto[8];
83592 +
83593 + /* next two structures not used */
83594 +
83595 + struct acl_ip_label *prev;
83596 + struct acl_ip_label *next;
83597 +};
83598 +
83599 +struct gr_arg {
83600 + struct user_acl_role_db role_db;
83601 + unsigned char pw[GR_PW_LEN];
83602 + unsigned char salt[GR_SALT_LEN];
83603 + unsigned char sum[GR_SHA_LEN];
83604 + unsigned char sp_role[GR_SPROLE_LEN];
83605 + struct sprole_pw *sprole_pws;
83606 + dev_t segv_device;
83607 + ino_t segv_inode;
83608 + uid_t segv_uid;
83609 + __u16 num_sprole_pws;
83610 + __u16 mode;
83611 +};
83612 +
83613 +struct gr_arg_wrapper {
83614 + struct gr_arg *arg;
83615 + __u32 version;
83616 + __u32 size;
83617 +};
83618 +
83619 +struct subject_map {
83620 + struct acl_subject_label *user;
83621 + struct acl_subject_label *kernel;
83622 + struct subject_map *prev;
83623 + struct subject_map *next;
83624 +};
83625 +
83626 +struct acl_subj_map_db {
83627 + struct subject_map **s_hash;
83628 + __u32 s_size;
83629 +};
83630 +
83631 +struct gr_policy_state {
83632 + struct sprole_pw **acl_special_roles;
83633 + __u16 num_sprole_pws;
83634 + struct acl_role_label *kernel_role;
83635 + struct acl_role_label *role_list;
83636 + struct acl_role_label *default_role;
83637 + struct acl_role_db acl_role_set;
83638 + struct acl_subj_map_db subj_map_set;
83639 + struct name_db name_set;
83640 + struct inodev_db inodev_set;
83641 +};
83642 +
83643 +struct gr_alloc_state {
83644 + unsigned long alloc_stack_next;
83645 + unsigned long alloc_stack_size;
83646 + void **alloc_stack;
83647 +};
83648 +
83649 +struct gr_reload_state {
83650 + struct gr_policy_state oldpolicy;
83651 + struct gr_alloc_state oldalloc;
83652 + struct gr_policy_state newpolicy;
83653 + struct gr_alloc_state newalloc;
83654 + struct gr_policy_state *oldpolicy_ptr;
83655 + struct gr_alloc_state *oldalloc_ptr;
83656 + unsigned char oldmode;
83657 +};
83658 +
83659 +/* End Data Structures Section */
83660 +
83661 +/* Hash functions generated by empirical testing by Brad Spengler
83662 + Makes good use of the low bits of the inode. Generally 0-1 times
83663 + in loop for successful match. 0-3 for unsuccessful match.
83664 + Shift/add algorithm with modulus of table size and an XOR*/
83665 +
83666 +static __inline__ unsigned int
83667 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
83668 +{
83669 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
83670 +}
83671 +
83672 + static __inline__ unsigned int
83673 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
83674 +{
83675 + return ((const unsigned long)userp % sz);
83676 +}
83677 +
83678 +static __inline__ unsigned int
83679 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
83680 +{
83681 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
83682 +}
83683 +
83684 +static __inline__ unsigned int
83685 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
83686 +{
83687 + return full_name_hash((const unsigned char *)name, len) % sz;
83688 +}
83689 +
83690 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
83691 + subj = NULL; \
83692 + iter = 0; \
83693 + while (iter < role->subj_hash_size) { \
83694 + if (subj == NULL) \
83695 + subj = role->subj_hash[iter]; \
83696 + if (subj == NULL) { \
83697 + iter++; \
83698 + continue; \
83699 + }
83700 +
83701 +#define FOR_EACH_SUBJECT_END(subj,iter) \
83702 + subj = subj->next; \
83703 + if (subj == NULL) \
83704 + iter++; \
83705 + }
83706 +
83707 +
83708 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
83709 + subj = role->hash->first; \
83710 + while (subj != NULL) {
83711 +
83712 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
83713 + subj = subj->next; \
83714 + }
83715 +
83716 +#endif
83717 +
83718 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
83719 new file mode 100644
83720 index 0000000..33ebd1f
83721 --- /dev/null
83722 +++ b/include/linux/gracl_compat.h
83723 @@ -0,0 +1,156 @@
83724 +#ifndef GR_ACL_COMPAT_H
83725 +#define GR_ACL_COMPAT_H
83726 +
83727 +#include <linux/resource.h>
83728 +#include <asm/resource.h>
83729 +
83730 +struct sprole_pw_compat {
83731 + compat_uptr_t rolename;
83732 + unsigned char salt[GR_SALT_LEN];
83733 + unsigned char sum[GR_SHA_LEN];
83734 +};
83735 +
83736 +struct gr_hash_struct_compat {
83737 + compat_uptr_t table;
83738 + compat_uptr_t nametable;
83739 + compat_uptr_t first;
83740 + __u32 table_size;
83741 + __u32 used_size;
83742 + int type;
83743 +};
83744 +
83745 +struct acl_subject_label_compat {
83746 + compat_uptr_t filename;
83747 + compat_ino_t inode;
83748 + __u32 device;
83749 + __u32 mode;
83750 + kernel_cap_t cap_mask;
83751 + kernel_cap_t cap_lower;
83752 + kernel_cap_t cap_invert_audit;
83753 +
83754 + struct compat_rlimit res[GR_NLIMITS];
83755 + __u32 resmask;
83756 +
83757 + __u8 user_trans_type;
83758 + __u8 group_trans_type;
83759 + compat_uptr_t user_transitions;
83760 + compat_uptr_t group_transitions;
83761 + __u16 user_trans_num;
83762 + __u16 group_trans_num;
83763 +
83764 + __u32 sock_families[2];
83765 + __u32 ip_proto[8];
83766 + __u32 ip_type;
83767 + compat_uptr_t ips;
83768 + __u32 ip_num;
83769 + __u32 inaddr_any_override;
83770 +
83771 + __u32 crashes;
83772 + compat_ulong_t expires;
83773 +
83774 + compat_uptr_t parent_subject;
83775 + compat_uptr_t hash;
83776 + compat_uptr_t prev;
83777 + compat_uptr_t next;
83778 +
83779 + compat_uptr_t obj_hash;
83780 + __u32 obj_hash_size;
83781 + __u16 pax_flags;
83782 +};
83783 +
83784 +struct role_allowed_ip_compat {
83785 + __u32 addr;
83786 + __u32 netmask;
83787 +
83788 + compat_uptr_t prev;
83789 + compat_uptr_t next;
83790 +};
83791 +
83792 +struct role_transition_compat {
83793 + compat_uptr_t rolename;
83794 +
83795 + compat_uptr_t prev;
83796 + compat_uptr_t next;
83797 +};
83798 +
83799 +struct acl_role_label_compat {
83800 + compat_uptr_t rolename;
83801 + uid_t uidgid;
83802 + __u16 roletype;
83803 +
83804 + __u16 auth_attempts;
83805 + compat_ulong_t expires;
83806 +
83807 + compat_uptr_t root_label;
83808 + compat_uptr_t hash;
83809 +
83810 + compat_uptr_t prev;
83811 + compat_uptr_t next;
83812 +
83813 + compat_uptr_t transitions;
83814 + compat_uptr_t allowed_ips;
83815 + compat_uptr_t domain_children;
83816 + __u16 domain_child_num;
83817 +
83818 + umode_t umask;
83819 +
83820 + compat_uptr_t subj_hash;
83821 + __u32 subj_hash_size;
83822 +};
83823 +
83824 +struct user_acl_role_db_compat {
83825 + compat_uptr_t r_table;
83826 + __u32 num_pointers;
83827 + __u32 num_roles;
83828 + __u32 num_domain_children;
83829 + __u32 num_subjects;
83830 + __u32 num_objects;
83831 +};
83832 +
83833 +struct acl_object_label_compat {
83834 + compat_uptr_t filename;
83835 + compat_ino_t inode;
83836 + __u32 device;
83837 + __u32 mode;
83838 +
83839 + compat_uptr_t nested;
83840 + compat_uptr_t globbed;
83841 +
83842 + compat_uptr_t prev;
83843 + compat_uptr_t next;
83844 +};
83845 +
83846 +struct acl_ip_label_compat {
83847 + compat_uptr_t iface;
83848 + __u32 addr;
83849 + __u32 netmask;
83850 + __u16 low, high;
83851 + __u8 mode;
83852 + __u32 type;
83853 + __u32 proto[8];
83854 +
83855 + compat_uptr_t prev;
83856 + compat_uptr_t next;
83857 +};
83858 +
83859 +struct gr_arg_compat {
83860 + struct user_acl_role_db_compat role_db;
83861 + unsigned char pw[GR_PW_LEN];
83862 + unsigned char salt[GR_SALT_LEN];
83863 + unsigned char sum[GR_SHA_LEN];
83864 + unsigned char sp_role[GR_SPROLE_LEN];
83865 + compat_uptr_t sprole_pws;
83866 + __u32 segv_device;
83867 + compat_ino_t segv_inode;
83868 + uid_t segv_uid;
83869 + __u16 num_sprole_pws;
83870 + __u16 mode;
83871 +};
83872 +
83873 +struct gr_arg_wrapper_compat {
83874 + compat_uptr_t arg;
83875 + __u32 version;
83876 + __u32 size;
83877 +};
83878 +
83879 +#endif
83880 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
83881 new file mode 100644
83882 index 0000000..323ecf2
83883 --- /dev/null
83884 +++ b/include/linux/gralloc.h
83885 @@ -0,0 +1,9 @@
83886 +#ifndef __GRALLOC_H
83887 +#define __GRALLOC_H
83888 +
83889 +void acl_free_all(void);
83890 +int acl_alloc_stack_init(unsigned long size);
83891 +void *acl_alloc(unsigned long len);
83892 +void *acl_alloc_num(unsigned long num, unsigned long len);
83893 +
83894 +#endif
83895 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
83896 new file mode 100644
83897 index 0000000..be66033
83898 --- /dev/null
83899 +++ b/include/linux/grdefs.h
83900 @@ -0,0 +1,140 @@
83901 +#ifndef GRDEFS_H
83902 +#define GRDEFS_H
83903 +
83904 +/* Begin grsecurity status declarations */
83905 +
83906 +enum {
83907 + GR_READY = 0x01,
83908 + GR_STATUS_INIT = 0x00 // disabled state
83909 +};
83910 +
83911 +/* Begin ACL declarations */
83912 +
83913 +/* Role flags */
83914 +
83915 +enum {
83916 + GR_ROLE_USER = 0x0001,
83917 + GR_ROLE_GROUP = 0x0002,
83918 + GR_ROLE_DEFAULT = 0x0004,
83919 + GR_ROLE_SPECIAL = 0x0008,
83920 + GR_ROLE_AUTH = 0x0010,
83921 + GR_ROLE_NOPW = 0x0020,
83922 + GR_ROLE_GOD = 0x0040,
83923 + GR_ROLE_LEARN = 0x0080,
83924 + GR_ROLE_TPE = 0x0100,
83925 + GR_ROLE_DOMAIN = 0x0200,
83926 + GR_ROLE_PAM = 0x0400,
83927 + GR_ROLE_PERSIST = 0x0800
83928 +};
83929 +
83930 +/* ACL Subject and Object mode flags */
83931 +enum {
83932 + GR_DELETED = 0x80000000
83933 +};
83934 +
83935 +/* ACL Object-only mode flags */
83936 +enum {
83937 + GR_READ = 0x00000001,
83938 + GR_APPEND = 0x00000002,
83939 + GR_WRITE = 0x00000004,
83940 + GR_EXEC = 0x00000008,
83941 + GR_FIND = 0x00000010,
83942 + GR_INHERIT = 0x00000020,
83943 + GR_SETID = 0x00000040,
83944 + GR_CREATE = 0x00000080,
83945 + GR_DELETE = 0x00000100,
83946 + GR_LINK = 0x00000200,
83947 + GR_AUDIT_READ = 0x00000400,
83948 + GR_AUDIT_APPEND = 0x00000800,
83949 + GR_AUDIT_WRITE = 0x00001000,
83950 + GR_AUDIT_EXEC = 0x00002000,
83951 + GR_AUDIT_FIND = 0x00004000,
83952 + GR_AUDIT_INHERIT= 0x00008000,
83953 + GR_AUDIT_SETID = 0x00010000,
83954 + GR_AUDIT_CREATE = 0x00020000,
83955 + GR_AUDIT_DELETE = 0x00040000,
83956 + GR_AUDIT_LINK = 0x00080000,
83957 + GR_PTRACERD = 0x00100000,
83958 + GR_NOPTRACE = 0x00200000,
83959 + GR_SUPPRESS = 0x00400000,
83960 + GR_NOLEARN = 0x00800000,
83961 + GR_INIT_TRANSFER= 0x01000000
83962 +};
83963 +
83964 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
83965 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
83966 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
83967 +
83968 +/* ACL subject-only mode flags */
83969 +enum {
83970 + GR_KILL = 0x00000001,
83971 + GR_VIEW = 0x00000002,
83972 + GR_PROTECTED = 0x00000004,
83973 + GR_LEARN = 0x00000008,
83974 + GR_OVERRIDE = 0x00000010,
83975 + /* just a placeholder, this mode is only used in userspace */
83976 + GR_DUMMY = 0x00000020,
83977 + GR_PROTSHM = 0x00000040,
83978 + GR_KILLPROC = 0x00000080,
83979 + GR_KILLIPPROC = 0x00000100,
83980 + /* just a placeholder, this mode is only used in userspace */
83981 + GR_NOTROJAN = 0x00000200,
83982 + GR_PROTPROCFD = 0x00000400,
83983 + GR_PROCACCT = 0x00000800,
83984 + GR_RELAXPTRACE = 0x00001000,
83985 + //GR_NESTED = 0x00002000,
83986 + GR_INHERITLEARN = 0x00004000,
83987 + GR_PROCFIND = 0x00008000,
83988 + GR_POVERRIDE = 0x00010000,
83989 + GR_KERNELAUTH = 0x00020000,
83990 + GR_ATSECURE = 0x00040000,
83991 + GR_SHMEXEC = 0x00080000
83992 +};
83993 +
83994 +enum {
83995 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
83996 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
83997 + GR_PAX_ENABLE_MPROTECT = 0x0004,
83998 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
83999 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
84000 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
84001 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
84002 + GR_PAX_DISABLE_MPROTECT = 0x0400,
84003 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
84004 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
84005 +};
84006 +
84007 +enum {
84008 + GR_ID_USER = 0x01,
84009 + GR_ID_GROUP = 0x02,
84010 +};
84011 +
84012 +enum {
84013 + GR_ID_ALLOW = 0x01,
84014 + GR_ID_DENY = 0x02,
84015 +};
84016 +
84017 +#define GR_CRASH_RES 31
84018 +#define GR_UIDTABLE_MAX 500
84019 +
84020 +/* begin resource learning section */
84021 +enum {
84022 + GR_RLIM_CPU_BUMP = 60,
84023 + GR_RLIM_FSIZE_BUMP = 50000,
84024 + GR_RLIM_DATA_BUMP = 10000,
84025 + GR_RLIM_STACK_BUMP = 1000,
84026 + GR_RLIM_CORE_BUMP = 10000,
84027 + GR_RLIM_RSS_BUMP = 500000,
84028 + GR_RLIM_NPROC_BUMP = 1,
84029 + GR_RLIM_NOFILE_BUMP = 5,
84030 + GR_RLIM_MEMLOCK_BUMP = 50000,
84031 + GR_RLIM_AS_BUMP = 500000,
84032 + GR_RLIM_LOCKS_BUMP = 2,
84033 + GR_RLIM_SIGPENDING_BUMP = 5,
84034 + GR_RLIM_MSGQUEUE_BUMP = 10000,
84035 + GR_RLIM_NICE_BUMP = 1,
84036 + GR_RLIM_RTPRIO_BUMP = 1,
84037 + GR_RLIM_RTTIME_BUMP = 1000000
84038 +};
84039 +
84040 +#endif
84041 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
84042 new file mode 100644
84043 index 0000000..d25522e
84044 --- /dev/null
84045 +++ b/include/linux/grinternal.h
84046 @@ -0,0 +1,229 @@
84047 +#ifndef __GRINTERNAL_H
84048 +#define __GRINTERNAL_H
84049 +
84050 +#ifdef CONFIG_GRKERNSEC
84051 +
84052 +#include <linux/fs.h>
84053 +#include <linux/mnt_namespace.h>
84054 +#include <linux/nsproxy.h>
84055 +#include <linux/gracl.h>
84056 +#include <linux/grdefs.h>
84057 +#include <linux/grmsg.h>
84058 +
84059 +void gr_add_learn_entry(const char *fmt, ...)
84060 + __attribute__ ((format (printf, 1, 2)));
84061 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
84062 + const struct vfsmount *mnt);
84063 +__u32 gr_check_create(const struct dentry *new_dentry,
84064 + const struct dentry *parent,
84065 + const struct vfsmount *mnt, const __u32 mode);
84066 +int gr_check_protected_task(const struct task_struct *task);
84067 +__u32 to_gr_audit(const __u32 reqmode);
84068 +int gr_set_acls(const int type);
84069 +int gr_acl_is_enabled(void);
84070 +char gr_roletype_to_char(void);
84071 +
84072 +void gr_handle_alertkill(struct task_struct *task);
84073 +char *gr_to_filename(const struct dentry *dentry,
84074 + const struct vfsmount *mnt);
84075 +char *gr_to_filename1(const struct dentry *dentry,
84076 + const struct vfsmount *mnt);
84077 +char *gr_to_filename2(const struct dentry *dentry,
84078 + const struct vfsmount *mnt);
84079 +char *gr_to_filename3(const struct dentry *dentry,
84080 + const struct vfsmount *mnt);
84081 +
84082 +extern int grsec_enable_ptrace_readexec;
84083 +extern int grsec_enable_harden_ptrace;
84084 +extern int grsec_enable_link;
84085 +extern int grsec_enable_fifo;
84086 +extern int grsec_enable_execve;
84087 +extern int grsec_enable_shm;
84088 +extern int grsec_enable_execlog;
84089 +extern int grsec_enable_signal;
84090 +extern int grsec_enable_audit_ptrace;
84091 +extern int grsec_enable_forkfail;
84092 +extern int grsec_enable_time;
84093 +extern int grsec_enable_rofs;
84094 +extern int grsec_deny_new_usb;
84095 +extern int grsec_enable_chroot_shmat;
84096 +extern int grsec_enable_chroot_mount;
84097 +extern int grsec_enable_chroot_double;
84098 +extern int grsec_enable_chroot_pivot;
84099 +extern int grsec_enable_chroot_chdir;
84100 +extern int grsec_enable_chroot_chmod;
84101 +extern int grsec_enable_chroot_mknod;
84102 +extern int grsec_enable_chroot_fchdir;
84103 +extern int grsec_enable_chroot_nice;
84104 +extern int grsec_enable_chroot_execlog;
84105 +extern int grsec_enable_chroot_caps;
84106 +extern int grsec_enable_chroot_sysctl;
84107 +extern int grsec_enable_chroot_unix;
84108 +extern int grsec_enable_symlinkown;
84109 +extern kgid_t grsec_symlinkown_gid;
84110 +extern int grsec_enable_tpe;
84111 +extern kgid_t grsec_tpe_gid;
84112 +extern int grsec_enable_tpe_all;
84113 +extern int grsec_enable_tpe_invert;
84114 +extern int grsec_enable_socket_all;
84115 +extern kgid_t grsec_socket_all_gid;
84116 +extern int grsec_enable_socket_client;
84117 +extern kgid_t grsec_socket_client_gid;
84118 +extern int grsec_enable_socket_server;
84119 +extern kgid_t grsec_socket_server_gid;
84120 +extern kgid_t grsec_audit_gid;
84121 +extern int grsec_enable_group;
84122 +extern int grsec_enable_log_rwxmaps;
84123 +extern int grsec_enable_mount;
84124 +extern int grsec_enable_chdir;
84125 +extern int grsec_resource_logging;
84126 +extern int grsec_enable_blackhole;
84127 +extern int grsec_lastack_retries;
84128 +extern int grsec_enable_brute;
84129 +extern int grsec_enable_harden_ipc;
84130 +extern int grsec_lock;
84131 +
84132 +extern spinlock_t grsec_alert_lock;
84133 +extern unsigned long grsec_alert_wtime;
84134 +extern unsigned long grsec_alert_fyet;
84135 +
84136 +extern spinlock_t grsec_audit_lock;
84137 +
84138 +extern rwlock_t grsec_exec_file_lock;
84139 +
84140 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
84141 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
84142 + (tsk)->exec_file->f_path.mnt) : "/")
84143 +
84144 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
84145 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
84146 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
84147 +
84148 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
84149 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
84150 + (tsk)->exec_file->f_path.mnt) : "/")
84151 +
84152 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
84153 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
84154 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
84155 +
84156 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
84157 +
84158 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
84159 +
84160 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
84161 +{
84162 + if (file1 && file2) {
84163 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
84164 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
84165 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
84166 + return true;
84167 + }
84168 +
84169 + return false;
84170 +}
84171 +
84172 +#define GR_CHROOT_CAPS {{ \
84173 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
84174 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
84175 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
84176 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
84177 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
84178 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
84179 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
84180 +
84181 +#define security_learn(normal_msg,args...) \
84182 +({ \
84183 + read_lock(&grsec_exec_file_lock); \
84184 + gr_add_learn_entry(normal_msg "\n", ## args); \
84185 + read_unlock(&grsec_exec_file_lock); \
84186 +})
84187 +
84188 +enum {
84189 + GR_DO_AUDIT,
84190 + GR_DONT_AUDIT,
84191 + /* used for non-audit messages that we shouldn't kill the task on */
84192 + GR_DONT_AUDIT_GOOD
84193 +};
84194 +
84195 +enum {
84196 + GR_TTYSNIFF,
84197 + GR_RBAC,
84198 + GR_RBAC_STR,
84199 + GR_STR_RBAC,
84200 + GR_RBAC_MODE2,
84201 + GR_RBAC_MODE3,
84202 + GR_FILENAME,
84203 + GR_SYSCTL_HIDDEN,
84204 + GR_NOARGS,
84205 + GR_ONE_INT,
84206 + GR_ONE_INT_TWO_STR,
84207 + GR_ONE_STR,
84208 + GR_STR_INT,
84209 + GR_TWO_STR_INT,
84210 + GR_TWO_INT,
84211 + GR_TWO_U64,
84212 + GR_THREE_INT,
84213 + GR_FIVE_INT_TWO_STR,
84214 + GR_TWO_STR,
84215 + GR_THREE_STR,
84216 + GR_FOUR_STR,
84217 + GR_STR_FILENAME,
84218 + GR_FILENAME_STR,
84219 + GR_FILENAME_TWO_INT,
84220 + GR_FILENAME_TWO_INT_STR,
84221 + GR_TEXTREL,
84222 + GR_PTRACE,
84223 + GR_RESOURCE,
84224 + GR_CAP,
84225 + GR_SIG,
84226 + GR_SIG2,
84227 + GR_CRASH1,
84228 + GR_CRASH2,
84229 + GR_PSACCT,
84230 + GR_RWXMAP,
84231 + GR_RWXMAPVMA
84232 +};
84233 +
84234 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
84235 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
84236 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
84237 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
84238 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
84239 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
84240 +#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)
84241 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
84242 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
84243 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
84244 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
84245 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
84246 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
84247 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
84248 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
84249 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
84250 +#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)
84251 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
84252 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
84253 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
84254 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
84255 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
84256 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
84257 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
84258 +#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)
84259 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
84260 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
84261 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
84262 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
84263 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
84264 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
84265 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
84266 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
84267 +#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)
84268 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
84269 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
84270 +
84271 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
84272 +
84273 +#endif
84274 +
84275 +#endif
84276 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
84277 new file mode 100644
84278 index 0000000..b02ba9d
84279 --- /dev/null
84280 +++ b/include/linux/grmsg.h
84281 @@ -0,0 +1,117 @@
84282 +#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"
84283 +#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"
84284 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
84285 +#define GR_STOPMOD_MSG "denied modification of module state by "
84286 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
84287 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
84288 +#define GR_IOPERM_MSG "denied use of ioperm() by "
84289 +#define GR_IOPL_MSG "denied use of iopl() by "
84290 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
84291 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
84292 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
84293 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
84294 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
84295 +#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"
84296 +#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"
84297 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
84298 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
84299 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
84300 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
84301 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
84302 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
84303 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
84304 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
84305 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
84306 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
84307 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
84308 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
84309 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
84310 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
84311 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
84312 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
84313 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
84314 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
84315 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
84316 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
84317 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
84318 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
84319 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
84320 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
84321 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
84322 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
84323 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
84324 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
84325 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
84326 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
84327 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
84328 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
84329 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
84330 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
84331 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
84332 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
84333 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
84334 +#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"
84335 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
84336 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
84337 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
84338 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
84339 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
84340 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
84341 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
84342 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
84343 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
84344 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
84345 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
84346 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
84347 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
84348 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
84349 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
84350 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
84351 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
84352 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
84353 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
84354 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
84355 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
84356 +#define GR_NICE_CHROOT_MSG "denied priority change by "
84357 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
84358 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
84359 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
84360 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
84361 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
84362 +#define GR_TIME_MSG "time set by "
84363 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
84364 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
84365 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
84366 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
84367 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
84368 +#define GR_BIND_MSG "denied bind() by "
84369 +#define GR_CONNECT_MSG "denied connect() by "
84370 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
84371 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
84372 +#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"
84373 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
84374 +#define GR_CAP_ACL_MSG "use of %s denied for "
84375 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
84376 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
84377 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
84378 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
84379 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
84380 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
84381 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
84382 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
84383 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
84384 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
84385 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
84386 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
84387 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
84388 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
84389 +#define GR_VM86_MSG "denied use of vm86 by "
84390 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
84391 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
84392 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
84393 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
84394 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
84395 +#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 "
84396 +#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 "
84397 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
84398 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
84399 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
84400 new file mode 100644
84401 index 0000000..10b9635
84402 --- /dev/null
84403 +++ b/include/linux/grsecurity.h
84404 @@ -0,0 +1,254 @@
84405 +#ifndef GR_SECURITY_H
84406 +#define GR_SECURITY_H
84407 +#include <linux/fs.h>
84408 +#include <linux/fs_struct.h>
84409 +#include <linux/binfmts.h>
84410 +#include <linux/gracl.h>
84411 +
84412 +/* notify of brain-dead configs */
84413 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84414 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
84415 +#endif
84416 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84417 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
84418 +#endif
84419 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
84420 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
84421 +#endif
84422 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
84423 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
84424 +#endif
84425 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
84426 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
84427 +#endif
84428 +
84429 +int gr_handle_new_usb(void);
84430 +
84431 +void gr_handle_brute_attach(int dumpable);
84432 +void gr_handle_brute_check(void);
84433 +void gr_handle_kernel_exploit(void);
84434 +
84435 +char gr_roletype_to_char(void);
84436 +
84437 +int gr_proc_is_restricted(void);
84438 +
84439 +int gr_acl_enable_at_secure(void);
84440 +
84441 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
84442 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
84443 +
84444 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
84445 +
84446 +void gr_del_task_from_ip_table(struct task_struct *p);
84447 +
84448 +int gr_pid_is_chrooted(struct task_struct *p);
84449 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
84450 +int gr_handle_chroot_nice(void);
84451 +int gr_handle_chroot_sysctl(const int op);
84452 +int gr_handle_chroot_setpriority(struct task_struct *p,
84453 + const int niceval);
84454 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
84455 +int gr_chroot_fhandle(void);
84456 +int gr_handle_chroot_chroot(const struct dentry *dentry,
84457 + const struct vfsmount *mnt);
84458 +void gr_handle_chroot_chdir(const struct path *path);
84459 +int gr_handle_chroot_chmod(const struct dentry *dentry,
84460 + const struct vfsmount *mnt, const int mode);
84461 +int gr_handle_chroot_mknod(const struct dentry *dentry,
84462 + const struct vfsmount *mnt, const int mode);
84463 +int gr_handle_chroot_mount(const struct dentry *dentry,
84464 + const struct vfsmount *mnt,
84465 + const char *dev_name);
84466 +int gr_handle_chroot_pivot(void);
84467 +int gr_handle_chroot_unix(const pid_t pid);
84468 +
84469 +int gr_handle_rawio(const struct inode *inode);
84470 +
84471 +void gr_handle_ioperm(void);
84472 +void gr_handle_iopl(void);
84473 +void gr_handle_msr_write(void);
84474 +
84475 +umode_t gr_acl_umask(void);
84476 +
84477 +int gr_tpe_allow(const struct file *file);
84478 +
84479 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
84480 +void gr_clear_chroot_entries(struct task_struct *task);
84481 +
84482 +void gr_log_forkfail(const int retval);
84483 +void gr_log_timechange(void);
84484 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
84485 +void gr_log_chdir(const struct dentry *dentry,
84486 + const struct vfsmount *mnt);
84487 +void gr_log_chroot_exec(const struct dentry *dentry,
84488 + const struct vfsmount *mnt);
84489 +void gr_log_remount(const char *devname, const int retval);
84490 +void gr_log_unmount(const char *devname, const int retval);
84491 +void gr_log_mount(const char *from, const char *to, const int retval);
84492 +void gr_log_textrel(struct vm_area_struct *vma);
84493 +void gr_log_ptgnustack(struct file *file);
84494 +void gr_log_rwxmmap(struct file *file);
84495 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
84496 +
84497 +int gr_handle_follow_link(const struct inode *parent,
84498 + const struct inode *inode,
84499 + const struct dentry *dentry,
84500 + const struct vfsmount *mnt);
84501 +int gr_handle_fifo(const struct dentry *dentry,
84502 + const struct vfsmount *mnt,
84503 + const struct dentry *dir, const int flag,
84504 + const int acc_mode);
84505 +int gr_handle_hardlink(const struct dentry *dentry,
84506 + const struct vfsmount *mnt,
84507 + struct inode *inode,
84508 + const int mode, const struct filename *to);
84509 +
84510 +int gr_is_capable(const int cap);
84511 +int gr_is_capable_nolog(const int cap);
84512 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
84513 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
84514 +
84515 +void gr_copy_label(struct task_struct *tsk);
84516 +void gr_handle_crash(struct task_struct *task, const int sig);
84517 +int gr_handle_signal(const struct task_struct *p, const int sig);
84518 +int gr_check_crash_uid(const kuid_t uid);
84519 +int gr_check_protected_task(const struct task_struct *task);
84520 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
84521 +int gr_acl_handle_mmap(const struct file *file,
84522 + const unsigned long prot);
84523 +int gr_acl_handle_mprotect(const struct file *file,
84524 + const unsigned long prot);
84525 +int gr_check_hidden_task(const struct task_struct *tsk);
84526 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
84527 + const struct vfsmount *mnt);
84528 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
84529 + const struct vfsmount *mnt);
84530 +__u32 gr_acl_handle_access(const struct dentry *dentry,
84531 + const struct vfsmount *mnt, const int fmode);
84532 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
84533 + const struct vfsmount *mnt, umode_t *mode);
84534 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
84535 + const struct vfsmount *mnt);
84536 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
84537 + const struct vfsmount *mnt);
84538 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
84539 + const struct vfsmount *mnt);
84540 +int gr_handle_ptrace(struct task_struct *task, const long request);
84541 +int gr_handle_proc_ptrace(struct task_struct *task);
84542 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
84543 + const struct vfsmount *mnt);
84544 +int gr_check_crash_exec(const struct file *filp);
84545 +int gr_acl_is_enabled(void);
84546 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
84547 + const kgid_t gid);
84548 +int gr_set_proc_label(const struct dentry *dentry,
84549 + const struct vfsmount *mnt,
84550 + const int unsafe_flags);
84551 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
84552 + const struct vfsmount *mnt);
84553 +__u32 gr_acl_handle_open(const struct dentry *dentry,
84554 + const struct vfsmount *mnt, int acc_mode);
84555 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
84556 + const struct dentry *p_dentry,
84557 + const struct vfsmount *p_mnt,
84558 + int open_flags, int acc_mode, const int imode);
84559 +void gr_handle_create(const struct dentry *dentry,
84560 + const struct vfsmount *mnt);
84561 +void gr_handle_proc_create(const struct dentry *dentry,
84562 + const struct inode *inode);
84563 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
84564 + const struct dentry *parent_dentry,
84565 + const struct vfsmount *parent_mnt,
84566 + const int mode);
84567 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
84568 + const struct dentry *parent_dentry,
84569 + const struct vfsmount *parent_mnt);
84570 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
84571 + const struct vfsmount *mnt);
84572 +void gr_handle_delete(const ino_t ino, const dev_t dev);
84573 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
84574 + const struct vfsmount *mnt);
84575 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
84576 + const struct dentry *parent_dentry,
84577 + const struct vfsmount *parent_mnt,
84578 + const struct filename *from);
84579 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
84580 + const struct dentry *parent_dentry,
84581 + const struct vfsmount *parent_mnt,
84582 + const struct dentry *old_dentry,
84583 + const struct vfsmount *old_mnt, const struct filename *to);
84584 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
84585 +int gr_acl_handle_rename(struct dentry *new_dentry,
84586 + struct dentry *parent_dentry,
84587 + const struct vfsmount *parent_mnt,
84588 + struct dentry *old_dentry,
84589 + struct inode *old_parent_inode,
84590 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
84591 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
84592 + struct dentry *old_dentry,
84593 + struct dentry *new_dentry,
84594 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
84595 +__u32 gr_check_link(const struct dentry *new_dentry,
84596 + const struct dentry *parent_dentry,
84597 + const struct vfsmount *parent_mnt,
84598 + const struct dentry *old_dentry,
84599 + const struct vfsmount *old_mnt);
84600 +int gr_acl_handle_filldir(const struct file *file, const char *name,
84601 + const unsigned int namelen, const ino_t ino);
84602 +
84603 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
84604 + const struct vfsmount *mnt);
84605 +void gr_acl_handle_exit(void);
84606 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
84607 +int gr_acl_handle_procpidmem(const struct task_struct *task);
84608 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
84609 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
84610 +void gr_audit_ptrace(struct task_struct *task);
84611 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
84612 +void gr_put_exec_file(struct task_struct *task);
84613 +
84614 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
84615 +
84616 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
84617 +extern void gr_learn_resource(const struct task_struct *task, const int res,
84618 + const unsigned long wanted, const int gt);
84619 +#else
84620 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
84621 + const unsigned long wanted, const int gt)
84622 +{
84623 +}
84624 +#endif
84625 +
84626 +#ifdef CONFIG_GRKERNSEC_RESLOG
84627 +extern void gr_log_resource(const struct task_struct *task, const int res,
84628 + const unsigned long wanted, const int gt);
84629 +#else
84630 +static inline void gr_log_resource(const struct task_struct *task, const int res,
84631 + const unsigned long wanted, const int gt)
84632 +{
84633 +}
84634 +#endif
84635 +
84636 +#ifdef CONFIG_GRKERNSEC
84637 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
84638 +void gr_handle_vm86(void);
84639 +void gr_handle_mem_readwrite(u64 from, u64 to);
84640 +
84641 +void gr_log_badprocpid(const char *entry);
84642 +
84643 +extern int grsec_enable_dmesg;
84644 +extern int grsec_disable_privio;
84645 +
84646 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84647 +extern kgid_t grsec_proc_gid;
84648 +#endif
84649 +
84650 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
84651 +extern int grsec_enable_chroot_findtask;
84652 +#endif
84653 +#ifdef CONFIG_GRKERNSEC_SETXID
84654 +extern int grsec_enable_setxid;
84655 +#endif
84656 +#endif
84657 +
84658 +#endif
84659 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
84660 new file mode 100644
84661 index 0000000..e7ffaaf
84662 --- /dev/null
84663 +++ b/include/linux/grsock.h
84664 @@ -0,0 +1,19 @@
84665 +#ifndef __GRSOCK_H
84666 +#define __GRSOCK_H
84667 +
84668 +extern void gr_attach_curr_ip(const struct sock *sk);
84669 +extern int gr_handle_sock_all(const int family, const int type,
84670 + const int protocol);
84671 +extern int gr_handle_sock_server(const struct sockaddr *sck);
84672 +extern int gr_handle_sock_server_other(const struct sock *sck);
84673 +extern int gr_handle_sock_client(const struct sockaddr *sck);
84674 +extern int gr_search_connect(struct socket * sock,
84675 + struct sockaddr_in * addr);
84676 +extern int gr_search_bind(struct socket * sock,
84677 + struct sockaddr_in * addr);
84678 +extern int gr_search_listen(struct socket * sock);
84679 +extern int gr_search_accept(struct socket * sock);
84680 +extern int gr_search_socket(const int domain, const int type,
84681 + const int protocol);
84682 +
84683 +#endif
84684 diff --git a/include/linux/hash.h b/include/linux/hash.h
84685 index bd1754c..69b7715 100644
84686 --- a/include/linux/hash.h
84687 +++ b/include/linux/hash.h
84688 @@ -37,6 +37,9 @@ static __always_inline u64 hash_64(u64 val, unsigned int bits)
84689 {
84690 u64 hash = val;
84691
84692 +#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
84693 + hash = hash * GOLDEN_RATIO_PRIME_64;
84694 +#else
84695 /* Sigh, gcc can't optimise this alone like it does for 32 bits. */
84696 u64 n = hash;
84697 n <<= 18;
84698 @@ -51,6 +54,7 @@ static __always_inline u64 hash_64(u64 val, unsigned int bits)
84699 hash += n;
84700 n <<= 2;
84701 hash += n;
84702 +#endif
84703
84704 /* High bits are more random, so use them. */
84705 return hash >> (64 - bits);
84706 @@ -83,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
84707 struct fast_hash_ops {
84708 u32 (*hash)(const void *data, u32 len, u32 seed);
84709 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
84710 -};
84711 +} __no_const;
84712
84713 /**
84714 * arch_fast_hash - Caclulates a hash over a given buffer that can have
84715 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
84716 index 7fb31da..08b5114 100644
84717 --- a/include/linux/highmem.h
84718 +++ b/include/linux/highmem.h
84719 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
84720 kunmap_atomic(kaddr);
84721 }
84722
84723 +static inline void sanitize_highpage(struct page *page)
84724 +{
84725 + void *kaddr;
84726 + unsigned long flags;
84727 +
84728 + local_irq_save(flags);
84729 + kaddr = kmap_atomic(page);
84730 + clear_page(kaddr);
84731 + kunmap_atomic(kaddr);
84732 + local_irq_restore(flags);
84733 +}
84734 +
84735 static inline void zero_user_segments(struct page *page,
84736 unsigned start1, unsigned end1,
84737 unsigned start2, unsigned end2)
84738 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
84739 index 1c7b89a..7dda400 100644
84740 --- a/include/linux/hwmon-sysfs.h
84741 +++ b/include/linux/hwmon-sysfs.h
84742 @@ -25,7 +25,8 @@
84743 struct sensor_device_attribute{
84744 struct device_attribute dev_attr;
84745 int index;
84746 -};
84747 +} __do_const;
84748 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
84749 #define to_sensor_dev_attr(_dev_attr) \
84750 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
84751
84752 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
84753 struct device_attribute dev_attr;
84754 u8 index;
84755 u8 nr;
84756 -};
84757 +} __do_const;
84758 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
84759 #define to_sensor_dev_attr_2(_dev_attr) \
84760 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
84761
84762 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
84763 index b556e0a..c10a515 100644
84764 --- a/include/linux/i2c.h
84765 +++ b/include/linux/i2c.h
84766 @@ -378,6 +378,7 @@ struct i2c_algorithm {
84767 /* To determine what the adapter supports */
84768 u32 (*functionality) (struct i2c_adapter *);
84769 };
84770 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
84771
84772 /**
84773 * struct i2c_bus_recovery_info - I2C bus recovery information
84774 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
84775 index d23c3c2..eb63c81 100644
84776 --- a/include/linux/i2o.h
84777 +++ b/include/linux/i2o.h
84778 @@ -565,7 +565,7 @@ struct i2o_controller {
84779 struct i2o_device *exec; /* Executive */
84780 #if BITS_PER_LONG == 64
84781 spinlock_t context_list_lock; /* lock for context_list */
84782 - atomic_t context_list_counter; /* needed for unique contexts */
84783 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
84784 struct list_head context_list; /* list of context id's
84785 and pointers */
84786 #endif
84787 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
84788 index aff7ad8..3942bbd 100644
84789 --- a/include/linux/if_pppox.h
84790 +++ b/include/linux/if_pppox.h
84791 @@ -76,7 +76,7 @@ struct pppox_proto {
84792 int (*ioctl)(struct socket *sock, unsigned int cmd,
84793 unsigned long arg);
84794 struct module *owner;
84795 -};
84796 +} __do_const;
84797
84798 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
84799 extern void unregister_pppox_proto(int proto_num);
84800 diff --git a/include/linux/init.h b/include/linux/init.h
84801 index 2df8e8d..3e1280d 100644
84802 --- a/include/linux/init.h
84803 +++ b/include/linux/init.h
84804 @@ -37,9 +37,17 @@
84805 * section.
84806 */
84807
84808 +#define add_init_latent_entropy __latent_entropy
84809 +
84810 +#ifdef CONFIG_MEMORY_HOTPLUG
84811 +#define add_meminit_latent_entropy
84812 +#else
84813 +#define add_meminit_latent_entropy __latent_entropy
84814 +#endif
84815 +
84816 /* These are for everybody (although not all archs will actually
84817 discard it in modules) */
84818 -#define __init __section(.init.text) __cold notrace
84819 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
84820 #define __initdata __section(.init.data)
84821 #define __initconst __constsection(.init.rodata)
84822 #define __exitdata __section(.exit.data)
84823 @@ -100,7 +108,7 @@
84824 #define __cpuexitconst
84825
84826 /* Used for MEMORY_HOTPLUG */
84827 -#define __meminit __section(.meminit.text) __cold notrace
84828 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
84829 #define __meminitdata __section(.meminit.data)
84830 #define __meminitconst __constsection(.meminit.rodata)
84831 #define __memexit __section(.memexit.text) __exitused __cold notrace
84832 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
84833 index 6df7f9f..d0bf699 100644
84834 --- a/include/linux/init_task.h
84835 +++ b/include/linux/init_task.h
84836 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
84837
84838 #define INIT_TASK_COMM "swapper"
84839
84840 +#ifdef CONFIG_X86
84841 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
84842 +#else
84843 +#define INIT_TASK_THREAD_INFO
84844 +#endif
84845 +
84846 #ifdef CONFIG_RT_MUTEXES
84847 # define INIT_RT_MUTEXES(tsk) \
84848 .pi_waiters = RB_ROOT, \
84849 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
84850 RCU_POINTER_INITIALIZER(cred, &init_cred), \
84851 .comm = INIT_TASK_COMM, \
84852 .thread = INIT_THREAD, \
84853 + INIT_TASK_THREAD_INFO \
84854 .fs = &init_fs, \
84855 .files = &init_files, \
84856 .signal = &init_signals, \
84857 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
84858 index 698ad05..8601bb7 100644
84859 --- a/include/linux/interrupt.h
84860 +++ b/include/linux/interrupt.h
84861 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
84862
84863 struct softirq_action
84864 {
84865 - void (*action)(struct softirq_action *);
84866 -};
84867 + void (*action)(void);
84868 +} __no_const;
84869
84870 asmlinkage void do_softirq(void);
84871 asmlinkage void __do_softirq(void);
84872 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
84873 }
84874 #endif
84875
84876 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
84877 +extern void open_softirq(int nr, void (*action)(void));
84878 extern void softirq_init(void);
84879 extern void __raise_softirq_irqoff(unsigned int nr);
84880
84881 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
84882 index b96a5b2..2732d1c 100644
84883 --- a/include/linux/iommu.h
84884 +++ b/include/linux/iommu.h
84885 @@ -131,7 +131,7 @@ struct iommu_ops {
84886 u32 (*domain_get_windows)(struct iommu_domain *domain);
84887
84888 unsigned long pgsize_bitmap;
84889 -};
84890 +} __do_const;
84891
84892 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
84893 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
84894 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
84895 index 5e3a906..3131d0f 100644
84896 --- a/include/linux/ioport.h
84897 +++ b/include/linux/ioport.h
84898 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
84899 int adjust_resource(struct resource *res, resource_size_t start,
84900 resource_size_t size);
84901 resource_size_t resource_alignment(struct resource *res);
84902 -static inline resource_size_t resource_size(const struct resource *res)
84903 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
84904 {
84905 return res->end - res->start + 1;
84906 }
84907 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
84908 index 35e7eca..6afb7ad 100644
84909 --- a/include/linux/ipc_namespace.h
84910 +++ b/include/linux/ipc_namespace.h
84911 @@ -69,7 +69,7 @@ struct ipc_namespace {
84912 struct user_namespace *user_ns;
84913
84914 unsigned int proc_inum;
84915 -};
84916 +} __randomize_layout;
84917
84918 extern struct ipc_namespace init_ipc_ns;
84919 extern atomic_t nr_ipc_ns;
84920 diff --git a/include/linux/irq.h b/include/linux/irq.h
84921 index 0d998d8..3a1c782 100644
84922 --- a/include/linux/irq.h
84923 +++ b/include/linux/irq.h
84924 @@ -344,7 +344,8 @@ struct irq_chip {
84925 void (*irq_release_resources)(struct irq_data *data);
84926
84927 unsigned long flags;
84928 -};
84929 +} __do_const;
84930 +typedef struct irq_chip __no_const irq_chip_no_const;
84931
84932 /*
84933 * irq_chip specific flags
84934 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
84935 index 45e2d8c..26d85da 100644
84936 --- a/include/linux/irqchip/arm-gic.h
84937 +++ b/include/linux/irqchip/arm-gic.h
84938 @@ -75,9 +75,11 @@
84939
84940 #ifndef __ASSEMBLY__
84941
84942 +#include <linux/irq.h>
84943 +
84944 struct device_node;
84945
84946 -extern struct irq_chip gic_arch_extn;
84947 +extern irq_chip_no_const gic_arch_extn;
84948
84949 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
84950 u32 offset, struct device_node *);
84951 diff --git a/include/linux/isdn_ppp.h b/include/linux/isdn_ppp.h
84952 index 8e10f57..d5f62bc 100644
84953 --- a/include/linux/isdn_ppp.h
84954 +++ b/include/linux/isdn_ppp.h
84955 @@ -180,8 +180,9 @@ struct ippp_struct {
84956 struct slcompress *slcomp;
84957 #endif
84958 #ifdef CONFIG_IPPP_FILTER
84959 - struct sk_filter *pass_filter; /* filter for packets to pass */
84960 - struct sk_filter *active_filter; /* filter for pkts to reset idle */
84961 + struct sock_filter *pass_filter; /* filter for packets to pass */
84962 + struct sock_filter *active_filter; /* filter for pkts to reset idle */
84963 + unsigned pass_len, active_len;
84964 #endif
84965 unsigned long debug;
84966 struct isdn_ppp_compressor *compressor,*decompressor;
84967 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
84968 index 1f44466..b481806 100644
84969 --- a/include/linux/jiffies.h
84970 +++ b/include/linux/jiffies.h
84971 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
84972 /*
84973 * Convert various time units to each other:
84974 */
84975 -extern unsigned int jiffies_to_msecs(const unsigned long j);
84976 -extern unsigned int jiffies_to_usecs(const unsigned long j);
84977 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
84978 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
84979
84980 -static inline u64 jiffies_to_nsecs(const unsigned long j)
84981 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
84982 {
84983 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
84984 }
84985
84986 -extern unsigned long msecs_to_jiffies(const unsigned int m);
84987 -extern unsigned long usecs_to_jiffies(const unsigned int u);
84988 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
84989 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
84990 extern unsigned long timespec_to_jiffies(const struct timespec *value);
84991 extern void jiffies_to_timespec(const unsigned long jiffies,
84992 - struct timespec *value);
84993 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
84994 + struct timespec *value) __intentional_overflow(-1);
84995 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
84996 extern void jiffies_to_timeval(const unsigned long jiffies,
84997 struct timeval *value);
84998
84999 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
85000 index 6883e19..e854fcb 100644
85001 --- a/include/linux/kallsyms.h
85002 +++ b/include/linux/kallsyms.h
85003 @@ -15,7 +15,8 @@
85004
85005 struct module;
85006
85007 -#ifdef CONFIG_KALLSYMS
85008 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
85009 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85010 /* Lookup the address for a symbol. Returns 0 if not found. */
85011 unsigned long kallsyms_lookup_name(const char *name);
85012
85013 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
85014 /* Stupid that this does nothing, but I didn't create this mess. */
85015 #define __print_symbol(fmt, addr)
85016 #endif /*CONFIG_KALLSYMS*/
85017 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
85018 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
85019 +extern unsigned long kallsyms_lookup_name(const char *name);
85020 +extern void __print_symbol(const char *fmt, unsigned long address);
85021 +extern int sprint_backtrace(char *buffer, unsigned long address);
85022 +extern int sprint_symbol(char *buffer, unsigned long address);
85023 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
85024 +const char *kallsyms_lookup(unsigned long addr,
85025 + unsigned long *symbolsize,
85026 + unsigned long *offset,
85027 + char **modname, char *namebuf);
85028 +extern int kallsyms_lookup_size_offset(unsigned long addr,
85029 + unsigned long *symbolsize,
85030 + unsigned long *offset);
85031 +#endif
85032
85033 /* This macro allows us to keep printk typechecking */
85034 static __printf(1, 2)
85035 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
85036 index a74c3a8..28d3f21 100644
85037 --- a/include/linux/key-type.h
85038 +++ b/include/linux/key-type.h
85039 @@ -131,7 +131,7 @@ struct key_type {
85040 /* internal fields */
85041 struct list_head link; /* link in types list */
85042 struct lock_class_key lock_class; /* key->sem lock class */
85043 -};
85044 +} __do_const;
85045
85046 extern struct key_type key_type_keyring;
85047
85048 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
85049 index 6b06d37..c134867 100644
85050 --- a/include/linux/kgdb.h
85051 +++ b/include/linux/kgdb.h
85052 @@ -52,7 +52,7 @@ extern int kgdb_connected;
85053 extern int kgdb_io_module_registered;
85054
85055 extern atomic_t kgdb_setting_breakpoint;
85056 -extern atomic_t kgdb_cpu_doing_single_step;
85057 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
85058
85059 extern struct task_struct *kgdb_usethread;
85060 extern struct task_struct *kgdb_contthread;
85061 @@ -254,7 +254,7 @@ struct kgdb_arch {
85062 void (*correct_hw_break)(void);
85063
85064 void (*enable_nmi)(bool on);
85065 -};
85066 +} __do_const;
85067
85068 /**
85069 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
85070 @@ -279,7 +279,7 @@ struct kgdb_io {
85071 void (*pre_exception) (void);
85072 void (*post_exception) (void);
85073 int is_console;
85074 -};
85075 +} __do_const;
85076
85077 extern struct kgdb_arch arch_kgdb_ops;
85078
85079 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
85080 index 0555cc6..40116ce 100644
85081 --- a/include/linux/kmod.h
85082 +++ b/include/linux/kmod.h
85083 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
85084 * usually useless though. */
85085 extern __printf(2, 3)
85086 int __request_module(bool wait, const char *name, ...);
85087 +extern __printf(3, 4)
85088 +int ___request_module(bool wait, char *param_name, const char *name, ...);
85089 #define request_module(mod...) __request_module(true, mod)
85090 #define request_module_nowait(mod...) __request_module(false, mod)
85091 #define try_then_request_module(x, mod...) \
85092 @@ -57,6 +59,9 @@ struct subprocess_info {
85093 struct work_struct work;
85094 struct completion *complete;
85095 char *path;
85096 +#ifdef CONFIG_GRKERNSEC
85097 + char *origpath;
85098 +#endif
85099 char **argv;
85100 char **envp;
85101 int wait;
85102 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
85103 index 2d61b90..a1d0a13 100644
85104 --- a/include/linux/kobject.h
85105 +++ b/include/linux/kobject.h
85106 @@ -118,7 +118,7 @@ struct kobj_type {
85107 struct attribute **default_attrs;
85108 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
85109 const void *(*namespace)(struct kobject *kobj);
85110 -};
85111 +} __do_const;
85112
85113 struct kobj_uevent_env {
85114 char *argv[3];
85115 @@ -142,6 +142,7 @@ struct kobj_attribute {
85116 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
85117 const char *buf, size_t count);
85118 };
85119 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
85120
85121 extern const struct sysfs_ops kobj_sysfs_ops;
85122
85123 @@ -169,7 +170,7 @@ struct kset {
85124 spinlock_t list_lock;
85125 struct kobject kobj;
85126 const struct kset_uevent_ops *uevent_ops;
85127 -};
85128 +} __randomize_layout;
85129
85130 extern void kset_init(struct kset *kset);
85131 extern int __must_check kset_register(struct kset *kset);
85132 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
85133 index df32d25..fb52e27 100644
85134 --- a/include/linux/kobject_ns.h
85135 +++ b/include/linux/kobject_ns.h
85136 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
85137 const void *(*netlink_ns)(struct sock *sk);
85138 const void *(*initial_ns)(void);
85139 void (*drop_ns)(void *);
85140 -};
85141 +} __do_const;
85142
85143 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
85144 int kobj_ns_type_registered(enum kobj_ns_type type);
85145 diff --git a/include/linux/kref.h b/include/linux/kref.h
85146 index 484604d..0f6c5b6 100644
85147 --- a/include/linux/kref.h
85148 +++ b/include/linux/kref.h
85149 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
85150 static inline int kref_sub(struct kref *kref, unsigned int count,
85151 void (*release)(struct kref *kref))
85152 {
85153 - WARN_ON(release == NULL);
85154 + BUG_ON(release == NULL);
85155
85156 if (atomic_sub_and_test((int) count, &kref->refcount)) {
85157 release(kref);
85158 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
85159 index ec4e3bd..14db03a 100644
85160 --- a/include/linux/kvm_host.h
85161 +++ b/include/linux/kvm_host.h
85162 @@ -468,7 +468,7 @@ static inline void kvm_irqfd_exit(void)
85163 {
85164 }
85165 #endif
85166 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85167 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85168 struct module *module);
85169 void kvm_exit(void);
85170
85171 @@ -634,7 +634,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
85172 struct kvm_guest_debug *dbg);
85173 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
85174
85175 -int kvm_arch_init(void *opaque);
85176 +int kvm_arch_init(const void *opaque);
85177 void kvm_arch_exit(void);
85178
85179 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
85180 diff --git a/include/linux/libata.h b/include/linux/libata.h
85181 index 92abb49..e7fff2a 100644
85182 --- a/include/linux/libata.h
85183 +++ b/include/linux/libata.h
85184 @@ -976,7 +976,7 @@ struct ata_port_operations {
85185 * fields must be pointers.
85186 */
85187 const struct ata_port_operations *inherits;
85188 -};
85189 +} __do_const;
85190
85191 struct ata_port_info {
85192 unsigned long flags;
85193 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
85194 index a6a42dd..6c5ebce 100644
85195 --- a/include/linux/linkage.h
85196 +++ b/include/linux/linkage.h
85197 @@ -36,6 +36,7 @@
85198 #endif
85199
85200 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
85201 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
85202 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
85203
85204 /*
85205 diff --git a/include/linux/list.h b/include/linux/list.h
85206 index ef95941..82db65a 100644
85207 --- a/include/linux/list.h
85208 +++ b/include/linux/list.h
85209 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
85210 extern void list_del(struct list_head *entry);
85211 #endif
85212
85213 +extern void __pax_list_add(struct list_head *new,
85214 + struct list_head *prev,
85215 + struct list_head *next);
85216 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
85217 +{
85218 + __pax_list_add(new, head, head->next);
85219 +}
85220 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
85221 +{
85222 + __pax_list_add(new, head->prev, head);
85223 +}
85224 +extern void pax_list_del(struct list_head *entry);
85225 +
85226 /**
85227 * list_replace - replace old entry by new one
85228 * @old : the element to be replaced
85229 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
85230 INIT_LIST_HEAD(entry);
85231 }
85232
85233 +extern void pax_list_del_init(struct list_head *entry);
85234 +
85235 /**
85236 * list_move - delete from one list and add as another's head
85237 * @list: the entry to move
85238 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
85239 index 4bfde0e..d6e2e09 100644
85240 --- a/include/linux/lockref.h
85241 +++ b/include/linux/lockref.h
85242 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
85243 return ((int)l->count < 0);
85244 }
85245
85246 +static inline unsigned int __lockref_read(struct lockref *lockref)
85247 +{
85248 + return lockref->count;
85249 +}
85250 +
85251 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
85252 +{
85253 + lockref->count = count;
85254 +}
85255 +
85256 +static inline void __lockref_inc(struct lockref *lockref)
85257 +{
85258 +
85259 +#ifdef CONFIG_PAX_REFCOUNT
85260 + atomic_inc((atomic_t *)&lockref->count);
85261 +#else
85262 + lockref->count++;
85263 +#endif
85264 +
85265 +}
85266 +
85267 +static inline void __lockref_dec(struct lockref *lockref)
85268 +{
85269 +
85270 +#ifdef CONFIG_PAX_REFCOUNT
85271 + atomic_dec((atomic_t *)&lockref->count);
85272 +#else
85273 + lockref->count--;
85274 +#endif
85275 +
85276 +}
85277 +
85278 #endif /* __LINUX_LOCKREF_H */
85279 diff --git a/include/linux/math64.h b/include/linux/math64.h
85280 index c45c089..298841c 100644
85281 --- a/include/linux/math64.h
85282 +++ b/include/linux/math64.h
85283 @@ -15,7 +15,7 @@
85284 * This is commonly provided by 32bit archs to provide an optimized 64bit
85285 * divide.
85286 */
85287 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
85288 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
85289 {
85290 *remainder = dividend % divisor;
85291 return dividend / divisor;
85292 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
85293 /**
85294 * div64_u64 - unsigned 64bit divide with 64bit divisor
85295 */
85296 -static inline u64 div64_u64(u64 dividend, u64 divisor)
85297 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85298 {
85299 return dividend / divisor;
85300 }
85301 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
85302 #define div64_ul(x, y) div_u64((x), (y))
85303
85304 #ifndef div_u64_rem
85305 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
85306 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
85307 {
85308 *remainder = do_div(dividend, divisor);
85309 return dividend;
85310 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
85311 #endif
85312
85313 #ifndef div64_u64
85314 -extern u64 div64_u64(u64 dividend, u64 divisor);
85315 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
85316 #endif
85317
85318 #ifndef div64_s64
85319 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
85320 * divide.
85321 */
85322 #ifndef div_u64
85323 -static inline u64 div_u64(u64 dividend, u32 divisor)
85324 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
85325 {
85326 u32 remainder;
85327 return div_u64_rem(dividend, divisor, &remainder);
85328 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
85329 index f230a97..714c006 100644
85330 --- a/include/linux/mempolicy.h
85331 +++ b/include/linux/mempolicy.h
85332 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
85333 }
85334
85335 #define vma_policy(vma) ((vma)->vm_policy)
85336 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
85337 +{
85338 + vma->vm_policy = pol;
85339 +}
85340
85341 static inline void mpol_get(struct mempolicy *pol)
85342 {
85343 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
85344 }
85345
85346 #define vma_policy(vma) NULL
85347 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
85348 +{
85349 +}
85350
85351 static inline int
85352 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
85353 diff --git a/include/linux/mm.h b/include/linux/mm.h
85354 index e03dd29..eaf923c 100644
85355 --- a/include/linux/mm.h
85356 +++ b/include/linux/mm.h
85357 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
85358 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
85359 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
85360 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
85361 +
85362 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
85363 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
85364 +#endif
85365 +
85366 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
85367
85368 #ifdef CONFIG_MEM_SOFT_DIRTY
85369 @@ -237,8 +242,8 @@ struct vm_operations_struct {
85370 /* called by access_process_vm when get_user_pages() fails, typically
85371 * for use by special VMAs that can switch between memory and hardware
85372 */
85373 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
85374 - void *buf, int len, int write);
85375 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
85376 + void *buf, size_t len, int write);
85377
85378 /* Called by the /proc/PID/maps code to ask the vma whether it
85379 * has a special name. Returning non-NULL will also cause this
85380 @@ -274,6 +279,7 @@ struct vm_operations_struct {
85381 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
85382 unsigned long size, pgoff_t pgoff);
85383 };
85384 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
85385
85386 struct mmu_gather;
85387 struct inode;
85388 @@ -1144,8 +1150,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
85389 unsigned long *pfn);
85390 int follow_phys(struct vm_area_struct *vma, unsigned long address,
85391 unsigned int flags, unsigned long *prot, resource_size_t *phys);
85392 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
85393 - void *buf, int len, int write);
85394 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
85395 + void *buf, size_t len, int write);
85396
85397 static inline void unmap_shared_mapping_range(struct address_space *mapping,
85398 loff_t const holebegin, loff_t const holelen)
85399 @@ -1184,9 +1190,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
85400 }
85401 #endif
85402
85403 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
85404 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
85405 - void *buf, int len, int write);
85406 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
85407 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
85408 + void *buf, size_t len, int write);
85409
85410 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
85411 unsigned long start, unsigned long nr_pages,
85412 @@ -1219,34 +1225,6 @@ int set_page_dirty_lock(struct page *page);
85413 int clear_page_dirty_for_io(struct page *page);
85414 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
85415
85416 -/* Is the vma a continuation of the stack vma above it? */
85417 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
85418 -{
85419 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
85420 -}
85421 -
85422 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
85423 - unsigned long addr)
85424 -{
85425 - return (vma->vm_flags & VM_GROWSDOWN) &&
85426 - (vma->vm_start == addr) &&
85427 - !vma_growsdown(vma->vm_prev, addr);
85428 -}
85429 -
85430 -/* Is the vma a continuation of the stack vma below it? */
85431 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
85432 -{
85433 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
85434 -}
85435 -
85436 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
85437 - unsigned long addr)
85438 -{
85439 - return (vma->vm_flags & VM_GROWSUP) &&
85440 - (vma->vm_end == addr) &&
85441 - !vma_growsup(vma->vm_next, addr);
85442 -}
85443 -
85444 extern pid_t
85445 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
85446
85447 @@ -1346,6 +1324,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
85448 }
85449 #endif
85450
85451 +#ifdef CONFIG_MMU
85452 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
85453 +#else
85454 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
85455 +{
85456 + return __pgprot(0);
85457 +}
85458 +#endif
85459 +
85460 int vma_wants_writenotify(struct vm_area_struct *vma);
85461
85462 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
85463 @@ -1364,8 +1351,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
85464 {
85465 return 0;
85466 }
85467 +
85468 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
85469 + unsigned long address)
85470 +{
85471 + return 0;
85472 +}
85473 #else
85474 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
85475 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
85476 #endif
85477
85478 #ifdef __PAGETABLE_PMD_FOLDED
85479 @@ -1374,8 +1368,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
85480 {
85481 return 0;
85482 }
85483 +
85484 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
85485 + unsigned long address)
85486 +{
85487 + return 0;
85488 +}
85489 #else
85490 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
85491 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
85492 #endif
85493
85494 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
85495 @@ -1393,11 +1394,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
85496 NULL: pud_offset(pgd, address);
85497 }
85498
85499 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
85500 +{
85501 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
85502 + NULL: pud_offset(pgd, address);
85503 +}
85504 +
85505 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
85506 {
85507 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
85508 NULL: pmd_offset(pud, address);
85509 }
85510 +
85511 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
85512 +{
85513 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
85514 + NULL: pmd_offset(pud, address);
85515 +}
85516 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
85517
85518 #if USE_SPLIT_PTE_PTLOCKS
85519 @@ -1796,7 +1809,7 @@ extern int install_special_mapping(struct mm_struct *mm,
85520 unsigned long addr, unsigned long len,
85521 unsigned long flags, struct page **pages);
85522
85523 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
85524 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
85525
85526 extern unsigned long mmap_region(struct file *file, unsigned long addr,
85527 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
85528 @@ -1804,6 +1817,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
85529 unsigned long len, unsigned long prot, unsigned long flags,
85530 unsigned long pgoff, unsigned long *populate);
85531 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
85532 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
85533
85534 #ifdef CONFIG_MMU
85535 extern int __mm_populate(unsigned long addr, unsigned long len,
85536 @@ -1832,10 +1846,11 @@ struct vm_unmapped_area_info {
85537 unsigned long high_limit;
85538 unsigned long align_mask;
85539 unsigned long align_offset;
85540 + unsigned long threadstack_offset;
85541 };
85542
85543 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
85544 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
85545 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
85546 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
85547
85548 /*
85549 * Search for an unmapped address range.
85550 @@ -1847,7 +1862,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
85551 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
85552 */
85553 static inline unsigned long
85554 -vm_unmapped_area(struct vm_unmapped_area_info *info)
85555 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
85556 {
85557 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
85558 return unmapped_area(info);
85559 @@ -1909,6 +1924,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
85560 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
85561 struct vm_area_struct **pprev);
85562
85563 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
85564 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
85565 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
85566 +
85567 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
85568 NULL if none. Assume start_addr < end_addr. */
85569 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
85570 @@ -1937,15 +1956,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
85571 return vma;
85572 }
85573
85574 -#ifdef CONFIG_MMU
85575 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
85576 -#else
85577 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
85578 -{
85579 - return __pgprot(0);
85580 -}
85581 -#endif
85582 -
85583 #ifdef CONFIG_NUMA_BALANCING
85584 unsigned long change_prot_numa(struct vm_area_struct *vma,
85585 unsigned long start, unsigned long end);
85586 @@ -1997,6 +2007,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
85587 static inline void vm_stat_account(struct mm_struct *mm,
85588 unsigned long flags, struct file *file, long pages)
85589 {
85590 +
85591 +#ifdef CONFIG_PAX_RANDMMAP
85592 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
85593 +#endif
85594 +
85595 mm->total_vm += pages;
85596 }
85597 #endif /* CONFIG_PROC_FS */
85598 @@ -2078,7 +2093,7 @@ extern int unpoison_memory(unsigned long pfn);
85599 extern int sysctl_memory_failure_early_kill;
85600 extern int sysctl_memory_failure_recovery;
85601 extern void shake_page(struct page *p, int access);
85602 -extern atomic_long_t num_poisoned_pages;
85603 +extern atomic_long_unchecked_t num_poisoned_pages;
85604 extern int soft_offline_page(struct page *page, int flags);
85605
85606 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
85607 @@ -2113,5 +2128,11 @@ void __init setup_nr_node_ids(void);
85608 static inline void setup_nr_node_ids(void) {}
85609 #endif
85610
85611 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
85612 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
85613 +#else
85614 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
85615 +#endif
85616 +
85617 #endif /* __KERNEL__ */
85618 #endif /* _LINUX_MM_H */
85619 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
85620 index 96c5750..15668ba 100644
85621 --- a/include/linux/mm_types.h
85622 +++ b/include/linux/mm_types.h
85623 @@ -308,7 +308,9 @@ struct vm_area_struct {
85624 #ifdef CONFIG_NUMA
85625 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
85626 #endif
85627 -};
85628 +
85629 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
85630 +} __randomize_layout;
85631
85632 struct core_thread {
85633 struct task_struct *task;
85634 @@ -454,7 +456,25 @@ struct mm_struct {
85635 bool tlb_flush_pending;
85636 #endif
85637 struct uprobes_state uprobes_state;
85638 -};
85639 +
85640 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85641 + unsigned long pax_flags;
85642 +#endif
85643 +
85644 +#ifdef CONFIG_PAX_DLRESOLVE
85645 + unsigned long call_dl_resolve;
85646 +#endif
85647 +
85648 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
85649 + unsigned long call_syscall;
85650 +#endif
85651 +
85652 +#ifdef CONFIG_PAX_ASLR
85653 + unsigned long delta_mmap; /* randomized offset */
85654 + unsigned long delta_stack; /* randomized offset */
85655 +#endif
85656 +
85657 +} __randomize_layout;
85658
85659 static inline void mm_init_cpumask(struct mm_struct *mm)
85660 {
85661 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
85662 index c5d5278..f0b68c8 100644
85663 --- a/include/linux/mmiotrace.h
85664 +++ b/include/linux/mmiotrace.h
85665 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
85666 /* Called from ioremap.c */
85667 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
85668 void __iomem *addr);
85669 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
85670 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
85671
85672 /* For anyone to insert markers. Remember trailing newline. */
85673 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
85674 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
85675 {
85676 }
85677
85678 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
85679 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
85680 {
85681 }
85682
85683 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
85684 index 6cbd1b6..b1d2f99 100644
85685 --- a/include/linux/mmzone.h
85686 +++ b/include/linux/mmzone.h
85687 @@ -412,7 +412,7 @@ struct zone {
85688 unsigned long flags; /* zone flags, see below */
85689
85690 /* Zone statistics */
85691 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85692 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85693
85694 /*
85695 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
85696 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
85697 index 44eeef0..a92d3f9 100644
85698 --- a/include/linux/mod_devicetable.h
85699 +++ b/include/linux/mod_devicetable.h
85700 @@ -139,7 +139,7 @@ struct usb_device_id {
85701 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
85702 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
85703
85704 -#define HID_ANY_ID (~0)
85705 +#define HID_ANY_ID (~0U)
85706 #define HID_BUS_ANY 0xffff
85707 #define HID_GROUP_ANY 0x0000
85708
85709 @@ -475,7 +475,7 @@ struct dmi_system_id {
85710 const char *ident;
85711 struct dmi_strmatch matches[4];
85712 void *driver_data;
85713 -};
85714 +} __do_const;
85715 /*
85716 * struct dmi_device_id appears during expansion of
85717 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
85718 diff --git a/include/linux/module.h b/include/linux/module.h
85719 index f520a76..5f898ef 100644
85720 --- a/include/linux/module.h
85721 +++ b/include/linux/module.h
85722 @@ -17,9 +17,11 @@
85723 #include <linux/moduleparam.h>
85724 #include <linux/jump_label.h>
85725 #include <linux/export.h>
85726 +#include <linux/fs.h>
85727
85728 #include <linux/percpu.h>
85729 #include <asm/module.h>
85730 +#include <asm/pgtable.h>
85731
85732 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
85733 #define MODULE_SIG_STRING "~Module signature appended~\n"
85734 @@ -42,7 +44,7 @@ struct module_kobject {
85735 struct kobject *drivers_dir;
85736 struct module_param_attrs *mp;
85737 struct completion *kobj_completion;
85738 -};
85739 +} __randomize_layout;
85740
85741 struct module_attribute {
85742 struct attribute attr;
85743 @@ -54,12 +56,13 @@ struct module_attribute {
85744 int (*test)(struct module *);
85745 void (*free)(struct module *);
85746 };
85747 +typedef struct module_attribute __no_const module_attribute_no_const;
85748
85749 struct module_version_attribute {
85750 struct module_attribute mattr;
85751 const char *module_name;
85752 const char *version;
85753 -} __attribute__ ((__aligned__(sizeof(void *))));
85754 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
85755
85756 extern ssize_t __modver_version_show(struct module_attribute *,
85757 struct module_kobject *, char *);
85758 @@ -235,7 +238,7 @@ struct module {
85759
85760 /* Sysfs stuff. */
85761 struct module_kobject mkobj;
85762 - struct module_attribute *modinfo_attrs;
85763 + module_attribute_no_const *modinfo_attrs;
85764 const char *version;
85765 const char *srcversion;
85766 struct kobject *holders_dir;
85767 @@ -284,19 +287,16 @@ struct module {
85768 int (*init)(void);
85769
85770 /* If this is non-NULL, vfree after init() returns */
85771 - void *module_init;
85772 + void *module_init_rx, *module_init_rw;
85773
85774 /* Here is the actual code + data, vfree'd on unload. */
85775 - void *module_core;
85776 + void *module_core_rx, *module_core_rw;
85777
85778 /* Here are the sizes of the init and core sections */
85779 - unsigned int init_size, core_size;
85780 + unsigned int init_size_rw, core_size_rw;
85781
85782 /* The size of the executable code in each section. */
85783 - unsigned int init_text_size, core_text_size;
85784 -
85785 - /* Size of RO sections of the module (text+rodata) */
85786 - unsigned int init_ro_size, core_ro_size;
85787 + unsigned int init_size_rx, core_size_rx;
85788
85789 /* Arch-specific module values */
85790 struct mod_arch_specific arch;
85791 @@ -352,6 +352,10 @@ struct module {
85792 #ifdef CONFIG_EVENT_TRACING
85793 struct ftrace_event_call **trace_events;
85794 unsigned int num_trace_events;
85795 + struct file_operations trace_id;
85796 + struct file_operations trace_enable;
85797 + struct file_operations trace_format;
85798 + struct file_operations trace_filter;
85799 #endif
85800 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
85801 unsigned int num_ftrace_callsites;
85802 @@ -375,7 +379,7 @@ struct module {
85803 ctor_fn_t *ctors;
85804 unsigned int num_ctors;
85805 #endif
85806 -};
85807 +} __randomize_layout;
85808 #ifndef MODULE_ARCH_INIT
85809 #define MODULE_ARCH_INIT {}
85810 #endif
85811 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
85812 bool is_module_percpu_address(unsigned long addr);
85813 bool is_module_text_address(unsigned long addr);
85814
85815 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
85816 +{
85817 +
85818 +#ifdef CONFIG_PAX_KERNEXEC
85819 + if (ktla_ktva(addr) >= (unsigned long)start &&
85820 + ktla_ktva(addr) < (unsigned long)start + size)
85821 + return 1;
85822 +#endif
85823 +
85824 + return ((void *)addr >= start && (void *)addr < start + size);
85825 +}
85826 +
85827 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
85828 +{
85829 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
85830 +}
85831 +
85832 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
85833 +{
85834 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
85835 +}
85836 +
85837 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
85838 +{
85839 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
85840 +}
85841 +
85842 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
85843 +{
85844 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
85845 +}
85846 +
85847 static inline int within_module_core(unsigned long addr, const struct module *mod)
85848 {
85849 - return (unsigned long)mod->module_core <= addr &&
85850 - addr < (unsigned long)mod->module_core + mod->core_size;
85851 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
85852 }
85853
85854 static inline int within_module_init(unsigned long addr, const struct module *mod)
85855 {
85856 - return (unsigned long)mod->module_init <= addr &&
85857 - addr < (unsigned long)mod->module_init + mod->init_size;
85858 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
85859 }
85860
85861 /* Search for module by name: must hold module_mutex. */
85862 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
85863 index 560ca53..ef621ef 100644
85864 --- a/include/linux/moduleloader.h
85865 +++ b/include/linux/moduleloader.h
85866 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
85867 sections. Returns NULL on failure. */
85868 void *module_alloc(unsigned long size);
85869
85870 +#ifdef CONFIG_PAX_KERNEXEC
85871 +void *module_alloc_exec(unsigned long size);
85872 +#else
85873 +#define module_alloc_exec(x) module_alloc(x)
85874 +#endif
85875 +
85876 /* Free memory returned from module_alloc. */
85877 void module_free(struct module *mod, void *module_region);
85878
85879 +#ifdef CONFIG_PAX_KERNEXEC
85880 +void module_free_exec(struct module *mod, void *module_region);
85881 +#else
85882 +#define module_free_exec(x, y) module_free((x), (y))
85883 +#endif
85884 +
85885 /*
85886 * Apply the given relocation to the (simplified) ELF. Return -error
85887 * or 0.
85888 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
85889 unsigned int relsec,
85890 struct module *me)
85891 {
85892 +#ifdef CONFIG_MODULES
85893 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
85894 +#endif
85895 return -ENOEXEC;
85896 }
85897 #endif
85898 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
85899 unsigned int relsec,
85900 struct module *me)
85901 {
85902 +#ifdef CONFIG_MODULES
85903 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
85904 +#endif
85905 return -ENOEXEC;
85906 }
85907 #endif
85908 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
85909 index b1990c5..2a6e611 100644
85910 --- a/include/linux/moduleparam.h
85911 +++ b/include/linux/moduleparam.h
85912 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
85913 * @len is usually just sizeof(string).
85914 */
85915 #define module_param_string(name, string, len, perm) \
85916 - static const struct kparam_string __param_string_##name \
85917 + static const struct kparam_string __param_string_##name __used \
85918 = { len, string }; \
85919 __module_param_call(MODULE_PARAM_PREFIX, name, \
85920 &param_ops_string, \
85921 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
85922 */
85923 #define module_param_array_named(name, array, type, nump, perm) \
85924 param_check_##type(name, &(array)[0]); \
85925 - static const struct kparam_array __param_arr_##name \
85926 + static const struct kparam_array __param_arr_##name __used \
85927 = { .max = ARRAY_SIZE(array), .num = nump, \
85928 .ops = &param_ops_##type, \
85929 .elemsize = sizeof(array[0]), .elem = array }; \
85930 diff --git a/include/linux/mount.h b/include/linux/mount.h
85931 index 839bac2..a96b37c 100644
85932 --- a/include/linux/mount.h
85933 +++ b/include/linux/mount.h
85934 @@ -59,7 +59,7 @@ struct vfsmount {
85935 struct dentry *mnt_root; /* root of the mounted tree */
85936 struct super_block *mnt_sb; /* pointer to superblock */
85937 int mnt_flags;
85938 -};
85939 +} __randomize_layout;
85940
85941 struct file; /* forward dec */
85942
85943 diff --git a/include/linux/namei.h b/include/linux/namei.h
85944 index 492de72..1bddcd4 100644
85945 --- a/include/linux/namei.h
85946 +++ b/include/linux/namei.h
85947 @@ -19,7 +19,7 @@ struct nameidata {
85948 unsigned seq, m_seq;
85949 int last_type;
85950 unsigned depth;
85951 - char *saved_names[MAX_NESTED_LINKS + 1];
85952 + const char *saved_names[MAX_NESTED_LINKS + 1];
85953 };
85954
85955 /*
85956 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
85957
85958 extern void nd_jump_link(struct nameidata *nd, struct path *path);
85959
85960 -static inline void nd_set_link(struct nameidata *nd, char *path)
85961 +static inline void nd_set_link(struct nameidata *nd, const char *path)
85962 {
85963 nd->saved_names[nd->depth] = path;
85964 }
85965
85966 -static inline char *nd_get_link(struct nameidata *nd)
85967 +static inline const char *nd_get_link(const struct nameidata *nd)
85968 {
85969 return nd->saved_names[nd->depth];
85970 }
85971 diff --git a/include/linux/net.h b/include/linux/net.h
85972 index 17d8339..81656c0 100644
85973 --- a/include/linux/net.h
85974 +++ b/include/linux/net.h
85975 @@ -192,7 +192,7 @@ struct net_proto_family {
85976 int (*create)(struct net *net, struct socket *sock,
85977 int protocol, int kern);
85978 struct module *owner;
85979 -};
85980 +} __do_const;
85981
85982 struct iovec;
85983 struct kvec;
85984 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
85985 index 66f9a04..056078d 100644
85986 --- a/include/linux/netdevice.h
85987 +++ b/include/linux/netdevice.h
85988 @@ -1145,6 +1145,7 @@ struct net_device_ops {
85989 void *priv);
85990 int (*ndo_get_lock_subclass)(struct net_device *dev);
85991 };
85992 +typedef struct net_device_ops __no_const net_device_ops_no_const;
85993
85994 /**
85995 * enum net_device_priv_flags - &struct net_device priv_flags
85996 @@ -1312,11 +1313,11 @@ struct net_device {
85997 struct net_device_stats stats;
85998
85999 /* dropped packets by core network, Do not use this in drivers */
86000 - atomic_long_t rx_dropped;
86001 - atomic_long_t tx_dropped;
86002 + atomic_long_unchecked_t rx_dropped;
86003 + atomic_long_unchecked_t tx_dropped;
86004
86005 /* Stats to monitor carrier on<->off transitions */
86006 - atomic_t carrier_changes;
86007 + atomic_unchecked_t carrier_changes;
86008
86009 #ifdef CONFIG_WIRELESS_EXT
86010 /* List of functions to handle Wireless Extensions (instead of ioctl).
86011 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
86012 index 2077489..a15e561 100644
86013 --- a/include/linux/netfilter.h
86014 +++ b/include/linux/netfilter.h
86015 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
86016 #endif
86017 /* Use the module struct to lock set/get code in place */
86018 struct module *owner;
86019 -};
86020 +} __do_const;
86021
86022 /* Function to register/unregister hook points. */
86023 int nf_register_hook(struct nf_hook_ops *reg);
86024 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
86025 index e955d47..04a5338 100644
86026 --- a/include/linux/netfilter/nfnetlink.h
86027 +++ b/include/linux/netfilter/nfnetlink.h
86028 @@ -19,7 +19,7 @@ struct nfnl_callback {
86029 const struct nlattr * const cda[]);
86030 const struct nla_policy *policy; /* netlink attribute policy */
86031 const u_int16_t attr_count; /* number of nlattr's */
86032 -};
86033 +} __do_const;
86034
86035 struct nfnetlink_subsystem {
86036 const char *name;
86037 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
86038 new file mode 100644
86039 index 0000000..33f4af8
86040 --- /dev/null
86041 +++ b/include/linux/netfilter/xt_gradm.h
86042 @@ -0,0 +1,9 @@
86043 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
86044 +#define _LINUX_NETFILTER_XT_GRADM_H 1
86045 +
86046 +struct xt_gradm_mtinfo {
86047 + __u16 flags;
86048 + __u16 invflags;
86049 +};
86050 +
86051 +#endif
86052 diff --git a/include/linux/nls.h b/include/linux/nls.h
86053 index 520681b..2b7fabb 100644
86054 --- a/include/linux/nls.h
86055 +++ b/include/linux/nls.h
86056 @@ -31,7 +31,7 @@ struct nls_table {
86057 const unsigned char *charset2upper;
86058 struct module *owner;
86059 struct nls_table *next;
86060 -};
86061 +} __do_const;
86062
86063 /* this value hold the maximum octet of charset */
86064 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
86065 @@ -46,7 +46,7 @@ enum utf16_endian {
86066 /* nls_base.c */
86067 extern int __register_nls(struct nls_table *, struct module *);
86068 extern int unregister_nls(struct nls_table *);
86069 -extern struct nls_table *load_nls(char *);
86070 +extern struct nls_table *load_nls(const char *);
86071 extern void unload_nls(struct nls_table *);
86072 extern struct nls_table *load_nls_default(void);
86073 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
86074 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
86075 index d14a4c3..a078786 100644
86076 --- a/include/linux/notifier.h
86077 +++ b/include/linux/notifier.h
86078 @@ -54,7 +54,8 @@ struct notifier_block {
86079 notifier_fn_t notifier_call;
86080 struct notifier_block __rcu *next;
86081 int priority;
86082 -};
86083 +} __do_const;
86084 +typedef struct notifier_block __no_const notifier_block_no_const;
86085
86086 struct atomic_notifier_head {
86087 spinlock_t lock;
86088 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
86089 index b2a0f15..4d7da32 100644
86090 --- a/include/linux/oprofile.h
86091 +++ b/include/linux/oprofile.h
86092 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
86093 int oprofilefs_create_ro_ulong(struct dentry * root,
86094 char const * name, ulong * val);
86095
86096 -/** Create a file for read-only access to an atomic_t. */
86097 +/** Create a file for read-only access to an atomic_unchecked_t. */
86098 int oprofilefs_create_ro_atomic(struct dentry * root,
86099 - char const * name, atomic_t * val);
86100 + char const * name, atomic_unchecked_t * val);
86101
86102 /** create a directory */
86103 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
86104 diff --git a/include/linux/padata.h b/include/linux/padata.h
86105 index 4386946..f50c615 100644
86106 --- a/include/linux/padata.h
86107 +++ b/include/linux/padata.h
86108 @@ -129,7 +129,7 @@ struct parallel_data {
86109 struct padata_serial_queue __percpu *squeue;
86110 atomic_t reorder_objects;
86111 atomic_t refcnt;
86112 - atomic_t seq_nr;
86113 + atomic_unchecked_t seq_nr;
86114 struct padata_cpumask cpumask;
86115 spinlock_t lock ____cacheline_aligned;
86116 unsigned int processed;
86117 diff --git a/include/linux/path.h b/include/linux/path.h
86118 index d137218..be0c176 100644
86119 --- a/include/linux/path.h
86120 +++ b/include/linux/path.h
86121 @@ -1,13 +1,15 @@
86122 #ifndef _LINUX_PATH_H
86123 #define _LINUX_PATH_H
86124
86125 +#include <linux/compiler.h>
86126 +
86127 struct dentry;
86128 struct vfsmount;
86129
86130 struct path {
86131 struct vfsmount *mnt;
86132 struct dentry *dentry;
86133 -};
86134 +} __randomize_layout;
86135
86136 extern void path_get(const struct path *);
86137 extern void path_put(const struct path *);
86138 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
86139 index 5f2e559..7d59314 100644
86140 --- a/include/linux/pci_hotplug.h
86141 +++ b/include/linux/pci_hotplug.h
86142 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
86143 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
86144 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
86145 int (*reset_slot) (struct hotplug_slot *slot, int probe);
86146 -};
86147 +} __do_const;
86148 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
86149
86150 /**
86151 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
86152 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
86153 index 707617a..28a2e7e 100644
86154 --- a/include/linux/perf_event.h
86155 +++ b/include/linux/perf_event.h
86156 @@ -339,8 +339,8 @@ struct perf_event {
86157
86158 enum perf_event_active_state state;
86159 unsigned int attach_state;
86160 - local64_t count;
86161 - atomic64_t child_count;
86162 + local64_t count; /* PaX: fix it one day */
86163 + atomic64_unchecked_t child_count;
86164
86165 /*
86166 * These are the total time in nanoseconds that the event
86167 @@ -391,8 +391,8 @@ struct perf_event {
86168 * These accumulate total time (in nanoseconds) that children
86169 * events have been enabled and running, respectively.
86170 */
86171 - atomic64_t child_total_time_enabled;
86172 - atomic64_t child_total_time_running;
86173 + atomic64_unchecked_t child_total_time_enabled;
86174 + atomic64_unchecked_t child_total_time_running;
86175
86176 /*
86177 * Protect attach/detach and child_list:
86178 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
86179 entry->ip[entry->nr++] = ip;
86180 }
86181
86182 -extern int sysctl_perf_event_paranoid;
86183 +extern int sysctl_perf_event_legitimately_concerned;
86184 extern int sysctl_perf_event_mlock;
86185 extern int sysctl_perf_event_sample_rate;
86186 extern int sysctl_perf_cpu_time_max_percent;
86187 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
86188 loff_t *ppos);
86189
86190
86191 +static inline bool perf_paranoid_any(void)
86192 +{
86193 + return sysctl_perf_event_legitimately_concerned > 2;
86194 +}
86195 +
86196 static inline bool perf_paranoid_tracepoint_raw(void)
86197 {
86198 - return sysctl_perf_event_paranoid > -1;
86199 + return sysctl_perf_event_legitimately_concerned > -1;
86200 }
86201
86202 static inline bool perf_paranoid_cpu(void)
86203 {
86204 - return sysctl_perf_event_paranoid > 0;
86205 + return sysctl_perf_event_legitimately_concerned > 0;
86206 }
86207
86208 static inline bool perf_paranoid_kernel(void)
86209 {
86210 - return sysctl_perf_event_paranoid > 1;
86211 + return sysctl_perf_event_legitimately_concerned > 1;
86212 }
86213
86214 extern void perf_event_init(void);
86215 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
86216 struct device_attribute attr;
86217 u64 id;
86218 const char *event_str;
86219 -};
86220 +} __do_const;
86221
86222 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
86223 static struct perf_pmu_events_attr _var = { \
86224 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
86225 index 7246ef3..1539ea4 100644
86226 --- a/include/linux/pid_namespace.h
86227 +++ b/include/linux/pid_namespace.h
86228 @@ -43,7 +43,7 @@ struct pid_namespace {
86229 int hide_pid;
86230 int reboot; /* group exit code if this pidns was rebooted */
86231 unsigned int proc_inum;
86232 -};
86233 +} __randomize_layout;
86234
86235 extern struct pid_namespace init_pid_ns;
86236
86237 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
86238 index eb8b8ac..62649e1 100644
86239 --- a/include/linux/pipe_fs_i.h
86240 +++ b/include/linux/pipe_fs_i.h
86241 @@ -47,10 +47,10 @@ struct pipe_inode_info {
86242 struct mutex mutex;
86243 wait_queue_head_t wait;
86244 unsigned int nrbufs, curbuf, buffers;
86245 - unsigned int readers;
86246 - unsigned int writers;
86247 - unsigned int files;
86248 - unsigned int waiting_writers;
86249 + atomic_t readers;
86250 + atomic_t writers;
86251 + atomic_t files;
86252 + atomic_t waiting_writers;
86253 unsigned int r_counter;
86254 unsigned int w_counter;
86255 struct page *tmp_page;
86256 diff --git a/include/linux/pm.h b/include/linux/pm.h
86257 index 72c0fe0..26918ed 100644
86258 --- a/include/linux/pm.h
86259 +++ b/include/linux/pm.h
86260 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
86261 struct dev_pm_domain {
86262 struct dev_pm_ops ops;
86263 };
86264 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
86265
86266 /*
86267 * The PM_EVENT_ messages are also used by drivers implementing the legacy
86268 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
86269 index 7c1d252..0e7061d 100644
86270 --- a/include/linux/pm_domain.h
86271 +++ b/include/linux/pm_domain.h
86272 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
86273 int (*thaw_early)(struct device *dev);
86274 int (*thaw)(struct device *dev);
86275 bool (*active_wakeup)(struct device *dev);
86276 -};
86277 +} __no_const;
86278
86279 struct gpd_cpu_data {
86280 unsigned int saved_exit_latency;
86281 - struct cpuidle_state *idle_state;
86282 + cpuidle_state_no_const *idle_state;
86283 };
86284
86285 struct generic_pm_domain {
86286 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
86287 index 43fd671..08c96ee 100644
86288 --- a/include/linux/pm_runtime.h
86289 +++ b/include/linux/pm_runtime.h
86290 @@ -118,7 +118,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
86291
86292 static inline void pm_runtime_mark_last_busy(struct device *dev)
86293 {
86294 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
86295 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
86296 }
86297
86298 #else /* !CONFIG_PM_RUNTIME */
86299 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
86300 index 195aafc..49a7bc2 100644
86301 --- a/include/linux/pnp.h
86302 +++ b/include/linux/pnp.h
86303 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
86304 struct pnp_fixup {
86305 char id[7];
86306 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
86307 -};
86308 +} __do_const;
86309
86310 /* config parameters */
86311 #define PNP_CONFIG_NORMAL 0x0001
86312 diff --git a/include/linux/poison.h b/include/linux/poison.h
86313 index 2110a81..13a11bb 100644
86314 --- a/include/linux/poison.h
86315 +++ b/include/linux/poison.h
86316 @@ -19,8 +19,8 @@
86317 * under normal circumstances, used to verify that nobody uses
86318 * non-initialized list entries.
86319 */
86320 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
86321 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
86322 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
86323 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
86324
86325 /********** include/linux/timer.h **********/
86326 /*
86327 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
86328 index d8b187c3..9a9257a 100644
86329 --- a/include/linux/power/smartreflex.h
86330 +++ b/include/linux/power/smartreflex.h
86331 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
86332 int (*notify)(struct omap_sr *sr, u32 status);
86333 u8 notify_flags;
86334 u8 class_type;
86335 -};
86336 +} __do_const;
86337
86338 /**
86339 * struct omap_sr_nvalue_table - Smartreflex n-target value info
86340 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
86341 index 4ea1d37..80f4b33 100644
86342 --- a/include/linux/ppp-comp.h
86343 +++ b/include/linux/ppp-comp.h
86344 @@ -84,7 +84,7 @@ struct compressor {
86345 struct module *owner;
86346 /* Extra skb space needed by the compressor algorithm */
86347 unsigned int comp_extra;
86348 -};
86349 +} __do_const;
86350
86351 /*
86352 * The return value from decompress routine is the length of the
86353 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
86354 index de83b4e..c4b997d 100644
86355 --- a/include/linux/preempt.h
86356 +++ b/include/linux/preempt.h
86357 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
86358 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
86359 #endif
86360
86361 +#define raw_preempt_count_add(val) __preempt_count_add(val)
86362 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
86363 +
86364 #define __preempt_count_inc() __preempt_count_add(1)
86365 #define __preempt_count_dec() __preempt_count_sub(1)
86366
86367 #define preempt_count_inc() preempt_count_add(1)
86368 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
86369 #define preempt_count_dec() preempt_count_sub(1)
86370 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
86371
86372 #ifdef CONFIG_PREEMPT_COUNT
86373
86374 @@ -41,6 +46,12 @@ do { \
86375 barrier(); \
86376 } while (0)
86377
86378 +#define raw_preempt_disable() \
86379 +do { \
86380 + raw_preempt_count_inc(); \
86381 + barrier(); \
86382 +} while (0)
86383 +
86384 #define sched_preempt_enable_no_resched() \
86385 do { \
86386 barrier(); \
86387 @@ -49,6 +60,12 @@ do { \
86388
86389 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
86390
86391 +#define raw_preempt_enable_no_resched() \
86392 +do { \
86393 + barrier(); \
86394 + raw_preempt_count_dec(); \
86395 +} while (0)
86396 +
86397 #ifdef CONFIG_PREEMPT
86398 #define preempt_enable() \
86399 do { \
86400 @@ -113,8 +130,10 @@ do { \
86401 * region.
86402 */
86403 #define preempt_disable() barrier()
86404 +#define raw_preempt_disable() barrier()
86405 #define sched_preempt_enable_no_resched() barrier()
86406 #define preempt_enable_no_resched() barrier()
86407 +#define raw_preempt_enable_no_resched() barrier()
86408 #define preempt_enable() barrier()
86409 #define preempt_check_resched() do { } while (0)
86410
86411 @@ -128,11 +147,13 @@ do { \
86412 /*
86413 * Modules have no business playing preemption tricks.
86414 */
86415 +#ifndef CONFIG_PAX_KERNEXEC
86416 #undef sched_preempt_enable_no_resched
86417 #undef preempt_enable_no_resched
86418 #undef preempt_enable_no_resched_notrace
86419 #undef preempt_check_resched
86420 #endif
86421 +#endif
86422
86423 #define preempt_set_need_resched() \
86424 do { \
86425 diff --git a/include/linux/printk.h b/include/linux/printk.h
86426 index 319ff7e..608849a 100644
86427 --- a/include/linux/printk.h
86428 +++ b/include/linux/printk.h
86429 @@ -121,6 +121,8 @@ static inline __printf(1, 2) __cold
86430 void early_printk(const char *s, ...) { }
86431 #endif
86432
86433 +extern int kptr_restrict;
86434 +
86435 #ifdef CONFIG_PRINTK
86436 asmlinkage __printf(5, 0)
86437 int vprintk_emit(int facility, int level,
86438 @@ -155,7 +157,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
86439
86440 extern int printk_delay_msec;
86441 extern int dmesg_restrict;
86442 -extern int kptr_restrict;
86443
86444 extern void wake_up_klogd(void);
86445
86446 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
86447 index 9d117f6..d832b31 100644
86448 --- a/include/linux/proc_fs.h
86449 +++ b/include/linux/proc_fs.h
86450 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
86451 extern struct proc_dir_entry *proc_symlink(const char *,
86452 struct proc_dir_entry *, const char *);
86453 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
86454 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
86455 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
86456 struct proc_dir_entry *, void *);
86457 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
86458 + struct proc_dir_entry *, void *);
86459 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
86460 struct proc_dir_entry *);
86461
86462 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
86463 return proc_create_data(name, mode, parent, proc_fops, NULL);
86464 }
86465
86466 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
86467 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
86468 +{
86469 +#ifdef CONFIG_GRKERNSEC_PROC_USER
86470 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
86471 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86472 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
86473 +#else
86474 + return proc_create_data(name, mode, parent, proc_fops, NULL);
86475 +#endif
86476 +}
86477 +
86478 +
86479 extern void proc_set_size(struct proc_dir_entry *, loff_t);
86480 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
86481 extern void *PDE_DATA(const struct inode *);
86482 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
86483 struct proc_dir_entry *parent,const char *dest) { return NULL;}
86484 static inline struct proc_dir_entry *proc_mkdir(const char *name,
86485 struct proc_dir_entry *parent) {return NULL;}
86486 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
86487 + struct proc_dir_entry *parent) { return NULL; }
86488 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
86489 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
86490 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
86491 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
86492 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
86493 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
86494 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
86495 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
86496 static inline struct proc_dir_entry *proc_net_mkdir(
86497 struct net *net, const char *name, struct proc_dir_entry *parent)
86498 {
86499 - return proc_mkdir_data(name, 0, parent, net);
86500 + return proc_mkdir_data_restrict(name, 0, parent, net);
86501 }
86502
86503 #endif /* _LINUX_PROC_FS_H */
86504 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
86505 index 34a1e10..70f6bde 100644
86506 --- a/include/linux/proc_ns.h
86507 +++ b/include/linux/proc_ns.h
86508 @@ -14,7 +14,7 @@ struct proc_ns_operations {
86509 void (*put)(void *ns);
86510 int (*install)(struct nsproxy *nsproxy, void *ns);
86511 unsigned int (*inum)(void *ns);
86512 -};
86513 +} __do_const __randomize_layout;
86514
86515 struct proc_ns {
86516 void *ns;
86517 diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
86518 index 7dfed71..1dc420b 100644
86519 --- a/include/linux/ptp_classify.h
86520 +++ b/include/linux/ptp_classify.h
86521 @@ -23,8 +23,15 @@
86522 #ifndef _PTP_CLASSIFY_H_
86523 #define _PTP_CLASSIFY_H_
86524
86525 +#include <linux/if_ether.h>
86526 +#include <linux/if_vlan.h>
86527 #include <linux/ip.h>
86528 -#include <linux/skbuff.h>
86529 +#include <linux/filter.h>
86530 +#ifdef __KERNEL__
86531 +#include <linux/in.h>
86532 +#else
86533 +#include <netinet/in.h>
86534 +#endif
86535
86536 #define PTP_CLASS_NONE 0x00 /* not a PTP event message */
86537 #define PTP_CLASS_V1 0x01 /* protocol version 1 */
86538 @@ -37,7 +44,7 @@
86539 #define PTP_CLASS_PMASK 0xf0 /* mask for the packet type field */
86540
86541 #define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4)
86542 -#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /* probably DNE */
86543 +#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6) /*probably DNE*/
86544 #define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4)
86545 #define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6)
86546 #define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2)
86547 @@ -46,34 +53,88 @@
86548 #define PTP_EV_PORT 319
86549 #define PTP_GEN_BIT 0x08 /* indicates general message, if set in message type */
86550
86551 +#define OFF_ETYPE 12
86552 +#define OFF_IHL 14
86553 +#define OFF_FRAG 20
86554 +#define OFF_PROTO4 23
86555 +#define OFF_NEXT 6
86556 +#define OFF_UDP_DST 2
86557 +
86558 #define OFF_PTP_SOURCE_UUID 22 /* PTPv1 only */
86559 #define OFF_PTP_SEQUENCE_ID 30
86560 #define OFF_PTP_CONTROL 32 /* PTPv1 only */
86561
86562 -/* Below defines should actually be removed at some point in time. */
86563 +#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
86564 +
86565 #define IP6_HLEN 40
86566 #define UDP_HLEN 8
86567 -#define OFF_IHL 14
86568 +
86569 +#define RELOFF_DST4 (ETH_HLEN + OFF_UDP_DST)
86570 +#define OFF_DST6 (ETH_HLEN + IP6_HLEN + OFF_UDP_DST)
86571 #define OFF_PTP6 (ETH_HLEN + IP6_HLEN + UDP_HLEN)
86572 -#define IPV4_HLEN(data) (((struct iphdr *)(data + OFF_IHL))->ihl << 2)
86573
86574 -#if defined(CONFIG_NET_PTP_CLASSIFY)
86575 -/**
86576 - * ptp_classify_raw - classify a PTP packet
86577 - * @skb: buffer
86578 - *
86579 - * Runs a minimal BPF dissector to classify a network packet to
86580 - * determine the PTP class. In case the skb does not contain any
86581 - * PTP protocol data, PTP_CLASS_NONE will be returned, otherwise
86582 - * PTP_CLASS_V1_IPV{4,6}, PTP_CLASS_V2_IPV{4,6} or
86583 - * PTP_CLASS_V2_{L2,VLAN}, depending on the packet content.
86584 - */
86585 -unsigned int ptp_classify_raw(const struct sk_buff *skb);
86586 +#define OP_AND (BPF_ALU | BPF_AND | BPF_K)
86587 +#define OP_JEQ (BPF_JMP | BPF_JEQ | BPF_K)
86588 +#define OP_JSET (BPF_JMP | BPF_JSET | BPF_K)
86589 +#define OP_LDB (BPF_LD | BPF_B | BPF_ABS)
86590 +#define OP_LDH (BPF_LD | BPF_H | BPF_ABS)
86591 +#define OP_LDHI (BPF_LD | BPF_H | BPF_IND)
86592 +#define OP_LDX (BPF_LDX | BPF_B | BPF_MSH)
86593 +#define OP_OR (BPF_ALU | BPF_OR | BPF_K)
86594 +#define OP_RETA (BPF_RET | BPF_A)
86595 +#define OP_RETK (BPF_RET | BPF_K)
86596
86597 -void __init ptp_classifier_init(void);
86598 -#else
86599 -static inline void ptp_classifier_init(void)
86600 +static inline int ptp_filter_init(struct sock_filter *f, int len)
86601 {
86602 + if (OP_LDH == f[0].code)
86603 + return sk_chk_filter(f, len);
86604 + else
86605 + return 0;
86606 }
86607 +
86608 +#define PTP_FILTER \
86609 + {OP_LDH, 0, 0, OFF_ETYPE }, /* */ \
86610 + {OP_JEQ, 0, 12, ETH_P_IP }, /* f goto L20 */ \
86611 + {OP_LDB, 0, 0, OFF_PROTO4 }, /* */ \
86612 + {OP_JEQ, 0, 9, IPPROTO_UDP }, /* f goto L10 */ \
86613 + {OP_LDH, 0, 0, OFF_FRAG }, /* */ \
86614 + {OP_JSET, 7, 0, 0x1fff }, /* t goto L11 */ \
86615 + {OP_LDX, 0, 0, OFF_IHL }, /* */ \
86616 + {OP_LDHI, 0, 0, RELOFF_DST4 }, /* */ \
86617 + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L12 */ \
86618 + {OP_LDHI, 0, 0, ETH_HLEN + UDP_HLEN }, /* */ \
86619 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
86620 + {OP_OR, 0, 0, PTP_CLASS_IPV4 }, /* */ \
86621 + {OP_RETA, 0, 0, 0 }, /* */ \
86622 +/*L1x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
86623 +/*L20*/ {OP_JEQ, 0, 9, ETH_P_IPV6 }, /* f goto L40 */ \
86624 + {OP_LDB, 0, 0, ETH_HLEN + OFF_NEXT }, /* */ \
86625 + {OP_JEQ, 0, 6, IPPROTO_UDP }, /* f goto L30 */ \
86626 + {OP_LDH, 0, 0, OFF_DST6 }, /* */ \
86627 + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L31 */ \
86628 + {OP_LDH, 0, 0, OFF_PTP6 }, /* */ \
86629 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
86630 + {OP_OR, 0, 0, PTP_CLASS_IPV6 }, /* */ \
86631 + {OP_RETA, 0, 0, 0 }, /* */ \
86632 +/*L3x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \
86633 +/*L40*/ {OP_JEQ, 0, 9, ETH_P_8021Q }, /* f goto L50 */ \
86634 + {OP_LDH, 0, 0, OFF_ETYPE + 4 }, /* */ \
86635 + {OP_JEQ, 0, 15, ETH_P_1588 }, /* f goto L60 */ \
86636 + {OP_LDB, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
86637 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
86638 + {OP_JEQ, 0, 12, 0 }, /* f goto L6x */ \
86639 + {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \
86640 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
86641 + {OP_OR, 0, 0, PTP_CLASS_VLAN }, /* */ \
86642 + {OP_RETA, 0, 0, 0 }, /* */ \
86643 +/*L50*/ {OP_JEQ, 0, 7, ETH_P_1588 }, /* f goto L61 */ \
86644 + {OP_LDB, 0, 0, ETH_HLEN }, /* */ \
86645 + {OP_AND, 0, 0, PTP_GEN_BIT }, /* */ \
86646 + {OP_JEQ, 0, 4, 0 }, /* f goto L6x */ \
86647 + {OP_LDH, 0, 0, ETH_HLEN }, /* */ \
86648 + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \
86649 + {OP_OR, 0, 0, PTP_CLASS_L2 }, /* */ \
86650 + {OP_RETA, 0, 0, 0 }, /* */ \
86651 +/*L6x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE },
86652 +
86653 #endif
86654 -#endif /* _PTP_CLASSIFY_H_ */
86655 diff --git a/include/linux/quota.h b/include/linux/quota.h
86656 index 0f3c5d3..bc559e3 100644
86657 --- a/include/linux/quota.h
86658 +++ b/include/linux/quota.h
86659 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
86660
86661 extern bool qid_eq(struct kqid left, struct kqid right);
86662 extern bool qid_lt(struct kqid left, struct kqid right);
86663 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
86664 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
86665 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
86666 extern bool qid_valid(struct kqid qid);
86667
86668 diff --git a/include/linux/random.h b/include/linux/random.h
86669 index 57fbbff..2170304 100644
86670 --- a/include/linux/random.h
86671 +++ b/include/linux/random.h
86672 @@ -9,9 +9,19 @@
86673 #include <uapi/linux/random.h>
86674
86675 extern void add_device_randomness(const void *, unsigned int);
86676 +
86677 +static inline void add_latent_entropy(void)
86678 +{
86679 +
86680 +#ifdef LATENT_ENTROPY_PLUGIN
86681 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
86682 +#endif
86683 +
86684 +}
86685 +
86686 extern void add_input_randomness(unsigned int type, unsigned int code,
86687 - unsigned int value);
86688 -extern void add_interrupt_randomness(int irq, int irq_flags);
86689 + unsigned int value) __latent_entropy;
86690 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
86691
86692 extern void get_random_bytes(void *buf, int nbytes);
86693 extern void get_random_bytes_arch(void *buf, int nbytes);
86694 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
86695 extern const struct file_operations random_fops, urandom_fops;
86696 #endif
86697
86698 -unsigned int get_random_int(void);
86699 +unsigned int __intentional_overflow(-1) get_random_int(void);
86700 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
86701
86702 -u32 prandom_u32(void);
86703 +u32 prandom_u32(void) __intentional_overflow(-1);
86704 void prandom_bytes(void *buf, int nbytes);
86705 void prandom_seed(u32 seed);
86706 void prandom_reseed_late(void);
86707 @@ -37,6 +47,11 @@ struct rnd_state {
86708 u32 prandom_u32_state(struct rnd_state *state);
86709 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
86710
86711 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
86712 +{
86713 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
86714 +}
86715 +
86716 /**
86717 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
86718 * @ep_ro: right open interval endpoint
86719 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
86720 *
86721 * Returns: pseudo-random number in interval [0, ep_ro)
86722 */
86723 -static inline u32 prandom_u32_max(u32 ep_ro)
86724 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
86725 {
86726 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
86727 }
86728 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
86729 index fea49b5..2ac22bb 100644
86730 --- a/include/linux/rbtree_augmented.h
86731 +++ b/include/linux/rbtree_augmented.h
86732 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
86733 old->rbaugmented = rbcompute(old); \
86734 } \
86735 rbstatic const struct rb_augment_callbacks rbname = { \
86736 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
86737 + .propagate = rbname ## _propagate, \
86738 + .copy = rbname ## _copy, \
86739 + .rotate = rbname ## _rotate \
86740 };
86741
86742
86743 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
86744 index 8183b46..a388711 100644
86745 --- a/include/linux/rculist.h
86746 +++ b/include/linux/rculist.h
86747 @@ -29,8 +29,8 @@
86748 */
86749 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
86750 {
86751 - ACCESS_ONCE(list->next) = list;
86752 - ACCESS_ONCE(list->prev) = list;
86753 + ACCESS_ONCE_RW(list->next) = list;
86754 + ACCESS_ONCE_RW(list->prev) = list;
86755 }
86756
86757 /*
86758 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
86759 struct list_head *prev, struct list_head *next);
86760 #endif
86761
86762 +void __pax_list_add_rcu(struct list_head *new,
86763 + struct list_head *prev, struct list_head *next);
86764 +
86765 /**
86766 * list_add_rcu - add a new entry to rcu-protected list
86767 * @new: new entry to be added
86768 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
86769 __list_add_rcu(new, head, head->next);
86770 }
86771
86772 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
86773 +{
86774 + __pax_list_add_rcu(new, head, head->next);
86775 +}
86776 +
86777 /**
86778 * list_add_tail_rcu - add a new entry to rcu-protected list
86779 * @new: new entry to be added
86780 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
86781 __list_add_rcu(new, head->prev, head);
86782 }
86783
86784 +static inline void pax_list_add_tail_rcu(struct list_head *new,
86785 + struct list_head *head)
86786 +{
86787 + __pax_list_add_rcu(new, head->prev, head);
86788 +}
86789 +
86790 /**
86791 * list_del_rcu - deletes entry from list without re-initialization
86792 * @entry: the element to delete from the list.
86793 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
86794 entry->prev = LIST_POISON2;
86795 }
86796
86797 +extern void pax_list_del_rcu(struct list_head *entry);
86798 +
86799 /**
86800 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
86801 * @n: the element to delete from the hash list.
86802 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
86803 index 48bf152..d38b785 100644
86804 --- a/include/linux/reboot.h
86805 +++ b/include/linux/reboot.h
86806 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
86807 */
86808
86809 extern void migrate_to_reboot_cpu(void);
86810 -extern void machine_restart(char *cmd);
86811 -extern void machine_halt(void);
86812 -extern void machine_power_off(void);
86813 +extern void machine_restart(char *cmd) __noreturn;
86814 +extern void machine_halt(void) __noreturn;
86815 +extern void machine_power_off(void) __noreturn;
86816
86817 extern void machine_shutdown(void);
86818 struct pt_regs;
86819 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
86820 */
86821
86822 extern void kernel_restart_prepare(char *cmd);
86823 -extern void kernel_restart(char *cmd);
86824 -extern void kernel_halt(void);
86825 -extern void kernel_power_off(void);
86826 +extern void kernel_restart(char *cmd) __noreturn;
86827 +extern void kernel_halt(void) __noreturn;
86828 +extern void kernel_power_off(void) __noreturn;
86829
86830 extern int C_A_D; /* for sysctl */
86831 void ctrl_alt_del(void);
86832 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
86833 * Emergency restart, callable from an interrupt handler.
86834 */
86835
86836 -extern void emergency_restart(void);
86837 +extern void emergency_restart(void) __noreturn;
86838 #include <asm/emergency-restart.h>
86839
86840 #endif /* _LINUX_REBOOT_H */
86841 diff --git a/include/linux/regset.h b/include/linux/regset.h
86842 index 8e0c9fe..ac4d221 100644
86843 --- a/include/linux/regset.h
86844 +++ b/include/linux/regset.h
86845 @@ -161,7 +161,8 @@ struct user_regset {
86846 unsigned int align;
86847 unsigned int bias;
86848 unsigned int core_note_type;
86849 -};
86850 +} __do_const;
86851 +typedef struct user_regset __no_const user_regset_no_const;
86852
86853 /**
86854 * struct user_regset_view - available regsets
86855 diff --git a/include/linux/relay.h b/include/linux/relay.h
86856 index d7c8359..818daf5 100644
86857 --- a/include/linux/relay.h
86858 +++ b/include/linux/relay.h
86859 @@ -157,7 +157,7 @@ struct rchan_callbacks
86860 * The callback should return 0 if successful, negative if not.
86861 */
86862 int (*remove_buf_file)(struct dentry *dentry);
86863 -};
86864 +} __no_const;
86865
86866 /*
86867 * CONFIG_RELAY kernel API, kernel/relay.c
86868 diff --git a/include/linux/rio.h b/include/linux/rio.h
86869 index 6bda06f..bf39a9b 100644
86870 --- a/include/linux/rio.h
86871 +++ b/include/linux/rio.h
86872 @@ -358,7 +358,7 @@ struct rio_ops {
86873 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
86874 u64 rstart, u32 size, u32 flags);
86875 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
86876 -};
86877 +} __no_const;
86878
86879 #define RIO_RESOURCE_MEM 0x00000100
86880 #define RIO_RESOURCE_DOORBELL 0x00000200
86881 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
86882 index be57450..31cf65e 100644
86883 --- a/include/linux/rmap.h
86884 +++ b/include/linux/rmap.h
86885 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
86886 void anon_vma_init(void); /* create anon_vma_cachep */
86887 int anon_vma_prepare(struct vm_area_struct *);
86888 void unlink_anon_vmas(struct vm_area_struct *);
86889 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
86890 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
86891 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
86892 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
86893
86894 static inline void anon_vma_merge(struct vm_area_struct *vma,
86895 struct vm_area_struct *next)
86896 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
86897 index a964f72..b475afb 100644
86898 --- a/include/linux/scatterlist.h
86899 +++ b/include/linux/scatterlist.h
86900 @@ -1,6 +1,7 @@
86901 #ifndef _LINUX_SCATTERLIST_H
86902 #define _LINUX_SCATTERLIST_H
86903
86904 +#include <linux/sched.h>
86905 #include <linux/string.h>
86906 #include <linux/bug.h>
86907 #include <linux/mm.h>
86908 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
86909 #ifdef CONFIG_DEBUG_SG
86910 BUG_ON(!virt_addr_valid(buf));
86911 #endif
86912 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86913 + if (object_starts_on_stack(buf)) {
86914 + void *adjbuf = buf - current->stack + current->lowmem_stack;
86915 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
86916 + } else
86917 +#endif
86918 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
86919 }
86920
86921 diff --git a/include/linux/sched.h b/include/linux/sched.h
86922 index 0376b05..82054c2 100644
86923 --- a/include/linux/sched.h
86924 +++ b/include/linux/sched.h
86925 @@ -131,6 +131,7 @@ struct fs_struct;
86926 struct perf_event_context;
86927 struct blk_plug;
86928 struct filename;
86929 +struct linux_binprm;
86930
86931 #define VMACACHE_BITS 2
86932 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
86933 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
86934 extern int in_sched_functions(unsigned long addr);
86935
86936 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
86937 -extern signed long schedule_timeout(signed long timeout);
86938 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
86939 extern signed long schedule_timeout_interruptible(signed long timeout);
86940 extern signed long schedule_timeout_killable(signed long timeout);
86941 extern signed long schedule_timeout_uninterruptible(signed long timeout);
86942 @@ -385,6 +386,19 @@ struct nsproxy;
86943 struct user_namespace;
86944
86945 #ifdef CONFIG_MMU
86946 +
86947 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
86948 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
86949 +#else
86950 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
86951 +{
86952 + return 0;
86953 +}
86954 +#endif
86955 +
86956 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
86957 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
86958 +
86959 extern void arch_pick_mmap_layout(struct mm_struct *mm);
86960 extern unsigned long
86961 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
86962 @@ -682,6 +696,17 @@ struct signal_struct {
86963 #ifdef CONFIG_TASKSTATS
86964 struct taskstats *stats;
86965 #endif
86966 +
86967 +#ifdef CONFIG_GRKERNSEC
86968 + u32 curr_ip;
86969 + u32 saved_ip;
86970 + u32 gr_saddr;
86971 + u32 gr_daddr;
86972 + u16 gr_sport;
86973 + u16 gr_dport;
86974 + u8 used_accept:1;
86975 +#endif
86976 +
86977 #ifdef CONFIG_AUDIT
86978 unsigned audit_tty;
86979 unsigned audit_tty_log_passwd;
86980 @@ -708,7 +733,7 @@ struct signal_struct {
86981 struct mutex cred_guard_mutex; /* guard against foreign influences on
86982 * credential calculations
86983 * (notably. ptrace) */
86984 -};
86985 +} __randomize_layout;
86986
86987 /*
86988 * Bits in flags field of signal_struct.
86989 @@ -761,6 +786,14 @@ struct user_struct {
86990 struct key *session_keyring; /* UID's default session keyring */
86991 #endif
86992
86993 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
86994 + unsigned char kernel_banned;
86995 +#endif
86996 +#ifdef CONFIG_GRKERNSEC_BRUTE
86997 + unsigned char suid_banned;
86998 + unsigned long suid_ban_expires;
86999 +#endif
87000 +
87001 /* Hash table maintenance information */
87002 struct hlist_node uidhash_node;
87003 kuid_t uid;
87004 @@ -768,7 +801,7 @@ struct user_struct {
87005 #ifdef CONFIG_PERF_EVENTS
87006 atomic_long_t locked_vm;
87007 #endif
87008 -};
87009 +} __randomize_layout;
87010
87011 extern int uids_sysfs_init(void);
87012
87013 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
87014 struct task_struct {
87015 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
87016 void *stack;
87017 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
87018 + void *lowmem_stack;
87019 +#endif
87020 atomic_t usage;
87021 unsigned int flags; /* per process flags, defined below */
87022 unsigned int ptrace;
87023 @@ -1349,8 +1385,8 @@ struct task_struct {
87024 struct list_head thread_node;
87025
87026 struct completion *vfork_done; /* for vfork() */
87027 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
87028 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
87029 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
87030 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
87031
87032 cputime_t utime, stime, utimescaled, stimescaled;
87033 cputime_t gtime;
87034 @@ -1375,11 +1411,6 @@ struct task_struct {
87035 struct task_cputime cputime_expires;
87036 struct list_head cpu_timers[3];
87037
87038 -/* process credentials */
87039 - const struct cred __rcu *real_cred; /* objective and real subjective task
87040 - * credentials (COW) */
87041 - const struct cred __rcu *cred; /* effective (overridable) subjective task
87042 - * credentials (COW) */
87043 char comm[TASK_COMM_LEN]; /* executable name excluding path
87044 - access with [gs]et_task_comm (which lock
87045 it with task_lock())
87046 @@ -1396,6 +1427,10 @@ struct task_struct {
87047 #endif
87048 /* CPU-specific state of this task */
87049 struct thread_struct thread;
87050 +/* thread_info moved to task_struct */
87051 +#ifdef CONFIG_X86
87052 + struct thread_info tinfo;
87053 +#endif
87054 /* filesystem information */
87055 struct fs_struct *fs;
87056 /* open file information */
87057 @@ -1472,6 +1507,10 @@ struct task_struct {
87058 gfp_t lockdep_reclaim_gfp;
87059 #endif
87060
87061 +/* process credentials */
87062 + const struct cred __rcu *real_cred; /* objective and real subjective task
87063 + * credentials (COW) */
87064 +
87065 /* journalling filesystem info */
87066 void *journal_info;
87067
87068 @@ -1510,6 +1549,10 @@ struct task_struct {
87069 /* cg_list protected by css_set_lock and tsk->alloc_lock */
87070 struct list_head cg_list;
87071 #endif
87072 +
87073 + const struct cred __rcu *cred; /* effective (overridable) subjective task
87074 + * credentials (COW) */
87075 +
87076 #ifdef CONFIG_FUTEX
87077 struct robust_list_head __user *robust_list;
87078 #ifdef CONFIG_COMPAT
87079 @@ -1655,7 +1698,78 @@ struct task_struct {
87080 unsigned int sequential_io;
87081 unsigned int sequential_io_avg;
87082 #endif
87083 -};
87084 +
87085 +#ifdef CONFIG_GRKERNSEC
87086 + /* grsecurity */
87087 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87088 + u64 exec_id;
87089 +#endif
87090 +#ifdef CONFIG_GRKERNSEC_SETXID
87091 + const struct cred *delayed_cred;
87092 +#endif
87093 + struct dentry *gr_chroot_dentry;
87094 + struct acl_subject_label *acl;
87095 + struct acl_subject_label *tmpacl;
87096 + struct acl_role_label *role;
87097 + struct file *exec_file;
87098 + unsigned long brute_expires;
87099 + u16 acl_role_id;
87100 + u8 inherited;
87101 + /* is this the task that authenticated to the special role */
87102 + u8 acl_sp_role;
87103 + u8 is_writable;
87104 + u8 brute;
87105 + u8 gr_is_chrooted;
87106 +#endif
87107 +
87108 +} __randomize_layout;
87109 +
87110 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
87111 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
87112 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
87113 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
87114 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
87115 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
87116 +
87117 +#ifdef CONFIG_PAX_SOFTMODE
87118 +extern int pax_softmode;
87119 +#endif
87120 +
87121 +extern int pax_check_flags(unsigned long *);
87122 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
87123 +
87124 +/* if tsk != current then task_lock must be held on it */
87125 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
87126 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
87127 +{
87128 + if (likely(tsk->mm))
87129 + return tsk->mm->pax_flags;
87130 + else
87131 + return 0UL;
87132 +}
87133 +
87134 +/* if tsk != current then task_lock must be held on it */
87135 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
87136 +{
87137 + if (likely(tsk->mm)) {
87138 + tsk->mm->pax_flags = flags;
87139 + return 0;
87140 + }
87141 + return -EINVAL;
87142 +}
87143 +#endif
87144 +
87145 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
87146 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
87147 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
87148 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
87149 +#endif
87150 +
87151 +struct path;
87152 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
87153 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
87154 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
87155 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
87156
87157 /* Future-safe accessor for struct task_struct's cpus_allowed. */
87158 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
87159 @@ -1737,7 +1851,7 @@ struct pid_namespace;
87160 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
87161 struct pid_namespace *ns);
87162
87163 -static inline pid_t task_pid_nr(struct task_struct *tsk)
87164 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
87165 {
87166 return tsk->pid;
87167 }
87168 @@ -2084,6 +2198,25 @@ extern u64 sched_clock_cpu(int cpu);
87169
87170 extern void sched_clock_init(void);
87171
87172 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
87173 +static inline void populate_stack(void)
87174 +{
87175 + struct task_struct *curtask = current;
87176 + int c;
87177 + int *ptr = curtask->stack;
87178 + int *end = curtask->stack + THREAD_SIZE;
87179 +
87180 + while (ptr < end) {
87181 + c = *(volatile int *)ptr;
87182 + ptr += PAGE_SIZE/sizeof(int);
87183 + }
87184 +}
87185 +#else
87186 +static inline void populate_stack(void)
87187 +{
87188 +}
87189 +#endif
87190 +
87191 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
87192 static inline void sched_clock_tick(void)
87193 {
87194 @@ -2217,7 +2350,9 @@ void yield(void);
87195 extern struct exec_domain default_exec_domain;
87196
87197 union thread_union {
87198 +#ifndef CONFIG_X86
87199 struct thread_info thread_info;
87200 +#endif
87201 unsigned long stack[THREAD_SIZE/sizeof(long)];
87202 };
87203
87204 @@ -2250,6 +2385,7 @@ extern struct pid_namespace init_pid_ns;
87205 */
87206
87207 extern struct task_struct *find_task_by_vpid(pid_t nr);
87208 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
87209 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
87210 struct pid_namespace *ns);
87211
87212 @@ -2412,7 +2548,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
87213 extern void exit_itimers(struct signal_struct *);
87214 extern void flush_itimer_signals(void);
87215
87216 -extern void do_group_exit(int);
87217 +extern __noreturn void do_group_exit(int);
87218
87219 extern int do_execve(struct filename *,
87220 const char __user * const __user *,
87221 @@ -2614,9 +2750,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
87222
87223 #endif
87224
87225 -static inline int object_is_on_stack(void *obj)
87226 +static inline int object_starts_on_stack(const void *obj)
87227 {
87228 - void *stack = task_stack_page(current);
87229 + const void *stack = task_stack_page(current);
87230
87231 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
87232 }
87233 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
87234 index 596a0e0..bea77ec 100644
87235 --- a/include/linux/sched/sysctl.h
87236 +++ b/include/linux/sched/sysctl.h
87237 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
87238 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
87239
87240 extern int sysctl_max_map_count;
87241 +extern unsigned long sysctl_heap_stack_gap;
87242
87243 extern unsigned int sysctl_sched_latency;
87244 extern unsigned int sysctl_sched_min_granularity;
87245 diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
87246 index 4054b09..6f19cfd 100644
87247 --- a/include/linux/seccomp.h
87248 +++ b/include/linux/seccomp.h
87249 @@ -76,6 +76,7 @@ static inline int seccomp_mode(struct seccomp *s)
87250 #ifdef CONFIG_SECCOMP_FILTER
87251 extern void put_seccomp_filter(struct task_struct *tsk);
87252 extern void get_seccomp_filter(struct task_struct *tsk);
87253 +extern u32 seccomp_bpf_load(int off);
87254 #else /* CONFIG_SECCOMP_FILTER */
87255 static inline void put_seccomp_filter(struct task_struct *tsk)
87256 {
87257 diff --git a/include/linux/security.h b/include/linux/security.h
87258 index 9c6b972..7e7c704 100644
87259 --- a/include/linux/security.h
87260 +++ b/include/linux/security.h
87261 @@ -27,6 +27,7 @@
87262 #include <linux/slab.h>
87263 #include <linux/err.h>
87264 #include <linux/string.h>
87265 +#include <linux/grsecurity.h>
87266
87267 struct linux_binprm;
87268 struct cred;
87269 @@ -116,8 +117,6 @@ struct seq_file;
87270
87271 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
87272
87273 -void reset_security_ops(void);
87274 -
87275 #ifdef CONFIG_MMU
87276 extern unsigned long mmap_min_addr;
87277 extern unsigned long dac_mmap_min_addr;
87278 @@ -1719,7 +1718,7 @@ struct security_operations {
87279 struct audit_context *actx);
87280 void (*audit_rule_free) (void *lsmrule);
87281 #endif /* CONFIG_AUDIT */
87282 -};
87283 +} __randomize_layout;
87284
87285 /* prototypes */
87286 extern int security_init(void);
87287 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
87288 index dc368b8..e895209 100644
87289 --- a/include/linux/semaphore.h
87290 +++ b/include/linux/semaphore.h
87291 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
87292 }
87293
87294 extern void down(struct semaphore *sem);
87295 -extern int __must_check down_interruptible(struct semaphore *sem);
87296 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
87297 extern int __must_check down_killable(struct semaphore *sem);
87298 extern int __must_check down_trylock(struct semaphore *sem);
87299 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
87300 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
87301 index 52e0097..383f21d 100644
87302 --- a/include/linux/seq_file.h
87303 +++ b/include/linux/seq_file.h
87304 @@ -27,6 +27,9 @@ struct seq_file {
87305 struct mutex lock;
87306 const struct seq_operations *op;
87307 int poll_event;
87308 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87309 + u64 exec_id;
87310 +#endif
87311 #ifdef CONFIG_USER_NS
87312 struct user_namespace *user_ns;
87313 #endif
87314 @@ -39,6 +42,7 @@ struct seq_operations {
87315 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
87316 int (*show) (struct seq_file *m, void *v);
87317 };
87318 +typedef struct seq_operations __no_const seq_operations_no_const;
87319
87320 #define SEQ_SKIP 1
87321
87322 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
87323
87324 char *mangle_path(char *s, const char *p, const char *esc);
87325 int seq_open(struct file *, const struct seq_operations *);
87326 +int seq_open_restrict(struct file *, const struct seq_operations *);
87327 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
87328 loff_t seq_lseek(struct file *, loff_t, int);
87329 int seq_release(struct inode *, struct file *);
87330 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
87331 }
87332
87333 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
87334 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
87335 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
87336 int single_release(struct inode *, struct file *);
87337 void *__seq_open_private(struct file *, const struct seq_operations *, int);
87338 diff --git a/include/linux/shm.h b/include/linux/shm.h
87339 index 57d7770..0936af6 100644
87340 --- a/include/linux/shm.h
87341 +++ b/include/linux/shm.h
87342 @@ -20,6 +20,10 @@ struct shmid_kernel /* private to the kernel */
87343
87344 /* The task created the shm object. NULL if the task is dead. */
87345 struct task_struct *shm_creator;
87346 +#ifdef CONFIG_GRKERNSEC
87347 + time_t shm_createtime;
87348 + pid_t shm_lapid;
87349 +#endif
87350 };
87351
87352 /* shm_mode upper byte flags */
87353 diff --git a/include/linux/signal.h b/include/linux/signal.h
87354 index c9e6536..923b302 100644
87355 --- a/include/linux/signal.h
87356 +++ b/include/linux/signal.h
87357 @@ -293,7 +293,7 @@ static inline void allow_signal(int sig)
87358 * know it'll be handled, so that they don't get converted to
87359 * SIGKILL or just silently dropped.
87360 */
87361 - kernel_sigaction(sig, (__force __sighandler_t)2);
87362 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
87363 }
87364
87365 static inline void disallow_signal(int sig)
87366 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
87367 index ec89301..4fd29a6 100644
87368 --- a/include/linux/skbuff.h
87369 +++ b/include/linux/skbuff.h
87370 @@ -725,7 +725,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
87371 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
87372 int node);
87373 struct sk_buff *build_skb(void *data, unsigned int frag_size);
87374 -static inline struct sk_buff *alloc_skb(unsigned int size,
87375 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
87376 gfp_t priority)
87377 {
87378 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
87379 @@ -1839,7 +1839,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
87380 return skb->inner_transport_header - skb->inner_network_header;
87381 }
87382
87383 -static inline int skb_network_offset(const struct sk_buff *skb)
87384 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
87385 {
87386 return skb_network_header(skb) - skb->data;
87387 }
87388 @@ -1911,7 +1911,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
87389 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
87390 */
87391 #ifndef NET_SKB_PAD
87392 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
87393 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
87394 #endif
87395
87396 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
87397 @@ -2518,7 +2518,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
87398 int *err);
87399 unsigned int datagram_poll(struct file *file, struct socket *sock,
87400 struct poll_table_struct *wait);
87401 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
87402 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
87403 struct iovec *to, int size);
87404 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
87405 struct iovec *iov);
87406 @@ -2664,6 +2664,8 @@ static inline ktime_t net_invalid_timestamp(void)
87407 return ktime_set(0, 0);
87408 }
87409
87410 +void skb_timestamping_init(void);
87411 +
87412 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
87413
87414 void skb_clone_tx_timestamp(struct sk_buff *skb);
87415 @@ -2907,6 +2909,9 @@ static inline void nf_reset(struct sk_buff *skb)
87416 nf_bridge_put(skb->nf_bridge);
87417 skb->nf_bridge = NULL;
87418 #endif
87419 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
87420 + skb->nf_trace = 0;
87421 +#endif
87422 }
87423
87424 static inline void nf_reset_trace(struct sk_buff *skb)
87425 diff --git a/include/linux/slab.h b/include/linux/slab.h
87426 index 1d9abb7..b1e8b10 100644
87427 --- a/include/linux/slab.h
87428 +++ b/include/linux/slab.h
87429 @@ -14,15 +14,29 @@
87430 #include <linux/gfp.h>
87431 #include <linux/types.h>
87432 #include <linux/workqueue.h>
87433 -
87434 +#include <linux/err.h>
87435
87436 /*
87437 * Flags to pass to kmem_cache_create().
87438 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
87439 */
87440 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
87441 +
87442 +#ifdef CONFIG_PAX_USERCOPY_SLABS
87443 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
87444 +#else
87445 +#define SLAB_USERCOPY 0x00000000UL
87446 +#endif
87447 +
87448 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
87449 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
87450 +
87451 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
87452 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
87453 +#else
87454 +#define SLAB_NO_SANITIZE 0x00000000UL
87455 +#endif
87456 +
87457 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
87458 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
87459 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
87460 @@ -98,10 +112,13 @@
87461 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
87462 * Both make kfree a no-op.
87463 */
87464 -#define ZERO_SIZE_PTR ((void *)16)
87465 +#define ZERO_SIZE_PTR \
87466 +({ \
87467 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
87468 + (void *)(-MAX_ERRNO-1L); \
87469 +})
87470
87471 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
87472 - (unsigned long)ZERO_SIZE_PTR)
87473 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
87474
87475 #include <linux/kmemleak.h>
87476
87477 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
87478 void kfree(const void *);
87479 void kzfree(const void *);
87480 size_t ksize(const void *);
87481 +const char *check_heap_object(const void *ptr, unsigned long n);
87482 +bool is_usercopy_object(const void *ptr);
87483
87484 /*
87485 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
87486 @@ -176,7 +195,7 @@ struct kmem_cache {
87487 unsigned int align; /* Alignment as calculated */
87488 unsigned long flags; /* Active flags on the slab */
87489 const char *name; /* Slab name for sysfs */
87490 - int refcount; /* Use counter */
87491 + atomic_t refcount; /* Use counter */
87492 void (*ctor)(void *); /* Called on object slot creation */
87493 struct list_head list; /* List of all slab caches on the system */
87494 };
87495 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
87496 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
87497 #endif
87498
87499 +#ifdef CONFIG_PAX_USERCOPY_SLABS
87500 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
87501 +#endif
87502 +
87503 /*
87504 * Figure out which kmalloc slab an allocation of a certain size
87505 * belongs to.
87506 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
87507 * 2 = 120 .. 192 bytes
87508 * n = 2^(n-1) .. 2^n -1
87509 */
87510 -static __always_inline int kmalloc_index(size_t size)
87511 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
87512 {
87513 if (!size)
87514 return 0;
87515 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
87516 }
87517 #endif /* !CONFIG_SLOB */
87518
87519 -void *__kmalloc(size_t size, gfp_t flags);
87520 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
87521 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
87522
87523 #ifdef CONFIG_NUMA
87524 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
87525 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
87526 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
87527 #else
87528 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
87529 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
87530 index 8235dfb..47ce586 100644
87531 --- a/include/linux/slab_def.h
87532 +++ b/include/linux/slab_def.h
87533 @@ -38,7 +38,7 @@ struct kmem_cache {
87534 /* 4) cache creation/removal */
87535 const char *name;
87536 struct list_head list;
87537 - int refcount;
87538 + atomic_t refcount;
87539 int object_size;
87540 int align;
87541
87542 @@ -54,10 +54,14 @@ struct kmem_cache {
87543 unsigned long node_allocs;
87544 unsigned long node_frees;
87545 unsigned long node_overflow;
87546 - atomic_t allochit;
87547 - atomic_t allocmiss;
87548 - atomic_t freehit;
87549 - atomic_t freemiss;
87550 + atomic_unchecked_t allochit;
87551 + atomic_unchecked_t allocmiss;
87552 + atomic_unchecked_t freehit;
87553 + atomic_unchecked_t freemiss;
87554 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
87555 + atomic_unchecked_t sanitized;
87556 + atomic_unchecked_t not_sanitized;
87557 +#endif
87558
87559 /*
87560 * If debugging is enabled, then the allocator can add additional
87561 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
87562 index d82abd4..408c3a0 100644
87563 --- a/include/linux/slub_def.h
87564 +++ b/include/linux/slub_def.h
87565 @@ -74,7 +74,7 @@ struct kmem_cache {
87566 struct kmem_cache_order_objects max;
87567 struct kmem_cache_order_objects min;
87568 gfp_t allocflags; /* gfp flags to use on each alloc */
87569 - int refcount; /* Refcount for slab cache destroy */
87570 + atomic_t refcount; /* Refcount for slab cache destroy */
87571 void (*ctor)(void *);
87572 int inuse; /* Offset to metadata */
87573 int align; /* Alignment */
87574 diff --git a/include/linux/smp.h b/include/linux/smp.h
87575 index 34347f2..8739978 100644
87576 --- a/include/linux/smp.h
87577 +++ b/include/linux/smp.h
87578 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
87579 #endif
87580
87581 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
87582 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
87583 #define put_cpu() preempt_enable()
87584 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
87585
87586 /*
87587 * Callback to arch code if there's nosmp or maxcpus=0 on the
87588 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
87589 index 46cca4c..3323536 100644
87590 --- a/include/linux/sock_diag.h
87591 +++ b/include/linux/sock_diag.h
87592 @@ -11,7 +11,7 @@ struct sock;
87593 struct sock_diag_handler {
87594 __u8 family;
87595 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
87596 -};
87597 +} __do_const;
87598
87599 int sock_diag_register(const struct sock_diag_handler *h);
87600 void sock_diag_unregister(const struct sock_diag_handler *h);
87601 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
87602 index 680f9a3..f13aeb0 100644
87603 --- a/include/linux/sonet.h
87604 +++ b/include/linux/sonet.h
87605 @@ -7,7 +7,7 @@
87606 #include <uapi/linux/sonet.h>
87607
87608 struct k_sonet_stats {
87609 -#define __HANDLE_ITEM(i) atomic_t i
87610 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
87611 __SONET_ITEMS
87612 #undef __HANDLE_ITEM
87613 };
87614 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
87615 index 07d8e53..dc934c9 100644
87616 --- a/include/linux/sunrpc/addr.h
87617 +++ b/include/linux/sunrpc/addr.h
87618 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
87619 {
87620 switch (sap->sa_family) {
87621 case AF_INET:
87622 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
87623 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
87624 case AF_INET6:
87625 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
87626 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
87627 }
87628 return 0;
87629 }
87630 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
87631 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
87632 const struct sockaddr *src)
87633 {
87634 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
87635 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
87636 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
87637
87638 dsin->sin_family = ssin->sin_family;
87639 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
87640 if (sa->sa_family != AF_INET6)
87641 return 0;
87642
87643 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
87644 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
87645 }
87646
87647 #endif /* _LINUX_SUNRPC_ADDR_H */
87648 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
87649 index 70736b9..37f33db 100644
87650 --- a/include/linux/sunrpc/clnt.h
87651 +++ b/include/linux/sunrpc/clnt.h
87652 @@ -97,7 +97,7 @@ struct rpc_procinfo {
87653 unsigned int p_timer; /* Which RTT timer to use */
87654 u32 p_statidx; /* Which procedure to account */
87655 const char * p_name; /* name of procedure */
87656 -};
87657 +} __do_const;
87658
87659 #ifdef __KERNEL__
87660
87661 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
87662 index 1bc7cd0..7912dc2 100644
87663 --- a/include/linux/sunrpc/svc.h
87664 +++ b/include/linux/sunrpc/svc.h
87665 @@ -417,7 +417,7 @@ struct svc_procedure {
87666 unsigned int pc_count; /* call count */
87667 unsigned int pc_cachetype; /* cache info (NFS) */
87668 unsigned int pc_xdrressize; /* maximum size of XDR reply */
87669 -};
87670 +} __do_const;
87671
87672 /*
87673 * Function prototypes.
87674 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
87675 index 5cf99a0..c0a1b98 100644
87676 --- a/include/linux/sunrpc/svc_rdma.h
87677 +++ b/include/linux/sunrpc/svc_rdma.h
87678 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
87679 extern unsigned int svcrdma_max_requests;
87680 extern unsigned int svcrdma_max_req_size;
87681
87682 -extern atomic_t rdma_stat_recv;
87683 -extern atomic_t rdma_stat_read;
87684 -extern atomic_t rdma_stat_write;
87685 -extern atomic_t rdma_stat_sq_starve;
87686 -extern atomic_t rdma_stat_rq_starve;
87687 -extern atomic_t rdma_stat_rq_poll;
87688 -extern atomic_t rdma_stat_rq_prod;
87689 -extern atomic_t rdma_stat_sq_poll;
87690 -extern atomic_t rdma_stat_sq_prod;
87691 +extern atomic_unchecked_t rdma_stat_recv;
87692 +extern atomic_unchecked_t rdma_stat_read;
87693 +extern atomic_unchecked_t rdma_stat_write;
87694 +extern atomic_unchecked_t rdma_stat_sq_starve;
87695 +extern atomic_unchecked_t rdma_stat_rq_starve;
87696 +extern atomic_unchecked_t rdma_stat_rq_poll;
87697 +extern atomic_unchecked_t rdma_stat_rq_prod;
87698 +extern atomic_unchecked_t rdma_stat_sq_poll;
87699 +extern atomic_unchecked_t rdma_stat_sq_prod;
87700
87701 #define RPCRDMA_VERSION 1
87702
87703 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
87704 index 8d71d65..f79586e 100644
87705 --- a/include/linux/sunrpc/svcauth.h
87706 +++ b/include/linux/sunrpc/svcauth.h
87707 @@ -120,7 +120,7 @@ struct auth_ops {
87708 int (*release)(struct svc_rqst *rq);
87709 void (*domain_release)(struct auth_domain *);
87710 int (*set_client)(struct svc_rqst *rq);
87711 -};
87712 +} __do_const;
87713
87714 #define SVC_GARBAGE 1
87715 #define SVC_SYSERR 2
87716 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
87717 index e7a018e..49f8b17 100644
87718 --- a/include/linux/swiotlb.h
87719 +++ b/include/linux/swiotlb.h
87720 @@ -60,7 +60,8 @@ extern void
87721
87722 extern void
87723 swiotlb_free_coherent(struct device *hwdev, size_t size,
87724 - void *vaddr, dma_addr_t dma_handle);
87725 + void *vaddr, dma_addr_t dma_handle,
87726 + struct dma_attrs *attrs);
87727
87728 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
87729 unsigned long offset, size_t size,
87730 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
87731 index b0881a0..559a440 100644
87732 --- a/include/linux/syscalls.h
87733 +++ b/include/linux/syscalls.h
87734 @@ -98,10 +98,16 @@ struct sigaltstack;
87735 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
87736
87737 #define __SC_DECL(t, a) t a
87738 +#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))
87739 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
87740 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
87741 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
87742 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
87743 +#define __SC_LONG(t, a) __typeof( \
87744 + __builtin_choose_expr( \
87745 + sizeof(t) > sizeof(int), \
87746 + (t) 0, \
87747 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
87748 + )) a
87749 #define __SC_CAST(t, a) (t) a
87750 #define __SC_ARGS(t, a) a
87751 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
87752 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
87753 asmlinkage long sys_fsync(unsigned int fd);
87754 asmlinkage long sys_fdatasync(unsigned int fd);
87755 asmlinkage long sys_bdflush(int func, long data);
87756 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
87757 - char __user *type, unsigned long flags,
87758 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
87759 + const char __user *type, unsigned long flags,
87760 void __user *data);
87761 -asmlinkage long sys_umount(char __user *name, int flags);
87762 -asmlinkage long sys_oldumount(char __user *name);
87763 +asmlinkage long sys_umount(const char __user *name, int flags);
87764 +asmlinkage long sys_oldumount(const char __user *name);
87765 asmlinkage long sys_truncate(const char __user *path, long length);
87766 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
87767 asmlinkage long sys_stat(const char __user *filename,
87768 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
87769 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
87770 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
87771 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
87772 - struct sockaddr __user *, int);
87773 + struct sockaddr __user *, int) __intentional_overflow(0);
87774 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
87775 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
87776 unsigned int vlen, unsigned flags);
87777 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
87778 index 27b3b0b..e093dd9 100644
87779 --- a/include/linux/syscore_ops.h
87780 +++ b/include/linux/syscore_ops.h
87781 @@ -16,7 +16,7 @@ struct syscore_ops {
87782 int (*suspend)(void);
87783 void (*resume)(void);
87784 void (*shutdown)(void);
87785 -};
87786 +} __do_const;
87787
87788 extern void register_syscore_ops(struct syscore_ops *ops);
87789 extern void unregister_syscore_ops(struct syscore_ops *ops);
87790 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
87791 index 14a8ff2..fa95f3a 100644
87792 --- a/include/linux/sysctl.h
87793 +++ b/include/linux/sysctl.h
87794 @@ -34,13 +34,13 @@ struct ctl_table_root;
87795 struct ctl_table_header;
87796 struct ctl_dir;
87797
87798 -typedef struct ctl_table ctl_table;
87799 -
87800 typedef int proc_handler (struct ctl_table *ctl, int write,
87801 void __user *buffer, size_t *lenp, loff_t *ppos);
87802
87803 extern int proc_dostring(struct ctl_table *, int,
87804 void __user *, size_t *, loff_t *);
87805 +extern int proc_dostring_modpriv(struct ctl_table *, int,
87806 + void __user *, size_t *, loff_t *);
87807 extern int proc_dointvec(struct ctl_table *, int,
87808 void __user *, size_t *, loff_t *);
87809 extern int proc_dointvec_minmax(struct ctl_table *, int,
87810 @@ -115,7 +115,9 @@ struct ctl_table
87811 struct ctl_table_poll *poll;
87812 void *extra1;
87813 void *extra2;
87814 -};
87815 +} __do_const __randomize_layout;
87816 +typedef struct ctl_table __no_const ctl_table_no_const;
87817 +typedef struct ctl_table ctl_table;
87818
87819 struct ctl_node {
87820 struct rb_node node;
87821 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
87822 index f97d0db..c1187dc 100644
87823 --- a/include/linux/sysfs.h
87824 +++ b/include/linux/sysfs.h
87825 @@ -34,7 +34,8 @@ struct attribute {
87826 struct lock_class_key *key;
87827 struct lock_class_key skey;
87828 #endif
87829 -};
87830 +} __do_const;
87831 +typedef struct attribute __no_const attribute_no_const;
87832
87833 /**
87834 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
87835 @@ -63,7 +64,8 @@ struct attribute_group {
87836 struct attribute *, int);
87837 struct attribute **attrs;
87838 struct bin_attribute **bin_attrs;
87839 -};
87840 +} __do_const;
87841 +typedef struct attribute_group __no_const attribute_group_no_const;
87842
87843 /**
87844 * Use these macros to make defining attributes easier. See include/linux/device.h
87845 @@ -128,7 +130,8 @@ struct bin_attribute {
87846 char *, loff_t, size_t);
87847 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
87848 struct vm_area_struct *vma);
87849 -};
87850 +} __do_const;
87851 +typedef struct bin_attribute __no_const bin_attribute_no_const;
87852
87853 /**
87854 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
87855 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
87856 index 387fa7d..3fcde6b 100644
87857 --- a/include/linux/sysrq.h
87858 +++ b/include/linux/sysrq.h
87859 @@ -16,6 +16,7 @@
87860
87861 #include <linux/errno.h>
87862 #include <linux/types.h>
87863 +#include <linux/compiler.h>
87864
87865 /* Possible values of bitmask for enabling sysrq functions */
87866 /* 0x0001 is reserved for enable everything */
87867 @@ -33,7 +34,7 @@ struct sysrq_key_op {
87868 char *help_msg;
87869 char *action_msg;
87870 int enable_mask;
87871 -};
87872 +} __do_const;
87873
87874 #ifdef CONFIG_MAGIC_SYSRQ
87875
87876 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
87877 index ff307b5..f1a4468 100644
87878 --- a/include/linux/thread_info.h
87879 +++ b/include/linux/thread_info.h
87880 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
87881 #error "no set_restore_sigmask() provided and default one won't work"
87882 #endif
87883
87884 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
87885 +
87886 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
87887 +{
87888 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
87889 +}
87890 +
87891 #endif /* __KERNEL__ */
87892
87893 #endif /* _LINUX_THREAD_INFO_H */
87894 diff --git a/include/linux/tty.h b/include/linux/tty.h
87895 index 1c3316a..ae83b9f 100644
87896 --- a/include/linux/tty.h
87897 +++ b/include/linux/tty.h
87898 @@ -202,7 +202,7 @@ struct tty_port {
87899 const struct tty_port_operations *ops; /* Port operations */
87900 spinlock_t lock; /* Lock protecting tty field */
87901 int blocked_open; /* Waiting to open */
87902 - int count; /* Usage count */
87903 + atomic_t count; /* Usage count */
87904 wait_queue_head_t open_wait; /* Open waiters */
87905 wait_queue_head_t close_wait; /* Close waiters */
87906 wait_queue_head_t delta_msr_wait; /* Modem status change */
87907 @@ -284,7 +284,7 @@ struct tty_struct {
87908 /* If the tty has a pending do_SAK, queue it here - akpm */
87909 struct work_struct SAK_work;
87910 struct tty_port *port;
87911 -};
87912 +} __randomize_layout;
87913
87914 /* Each of a tty's open files has private_data pointing to tty_file_private */
87915 struct tty_file_private {
87916 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
87917 struct tty_struct *tty, struct file *filp);
87918 static inline int tty_port_users(struct tty_port *port)
87919 {
87920 - return port->count + port->blocked_open;
87921 + return atomic_read(&port->count) + port->blocked_open;
87922 }
87923
87924 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
87925 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
87926 index 756a609..89db85e 100644
87927 --- a/include/linux/tty_driver.h
87928 +++ b/include/linux/tty_driver.h
87929 @@ -285,7 +285,7 @@ struct tty_operations {
87930 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
87931 #endif
87932 const struct file_operations *proc_fops;
87933 -};
87934 +} __do_const __randomize_layout;
87935
87936 struct tty_driver {
87937 int magic; /* magic number for this structure */
87938 @@ -319,7 +319,7 @@ struct tty_driver {
87939
87940 const struct tty_operations *ops;
87941 struct list_head tty_drivers;
87942 -};
87943 +} __randomize_layout;
87944
87945 extern struct list_head tty_drivers;
87946
87947 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
87948 index 00c9d68..bc0188b 100644
87949 --- a/include/linux/tty_ldisc.h
87950 +++ b/include/linux/tty_ldisc.h
87951 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
87952
87953 struct module *owner;
87954
87955 - int refcount;
87956 + atomic_t refcount;
87957 };
87958
87959 struct tty_ldisc {
87960 diff --git a/include/linux/types.h b/include/linux/types.h
87961 index a0bb704..f511c77 100644
87962 --- a/include/linux/types.h
87963 +++ b/include/linux/types.h
87964 @@ -177,10 +177,26 @@ typedef struct {
87965 int counter;
87966 } atomic_t;
87967
87968 +#ifdef CONFIG_PAX_REFCOUNT
87969 +typedef struct {
87970 + int counter;
87971 +} atomic_unchecked_t;
87972 +#else
87973 +typedef atomic_t atomic_unchecked_t;
87974 +#endif
87975 +
87976 #ifdef CONFIG_64BIT
87977 typedef struct {
87978 long counter;
87979 } atomic64_t;
87980 +
87981 +#ifdef CONFIG_PAX_REFCOUNT
87982 +typedef struct {
87983 + long counter;
87984 +} atomic64_unchecked_t;
87985 +#else
87986 +typedef atomic64_t atomic64_unchecked_t;
87987 +#endif
87988 #endif
87989
87990 struct list_head {
87991 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
87992 index ecd3319..8a36ded 100644
87993 --- a/include/linux/uaccess.h
87994 +++ b/include/linux/uaccess.h
87995 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
87996 long ret; \
87997 mm_segment_t old_fs = get_fs(); \
87998 \
87999 - set_fs(KERNEL_DS); \
88000 pagefault_disable(); \
88001 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
88002 - pagefault_enable(); \
88003 + set_fs(KERNEL_DS); \
88004 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
88005 set_fs(old_fs); \
88006 + pagefault_enable(); \
88007 ret; \
88008 })
88009
88010 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
88011 index 2d1f9b6..d7a9fce 100644
88012 --- a/include/linux/uidgid.h
88013 +++ b/include/linux/uidgid.h
88014 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
88015
88016 #endif /* CONFIG_USER_NS */
88017
88018 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
88019 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
88020 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
88021 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
88022 +
88023 #endif /* _LINUX_UIDGID_H */
88024 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
88025 index 99c1b4d..562e6f3 100644
88026 --- a/include/linux/unaligned/access_ok.h
88027 +++ b/include/linux/unaligned/access_ok.h
88028 @@ -4,34 +4,34 @@
88029 #include <linux/kernel.h>
88030 #include <asm/byteorder.h>
88031
88032 -static inline u16 get_unaligned_le16(const void *p)
88033 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
88034 {
88035 - return le16_to_cpup((__le16 *)p);
88036 + return le16_to_cpup((const __le16 *)p);
88037 }
88038
88039 -static inline u32 get_unaligned_le32(const void *p)
88040 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
88041 {
88042 - return le32_to_cpup((__le32 *)p);
88043 + return le32_to_cpup((const __le32 *)p);
88044 }
88045
88046 -static inline u64 get_unaligned_le64(const void *p)
88047 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
88048 {
88049 - return le64_to_cpup((__le64 *)p);
88050 + return le64_to_cpup((const __le64 *)p);
88051 }
88052
88053 -static inline u16 get_unaligned_be16(const void *p)
88054 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
88055 {
88056 - return be16_to_cpup((__be16 *)p);
88057 + return be16_to_cpup((const __be16 *)p);
88058 }
88059
88060 -static inline u32 get_unaligned_be32(const void *p)
88061 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
88062 {
88063 - return be32_to_cpup((__be32 *)p);
88064 + return be32_to_cpup((const __be32 *)p);
88065 }
88066
88067 -static inline u64 get_unaligned_be64(const void *p)
88068 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
88069 {
88070 - return be64_to_cpup((__be64 *)p);
88071 + return be64_to_cpup((const __be64 *)p);
88072 }
88073
88074 static inline void put_unaligned_le16(u16 val, void *p)
88075 diff --git a/include/linux/usb.h b/include/linux/usb.h
88076 index d2465bc..5256de4 100644
88077 --- a/include/linux/usb.h
88078 +++ b/include/linux/usb.h
88079 @@ -571,7 +571,7 @@ struct usb_device {
88080 int maxchild;
88081
88082 u32 quirks;
88083 - atomic_t urbnum;
88084 + atomic_unchecked_t urbnum;
88085
88086 unsigned long active_duration;
88087
88088 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
88089
88090 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
88091 __u8 request, __u8 requesttype, __u16 value, __u16 index,
88092 - void *data, __u16 size, int timeout);
88093 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
88094 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
88095 void *data, int len, int *actual_length, int timeout);
88096 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
88097 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
88098 index e452ba6..78f8e80 100644
88099 --- a/include/linux/usb/renesas_usbhs.h
88100 +++ b/include/linux/usb/renesas_usbhs.h
88101 @@ -39,7 +39,7 @@ enum {
88102 */
88103 struct renesas_usbhs_driver_callback {
88104 int (*notify_hotplug)(struct platform_device *pdev);
88105 -};
88106 +} __no_const;
88107
88108 /*
88109 * callback functions for platform
88110 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
88111 index 4836ba3..603f6ee 100644
88112 --- a/include/linux/user_namespace.h
88113 +++ b/include/linux/user_namespace.h
88114 @@ -33,7 +33,7 @@ struct user_namespace {
88115 struct key *persistent_keyring_register;
88116 struct rw_semaphore persistent_keyring_register_sem;
88117 #endif
88118 -};
88119 +} __randomize_layout;
88120
88121 extern struct user_namespace init_user_ns;
88122
88123 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
88124 index 239e277..22a5cf5 100644
88125 --- a/include/linux/utsname.h
88126 +++ b/include/linux/utsname.h
88127 @@ -24,7 +24,7 @@ struct uts_namespace {
88128 struct new_utsname name;
88129 struct user_namespace *user_ns;
88130 unsigned int proc_inum;
88131 -};
88132 +} __randomize_layout;
88133 extern struct uts_namespace init_uts_ns;
88134
88135 #ifdef CONFIG_UTS_NS
88136 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
88137 index 6f8fbcf..4efc177 100644
88138 --- a/include/linux/vermagic.h
88139 +++ b/include/linux/vermagic.h
88140 @@ -25,9 +25,42 @@
88141 #define MODULE_ARCH_VERMAGIC ""
88142 #endif
88143
88144 +#ifdef CONFIG_PAX_REFCOUNT
88145 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
88146 +#else
88147 +#define MODULE_PAX_REFCOUNT ""
88148 +#endif
88149 +
88150 +#ifdef CONSTIFY_PLUGIN
88151 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
88152 +#else
88153 +#define MODULE_CONSTIFY_PLUGIN ""
88154 +#endif
88155 +
88156 +#ifdef STACKLEAK_PLUGIN
88157 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
88158 +#else
88159 +#define MODULE_STACKLEAK_PLUGIN ""
88160 +#endif
88161 +
88162 +#ifdef RANDSTRUCT_PLUGIN
88163 +#include <generated/randomize_layout_hash.h>
88164 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
88165 +#else
88166 +#define MODULE_RANDSTRUCT_PLUGIN
88167 +#endif
88168 +
88169 +#ifdef CONFIG_GRKERNSEC
88170 +#define MODULE_GRSEC "GRSEC "
88171 +#else
88172 +#define MODULE_GRSEC ""
88173 +#endif
88174 +
88175 #define VERMAGIC_STRING \
88176 UTS_RELEASE " " \
88177 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
88178 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
88179 - MODULE_ARCH_VERMAGIC
88180 + MODULE_ARCH_VERMAGIC \
88181 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
88182 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
88183
88184 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
88185 index 502073a..a7de024 100644
88186 --- a/include/linux/vga_switcheroo.h
88187 +++ b/include/linux/vga_switcheroo.h
88188 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
88189
88190 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
88191
88192 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
88193 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
88194 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
88195 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
88196 #else
88197
88198 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
88199 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
88200
88201 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
88202
88203 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
88204 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
88205 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
88206 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
88207
88208 #endif
88209 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
88210 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
88211 index 4b8a891..e9a2863 100644
88212 --- a/include/linux/vmalloc.h
88213 +++ b/include/linux/vmalloc.h
88214 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
88215 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
88216 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
88217 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
88218 +
88219 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
88220 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
88221 +#endif
88222 +
88223 /* bits [20..32] reserved for arch specific ioremap internals */
88224
88225 /*
88226 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
88227 unsigned long flags, pgprot_t prot);
88228 extern void vunmap(const void *addr);
88229
88230 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88231 +extern void unmap_process_stacks(struct task_struct *task);
88232 +#endif
88233 +
88234 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
88235 unsigned long uaddr, void *kaddr,
88236 unsigned long size);
88237 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
88238
88239 /* for /dev/kmem */
88240 extern long vread(char *buf, char *addr, unsigned long count);
88241 -extern long vwrite(char *buf, char *addr, unsigned long count);
88242 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
88243
88244 /*
88245 * Internals. Dont't use..
88246 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
88247 index 82e7db7..f8ce3d0 100644
88248 --- a/include/linux/vmstat.h
88249 +++ b/include/linux/vmstat.h
88250 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
88251 /*
88252 * Zone based page accounting with per cpu differentials.
88253 */
88254 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
88255 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
88256
88257 static inline void zone_page_state_add(long x, struct zone *zone,
88258 enum zone_stat_item item)
88259 {
88260 - atomic_long_add(x, &zone->vm_stat[item]);
88261 - atomic_long_add(x, &vm_stat[item]);
88262 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
88263 + atomic_long_add_unchecked(x, &vm_stat[item]);
88264 }
88265
88266 -static inline unsigned long global_page_state(enum zone_stat_item item)
88267 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
88268 {
88269 - long x = atomic_long_read(&vm_stat[item]);
88270 + long x = atomic_long_read_unchecked(&vm_stat[item]);
88271 #ifdef CONFIG_SMP
88272 if (x < 0)
88273 x = 0;
88274 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
88275 return x;
88276 }
88277
88278 -static inline unsigned long zone_page_state(struct zone *zone,
88279 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
88280 enum zone_stat_item item)
88281 {
88282 - long x = atomic_long_read(&zone->vm_stat[item]);
88283 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
88284 #ifdef CONFIG_SMP
88285 if (x < 0)
88286 x = 0;
88287 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
88288 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
88289 enum zone_stat_item item)
88290 {
88291 - long x = atomic_long_read(&zone->vm_stat[item]);
88292 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
88293
88294 #ifdef CONFIG_SMP
88295 int cpu;
88296 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
88297
88298 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
88299 {
88300 - atomic_long_inc(&zone->vm_stat[item]);
88301 - atomic_long_inc(&vm_stat[item]);
88302 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
88303 + atomic_long_inc_unchecked(&vm_stat[item]);
88304 }
88305
88306 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
88307 {
88308 - atomic_long_dec(&zone->vm_stat[item]);
88309 - atomic_long_dec(&vm_stat[item]);
88310 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
88311 + atomic_long_dec_unchecked(&vm_stat[item]);
88312 }
88313
88314 static inline void __inc_zone_page_state(struct page *page,
88315 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
88316 index 91b0a68..0e9adf6 100644
88317 --- a/include/linux/xattr.h
88318 +++ b/include/linux/xattr.h
88319 @@ -28,7 +28,7 @@ struct xattr_handler {
88320 size_t size, int handler_flags);
88321 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
88322 size_t size, int flags, int handler_flags);
88323 -};
88324 +} __do_const;
88325
88326 struct xattr {
88327 const char *name;
88328 @@ -37,6 +37,9 @@ struct xattr {
88329 };
88330
88331 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
88332 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
88333 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
88334 +#endif
88335 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
88336 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
88337 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
88338 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
88339 index 9c5a6b4..09c9438 100644
88340 --- a/include/linux/zlib.h
88341 +++ b/include/linux/zlib.h
88342 @@ -31,6 +31,7 @@
88343 #define _ZLIB_H
88344
88345 #include <linux/zconf.h>
88346 +#include <linux/compiler.h>
88347
88348 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
88349 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
88350 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
88351
88352 /* basic functions */
88353
88354 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
88355 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
88356 /*
88357 Returns the number of bytes that needs to be allocated for a per-
88358 stream workspace with the specified parameters. A pointer to this
88359 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
88360 index eec6e46..82d5641 100644
88361 --- a/include/media/v4l2-dev.h
88362 +++ b/include/media/v4l2-dev.h
88363 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
88364 int (*mmap) (struct file *, struct vm_area_struct *);
88365 int (*open) (struct file *);
88366 int (*release) (struct file *);
88367 -};
88368 +} __do_const;
88369
88370 /*
88371 * Newer version of video_device, handled by videodev2.c
88372 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
88373 index ffb69da..040393e 100644
88374 --- a/include/media/v4l2-device.h
88375 +++ b/include/media/v4l2-device.h
88376 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
88377 this function returns 0. If the name ends with a digit (e.g. cx18),
88378 then the name will be set to cx18-0 since cx180 looks really odd. */
88379 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
88380 - atomic_t *instance);
88381 + atomic_unchecked_t *instance);
88382
88383 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
88384 Since the parent disappears this ensures that v4l2_dev doesn't have an
88385 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
88386 index d9fa68f..45c88d1 100644
88387 --- a/include/net/9p/transport.h
88388 +++ b/include/net/9p/transport.h
88389 @@ -63,7 +63,7 @@ struct p9_trans_module {
88390 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
88391 int (*zc_request)(struct p9_client *, struct p9_req_t *,
88392 char *, char *, int , int, int, int);
88393 -};
88394 +} __do_const;
88395
88396 void v9fs_register_trans(struct p9_trans_module *m);
88397 void v9fs_unregister_trans(struct p9_trans_module *m);
88398 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
88399 index a175ba4..196eb82 100644
88400 --- a/include/net/af_unix.h
88401 +++ b/include/net/af_unix.h
88402 @@ -36,7 +36,7 @@ struct unix_skb_parms {
88403 u32 secid; /* Security ID */
88404 #endif
88405 u32 consumed;
88406 -};
88407 +} __randomize_layout;
88408
88409 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
88410 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
88411 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
88412 index 4abdcb2..945c5cc 100644
88413 --- a/include/net/bluetooth/l2cap.h
88414 +++ b/include/net/bluetooth/l2cap.h
88415 @@ -601,7 +601,7 @@ struct l2cap_ops {
88416 long (*get_sndtimeo) (struct l2cap_chan *chan);
88417 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
88418 unsigned long len, int nb);
88419 -};
88420 +} __do_const;
88421
88422 struct l2cap_conn {
88423 struct hci_conn *hcon;
88424 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
88425 index f2ae33d..c457cf0 100644
88426 --- a/include/net/caif/cfctrl.h
88427 +++ b/include/net/caif/cfctrl.h
88428 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
88429 void (*radioset_rsp)(void);
88430 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
88431 struct cflayer *client_layer);
88432 -};
88433 +} __no_const;
88434
88435 /* Link Setup Parameters for CAIF-Links. */
88436 struct cfctrl_link_param {
88437 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
88438 struct cfctrl {
88439 struct cfsrvl serv;
88440 struct cfctrl_rsp res;
88441 - atomic_t req_seq_no;
88442 - atomic_t rsp_seq_no;
88443 + atomic_unchecked_t req_seq_no;
88444 + atomic_unchecked_t rsp_seq_no;
88445 struct list_head list;
88446 /* Protects from simultaneous access to first_req list */
88447 spinlock_t info_list_lock;
88448 diff --git a/include/net/flow.h b/include/net/flow.h
88449 index 8109a15..504466d 100644
88450 --- a/include/net/flow.h
88451 +++ b/include/net/flow.h
88452 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
88453
88454 void flow_cache_flush(struct net *net);
88455 void flow_cache_flush_deferred(struct net *net);
88456 -extern atomic_t flow_cache_genid;
88457 +extern atomic_unchecked_t flow_cache_genid;
88458
88459 #endif
88460 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
88461 index 93695f0..766d71c 100644
88462 --- a/include/net/genetlink.h
88463 +++ b/include/net/genetlink.h
88464 @@ -120,7 +120,7 @@ struct genl_ops {
88465 u8 cmd;
88466 u8 internal_flags;
88467 u8 flags;
88468 -};
88469 +} __do_const;
88470
88471 int __genl_register_family(struct genl_family *family);
88472
88473 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
88474 index 734d9b5..48a9a4b 100644
88475 --- a/include/net/gro_cells.h
88476 +++ b/include/net/gro_cells.h
88477 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
88478 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
88479
88480 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
88481 - atomic_long_inc(&dev->rx_dropped);
88482 + atomic_long_inc_unchecked(&dev->rx_dropped);
88483 kfree_skb(skb);
88484 return;
88485 }
88486 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
88487 index 7a43138..bc76865 100644
88488 --- a/include/net/inet_connection_sock.h
88489 +++ b/include/net/inet_connection_sock.h
88490 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
88491 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
88492 int (*bind_conflict)(const struct sock *sk,
88493 const struct inet_bind_bucket *tb, bool relax);
88494 -};
88495 +} __do_const;
88496
88497 /** inet_connection_sock - INET connection oriented sock
88498 *
88499 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
88500 index 01d590e..f69c61d 100644
88501 --- a/include/net/inetpeer.h
88502 +++ b/include/net/inetpeer.h
88503 @@ -47,7 +47,7 @@ struct inet_peer {
88504 */
88505 union {
88506 struct {
88507 - atomic_t rid; /* Frag reception counter */
88508 + atomic_unchecked_t rid; /* Frag reception counter */
88509 };
88510 struct rcu_head rcu;
88511 struct inet_peer *gc_next;
88512 diff --git a/include/net/ip.h b/include/net/ip.h
88513 index 7596eb2..f7f5fad 100644
88514 --- a/include/net/ip.h
88515 +++ b/include/net/ip.h
88516 @@ -309,7 +309,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
88517 }
88518 }
88519
88520 -u32 ip_idents_reserve(u32 hash, int segs);
88521 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
88522 void __ip_select_ident(struct iphdr *iph, int segs);
88523
88524 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
88525 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
88526 index 9922093..a1755d6 100644
88527 --- a/include/net/ip_fib.h
88528 +++ b/include/net/ip_fib.h
88529 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
88530
88531 #define FIB_RES_SADDR(net, res) \
88532 ((FIB_RES_NH(res).nh_saddr_genid == \
88533 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
88534 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
88535 FIB_RES_NH(res).nh_saddr : \
88536 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
88537 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
88538 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
88539 index 624a8a5..b1e2a24 100644
88540 --- a/include/net/ip_vs.h
88541 +++ b/include/net/ip_vs.h
88542 @@ -558,7 +558,7 @@ struct ip_vs_conn {
88543 struct ip_vs_conn *control; /* Master control connection */
88544 atomic_t n_control; /* Number of controlled ones */
88545 struct ip_vs_dest *dest; /* real server */
88546 - atomic_t in_pkts; /* incoming packet counter */
88547 + atomic_unchecked_t in_pkts; /* incoming packet counter */
88548
88549 /* packet transmitter for different forwarding methods. If it
88550 mangles the packet, it must return NF_DROP or better NF_STOLEN,
88551 @@ -705,7 +705,7 @@ struct ip_vs_dest {
88552 __be16 port; /* port number of the server */
88553 union nf_inet_addr addr; /* IP address of the server */
88554 volatile unsigned int flags; /* dest status flags */
88555 - atomic_t conn_flags; /* flags to copy to conn */
88556 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
88557 atomic_t weight; /* server weight */
88558
88559 atomic_t refcnt; /* reference counter */
88560 @@ -960,11 +960,11 @@ struct netns_ipvs {
88561 /* ip_vs_lblc */
88562 int sysctl_lblc_expiration;
88563 struct ctl_table_header *lblc_ctl_header;
88564 - struct ctl_table *lblc_ctl_table;
88565 + ctl_table_no_const *lblc_ctl_table;
88566 /* ip_vs_lblcr */
88567 int sysctl_lblcr_expiration;
88568 struct ctl_table_header *lblcr_ctl_header;
88569 - struct ctl_table *lblcr_ctl_table;
88570 + ctl_table_no_const *lblcr_ctl_table;
88571 /* ip_vs_est */
88572 struct list_head est_list; /* estimator list */
88573 spinlock_t est_lock;
88574 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
88575 index 8d4f588..2e37ad2 100644
88576 --- a/include/net/irda/ircomm_tty.h
88577 +++ b/include/net/irda/ircomm_tty.h
88578 @@ -33,6 +33,7 @@
88579 #include <linux/termios.h>
88580 #include <linux/timer.h>
88581 #include <linux/tty.h> /* struct tty_struct */
88582 +#include <asm/local.h>
88583
88584 #include <net/irda/irias_object.h>
88585 #include <net/irda/ircomm_core.h>
88586 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
88587 index 714cc9a..ea05f3e 100644
88588 --- a/include/net/iucv/af_iucv.h
88589 +++ b/include/net/iucv/af_iucv.h
88590 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
88591 struct iucv_sock_list {
88592 struct hlist_head head;
88593 rwlock_t lock;
88594 - atomic_t autobind_name;
88595 + atomic_unchecked_t autobind_name;
88596 };
88597
88598 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
88599 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
88600 index f3be818..bf46196 100644
88601 --- a/include/net/llc_c_ac.h
88602 +++ b/include/net/llc_c_ac.h
88603 @@ -87,7 +87,7 @@
88604 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
88605 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
88606
88607 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
88608 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
88609
88610 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
88611 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
88612 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
88613 index 3948cf1..83b28c4 100644
88614 --- a/include/net/llc_c_ev.h
88615 +++ b/include/net/llc_c_ev.h
88616 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
88617 return (struct llc_conn_state_ev *)skb->cb;
88618 }
88619
88620 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
88621 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
88622 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
88623 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
88624
88625 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
88626 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
88627 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
88628 index 0e79cfb..f46db31 100644
88629 --- a/include/net/llc_c_st.h
88630 +++ b/include/net/llc_c_st.h
88631 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
88632 u8 next_state;
88633 llc_conn_ev_qfyr_t *ev_qualifiers;
88634 llc_conn_action_t *ev_actions;
88635 -};
88636 +} __do_const;
88637
88638 struct llc_conn_state {
88639 u8 current_state;
88640 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
88641 index a61b98c..aade1eb 100644
88642 --- a/include/net/llc_s_ac.h
88643 +++ b/include/net/llc_s_ac.h
88644 @@ -23,7 +23,7 @@
88645 #define SAP_ACT_TEST_IND 9
88646
88647 /* All action functions must look like this */
88648 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
88649 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
88650
88651 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
88652 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
88653 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
88654 index 567c681..cd73ac02 100644
88655 --- a/include/net/llc_s_st.h
88656 +++ b/include/net/llc_s_st.h
88657 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
88658 llc_sap_ev_t ev;
88659 u8 next_state;
88660 llc_sap_action_t *ev_actions;
88661 -};
88662 +} __do_const;
88663
88664 struct llc_sap_state {
88665 u8 curr_state;
88666 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
88667 index 421b6ec..5a03729 100644
88668 --- a/include/net/mac80211.h
88669 +++ b/include/net/mac80211.h
88670 @@ -4588,7 +4588,7 @@ struct rate_control_ops {
88671 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
88672
88673 u32 (*get_expected_throughput)(void *priv_sta);
88674 -};
88675 +} __do_const;
88676
88677 static inline int rate_supported(struct ieee80211_sta *sta,
88678 enum ieee80211_band band,
88679 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
88680 index 47f4254..fd095bc 100644
88681 --- a/include/net/neighbour.h
88682 +++ b/include/net/neighbour.h
88683 @@ -163,7 +163,7 @@ struct neigh_ops {
88684 void (*error_report)(struct neighbour *, struct sk_buff *);
88685 int (*output)(struct neighbour *, struct sk_buff *);
88686 int (*connected_output)(struct neighbour *, struct sk_buff *);
88687 -};
88688 +} __do_const;
88689
88690 struct pneigh_entry {
88691 struct pneigh_entry *next;
88692 @@ -217,7 +217,7 @@ struct neigh_table {
88693 struct neigh_statistics __percpu *stats;
88694 struct neigh_hash_table __rcu *nht;
88695 struct pneigh_entry **phash_buckets;
88696 -};
88697 +} __randomize_layout;
88698
88699 static inline int neigh_parms_family(struct neigh_parms *p)
88700 {
88701 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
88702 index 361d260..903d15f 100644
88703 --- a/include/net/net_namespace.h
88704 +++ b/include/net/net_namespace.h
88705 @@ -129,8 +129,8 @@ struct net {
88706 struct netns_ipvs *ipvs;
88707 #endif
88708 struct sock *diag_nlsk;
88709 - atomic_t fnhe_genid;
88710 -};
88711 + atomic_unchecked_t fnhe_genid;
88712 +} __randomize_layout;
88713
88714 #include <linux/seq_file_net.h>
88715
88716 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
88717 #define __net_init __init
88718 #define __net_exit __exit_refok
88719 #define __net_initdata __initdata
88720 +#ifdef CONSTIFY_PLUGIN
88721 #define __net_initconst __initconst
88722 +#else
88723 +#define __net_initconst __initdata
88724 +#endif
88725 #endif
88726
88727 struct pernet_operations {
88728 @@ -296,7 +300,7 @@ struct pernet_operations {
88729 void (*exit_batch)(struct list_head *net_exit_list);
88730 int *id;
88731 size_t size;
88732 -};
88733 +} __do_const;
88734
88735 /*
88736 * Use these carefully. If you implement a network device and it
88737 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
88738
88739 static inline int rt_genid_ipv4(struct net *net)
88740 {
88741 - return atomic_read(&net->ipv4.rt_genid);
88742 + return atomic_read_unchecked(&net->ipv4.rt_genid);
88743 }
88744
88745 static inline void rt_genid_bump_ipv4(struct net *net)
88746 {
88747 - atomic_inc(&net->ipv4.rt_genid);
88748 + atomic_inc_unchecked(&net->ipv4.rt_genid);
88749 }
88750
88751 #if IS_ENABLED(CONFIG_IPV6)
88752 static inline int rt_genid_ipv6(struct net *net)
88753 {
88754 - return atomic_read(&net->ipv6.rt_genid);
88755 + return atomic_read_unchecked(&net->ipv6.rt_genid);
88756 }
88757
88758 static inline void rt_genid_bump_ipv6(struct net *net)
88759 {
88760 - atomic_inc(&net->ipv6.rt_genid);
88761 + atomic_inc_unchecked(&net->ipv6.rt_genid);
88762 }
88763 #else
88764 static inline int rt_genid_ipv6(struct net *net)
88765 @@ -390,12 +394,12 @@ static inline void rt_genid_bump_all(struct net *net)
88766
88767 static inline int fnhe_genid(struct net *net)
88768 {
88769 - return atomic_read(&net->fnhe_genid);
88770 + return atomic_read_unchecked(&net->fnhe_genid);
88771 }
88772
88773 static inline void fnhe_genid_bump(struct net *net)
88774 {
88775 - atomic_inc(&net->fnhe_genid);
88776 + atomic_inc_unchecked(&net->fnhe_genid);
88777 }
88778
88779 #endif /* __NET_NET_NAMESPACE_H */
88780 diff --git a/include/net/netdma.h b/include/net/netdma.h
88781 index 8ba8ce2..99b7fff 100644
88782 --- a/include/net/netdma.h
88783 +++ b/include/net/netdma.h
88784 @@ -24,7 +24,7 @@
88785 #include <linux/dmaengine.h>
88786 #include <linux/skbuff.h>
88787
88788 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
88789 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
88790 struct sk_buff *skb, int offset, struct iovec *to,
88791 size_t len, struct dma_pinned_list *pinned_list);
88792
88793 diff --git a/include/net/netlink.h b/include/net/netlink.h
88794 index 2b47eaa..6d5bcc2 100644
88795 --- a/include/net/netlink.h
88796 +++ b/include/net/netlink.h
88797 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
88798 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
88799 {
88800 if (mark)
88801 - skb_trim(skb, (unsigned char *) mark - skb->data);
88802 + skb_trim(skb, (const unsigned char *) mark - skb->data);
88803 }
88804
88805 /**
88806 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
88807 index 773cce3..6a11852 100644
88808 --- a/include/net/netns/conntrack.h
88809 +++ b/include/net/netns/conntrack.h
88810 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
88811 struct nf_proto_net {
88812 #ifdef CONFIG_SYSCTL
88813 struct ctl_table_header *ctl_table_header;
88814 - struct ctl_table *ctl_table;
88815 + ctl_table_no_const *ctl_table;
88816 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
88817 struct ctl_table_header *ctl_compat_header;
88818 - struct ctl_table *ctl_compat_table;
88819 + ctl_table_no_const *ctl_compat_table;
88820 #endif
88821 #endif
88822 unsigned int users;
88823 @@ -59,7 +59,7 @@ struct nf_ip_net {
88824 struct nf_icmp_net icmpv6;
88825 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
88826 struct ctl_table_header *ctl_table_header;
88827 - struct ctl_table *ctl_table;
88828 + ctl_table_no_const *ctl_table;
88829 #endif
88830 };
88831
88832 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
88833 index aec5e12..807233f 100644
88834 --- a/include/net/netns/ipv4.h
88835 +++ b/include/net/netns/ipv4.h
88836 @@ -82,7 +82,7 @@ struct netns_ipv4 {
88837
88838 struct ping_group_range ping_group_range;
88839
88840 - atomic_t dev_addr_genid;
88841 + atomic_unchecked_t dev_addr_genid;
88842
88843 #ifdef CONFIG_SYSCTL
88844 unsigned long *sysctl_local_reserved_ports;
88845 @@ -96,6 +96,6 @@ struct netns_ipv4 {
88846 struct fib_rules_ops *mr_rules_ops;
88847 #endif
88848 #endif
88849 - atomic_t rt_genid;
88850 + atomic_unchecked_t rt_genid;
88851 };
88852 #endif
88853 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
88854 index 19d3446..3c87195 100644
88855 --- a/include/net/netns/ipv6.h
88856 +++ b/include/net/netns/ipv6.h
88857 @@ -74,8 +74,8 @@ struct netns_ipv6 {
88858 struct fib_rules_ops *mr6_rules_ops;
88859 #endif
88860 #endif
88861 - atomic_t dev_addr_genid;
88862 - atomic_t rt_genid;
88863 + atomic_unchecked_t dev_addr_genid;
88864 + atomic_unchecked_t rt_genid;
88865 };
88866
88867 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
88868 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
88869 index 3492434..209f58c 100644
88870 --- a/include/net/netns/xfrm.h
88871 +++ b/include/net/netns/xfrm.h
88872 @@ -64,7 +64,7 @@ struct netns_xfrm {
88873
88874 /* flow cache part */
88875 struct flow_cache flow_cache_global;
88876 - atomic_t flow_cache_genid;
88877 + atomic_unchecked_t flow_cache_genid;
88878 struct list_head flow_cache_gc_list;
88879 spinlock_t flow_cache_gc_lock;
88880 struct work_struct flow_cache_gc_work;
88881 diff --git a/include/net/ping.h b/include/net/ping.h
88882 index 026479b..d9b2829 100644
88883 --- a/include/net/ping.h
88884 +++ b/include/net/ping.h
88885 @@ -54,7 +54,7 @@ struct ping_iter_state {
88886
88887 extern struct proto ping_prot;
88888 #if IS_ENABLED(CONFIG_IPV6)
88889 -extern struct pingv6_ops pingv6_ops;
88890 +extern struct pingv6_ops *pingv6_ops;
88891 #endif
88892
88893 struct pingfakehdr {
88894 diff --git a/include/net/protocol.h b/include/net/protocol.h
88895 index d6fcc1f..ca277058 100644
88896 --- a/include/net/protocol.h
88897 +++ b/include/net/protocol.h
88898 @@ -49,7 +49,7 @@ struct net_protocol {
88899 * socket lookup?
88900 */
88901 icmp_strict_tag_validation:1;
88902 -};
88903 +} __do_const;
88904
88905 #if IS_ENABLED(CONFIG_IPV6)
88906 struct inet6_protocol {
88907 @@ -62,7 +62,7 @@ struct inet6_protocol {
88908 u8 type, u8 code, int offset,
88909 __be32 info);
88910 unsigned int flags; /* INET6_PROTO_xxx */
88911 -};
88912 +} __do_const;
88913
88914 #define INET6_PROTO_NOPOLICY 0x1
88915 #define INET6_PROTO_FINAL 0x2
88916 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
88917 index 72240e5..8c14bef 100644
88918 --- a/include/net/rtnetlink.h
88919 +++ b/include/net/rtnetlink.h
88920 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
88921 int (*fill_slave_info)(struct sk_buff *skb,
88922 const struct net_device *dev,
88923 const struct net_device *slave_dev);
88924 -};
88925 +} __do_const;
88926
88927 int __rtnl_link_register(struct rtnl_link_ops *ops);
88928 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
88929 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
88930 index 4a5b9a3..ca27d73 100644
88931 --- a/include/net/sctp/checksum.h
88932 +++ b/include/net/sctp/checksum.h
88933 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
88934 unsigned int offset)
88935 {
88936 struct sctphdr *sh = sctp_hdr(skb);
88937 - __le32 ret, old = sh->checksum;
88938 - const struct skb_checksum_ops ops = {
88939 + __le32 ret, old = sh->checksum;
88940 + static const struct skb_checksum_ops ops = {
88941 .update = sctp_csum_update,
88942 .combine = sctp_csum_combine,
88943 };
88944 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
88945 index 7f4eeb3..37e8fe1 100644
88946 --- a/include/net/sctp/sm.h
88947 +++ b/include/net/sctp/sm.h
88948 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
88949 typedef struct {
88950 sctp_state_fn_t *fn;
88951 const char *name;
88952 -} sctp_sm_table_entry_t;
88953 +} __do_const sctp_sm_table_entry_t;
88954
88955 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
88956 * currently in use.
88957 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
88958 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
88959
88960 /* Extern declarations for major data structures. */
88961 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
88962 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
88963
88964
88965 /* Get the size of a DATA chunk payload. */
88966 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
88967 index f38588bf..94c1795 100644
88968 --- a/include/net/sctp/structs.h
88969 +++ b/include/net/sctp/structs.h
88970 @@ -507,7 +507,7 @@ struct sctp_pf {
88971 struct sctp_association *asoc);
88972 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
88973 struct sctp_af *af;
88974 -};
88975 +} __do_const;
88976
88977
88978 /* Structure to track chunk fragments that have been acked, but peer
88979 diff --git a/include/net/sock.h b/include/net/sock.h
88980 index 1563507..20d5d0e 100644
88981 --- a/include/net/sock.h
88982 +++ b/include/net/sock.h
88983 @@ -349,7 +349,7 @@ struct sock {
88984 unsigned int sk_napi_id;
88985 unsigned int sk_ll_usec;
88986 #endif
88987 - atomic_t sk_drops;
88988 + atomic_unchecked_t sk_drops;
88989 int sk_rcvbuf;
88990
88991 struct sk_filter __rcu *sk_filter;
88992 @@ -1038,7 +1038,7 @@ struct proto {
88993 void (*destroy_cgroup)(struct mem_cgroup *memcg);
88994 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
88995 #endif
88996 -};
88997 +} __randomize_layout;
88998
88999 /*
89000 * Bits in struct cg_proto.flags
89001 @@ -1225,7 +1225,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
89002 return ret >> PAGE_SHIFT;
89003 }
89004
89005 -static inline long
89006 +static inline long __intentional_overflow(-1)
89007 sk_memory_allocated(const struct sock *sk)
89008 {
89009 struct proto *prot = sk->sk_prot;
89010 @@ -1370,7 +1370,7 @@ struct sock_iocb {
89011 struct scm_cookie *scm;
89012 struct msghdr *msg, async_msg;
89013 struct kiocb *kiocb;
89014 -};
89015 +} __randomize_layout;
89016
89017 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
89018 {
89019 @@ -1623,6 +1623,33 @@ void sk_common_release(struct sock *sk);
89020 /* Initialise core socket variables */
89021 void sock_init_data(struct socket *sock, struct sock *sk);
89022
89023 +void sk_filter_release_rcu(struct rcu_head *rcu);
89024 +
89025 +/**
89026 + * sk_filter_release - release a socket filter
89027 + * @fp: filter to remove
89028 + *
89029 + * Remove a filter from a socket and release its resources.
89030 + */
89031 +
89032 +static inline void sk_filter_release(struct sk_filter *fp)
89033 +{
89034 + if (atomic_dec_and_test(&fp->refcnt))
89035 + call_rcu(&fp->rcu, sk_filter_release_rcu);
89036 +}
89037 +
89038 +static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
89039 +{
89040 + atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
89041 + sk_filter_release(fp);
89042 +}
89043 +
89044 +static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
89045 +{
89046 + atomic_inc(&fp->refcnt);
89047 + atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
89048 +}
89049 +
89050 /*
89051 * Socket reference counting postulates.
89052 *
89053 @@ -1805,7 +1832,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
89054 }
89055
89056 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
89057 - char __user *from, char *to,
89058 + char __user *from, unsigned char *to,
89059 int copy, int offset)
89060 {
89061 if (skb->ip_summed == CHECKSUM_NONE) {
89062 @@ -2067,7 +2094,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
89063 }
89064 }
89065
89066 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
89067 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
89068
89069 /**
89070 * sk_page_frag - return an appropriate page_frag
89071 diff --git a/include/net/tcp.h b/include/net/tcp.h
89072 index 7286db8..f1aa7dc 100644
89073 --- a/include/net/tcp.h
89074 +++ b/include/net/tcp.h
89075 @@ -535,7 +535,7 @@ void tcp_retransmit_timer(struct sock *sk);
89076 void tcp_xmit_retransmit_queue(struct sock *);
89077 void tcp_simple_retransmit(struct sock *);
89078 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
89079 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
89080 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
89081
89082 void tcp_send_probe0(struct sock *);
89083 void tcp_send_partial(struct sock *);
89084 @@ -708,8 +708,8 @@ struct tcp_skb_cb {
89085 struct inet6_skb_parm h6;
89086 #endif
89087 } header; /* For incoming frames */
89088 - __u32 seq; /* Starting sequence number */
89089 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
89090 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
89091 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
89092 __u32 when; /* used to compute rtt's */
89093 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
89094
89095 @@ -723,7 +723,7 @@ struct tcp_skb_cb {
89096
89097 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
89098 /* 1 byte hole */
89099 - __u32 ack_seq; /* Sequence number ACK'd */
89100 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
89101 };
89102
89103 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
89104 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
89105 index 721e9c3b..3c81bbf 100644
89106 --- a/include/net/xfrm.h
89107 +++ b/include/net/xfrm.h
89108 @@ -285,7 +285,6 @@ struct xfrm_dst;
89109 struct xfrm_policy_afinfo {
89110 unsigned short family;
89111 struct dst_ops *dst_ops;
89112 - void (*garbage_collect)(struct net *net);
89113 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
89114 const xfrm_address_t *saddr,
89115 const xfrm_address_t *daddr);
89116 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
89117 struct net_device *dev,
89118 const struct flowi *fl);
89119 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
89120 -};
89121 +} __do_const;
89122
89123 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
89124 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
89125 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
89126 int (*transport_finish)(struct sk_buff *skb,
89127 int async);
89128 void (*local_error)(struct sk_buff *skb, u32 mtu);
89129 -};
89130 +} __do_const;
89131
89132 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
89133 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
89134 @@ -437,7 +436,7 @@ struct xfrm_mode {
89135 struct module *owner;
89136 unsigned int encap;
89137 int flags;
89138 -};
89139 +} __do_const;
89140
89141 /* Flags for xfrm_mode. */
89142 enum {
89143 @@ -534,7 +533,7 @@ struct xfrm_policy {
89144 struct timer_list timer;
89145
89146 struct flow_cache_object flo;
89147 - atomic_t genid;
89148 + atomic_unchecked_t genid;
89149 u32 priority;
89150 u32 index;
89151 struct xfrm_mark mark;
89152 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
89153 }
89154
89155 void xfrm_garbage_collect(struct net *net);
89156 +void xfrm_garbage_collect_deferred(struct net *net);
89157
89158 #else
89159
89160 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
89161 static inline void xfrm_garbage_collect(struct net *net)
89162 {
89163 }
89164 +static inline void xfrm_garbage_collect_deferred(struct net *net)
89165 +{
89166 +}
89167 #endif
89168
89169 static __inline__
89170 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
89171 index 1017e0b..227aa4d 100644
89172 --- a/include/rdma/iw_cm.h
89173 +++ b/include/rdma/iw_cm.h
89174 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
89175 int backlog);
89176
89177 int (*destroy_listen)(struct iw_cm_id *cm_id);
89178 -};
89179 +} __no_const;
89180
89181 /**
89182 * iw_create_cm_id - Create an IW CM identifier.
89183 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
89184 index 52beadf..598734c 100644
89185 --- a/include/scsi/libfc.h
89186 +++ b/include/scsi/libfc.h
89187 @@ -771,6 +771,7 @@ struct libfc_function_template {
89188 */
89189 void (*disc_stop_final) (struct fc_lport *);
89190 };
89191 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
89192
89193 /**
89194 * struct fc_disc - Discovery context
89195 @@ -875,7 +876,7 @@ struct fc_lport {
89196 struct fc_vport *vport;
89197
89198 /* Operational Information */
89199 - struct libfc_function_template tt;
89200 + libfc_function_template_no_const tt;
89201 u8 link_up;
89202 u8 qfull;
89203 enum fc_lport_state state;
89204 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
89205 index 27ab310..60dc245 100644
89206 --- a/include/scsi/scsi_device.h
89207 +++ b/include/scsi/scsi_device.h
89208 @@ -187,9 +187,9 @@ struct scsi_device {
89209 unsigned int max_device_blocked; /* what device_blocked counts down from */
89210 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
89211
89212 - atomic_t iorequest_cnt;
89213 - atomic_t iodone_cnt;
89214 - atomic_t ioerr_cnt;
89215 + atomic_unchecked_t iorequest_cnt;
89216 + atomic_unchecked_t iodone_cnt;
89217 + atomic_unchecked_t ioerr_cnt;
89218
89219 struct device sdev_gendev,
89220 sdev_dev;
89221 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
89222 index 8c79980..723f6f9 100644
89223 --- a/include/scsi/scsi_transport_fc.h
89224 +++ b/include/scsi/scsi_transport_fc.h
89225 @@ -752,7 +752,8 @@ struct fc_function_template {
89226 unsigned long show_host_system_hostname:1;
89227
89228 unsigned long disable_target_scan:1;
89229 -};
89230 +} __do_const;
89231 +typedef struct fc_function_template __no_const fc_function_template_no_const;
89232
89233
89234 /**
89235 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
89236 index ae6c3b8..fd748ac 100644
89237 --- a/include/sound/compress_driver.h
89238 +++ b/include/sound/compress_driver.h
89239 @@ -128,7 +128,7 @@ struct snd_compr_ops {
89240 struct snd_compr_caps *caps);
89241 int (*get_codec_caps) (struct snd_compr_stream *stream,
89242 struct snd_compr_codec_caps *codec);
89243 -};
89244 +} __no_const;
89245
89246 /**
89247 * struct snd_compr: Compressed device
89248 diff --git a/include/sound/soc.h b/include/sound/soc.h
89249 index ed9e2d7..aad0887 100644
89250 --- a/include/sound/soc.h
89251 +++ b/include/sound/soc.h
89252 @@ -798,7 +798,7 @@ struct snd_soc_codec_driver {
89253 /* probe ordering - for components with runtime dependencies */
89254 int probe_order;
89255 int remove_order;
89256 -};
89257 +} __do_const;
89258
89259 /* SoC platform interface */
89260 struct snd_soc_platform_driver {
89261 @@ -845,7 +845,7 @@ struct snd_soc_platform_driver {
89262 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
89263 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
89264 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
89265 -};
89266 +} __do_const;
89267
89268 struct snd_soc_platform {
89269 const char *name;
89270 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
89271 index 9ec9864..e2ee1ee 100644
89272 --- a/include/target/target_core_base.h
89273 +++ b/include/target/target_core_base.h
89274 @@ -761,7 +761,7 @@ struct se_device {
89275 atomic_long_t write_bytes;
89276 /* Active commands on this virtual SE device */
89277 atomic_t simple_cmds;
89278 - atomic_t dev_ordered_id;
89279 + atomic_unchecked_t dev_ordered_id;
89280 atomic_t dev_ordered_sync;
89281 atomic_t dev_qf_count;
89282 int export_count;
89283 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
89284 new file mode 100644
89285 index 0000000..fb634b7
89286 --- /dev/null
89287 +++ b/include/trace/events/fs.h
89288 @@ -0,0 +1,53 @@
89289 +#undef TRACE_SYSTEM
89290 +#define TRACE_SYSTEM fs
89291 +
89292 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
89293 +#define _TRACE_FS_H
89294 +
89295 +#include <linux/fs.h>
89296 +#include <linux/tracepoint.h>
89297 +
89298 +TRACE_EVENT(do_sys_open,
89299 +
89300 + TP_PROTO(const char *filename, int flags, int mode),
89301 +
89302 + TP_ARGS(filename, flags, mode),
89303 +
89304 + TP_STRUCT__entry(
89305 + __string( filename, filename )
89306 + __field( int, flags )
89307 + __field( int, mode )
89308 + ),
89309 +
89310 + TP_fast_assign(
89311 + __assign_str(filename, filename);
89312 + __entry->flags = flags;
89313 + __entry->mode = mode;
89314 + ),
89315 +
89316 + TP_printk("\"%s\" %x %o",
89317 + __get_str(filename), __entry->flags, __entry->mode)
89318 +);
89319 +
89320 +TRACE_EVENT(open_exec,
89321 +
89322 + TP_PROTO(const char *filename),
89323 +
89324 + TP_ARGS(filename),
89325 +
89326 + TP_STRUCT__entry(
89327 + __string( filename, filename )
89328 + ),
89329 +
89330 + TP_fast_assign(
89331 + __assign_str(filename, filename);
89332 + ),
89333 +
89334 + TP_printk("\"%s\"",
89335 + __get_str(filename))
89336 +);
89337 +
89338 +#endif /* _TRACE_FS_H */
89339 +
89340 +/* This part must be outside protection */
89341 +#include <trace/define_trace.h>
89342 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
89343 index 1c09820..7f5ec79 100644
89344 --- a/include/trace/events/irq.h
89345 +++ b/include/trace/events/irq.h
89346 @@ -36,7 +36,7 @@ struct softirq_action;
89347 */
89348 TRACE_EVENT(irq_handler_entry,
89349
89350 - TP_PROTO(int irq, struct irqaction *action),
89351 + TP_PROTO(int irq, const struct irqaction *action),
89352
89353 TP_ARGS(irq, action),
89354
89355 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
89356 */
89357 TRACE_EVENT(irq_handler_exit,
89358
89359 - TP_PROTO(int irq, struct irqaction *action, int ret),
89360 + TP_PROTO(int irq, const struct irqaction *action, int ret),
89361
89362 TP_ARGS(irq, action, ret),
89363
89364 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
89365 index 7caf44c..23c6f27 100644
89366 --- a/include/uapi/linux/a.out.h
89367 +++ b/include/uapi/linux/a.out.h
89368 @@ -39,6 +39,14 @@ enum machine_type {
89369 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
89370 };
89371
89372 +/* Constants for the N_FLAGS field */
89373 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
89374 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
89375 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
89376 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
89377 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
89378 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
89379 +
89380 #if !defined (N_MAGIC)
89381 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
89382 #endif
89383 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
89384 index 22b6ad3..aeba37e 100644
89385 --- a/include/uapi/linux/bcache.h
89386 +++ b/include/uapi/linux/bcache.h
89387 @@ -5,6 +5,7 @@
89388 * Bcache on disk data structures
89389 */
89390
89391 +#include <linux/compiler.h>
89392 #include <asm/types.h>
89393
89394 #define BITMASK(name, type, field, offset, size) \
89395 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
89396 /* Btree keys - all units are in sectors */
89397
89398 struct bkey {
89399 - __u64 high;
89400 - __u64 low;
89401 + __u64 high __intentional_overflow(-1);
89402 + __u64 low __intentional_overflow(-1);
89403 __u64 ptr[];
89404 };
89405
89406 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
89407 index d876736..ccce5c0 100644
89408 --- a/include/uapi/linux/byteorder/little_endian.h
89409 +++ b/include/uapi/linux/byteorder/little_endian.h
89410 @@ -42,51 +42,51 @@
89411
89412 static inline __le64 __cpu_to_le64p(const __u64 *p)
89413 {
89414 - return (__force __le64)*p;
89415 + return (__force const __le64)*p;
89416 }
89417 -static inline __u64 __le64_to_cpup(const __le64 *p)
89418 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
89419 {
89420 - return (__force __u64)*p;
89421 + return (__force const __u64)*p;
89422 }
89423 static inline __le32 __cpu_to_le32p(const __u32 *p)
89424 {
89425 - return (__force __le32)*p;
89426 + return (__force const __le32)*p;
89427 }
89428 static inline __u32 __le32_to_cpup(const __le32 *p)
89429 {
89430 - return (__force __u32)*p;
89431 + return (__force const __u32)*p;
89432 }
89433 static inline __le16 __cpu_to_le16p(const __u16 *p)
89434 {
89435 - return (__force __le16)*p;
89436 + return (__force const __le16)*p;
89437 }
89438 static inline __u16 __le16_to_cpup(const __le16 *p)
89439 {
89440 - return (__force __u16)*p;
89441 + return (__force const __u16)*p;
89442 }
89443 static inline __be64 __cpu_to_be64p(const __u64 *p)
89444 {
89445 - return (__force __be64)__swab64p(p);
89446 + return (__force const __be64)__swab64p(p);
89447 }
89448 static inline __u64 __be64_to_cpup(const __be64 *p)
89449 {
89450 - return __swab64p((__u64 *)p);
89451 + return __swab64p((const __u64 *)p);
89452 }
89453 static inline __be32 __cpu_to_be32p(const __u32 *p)
89454 {
89455 - return (__force __be32)__swab32p(p);
89456 + return (__force const __be32)__swab32p(p);
89457 }
89458 -static inline __u32 __be32_to_cpup(const __be32 *p)
89459 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
89460 {
89461 - return __swab32p((__u32 *)p);
89462 + return __swab32p((const __u32 *)p);
89463 }
89464 static inline __be16 __cpu_to_be16p(const __u16 *p)
89465 {
89466 - return (__force __be16)__swab16p(p);
89467 + return (__force const __be16)__swab16p(p);
89468 }
89469 static inline __u16 __be16_to_cpup(const __be16 *p)
89470 {
89471 - return __swab16p((__u16 *)p);
89472 + return __swab16p((const __u16 *)p);
89473 }
89474 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
89475 #define __le64_to_cpus(x) do { (void)(x); } while (0)
89476 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
89477 index ef6103b..d4e65dd 100644
89478 --- a/include/uapi/linux/elf.h
89479 +++ b/include/uapi/linux/elf.h
89480 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
89481 #define PT_GNU_EH_FRAME 0x6474e550
89482
89483 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
89484 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
89485 +
89486 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
89487 +
89488 +/* Constants for the e_flags field */
89489 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
89490 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
89491 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
89492 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
89493 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
89494 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
89495
89496 /*
89497 * Extended Numbering
89498 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
89499 #define DT_DEBUG 21
89500 #define DT_TEXTREL 22
89501 #define DT_JMPREL 23
89502 +#define DT_FLAGS 30
89503 + #define DF_TEXTREL 0x00000004
89504 #define DT_ENCODING 32
89505 #define OLD_DT_LOOS 0x60000000
89506 #define DT_LOOS 0x6000000d
89507 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
89508 #define PF_W 0x2
89509 #define PF_X 0x1
89510
89511 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
89512 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
89513 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
89514 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
89515 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
89516 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
89517 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
89518 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
89519 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
89520 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
89521 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
89522 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
89523 +
89524 typedef struct elf32_phdr{
89525 Elf32_Word p_type;
89526 Elf32_Off p_offset;
89527 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
89528 #define EI_OSABI 7
89529 #define EI_PAD 8
89530
89531 +#define EI_PAX 14
89532 +
89533 #define ELFMAG0 0x7f /* EI_MAG */
89534 #define ELFMAG1 'E'
89535 #define ELFMAG2 'L'
89536 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
89537 index aa169c4..6a2771d 100644
89538 --- a/include/uapi/linux/personality.h
89539 +++ b/include/uapi/linux/personality.h
89540 @@ -30,6 +30,7 @@ enum {
89541 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
89542 ADDR_NO_RANDOMIZE | \
89543 ADDR_COMPAT_LAYOUT | \
89544 + ADDR_LIMIT_3GB | \
89545 MMAP_PAGE_ZERO)
89546
89547 /*
89548 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
89549 index 7530e74..e714828 100644
89550 --- a/include/uapi/linux/screen_info.h
89551 +++ b/include/uapi/linux/screen_info.h
89552 @@ -43,7 +43,8 @@ struct screen_info {
89553 __u16 pages; /* 0x32 */
89554 __u16 vesa_attributes; /* 0x34 */
89555 __u32 capabilities; /* 0x36 */
89556 - __u8 _reserved[6]; /* 0x3a */
89557 + __u16 vesapm_size; /* 0x3a */
89558 + __u8 _reserved[4]; /* 0x3c */
89559 } __attribute__((packed));
89560
89561 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
89562 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
89563 index 0e011eb..82681b1 100644
89564 --- a/include/uapi/linux/swab.h
89565 +++ b/include/uapi/linux/swab.h
89566 @@ -43,7 +43,7 @@
89567 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
89568 */
89569
89570 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
89571 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
89572 {
89573 #ifdef __HAVE_BUILTIN_BSWAP16__
89574 return __builtin_bswap16(val);
89575 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
89576 #endif
89577 }
89578
89579 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
89580 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
89581 {
89582 #ifdef __HAVE_BUILTIN_BSWAP32__
89583 return __builtin_bswap32(val);
89584 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
89585 #endif
89586 }
89587
89588 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
89589 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
89590 {
89591 #ifdef __HAVE_BUILTIN_BSWAP64__
89592 return __builtin_bswap64(val);
89593 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
89594 index 6d67213..552fdd9 100644
89595 --- a/include/uapi/linux/sysctl.h
89596 +++ b/include/uapi/linux/sysctl.h
89597 @@ -155,8 +155,6 @@ enum
89598 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
89599 };
89600
89601 -
89602 -
89603 /* CTL_VM names: */
89604 enum
89605 {
89606 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
89607 index 168ff50..a921df2 100644
89608 --- a/include/uapi/linux/videodev2.h
89609 +++ b/include/uapi/linux/videodev2.h
89610 @@ -1253,7 +1253,7 @@ struct v4l2_ext_control {
89611 union {
89612 __s32 value;
89613 __s64 value64;
89614 - char *string;
89615 + char __user *string;
89616 };
89617 } __attribute__ ((packed));
89618
89619 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
89620 index c38355c..17a57bc 100644
89621 --- a/include/uapi/linux/xattr.h
89622 +++ b/include/uapi/linux/xattr.h
89623 @@ -73,5 +73,9 @@
89624 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
89625 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
89626
89627 +/* User namespace */
89628 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
89629 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
89630 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
89631
89632 #endif /* _UAPI_LINUX_XATTR_H */
89633 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
89634 index f9466fa..f4e2b81 100644
89635 --- a/include/video/udlfb.h
89636 +++ b/include/video/udlfb.h
89637 @@ -53,10 +53,10 @@ struct dlfb_data {
89638 u32 pseudo_palette[256];
89639 int blank_mode; /*one of FB_BLANK_ */
89640 /* blit-only rendering path metrics, exposed through sysfs */
89641 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
89642 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
89643 - atomic_t bytes_sent; /* to usb, after compression including overhead */
89644 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
89645 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
89646 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
89647 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
89648 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
89649 };
89650
89651 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
89652 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
89653 index 30f5362..8ed8ac9 100644
89654 --- a/include/video/uvesafb.h
89655 +++ b/include/video/uvesafb.h
89656 @@ -122,6 +122,7 @@ struct uvesafb_par {
89657 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
89658 u8 pmi_setpal; /* PMI for palette changes */
89659 u16 *pmi_base; /* protected mode interface location */
89660 + u8 *pmi_code; /* protected mode code location */
89661 void *pmi_start;
89662 void *pmi_pal;
89663 u8 *vbe_state_orig; /*
89664 diff --git a/init/Kconfig b/init/Kconfig
89665 index 9d76b99..d378b1e 100644
89666 --- a/init/Kconfig
89667 +++ b/init/Kconfig
89668 @@ -1105,6 +1105,7 @@ endif # CGROUPS
89669
89670 config CHECKPOINT_RESTORE
89671 bool "Checkpoint/restore support" if EXPERT
89672 + depends on !GRKERNSEC
89673 default n
89674 help
89675 Enables additional kernel features in a sake of checkpoint/restore.
89676 @@ -1589,7 +1590,7 @@ config SLUB_DEBUG
89677
89678 config COMPAT_BRK
89679 bool "Disable heap randomization"
89680 - default y
89681 + default n
89682 help
89683 Randomizing heap placement makes heap exploits harder, but it
89684 also breaks ancient binaries (including anything libc5 based).
89685 @@ -1877,7 +1878,7 @@ config INIT_ALL_POSSIBLE
89686 config STOP_MACHINE
89687 bool
89688 default y
89689 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
89690 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
89691 help
89692 Need stop_machine() primitive.
89693
89694 diff --git a/init/Makefile b/init/Makefile
89695 index 7bc47ee..6da2dc7 100644
89696 --- a/init/Makefile
89697 +++ b/init/Makefile
89698 @@ -2,6 +2,9 @@
89699 # Makefile for the linux kernel.
89700 #
89701
89702 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
89703 +asflags-y := $(GCC_PLUGINS_AFLAGS)
89704 +
89705 obj-y := main.o version.o mounts.o
89706 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
89707 obj-y += noinitramfs.o
89708 diff --git a/init/do_mounts.c b/init/do_mounts.c
89709 index 82f2288..ea1430a 100644
89710 --- a/init/do_mounts.c
89711 +++ b/init/do_mounts.c
89712 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
89713 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
89714 {
89715 struct super_block *s;
89716 - int err = sys_mount(name, "/root", fs, flags, data);
89717 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
89718 if (err)
89719 return err;
89720
89721 - sys_chdir("/root");
89722 + sys_chdir((const char __force_user *)"/root");
89723 s = current->fs->pwd.dentry->d_sb;
89724 ROOT_DEV = s->s_dev;
89725 printk(KERN_INFO
89726 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
89727 va_start(args, fmt);
89728 vsprintf(buf, fmt, args);
89729 va_end(args);
89730 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
89731 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
89732 if (fd >= 0) {
89733 sys_ioctl(fd, FDEJECT, 0);
89734 sys_close(fd);
89735 }
89736 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
89737 - fd = sys_open("/dev/console", O_RDWR, 0);
89738 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
89739 if (fd >= 0) {
89740 sys_ioctl(fd, TCGETS, (long)&termios);
89741 termios.c_lflag &= ~ICANON;
89742 sys_ioctl(fd, TCSETSF, (long)&termios);
89743 - sys_read(fd, &c, 1);
89744 + sys_read(fd, (char __user *)&c, 1);
89745 termios.c_lflag |= ICANON;
89746 sys_ioctl(fd, TCSETSF, (long)&termios);
89747 sys_close(fd);
89748 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
89749 mount_root();
89750 out:
89751 devtmpfs_mount("dev");
89752 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
89753 - sys_chroot(".");
89754 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
89755 + sys_chroot((const char __force_user *)".");
89756 }
89757
89758 static bool is_tmpfs;
89759 diff --git a/init/do_mounts.h b/init/do_mounts.h
89760 index f5b978a..69dbfe8 100644
89761 --- a/init/do_mounts.h
89762 +++ b/init/do_mounts.h
89763 @@ -15,15 +15,15 @@ extern int root_mountflags;
89764
89765 static inline int create_dev(char *name, dev_t dev)
89766 {
89767 - sys_unlink(name);
89768 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
89769 + sys_unlink((char __force_user *)name);
89770 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
89771 }
89772
89773 #if BITS_PER_LONG == 32
89774 static inline u32 bstat(char *name)
89775 {
89776 struct stat64 stat;
89777 - if (sys_stat64(name, &stat) != 0)
89778 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
89779 return 0;
89780 if (!S_ISBLK(stat.st_mode))
89781 return 0;
89782 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
89783 static inline u32 bstat(char *name)
89784 {
89785 struct stat stat;
89786 - if (sys_newstat(name, &stat) != 0)
89787 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
89788 return 0;
89789 if (!S_ISBLK(stat.st_mode))
89790 return 0;
89791 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
89792 index 3e0878e..8a9d7a0 100644
89793 --- a/init/do_mounts_initrd.c
89794 +++ b/init/do_mounts_initrd.c
89795 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
89796 {
89797 sys_unshare(CLONE_FS | CLONE_FILES);
89798 /* stdin/stdout/stderr for /linuxrc */
89799 - sys_open("/dev/console", O_RDWR, 0);
89800 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
89801 sys_dup(0);
89802 sys_dup(0);
89803 /* move initrd over / and chdir/chroot in initrd root */
89804 - sys_chdir("/root");
89805 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
89806 - sys_chroot(".");
89807 + sys_chdir((const char __force_user *)"/root");
89808 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
89809 + sys_chroot((const char __force_user *)".");
89810 sys_setsid();
89811 return 0;
89812 }
89813 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
89814 create_dev("/dev/root.old", Root_RAM0);
89815 /* mount initrd on rootfs' /root */
89816 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
89817 - sys_mkdir("/old", 0700);
89818 - sys_chdir("/old");
89819 + sys_mkdir((const char __force_user *)"/old", 0700);
89820 + sys_chdir((const char __force_user *)"/old");
89821
89822 /* try loading default modules from initrd */
89823 load_default_modules();
89824 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
89825 current->flags &= ~PF_FREEZER_SKIP;
89826
89827 /* move initrd to rootfs' /old */
89828 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
89829 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
89830 /* switch root and cwd back to / of rootfs */
89831 - sys_chroot("..");
89832 + sys_chroot((const char __force_user *)"..");
89833
89834 if (new_decode_dev(real_root_dev) == Root_RAM0) {
89835 - sys_chdir("/old");
89836 + sys_chdir((const char __force_user *)"/old");
89837 return;
89838 }
89839
89840 - sys_chdir("/");
89841 + sys_chdir((const char __force_user *)"/");
89842 ROOT_DEV = new_decode_dev(real_root_dev);
89843 mount_root();
89844
89845 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
89846 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
89847 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
89848 if (!error)
89849 printk("okay\n");
89850 else {
89851 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
89852 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
89853 if (error == -ENOENT)
89854 printk("/initrd does not exist. Ignored.\n");
89855 else
89856 printk("failed\n");
89857 printk(KERN_NOTICE "Unmounting old root\n");
89858 - sys_umount("/old", MNT_DETACH);
89859 + sys_umount((char __force_user *)"/old", MNT_DETACH);
89860 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
89861 if (fd < 0) {
89862 error = fd;
89863 @@ -127,11 +127,11 @@ int __init initrd_load(void)
89864 * mounted in the normal path.
89865 */
89866 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
89867 - sys_unlink("/initrd.image");
89868 + sys_unlink((const char __force_user *)"/initrd.image");
89869 handle_initrd();
89870 return 1;
89871 }
89872 }
89873 - sys_unlink("/initrd.image");
89874 + sys_unlink((const char __force_user *)"/initrd.image");
89875 return 0;
89876 }
89877 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
89878 index 8cb6db5..d729f50 100644
89879 --- a/init/do_mounts_md.c
89880 +++ b/init/do_mounts_md.c
89881 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
89882 partitioned ? "_d" : "", minor,
89883 md_setup_args[ent].device_names);
89884
89885 - fd = sys_open(name, 0, 0);
89886 + fd = sys_open((char __force_user *)name, 0, 0);
89887 if (fd < 0) {
89888 printk(KERN_ERR "md: open failed - cannot start "
89889 "array %s\n", name);
89890 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
89891 * array without it
89892 */
89893 sys_close(fd);
89894 - fd = sys_open(name, 0, 0);
89895 + fd = sys_open((char __force_user *)name, 0, 0);
89896 sys_ioctl(fd, BLKRRPART, 0);
89897 }
89898 sys_close(fd);
89899 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
89900
89901 wait_for_device_probe();
89902
89903 - fd = sys_open("/dev/md0", 0, 0);
89904 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
89905 if (fd >= 0) {
89906 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
89907 sys_close(fd);
89908 diff --git a/init/init_task.c b/init/init_task.c
89909 index ba0a7f36..2bcf1d5 100644
89910 --- a/init/init_task.c
89911 +++ b/init/init_task.c
89912 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
89913 * Initial thread structure. Alignment of this is handled by a special
89914 * linker map entry.
89915 */
89916 +#ifdef CONFIG_X86
89917 +union thread_union init_thread_union __init_task_data;
89918 +#else
89919 union thread_union init_thread_union __init_task_data =
89920 { INIT_THREAD_INFO(init_task) };
89921 +#endif
89922 diff --git a/init/initramfs.c b/init/initramfs.c
89923 index a8497fa..35b3c90 100644
89924 --- a/init/initramfs.c
89925 +++ b/init/initramfs.c
89926 @@ -84,7 +84,7 @@ static void __init free_hash(void)
89927 }
89928 }
89929
89930 -static long __init do_utime(char *filename, time_t mtime)
89931 +static long __init do_utime(char __force_user *filename, time_t mtime)
89932 {
89933 struct timespec t[2];
89934
89935 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
89936 struct dir_entry *de, *tmp;
89937 list_for_each_entry_safe(de, tmp, &dir_list, list) {
89938 list_del(&de->list);
89939 - do_utime(de->name, de->mtime);
89940 + do_utime((char __force_user *)de->name, de->mtime);
89941 kfree(de->name);
89942 kfree(de);
89943 }
89944 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
89945 if (nlink >= 2) {
89946 char *old = find_link(major, minor, ino, mode, collected);
89947 if (old)
89948 - return (sys_link(old, collected) < 0) ? -1 : 1;
89949 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
89950 }
89951 return 0;
89952 }
89953 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
89954 {
89955 struct stat st;
89956
89957 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
89958 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
89959 if (S_ISDIR(st.st_mode))
89960 - sys_rmdir(path);
89961 + sys_rmdir((char __force_user *)path);
89962 else
89963 - sys_unlink(path);
89964 + sys_unlink((char __force_user *)path);
89965 }
89966 }
89967
89968 @@ -315,7 +315,7 @@ static int __init do_name(void)
89969 int openflags = O_WRONLY|O_CREAT;
89970 if (ml != 1)
89971 openflags |= O_TRUNC;
89972 - wfd = sys_open(collected, openflags, mode);
89973 + wfd = sys_open((char __force_user *)collected, openflags, mode);
89974
89975 if (wfd >= 0) {
89976 sys_fchown(wfd, uid, gid);
89977 @@ -327,17 +327,17 @@ static int __init do_name(void)
89978 }
89979 }
89980 } else if (S_ISDIR(mode)) {
89981 - sys_mkdir(collected, mode);
89982 - sys_chown(collected, uid, gid);
89983 - sys_chmod(collected, mode);
89984 + sys_mkdir((char __force_user *)collected, mode);
89985 + sys_chown((char __force_user *)collected, uid, gid);
89986 + sys_chmod((char __force_user *)collected, mode);
89987 dir_add(collected, mtime);
89988 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
89989 S_ISFIFO(mode) || S_ISSOCK(mode)) {
89990 if (maybe_link() == 0) {
89991 - sys_mknod(collected, mode, rdev);
89992 - sys_chown(collected, uid, gid);
89993 - sys_chmod(collected, mode);
89994 - do_utime(collected, mtime);
89995 + sys_mknod((char __force_user *)collected, mode, rdev);
89996 + sys_chown((char __force_user *)collected, uid, gid);
89997 + sys_chmod((char __force_user *)collected, mode);
89998 + do_utime((char __force_user *)collected, mtime);
89999 }
90000 }
90001 return 0;
90002 @@ -346,15 +346,15 @@ static int __init do_name(void)
90003 static int __init do_copy(void)
90004 {
90005 if (count >= body_len) {
90006 - sys_write(wfd, victim, body_len);
90007 + sys_write(wfd, (char __force_user *)victim, body_len);
90008 sys_close(wfd);
90009 - do_utime(vcollected, mtime);
90010 + do_utime((char __force_user *)vcollected, mtime);
90011 kfree(vcollected);
90012 eat(body_len);
90013 state = SkipIt;
90014 return 0;
90015 } else {
90016 - sys_write(wfd, victim, count);
90017 + sys_write(wfd, (char __force_user *)victim, count);
90018 body_len -= count;
90019 eat(count);
90020 return 1;
90021 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
90022 {
90023 collected[N_ALIGN(name_len) + body_len] = '\0';
90024 clean_path(collected, 0);
90025 - sys_symlink(collected + N_ALIGN(name_len), collected);
90026 - sys_lchown(collected, uid, gid);
90027 - do_utime(collected, mtime);
90028 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
90029 + sys_lchown((char __force_user *)collected, uid, gid);
90030 + do_utime((char __force_user *)collected, mtime);
90031 state = SkipIt;
90032 next_state = Reset;
90033 return 0;
90034 diff --git a/init/main.c b/init/main.c
90035 index e8ae1fe..f60f98c 100644
90036 --- a/init/main.c
90037 +++ b/init/main.c
90038 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
90039 static inline void mark_rodata_ro(void) { }
90040 #endif
90041
90042 +extern void grsecurity_init(void);
90043 +
90044 /*
90045 * Debug helper: via this flag we know that we are in 'early bootup code'
90046 * where only the boot processor is running with IRQ disabled. This means
90047 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
90048
90049 __setup("reset_devices", set_reset_devices);
90050
90051 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90052 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
90053 +static int __init setup_grsec_proc_gid(char *str)
90054 +{
90055 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
90056 + return 1;
90057 +}
90058 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
90059 +#endif
90060 +
90061 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
90062 +unsigned long pax_user_shadow_base __read_only;
90063 +EXPORT_SYMBOL(pax_user_shadow_base);
90064 +extern char pax_enter_kernel_user[];
90065 +extern char pax_exit_kernel_user[];
90066 +#endif
90067 +
90068 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
90069 +static int __init setup_pax_nouderef(char *str)
90070 +{
90071 +#ifdef CONFIG_X86_32
90072 + unsigned int cpu;
90073 + struct desc_struct *gdt;
90074 +
90075 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
90076 + gdt = get_cpu_gdt_table(cpu);
90077 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
90078 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
90079 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
90080 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
90081 + }
90082 + loadsegment(ds, __KERNEL_DS);
90083 + loadsegment(es, __KERNEL_DS);
90084 + loadsegment(ss, __KERNEL_DS);
90085 +#else
90086 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
90087 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
90088 + clone_pgd_mask = ~(pgdval_t)0UL;
90089 + pax_user_shadow_base = 0UL;
90090 + setup_clear_cpu_cap(X86_FEATURE_PCID);
90091 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
90092 +#endif
90093 +
90094 + return 0;
90095 +}
90096 +early_param("pax_nouderef", setup_pax_nouderef);
90097 +
90098 +#ifdef CONFIG_X86_64
90099 +static int __init setup_pax_weakuderef(char *str)
90100 +{
90101 + if (clone_pgd_mask != ~(pgdval_t)0UL)
90102 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
90103 + return 1;
90104 +}
90105 +__setup("pax_weakuderef", setup_pax_weakuderef);
90106 +#endif
90107 +#endif
90108 +
90109 +#ifdef CONFIG_PAX_SOFTMODE
90110 +int pax_softmode;
90111 +
90112 +static int __init setup_pax_softmode(char *str)
90113 +{
90114 + get_option(&str, &pax_softmode);
90115 + return 1;
90116 +}
90117 +__setup("pax_softmode=", setup_pax_softmode);
90118 +#endif
90119 +
90120 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
90121 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
90122 static const char *panic_later, *panic_param;
90123 @@ -727,7 +798,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
90124 struct blacklist_entry *entry;
90125 char *fn_name;
90126
90127 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
90128 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
90129 if (!fn_name)
90130 return false;
90131
90132 @@ -779,7 +850,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
90133 {
90134 int count = preempt_count();
90135 int ret;
90136 - char msgbuf[64];
90137 + const char *msg1 = "", *msg2 = "";
90138
90139 if (initcall_blacklisted(fn))
90140 return -EPERM;
90141 @@ -789,18 +860,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
90142 else
90143 ret = fn();
90144
90145 - msgbuf[0] = 0;
90146 -
90147 if (preempt_count() != count) {
90148 - sprintf(msgbuf, "preemption imbalance ");
90149 + msg1 = " preemption imbalance";
90150 preempt_count_set(count);
90151 }
90152 if (irqs_disabled()) {
90153 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
90154 + msg2 = " disabled interrupts";
90155 local_irq_enable();
90156 }
90157 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
90158 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
90159
90160 + add_latent_entropy();
90161 return ret;
90162 }
90163
90164 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
90165 {
90166 argv_init[0] = init_filename;
90167 return do_execve(getname_kernel(init_filename),
90168 - (const char __user *const __user *)argv_init,
90169 - (const char __user *const __user *)envp_init);
90170 + (const char __user *const __force_user *)argv_init,
90171 + (const char __user *const __force_user *)envp_init);
90172 }
90173
90174 static int try_to_run_init_process(const char *init_filename)
90175 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
90176 return ret;
90177 }
90178
90179 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
90180 +extern int gr_init_ran;
90181 +#endif
90182 +
90183 static noinline void __init kernel_init_freeable(void);
90184
90185 static int __ref kernel_init(void *unused)
90186 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
90187 ramdisk_execute_command, ret);
90188 }
90189
90190 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
90191 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
90192 + gr_init_ran = 1;
90193 +#endif
90194 +
90195 /*
90196 * We try each of these until one succeeds.
90197 *
90198 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
90199 do_basic_setup();
90200
90201 /* Open the /dev/console on the rootfs, this should never fail */
90202 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
90203 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
90204 pr_err("Warning: unable to open an initial console.\n");
90205
90206 (void) sys_dup(0);
90207 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
90208 if (!ramdisk_execute_command)
90209 ramdisk_execute_command = "/init";
90210
90211 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
90212 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
90213 ramdisk_execute_command = NULL;
90214 prepare_namespace();
90215 }
90216
90217 + grsecurity_init();
90218 +
90219 /*
90220 * Ok, we have completed the initial bootup, and
90221 * we're essentially up and running. Get rid of the
90222 diff --git a/ipc/compat.c b/ipc/compat.c
90223 index b5ef4f7..ff31d87 100644
90224 --- a/ipc/compat.c
90225 +++ b/ipc/compat.c
90226 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
90227 COMPAT_SHMLBA);
90228 if (err < 0)
90229 return err;
90230 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
90231 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
90232 }
90233 case SHMDT:
90234 return sys_shmdt(compat_ptr(ptr));
90235 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
90236 index c3f0326..d4e0579 100644
90237 --- a/ipc/ipc_sysctl.c
90238 +++ b/ipc/ipc_sysctl.c
90239 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
90240 static int proc_ipc_dointvec(struct ctl_table *table, int write,
90241 void __user *buffer, size_t *lenp, loff_t *ppos)
90242 {
90243 - struct ctl_table ipc_table;
90244 + ctl_table_no_const ipc_table;
90245
90246 memcpy(&ipc_table, table, sizeof(ipc_table));
90247 ipc_table.data = get_ipc(table);
90248 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
90249 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
90250 void __user *buffer, size_t *lenp, loff_t *ppos)
90251 {
90252 - struct ctl_table ipc_table;
90253 + ctl_table_no_const ipc_table;
90254
90255 memcpy(&ipc_table, table, sizeof(ipc_table));
90256 ipc_table.data = get_ipc(table);
90257 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
90258 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
90259 void __user *buffer, size_t *lenp, loff_t *ppos)
90260 {
90261 - struct ctl_table ipc_table;
90262 + ctl_table_no_const ipc_table;
90263 size_t lenp_bef = *lenp;
90264 int rc;
90265
90266 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
90267 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
90268 void __user *buffer, size_t *lenp, loff_t *ppos)
90269 {
90270 - struct ctl_table ipc_table;
90271 + ctl_table_no_const ipc_table;
90272 memcpy(&ipc_table, table, sizeof(ipc_table));
90273 ipc_table.data = get_ipc(table);
90274
90275 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
90276 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
90277 void __user *buffer, size_t *lenp, loff_t *ppos)
90278 {
90279 - struct ctl_table ipc_table;
90280 + ctl_table_no_const ipc_table;
90281 size_t lenp_bef = *lenp;
90282 int oldval;
90283 int rc;
90284 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
90285 index 68d4e95..1477ded 100644
90286 --- a/ipc/mq_sysctl.c
90287 +++ b/ipc/mq_sysctl.c
90288 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
90289 static int proc_mq_dointvec(struct ctl_table *table, int write,
90290 void __user *buffer, size_t *lenp, loff_t *ppos)
90291 {
90292 - struct ctl_table mq_table;
90293 + ctl_table_no_const mq_table;
90294 memcpy(&mq_table, table, sizeof(mq_table));
90295 mq_table.data = get_mq(table);
90296
90297 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
90298 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
90299 void __user *buffer, size_t *lenp, loff_t *ppos)
90300 {
90301 - struct ctl_table mq_table;
90302 + ctl_table_no_const mq_table;
90303 memcpy(&mq_table, table, sizeof(mq_table));
90304 mq_table.data = get_mq(table);
90305
90306 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
90307 index 4fcf39a..d3cc2ec 100644
90308 --- a/ipc/mqueue.c
90309 +++ b/ipc/mqueue.c
90310 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
90311 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
90312 info->attr.mq_msgsize);
90313
90314 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
90315 spin_lock(&mq_lock);
90316 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
90317 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
90318 diff --git a/ipc/shm.c b/ipc/shm.c
90319 index 89fc354..cf56786 100644
90320 --- a/ipc/shm.c
90321 +++ b/ipc/shm.c
90322 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
90323 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
90324 #endif
90325
90326 +#ifdef CONFIG_GRKERNSEC
90327 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
90328 + const time_t shm_createtime, const kuid_t cuid,
90329 + const int shmid);
90330 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
90331 + const time_t shm_createtime);
90332 +#endif
90333 +
90334 void shm_init_ns(struct ipc_namespace *ns)
90335 {
90336 ns->shm_ctlmax = SHMMAX;
90337 @@ -557,6 +565,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
90338 shp->shm_lprid = 0;
90339 shp->shm_atim = shp->shm_dtim = 0;
90340 shp->shm_ctim = get_seconds();
90341 +#ifdef CONFIG_GRKERNSEC
90342 + {
90343 + struct timespec timeval;
90344 + do_posix_clock_monotonic_gettime(&timeval);
90345 +
90346 + shp->shm_createtime = timeval.tv_sec;
90347 + }
90348 +#endif
90349 shp->shm_segsz = size;
90350 shp->shm_nattch = 0;
90351 shp->shm_file = file;
90352 @@ -1092,6 +1108,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
90353 f_mode = FMODE_READ | FMODE_WRITE;
90354 }
90355 if (shmflg & SHM_EXEC) {
90356 +
90357 +#ifdef CONFIG_PAX_MPROTECT
90358 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
90359 + goto out;
90360 +#endif
90361 +
90362 prot |= PROT_EXEC;
90363 acc_mode |= S_IXUGO;
90364 }
90365 @@ -1116,6 +1138,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
90366 if (err)
90367 goto out_unlock;
90368
90369 +#ifdef CONFIG_GRKERNSEC
90370 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
90371 + shp->shm_perm.cuid, shmid) ||
90372 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
90373 + err = -EACCES;
90374 + goto out_unlock;
90375 + }
90376 +#endif
90377 +
90378 ipc_lock_object(&shp->shm_perm);
90379
90380 /* check if shm_destroy() is tearing down shp */
90381 @@ -1128,6 +1159,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
90382 path = shp->shm_file->f_path;
90383 path_get(&path);
90384 shp->shm_nattch++;
90385 +#ifdef CONFIG_GRKERNSEC
90386 + shp->shm_lapid = current->pid;
90387 +#endif
90388 size = i_size_read(path.dentry->d_inode);
90389 ipc_unlock_object(&shp->shm_perm);
90390 rcu_read_unlock();
90391 diff --git a/ipc/util.c b/ipc/util.c
90392 index 27d74e6..8be0be2 100644
90393 --- a/ipc/util.c
90394 +++ b/ipc/util.c
90395 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
90396 int (*show)(struct seq_file *, void *);
90397 };
90398
90399 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
90400 +
90401 static void ipc_memory_notifier(struct work_struct *work)
90402 {
90403 ipcns_notify(IPCNS_MEMCHANGED);
90404 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
90405 granted_mode >>= 6;
90406 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
90407 granted_mode >>= 3;
90408 +
90409 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
90410 + return -1;
90411 +
90412 /* is there some bit set in requested_mode but not in granted_mode? */
90413 if ((requested_mode & ~granted_mode & 0007) &&
90414 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
90415 diff --git a/kernel/acct.c b/kernel/acct.c
90416 index 808a86f..da69695 100644
90417 --- a/kernel/acct.c
90418 +++ b/kernel/acct.c
90419 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
90420 */
90421 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
90422 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
90423 - file->f_op->write(file, (char *)&ac,
90424 + file->f_op->write(file, (char __force_user *)&ac,
90425 sizeof(acct_t), &file->f_pos);
90426 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
90427 set_fs(fs);
90428 diff --git a/kernel/audit.c b/kernel/audit.c
90429 index 3ef2e0e..8873765 100644
90430 --- a/kernel/audit.c
90431 +++ b/kernel/audit.c
90432 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
90433 3) suppressed due to audit_rate_limit
90434 4) suppressed due to audit_backlog_limit
90435 */
90436 -static atomic_t audit_lost = ATOMIC_INIT(0);
90437 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
90438
90439 /* The netlink socket. */
90440 static struct sock *audit_sock;
90441 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
90442 unsigned long now;
90443 int print;
90444
90445 - atomic_inc(&audit_lost);
90446 + atomic_inc_unchecked(&audit_lost);
90447
90448 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
90449
90450 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
90451 if (print) {
90452 if (printk_ratelimit())
90453 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
90454 - atomic_read(&audit_lost),
90455 + atomic_read_unchecked(&audit_lost),
90456 audit_rate_limit,
90457 audit_backlog_limit);
90458 audit_panic(message);
90459 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
90460 s.pid = audit_pid;
90461 s.rate_limit = audit_rate_limit;
90462 s.backlog_limit = audit_backlog_limit;
90463 - s.lost = atomic_read(&audit_lost);
90464 + s.lost = atomic_read_unchecked(&audit_lost);
90465 s.backlog = skb_queue_len(&audit_skb_queue);
90466 s.version = AUDIT_VERSION_LATEST;
90467 s.backlog_wait_time = audit_backlog_wait_time;
90468 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
90469 index 21eae3c..66db239 100644
90470 --- a/kernel/auditsc.c
90471 +++ b/kernel/auditsc.c
90472 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
90473 }
90474
90475 /* global counter which is incremented every time something logs in */
90476 -static atomic_t session_id = ATOMIC_INIT(0);
90477 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
90478
90479 static int audit_set_loginuid_perm(kuid_t loginuid)
90480 {
90481 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
90482
90483 /* are we setting or clearing? */
90484 if (uid_valid(loginuid))
90485 - sessionid = (unsigned int)atomic_inc_return(&session_id);
90486 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
90487
90488 task->sessionid = sessionid;
90489 task->loginuid = loginuid;
90490 diff --git a/kernel/capability.c b/kernel/capability.c
90491 index a5cf13c..07a2647 100644
90492 --- a/kernel/capability.c
90493 +++ b/kernel/capability.c
90494 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
90495 * before modification is attempted and the application
90496 * fails.
90497 */
90498 + if (tocopy > ARRAY_SIZE(kdata))
90499 + return -EFAULT;
90500 +
90501 if (copy_to_user(dataptr, kdata, tocopy
90502 * sizeof(struct __user_cap_data_struct))) {
90503 return -EFAULT;
90504 @@ -293,10 +296,11 @@ bool has_ns_capability(struct task_struct *t,
90505 int ret;
90506
90507 rcu_read_lock();
90508 - ret = security_capable(__task_cred(t), ns, cap);
90509 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
90510 + gr_task_is_capable(t, __task_cred(t), cap);
90511 rcu_read_unlock();
90512
90513 - return (ret == 0);
90514 + return ret;
90515 }
90516
90517 /**
90518 @@ -333,10 +337,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
90519 int ret;
90520
90521 rcu_read_lock();
90522 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
90523 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
90524 rcu_read_unlock();
90525
90526 - return (ret == 0);
90527 + return ret;
90528 }
90529
90530 /**
90531 @@ -374,7 +378,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
90532 BUG();
90533 }
90534
90535 - if (security_capable(current_cred(), ns, cap) == 0) {
90536 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
90537 current->flags |= PF_SUPERPRIV;
90538 return true;
90539 }
90540 @@ -382,6 +386,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
90541 }
90542 EXPORT_SYMBOL(ns_capable);
90543
90544 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
90545 +{
90546 + if (unlikely(!cap_valid(cap))) {
90547 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
90548 + BUG();
90549 + }
90550 +
90551 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
90552 + current->flags |= PF_SUPERPRIV;
90553 + return true;
90554 + }
90555 + return false;
90556 +}
90557 +EXPORT_SYMBOL(ns_capable_nolog);
90558 +
90559 /**
90560 * file_ns_capable - Determine if the file's opener had a capability in effect
90561 * @file: The file we want to check
90562 @@ -423,6 +442,12 @@ bool capable(int cap)
90563 }
90564 EXPORT_SYMBOL(capable);
90565
90566 +bool capable_nolog(int cap)
90567 +{
90568 + return ns_capable_nolog(&init_user_ns, cap);
90569 +}
90570 +EXPORT_SYMBOL(capable_nolog);
90571 +
90572 /**
90573 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
90574 * @inode: The inode in question
90575 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
90576 kgid_has_mapping(ns, inode->i_gid);
90577 }
90578 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
90579 +
90580 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
90581 +{
90582 + struct user_namespace *ns = current_user_ns();
90583 +
90584 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
90585 + kgid_has_mapping(ns, inode->i_gid);
90586 +}
90587 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
90588 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
90589 index 70776ae..09c4988 100644
90590 --- a/kernel/cgroup.c
90591 +++ b/kernel/cgroup.c
90592 @@ -5146,6 +5146,14 @@ static void cgroup_release_agent(struct work_struct *work)
90593 release_list);
90594 list_del_init(&cgrp->release_list);
90595 raw_spin_unlock(&release_list_lock);
90596 +
90597 + /*
90598 + * don't bother calling call_usermodehelper if we haven't
90599 + * configured a binary to execute
90600 + */
90601 + if (cgrp->root->release_agent_path[0] == '\0')
90602 + goto continue_free;
90603 +
90604 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
90605 if (!pathbuf)
90606 goto continue_free;
90607 @@ -5336,7 +5344,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
90608 struct task_struct *task;
90609 int count = 0;
90610
90611 - seq_printf(seq, "css_set %p\n", cset);
90612 + seq_printf(seq, "css_set %pK\n", cset);
90613
90614 list_for_each_entry(task, &cset->tasks, cg_list) {
90615 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
90616 diff --git a/kernel/compat.c b/kernel/compat.c
90617 index 633394f..bdfa969 100644
90618 --- a/kernel/compat.c
90619 +++ b/kernel/compat.c
90620 @@ -13,6 +13,7 @@
90621
90622 #include <linux/linkage.h>
90623 #include <linux/compat.h>
90624 +#include <linux/module.h>
90625 #include <linux/errno.h>
90626 #include <linux/time.h>
90627 #include <linux/signal.h>
90628 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
90629 mm_segment_t oldfs;
90630 long ret;
90631
90632 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
90633 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
90634 oldfs = get_fs();
90635 set_fs(KERNEL_DS);
90636 ret = hrtimer_nanosleep_restart(restart);
90637 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
90638 oldfs = get_fs();
90639 set_fs(KERNEL_DS);
90640 ret = hrtimer_nanosleep(&tu,
90641 - rmtp ? (struct timespec __user *)&rmt : NULL,
90642 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
90643 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
90644 set_fs(oldfs);
90645
90646 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
90647 mm_segment_t old_fs = get_fs();
90648
90649 set_fs(KERNEL_DS);
90650 - ret = sys_sigpending((old_sigset_t __user *) &s);
90651 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
90652 set_fs(old_fs);
90653 if (ret == 0)
90654 ret = put_user(s, set);
90655 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
90656 mm_segment_t old_fs = get_fs();
90657
90658 set_fs(KERNEL_DS);
90659 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
90660 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
90661 set_fs(old_fs);
90662
90663 if (!ret) {
90664 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
90665 set_fs (KERNEL_DS);
90666 ret = sys_wait4(pid,
90667 (stat_addr ?
90668 - (unsigned int __user *) &status : NULL),
90669 - options, (struct rusage __user *) &r);
90670 + (unsigned int __force_user *) &status : NULL),
90671 + options, (struct rusage __force_user *) &r);
90672 set_fs (old_fs);
90673
90674 if (ret > 0) {
90675 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
90676 memset(&info, 0, sizeof(info));
90677
90678 set_fs(KERNEL_DS);
90679 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
90680 - uru ? (struct rusage __user *)&ru : NULL);
90681 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
90682 + uru ? (struct rusage __force_user *)&ru : NULL);
90683 set_fs(old_fs);
90684
90685 if ((ret < 0) || (info.si_signo == 0))
90686 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
90687 oldfs = get_fs();
90688 set_fs(KERNEL_DS);
90689 err = sys_timer_settime(timer_id, flags,
90690 - (struct itimerspec __user *) &newts,
90691 - (struct itimerspec __user *) &oldts);
90692 + (struct itimerspec __force_user *) &newts,
90693 + (struct itimerspec __force_user *) &oldts);
90694 set_fs(oldfs);
90695 if (!err && old && put_compat_itimerspec(old, &oldts))
90696 return -EFAULT;
90697 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
90698 oldfs = get_fs();
90699 set_fs(KERNEL_DS);
90700 err = sys_timer_gettime(timer_id,
90701 - (struct itimerspec __user *) &ts);
90702 + (struct itimerspec __force_user *) &ts);
90703 set_fs(oldfs);
90704 if (!err && put_compat_itimerspec(setting, &ts))
90705 return -EFAULT;
90706 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
90707 oldfs = get_fs();
90708 set_fs(KERNEL_DS);
90709 err = sys_clock_settime(which_clock,
90710 - (struct timespec __user *) &ts);
90711 + (struct timespec __force_user *) &ts);
90712 set_fs(oldfs);
90713 return err;
90714 }
90715 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
90716 oldfs = get_fs();
90717 set_fs(KERNEL_DS);
90718 err = sys_clock_gettime(which_clock,
90719 - (struct timespec __user *) &ts);
90720 + (struct timespec __force_user *) &ts);
90721 set_fs(oldfs);
90722 if (!err && compat_put_timespec(&ts, tp))
90723 return -EFAULT;
90724 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
90725
90726 oldfs = get_fs();
90727 set_fs(KERNEL_DS);
90728 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
90729 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
90730 set_fs(oldfs);
90731
90732 err = compat_put_timex(utp, &txc);
90733 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
90734 oldfs = get_fs();
90735 set_fs(KERNEL_DS);
90736 err = sys_clock_getres(which_clock,
90737 - (struct timespec __user *) &ts);
90738 + (struct timespec __force_user *) &ts);
90739 set_fs(oldfs);
90740 if (!err && tp && compat_put_timespec(&ts, tp))
90741 return -EFAULT;
90742 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
90743 struct timespec tu;
90744 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
90745
90746 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
90747 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
90748 oldfs = get_fs();
90749 set_fs(KERNEL_DS);
90750 err = clock_nanosleep_restart(restart);
90751 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
90752 oldfs = get_fs();
90753 set_fs(KERNEL_DS);
90754 err = sys_clock_nanosleep(which_clock, flags,
90755 - (struct timespec __user *) &in,
90756 - (struct timespec __user *) &out);
90757 + (struct timespec __force_user *) &in,
90758 + (struct timespec __force_user *) &out);
90759 set_fs(oldfs);
90760
90761 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
90762 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
90763 mm_segment_t old_fs = get_fs();
90764
90765 set_fs(KERNEL_DS);
90766 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
90767 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
90768 set_fs(old_fs);
90769 if (compat_put_timespec(&t, interval))
90770 return -EFAULT;
90771 diff --git a/kernel/configs.c b/kernel/configs.c
90772 index c18b1f1..b9a0132 100644
90773 --- a/kernel/configs.c
90774 +++ b/kernel/configs.c
90775 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
90776 struct proc_dir_entry *entry;
90777
90778 /* create the current config file */
90779 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
90780 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
90781 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
90782 + &ikconfig_file_ops);
90783 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90784 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
90785 + &ikconfig_file_ops);
90786 +#endif
90787 +#else
90788 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
90789 &ikconfig_file_ops);
90790 +#endif
90791 +
90792 if (!entry)
90793 return -ENOMEM;
90794
90795 diff --git a/kernel/cred.c b/kernel/cred.c
90796 index e0573a4..26c0fd3 100644
90797 --- a/kernel/cred.c
90798 +++ b/kernel/cred.c
90799 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
90800 validate_creds(cred);
90801 alter_cred_subscribers(cred, -1);
90802 put_cred(cred);
90803 +
90804 +#ifdef CONFIG_GRKERNSEC_SETXID
90805 + cred = (struct cred *) tsk->delayed_cred;
90806 + if (cred != NULL) {
90807 + tsk->delayed_cred = NULL;
90808 + validate_creds(cred);
90809 + alter_cred_subscribers(cred, -1);
90810 + put_cred(cred);
90811 + }
90812 +#endif
90813 }
90814
90815 /**
90816 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
90817 * Always returns 0 thus allowing this function to be tail-called at the end
90818 * of, say, sys_setgid().
90819 */
90820 -int commit_creds(struct cred *new)
90821 +static int __commit_creds(struct cred *new)
90822 {
90823 struct task_struct *task = current;
90824 const struct cred *old = task->real_cred;
90825 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
90826
90827 get_cred(new); /* we will require a ref for the subj creds too */
90828
90829 + gr_set_role_label(task, new->uid, new->gid);
90830 +
90831 /* dumpability changes */
90832 if (!uid_eq(old->euid, new->euid) ||
90833 !gid_eq(old->egid, new->egid) ||
90834 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
90835 put_cred(old);
90836 return 0;
90837 }
90838 +#ifdef CONFIG_GRKERNSEC_SETXID
90839 +extern int set_user(struct cred *new);
90840 +
90841 +void gr_delayed_cred_worker(void)
90842 +{
90843 + const struct cred *new = current->delayed_cred;
90844 + struct cred *ncred;
90845 +
90846 + current->delayed_cred = NULL;
90847 +
90848 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
90849 + // from doing get_cred on it when queueing this
90850 + put_cred(new);
90851 + return;
90852 + } else if (new == NULL)
90853 + return;
90854 +
90855 + ncred = prepare_creds();
90856 + if (!ncred)
90857 + goto die;
90858 + // uids
90859 + ncred->uid = new->uid;
90860 + ncred->euid = new->euid;
90861 + ncred->suid = new->suid;
90862 + ncred->fsuid = new->fsuid;
90863 + // gids
90864 + ncred->gid = new->gid;
90865 + ncred->egid = new->egid;
90866 + ncred->sgid = new->sgid;
90867 + ncred->fsgid = new->fsgid;
90868 + // groups
90869 + set_groups(ncred, new->group_info);
90870 + // caps
90871 + ncred->securebits = new->securebits;
90872 + ncred->cap_inheritable = new->cap_inheritable;
90873 + ncred->cap_permitted = new->cap_permitted;
90874 + ncred->cap_effective = new->cap_effective;
90875 + ncred->cap_bset = new->cap_bset;
90876 +
90877 + if (set_user(ncred)) {
90878 + abort_creds(ncred);
90879 + goto die;
90880 + }
90881 +
90882 + // from doing get_cred on it when queueing this
90883 + put_cred(new);
90884 +
90885 + __commit_creds(ncred);
90886 + return;
90887 +die:
90888 + // from doing get_cred on it when queueing this
90889 + put_cred(new);
90890 + do_group_exit(SIGKILL);
90891 +}
90892 +#endif
90893 +
90894 +int commit_creds(struct cred *new)
90895 +{
90896 +#ifdef CONFIG_GRKERNSEC_SETXID
90897 + int ret;
90898 + int schedule_it = 0;
90899 + struct task_struct *t;
90900 + unsigned oldsecurebits = current_cred()->securebits;
90901 +
90902 + /* we won't get called with tasklist_lock held for writing
90903 + and interrupts disabled as the cred struct in that case is
90904 + init_cred
90905 + */
90906 + if (grsec_enable_setxid && !current_is_single_threaded() &&
90907 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
90908 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
90909 + schedule_it = 1;
90910 + }
90911 + ret = __commit_creds(new);
90912 + if (schedule_it) {
90913 + rcu_read_lock();
90914 + read_lock(&tasklist_lock);
90915 + for (t = next_thread(current); t != current;
90916 + t = next_thread(t)) {
90917 + /* we'll check if the thread has uid 0 in
90918 + * the delayed worker routine
90919 + */
90920 + if (task_securebits(t) == oldsecurebits &&
90921 + t->delayed_cred == NULL) {
90922 + t->delayed_cred = get_cred(new);
90923 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
90924 + set_tsk_need_resched(t);
90925 + }
90926 + }
90927 + read_unlock(&tasklist_lock);
90928 + rcu_read_unlock();
90929 + }
90930 +
90931 + return ret;
90932 +#else
90933 + return __commit_creds(new);
90934 +#endif
90935 +}
90936 +
90937 EXPORT_SYMBOL(commit_creds);
90938
90939 /**
90940 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
90941 index 1adf62b..7736e06 100644
90942 --- a/kernel/debug/debug_core.c
90943 +++ b/kernel/debug/debug_core.c
90944 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
90945 */
90946 static atomic_t masters_in_kgdb;
90947 static atomic_t slaves_in_kgdb;
90948 -static atomic_t kgdb_break_tasklet_var;
90949 +static atomic_unchecked_t kgdb_break_tasklet_var;
90950 atomic_t kgdb_setting_breakpoint;
90951
90952 struct task_struct *kgdb_usethread;
90953 @@ -134,7 +134,7 @@ int kgdb_single_step;
90954 static pid_t kgdb_sstep_pid;
90955
90956 /* to keep track of the CPU which is doing the single stepping*/
90957 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
90958 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
90959
90960 /*
90961 * If you are debugging a problem where roundup (the collection of
90962 @@ -549,7 +549,7 @@ return_normal:
90963 * kernel will only try for the value of sstep_tries before
90964 * giving up and continuing on.
90965 */
90966 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
90967 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
90968 (kgdb_info[cpu].task &&
90969 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
90970 atomic_set(&kgdb_active, -1);
90971 @@ -647,8 +647,8 @@ cpu_master_loop:
90972 }
90973
90974 kgdb_restore:
90975 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
90976 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
90977 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
90978 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
90979 if (kgdb_info[sstep_cpu].task)
90980 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
90981 else
90982 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
90983 static void kgdb_tasklet_bpt(unsigned long ing)
90984 {
90985 kgdb_breakpoint();
90986 - atomic_set(&kgdb_break_tasklet_var, 0);
90987 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
90988 }
90989
90990 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
90991
90992 void kgdb_schedule_breakpoint(void)
90993 {
90994 - if (atomic_read(&kgdb_break_tasklet_var) ||
90995 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
90996 atomic_read(&kgdb_active) != -1 ||
90997 atomic_read(&kgdb_setting_breakpoint))
90998 return;
90999 - atomic_inc(&kgdb_break_tasklet_var);
91000 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
91001 tasklet_schedule(&kgdb_tasklet_breakpoint);
91002 }
91003 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
91004 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
91005 index 2f7c760..95b6a66 100644
91006 --- a/kernel/debug/kdb/kdb_main.c
91007 +++ b/kernel/debug/kdb/kdb_main.c
91008 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
91009 continue;
91010
91011 kdb_printf("%-20s%8u 0x%p ", mod->name,
91012 - mod->core_size, (void *)mod);
91013 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
91014 #ifdef CONFIG_MODULE_UNLOAD
91015 kdb_printf("%4ld ", module_refcount(mod));
91016 #endif
91017 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
91018 kdb_printf(" (Loading)");
91019 else
91020 kdb_printf(" (Live)");
91021 - kdb_printf(" 0x%p", mod->module_core);
91022 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
91023
91024 #ifdef CONFIG_MODULE_UNLOAD
91025 {
91026 diff --git a/kernel/events/core.c b/kernel/events/core.c
91027 index 6b17ac1..00fd505 100644
91028 --- a/kernel/events/core.c
91029 +++ b/kernel/events/core.c
91030 @@ -160,8 +160,15 @@ static struct srcu_struct pmus_srcu;
91031 * 0 - disallow raw tracepoint access for unpriv
91032 * 1 - disallow cpu events for unpriv
91033 * 2 - disallow kernel profiling for unpriv
91034 + * 3 - disallow all unpriv perf event use
91035 */
91036 -int sysctl_perf_event_paranoid __read_mostly = 1;
91037 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
91038 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
91039 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
91040 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
91041 +#else
91042 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
91043 +#endif
91044
91045 /* Minimum for 512 kiB + 1 user control page */
91046 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
91047 @@ -187,7 +194,7 @@ void update_perf_cpu_limits(void)
91048
91049 tmp *= sysctl_perf_cpu_time_max_percent;
91050 do_div(tmp, 100);
91051 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
91052 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
91053 }
91054
91055 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
91056 @@ -293,7 +300,7 @@ void perf_sample_event_took(u64 sample_len_ns)
91057 }
91058 }
91059
91060 -static atomic64_t perf_event_id;
91061 +static atomic64_unchecked_t perf_event_id;
91062
91063 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
91064 enum event_type_t event_type);
91065 @@ -3023,7 +3030,7 @@ static void __perf_event_read(void *info)
91066
91067 static inline u64 perf_event_count(struct perf_event *event)
91068 {
91069 - return local64_read(&event->count) + atomic64_read(&event->child_count);
91070 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
91071 }
91072
91073 static u64 perf_event_read(struct perf_event *event)
91074 @@ -3399,9 +3406,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
91075 mutex_lock(&event->child_mutex);
91076 total += perf_event_read(event);
91077 *enabled += event->total_time_enabled +
91078 - atomic64_read(&event->child_total_time_enabled);
91079 + atomic64_read_unchecked(&event->child_total_time_enabled);
91080 *running += event->total_time_running +
91081 - atomic64_read(&event->child_total_time_running);
91082 + atomic64_read_unchecked(&event->child_total_time_running);
91083
91084 list_for_each_entry(child, &event->child_list, child_list) {
91085 total += perf_event_read(child);
91086 @@ -3830,10 +3837,10 @@ void perf_event_update_userpage(struct perf_event *event)
91087 userpg->offset -= local64_read(&event->hw.prev_count);
91088
91089 userpg->time_enabled = enabled +
91090 - atomic64_read(&event->child_total_time_enabled);
91091 + atomic64_read_unchecked(&event->child_total_time_enabled);
91092
91093 userpg->time_running = running +
91094 - atomic64_read(&event->child_total_time_running);
91095 + atomic64_read_unchecked(&event->child_total_time_running);
91096
91097 arch_perf_update_userpage(userpg, now);
91098
91099 @@ -4397,7 +4404,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
91100
91101 /* Data. */
91102 sp = perf_user_stack_pointer(regs);
91103 - rem = __output_copy_user(handle, (void *) sp, dump_size);
91104 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
91105 dyn_size = dump_size - rem;
91106
91107 perf_output_skip(handle, rem);
91108 @@ -4488,11 +4495,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
91109 values[n++] = perf_event_count(event);
91110 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
91111 values[n++] = enabled +
91112 - atomic64_read(&event->child_total_time_enabled);
91113 + atomic64_read_unchecked(&event->child_total_time_enabled);
91114 }
91115 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
91116 values[n++] = running +
91117 - atomic64_read(&event->child_total_time_running);
91118 + atomic64_read_unchecked(&event->child_total_time_running);
91119 }
91120 if (read_format & PERF_FORMAT_ID)
91121 values[n++] = primary_event_id(event);
91122 @@ -6801,7 +6808,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
91123 event->parent = parent_event;
91124
91125 event->ns = get_pid_ns(task_active_pid_ns(current));
91126 - event->id = atomic64_inc_return(&perf_event_id);
91127 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
91128
91129 event->state = PERF_EVENT_STATE_INACTIVE;
91130
91131 @@ -7080,6 +7087,11 @@ SYSCALL_DEFINE5(perf_event_open,
91132 if (flags & ~PERF_FLAG_ALL)
91133 return -EINVAL;
91134
91135 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
91136 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
91137 + return -EACCES;
91138 +#endif
91139 +
91140 err = perf_copy_attr(attr_uptr, &attr);
91141 if (err)
91142 return err;
91143 @@ -7432,10 +7444,10 @@ static void sync_child_event(struct perf_event *child_event,
91144 /*
91145 * Add back the child's count to the parent's count:
91146 */
91147 - atomic64_add(child_val, &parent_event->child_count);
91148 - atomic64_add(child_event->total_time_enabled,
91149 + atomic64_add_unchecked(child_val, &parent_event->child_count);
91150 + atomic64_add_unchecked(child_event->total_time_enabled,
91151 &parent_event->child_total_time_enabled);
91152 - atomic64_add(child_event->total_time_running,
91153 + atomic64_add_unchecked(child_event->total_time_running,
91154 &parent_event->child_total_time_running);
91155
91156 /*
91157 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
91158 index 569b2187..19940d9 100644
91159 --- a/kernel/events/internal.h
91160 +++ b/kernel/events/internal.h
91161 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
91162 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
91163 }
91164
91165 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
91166 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
91167 static inline unsigned long \
91168 func_name(struct perf_output_handle *handle, \
91169 - const void *buf, unsigned long len) \
91170 + const void user *buf, unsigned long len) \
91171 { \
91172 unsigned long size, written; \
91173 \
91174 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
91175 return 0;
91176 }
91177
91178 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
91179 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
91180
91181 static inline unsigned long
91182 memcpy_skip(void *dst, const void *src, unsigned long n)
91183 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
91184 return 0;
91185 }
91186
91187 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
91188 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
91189
91190 #ifndef arch_perf_out_copy_user
91191 #define arch_perf_out_copy_user arch_perf_out_copy_user
91192 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
91193 }
91194 #endif
91195
91196 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
91197 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
91198
91199 /* Callchain handling */
91200 extern struct perf_callchain_entry *
91201 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
91202 index 6f3254e..e4c1fe4 100644
91203 --- a/kernel/events/uprobes.c
91204 +++ b/kernel/events/uprobes.c
91205 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
91206 {
91207 struct page *page;
91208 uprobe_opcode_t opcode;
91209 - int result;
91210 + long result;
91211
91212 pagefault_disable();
91213 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
91214 diff --git a/kernel/exit.c b/kernel/exit.c
91215 index e5c4668..592d2e5 100644
91216 --- a/kernel/exit.c
91217 +++ b/kernel/exit.c
91218 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
91219 struct task_struct *leader;
91220 int zap_leader;
91221 repeat:
91222 +#ifdef CONFIG_NET
91223 + gr_del_task_from_ip_table(p);
91224 +#endif
91225 +
91226 /* don't need to get the RCU readlock here - the process is dead and
91227 * can't be modifying its own credentials. But shut RCU-lockdep up */
91228 rcu_read_lock();
91229 @@ -664,6 +668,8 @@ void do_exit(long code)
91230 struct task_struct *tsk = current;
91231 int group_dead;
91232
91233 + set_fs(USER_DS);
91234 +
91235 profile_task_exit(tsk);
91236
91237 WARN_ON(blk_needs_flush_plug(tsk));
91238 @@ -680,7 +686,6 @@ void do_exit(long code)
91239 * mm_release()->clear_child_tid() from writing to a user-controlled
91240 * kernel address.
91241 */
91242 - set_fs(USER_DS);
91243
91244 ptrace_event(PTRACE_EVENT_EXIT, code);
91245
91246 @@ -739,6 +744,9 @@ void do_exit(long code)
91247 tsk->exit_code = code;
91248 taskstats_exit(tsk, group_dead);
91249
91250 + gr_acl_handle_psacct(tsk, code);
91251 + gr_acl_handle_exit();
91252 +
91253 exit_mm(tsk);
91254
91255 if (group_dead)
91256 @@ -858,7 +866,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
91257 * Take down every thread in the group. This is called by fatal signals
91258 * as well as by sys_exit_group (below).
91259 */
91260 -void
91261 +__noreturn void
91262 do_group_exit(int exit_code)
91263 {
91264 struct signal_struct *sig = current->signal;
91265 diff --git a/kernel/fork.c b/kernel/fork.c
91266 index 6a13c46..a623c8e 100644
91267 --- a/kernel/fork.c
91268 +++ b/kernel/fork.c
91269 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
91270 # endif
91271 #endif
91272
91273 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
91274 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
91275 + int node, void **lowmem_stack)
91276 +{
91277 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
91278 + void *ret = NULL;
91279 + unsigned int i;
91280 +
91281 + *lowmem_stack = alloc_thread_info_node(tsk, node);
91282 + if (*lowmem_stack == NULL)
91283 + goto out;
91284 +
91285 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
91286 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
91287 +
91288 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
91289 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
91290 + if (ret == NULL) {
91291 + free_thread_info(*lowmem_stack);
91292 + *lowmem_stack = NULL;
91293 + }
91294 +
91295 +out:
91296 + return ret;
91297 +}
91298 +
91299 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
91300 +{
91301 + unmap_process_stacks(tsk);
91302 +}
91303 +#else
91304 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
91305 + int node, void **lowmem_stack)
91306 +{
91307 + return alloc_thread_info_node(tsk, node);
91308 +}
91309 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
91310 +{
91311 + free_thread_info(ti);
91312 +}
91313 +#endif
91314 +
91315 /* SLAB cache for signal_struct structures (tsk->signal) */
91316 static struct kmem_cache *signal_cachep;
91317
91318 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
91319 /* SLAB cache for mm_struct structures (tsk->mm) */
91320 static struct kmem_cache *mm_cachep;
91321
91322 -static void account_kernel_stack(struct thread_info *ti, int account)
91323 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
91324 {
91325 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
91326 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
91327 +#else
91328 struct zone *zone = page_zone(virt_to_page(ti));
91329 +#endif
91330
91331 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
91332 }
91333
91334 void free_task(struct task_struct *tsk)
91335 {
91336 - account_kernel_stack(tsk->stack, -1);
91337 + account_kernel_stack(tsk, tsk->stack, -1);
91338 arch_release_thread_info(tsk->stack);
91339 - free_thread_info(tsk->stack);
91340 + gr_free_thread_info(tsk, tsk->stack);
91341 rt_mutex_debug_task_free(tsk);
91342 ftrace_graph_exit_task(tsk);
91343 put_seccomp_filter(tsk);
91344 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
91345 struct task_struct *tsk;
91346 struct thread_info *ti;
91347 unsigned long *stackend;
91348 + void *lowmem_stack;
91349 int node = tsk_fork_get_node(orig);
91350 int err;
91351
91352 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
91353 if (!tsk)
91354 return NULL;
91355
91356 - ti = alloc_thread_info_node(tsk, node);
91357 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
91358 if (!ti)
91359 goto free_tsk;
91360
91361 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
91362 goto free_ti;
91363
91364 tsk->stack = ti;
91365 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
91366 + tsk->lowmem_stack = lowmem_stack;
91367 +#endif
91368
91369 setup_thread_stack(tsk, orig);
91370 clear_user_return_notifier(tsk);
91371 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
91372 *stackend = STACK_END_MAGIC; /* for overflow detection */
91373
91374 #ifdef CONFIG_CC_STACKPROTECTOR
91375 - tsk->stack_canary = get_random_int();
91376 + tsk->stack_canary = pax_get_random_long();
91377 #endif
91378
91379 /*
91380 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
91381 tsk->splice_pipe = NULL;
91382 tsk->task_frag.page = NULL;
91383
91384 - account_kernel_stack(ti, 1);
91385 + account_kernel_stack(tsk, ti, 1);
91386
91387 return tsk;
91388
91389 free_ti:
91390 - free_thread_info(ti);
91391 + gr_free_thread_info(tsk, ti);
91392 free_tsk:
91393 free_task_struct(tsk);
91394 return NULL;
91395 }
91396
91397 #ifdef CONFIG_MMU
91398 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
91399 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
91400 +{
91401 + struct vm_area_struct *tmp;
91402 + unsigned long charge;
91403 + struct file *file;
91404 + int retval;
91405 +
91406 + charge = 0;
91407 + if (mpnt->vm_flags & VM_ACCOUNT) {
91408 + unsigned long len = vma_pages(mpnt);
91409 +
91410 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
91411 + goto fail_nomem;
91412 + charge = len;
91413 + }
91414 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
91415 + if (!tmp)
91416 + goto fail_nomem;
91417 + *tmp = *mpnt;
91418 + tmp->vm_mm = mm;
91419 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
91420 + retval = vma_dup_policy(mpnt, tmp);
91421 + if (retval)
91422 + goto fail_nomem_policy;
91423 + if (anon_vma_fork(tmp, mpnt))
91424 + goto fail_nomem_anon_vma_fork;
91425 + tmp->vm_flags &= ~VM_LOCKED;
91426 + tmp->vm_next = tmp->vm_prev = NULL;
91427 + tmp->vm_mirror = NULL;
91428 + file = tmp->vm_file;
91429 + if (file) {
91430 + struct inode *inode = file_inode(file);
91431 + struct address_space *mapping = file->f_mapping;
91432 +
91433 + get_file(file);
91434 + if (tmp->vm_flags & VM_DENYWRITE)
91435 + atomic_dec(&inode->i_writecount);
91436 + mutex_lock(&mapping->i_mmap_mutex);
91437 + if (tmp->vm_flags & VM_SHARED)
91438 + mapping->i_mmap_writable++;
91439 + flush_dcache_mmap_lock(mapping);
91440 + /* insert tmp into the share list, just after mpnt */
91441 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
91442 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
91443 + else
91444 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
91445 + flush_dcache_mmap_unlock(mapping);
91446 + mutex_unlock(&mapping->i_mmap_mutex);
91447 + }
91448 +
91449 + /*
91450 + * Clear hugetlb-related page reserves for children. This only
91451 + * affects MAP_PRIVATE mappings. Faults generated by the child
91452 + * are not guaranteed to succeed, even if read-only
91453 + */
91454 + if (is_vm_hugetlb_page(tmp))
91455 + reset_vma_resv_huge_pages(tmp);
91456 +
91457 + return tmp;
91458 +
91459 +fail_nomem_anon_vma_fork:
91460 + mpol_put(vma_policy(tmp));
91461 +fail_nomem_policy:
91462 + kmem_cache_free(vm_area_cachep, tmp);
91463 +fail_nomem:
91464 + vm_unacct_memory(charge);
91465 + return NULL;
91466 +}
91467 +
91468 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
91469 {
91470 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
91471 struct rb_node **rb_link, *rb_parent;
91472 int retval;
91473 - unsigned long charge;
91474
91475 uprobe_start_dup_mmap();
91476 down_write(&oldmm->mmap_sem);
91477 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
91478
91479 prev = NULL;
91480 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
91481 - struct file *file;
91482 -
91483 if (mpnt->vm_flags & VM_DONTCOPY) {
91484 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
91485 -vma_pages(mpnt));
91486 continue;
91487 }
91488 - charge = 0;
91489 - if (mpnt->vm_flags & VM_ACCOUNT) {
91490 - unsigned long len = vma_pages(mpnt);
91491 -
91492 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
91493 - goto fail_nomem;
91494 - charge = len;
91495 - }
91496 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
91497 - if (!tmp)
91498 - goto fail_nomem;
91499 - *tmp = *mpnt;
91500 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
91501 - retval = vma_dup_policy(mpnt, tmp);
91502 - if (retval)
91503 - goto fail_nomem_policy;
91504 - tmp->vm_mm = mm;
91505 - if (anon_vma_fork(tmp, mpnt))
91506 - goto fail_nomem_anon_vma_fork;
91507 - tmp->vm_flags &= ~VM_LOCKED;
91508 - tmp->vm_next = tmp->vm_prev = NULL;
91509 - file = tmp->vm_file;
91510 - if (file) {
91511 - struct inode *inode = file_inode(file);
91512 - struct address_space *mapping = file->f_mapping;
91513 -
91514 - get_file(file);
91515 - if (tmp->vm_flags & VM_DENYWRITE)
91516 - atomic_dec(&inode->i_writecount);
91517 - mutex_lock(&mapping->i_mmap_mutex);
91518 - if (tmp->vm_flags & VM_SHARED)
91519 - mapping->i_mmap_writable++;
91520 - flush_dcache_mmap_lock(mapping);
91521 - /* insert tmp into the share list, just after mpnt */
91522 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
91523 - vma_nonlinear_insert(tmp,
91524 - &mapping->i_mmap_nonlinear);
91525 - else
91526 - vma_interval_tree_insert_after(tmp, mpnt,
91527 - &mapping->i_mmap);
91528 - flush_dcache_mmap_unlock(mapping);
91529 - mutex_unlock(&mapping->i_mmap_mutex);
91530 + tmp = dup_vma(mm, oldmm, mpnt);
91531 + if (!tmp) {
91532 + retval = -ENOMEM;
91533 + goto out;
91534 }
91535
91536 /*
91537 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
91538 if (retval)
91539 goto out;
91540 }
91541 +
91542 +#ifdef CONFIG_PAX_SEGMEXEC
91543 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
91544 + struct vm_area_struct *mpnt_m;
91545 +
91546 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
91547 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
91548 +
91549 + if (!mpnt->vm_mirror)
91550 + continue;
91551 +
91552 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
91553 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
91554 + mpnt->vm_mirror = mpnt_m;
91555 + } else {
91556 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
91557 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
91558 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
91559 + mpnt->vm_mirror->vm_mirror = mpnt;
91560 + }
91561 + }
91562 + BUG_ON(mpnt_m);
91563 + }
91564 +#endif
91565 +
91566 /* a new mm has just been created */
91567 arch_dup_mmap(oldmm, mm);
91568 retval = 0;
91569 @@ -472,14 +575,6 @@ out:
91570 up_write(&oldmm->mmap_sem);
91571 uprobe_end_dup_mmap();
91572 return retval;
91573 -fail_nomem_anon_vma_fork:
91574 - mpol_put(vma_policy(tmp));
91575 -fail_nomem_policy:
91576 - kmem_cache_free(vm_area_cachep, tmp);
91577 -fail_nomem:
91578 - retval = -ENOMEM;
91579 - vm_unacct_memory(charge);
91580 - goto out;
91581 }
91582
91583 static inline int mm_alloc_pgd(struct mm_struct *mm)
91584 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
91585 return ERR_PTR(err);
91586
91587 mm = get_task_mm(task);
91588 - if (mm && mm != current->mm &&
91589 - !ptrace_may_access(task, mode)) {
91590 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
91591 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
91592 mmput(mm);
91593 mm = ERR_PTR(-EACCES);
91594 }
91595 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
91596 spin_unlock(&fs->lock);
91597 return -EAGAIN;
91598 }
91599 - fs->users++;
91600 + atomic_inc(&fs->users);
91601 spin_unlock(&fs->lock);
91602 return 0;
91603 }
91604 tsk->fs = copy_fs_struct(fs);
91605 if (!tsk->fs)
91606 return -ENOMEM;
91607 + /* Carry through gr_chroot_dentry and is_chrooted instead
91608 + of recomputing it here. Already copied when the task struct
91609 + is duplicated. This allows pivot_root to not be treated as
91610 + a chroot
91611 + */
91612 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
91613 +
91614 return 0;
91615 }
91616
91617 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
91618 * parts of the process environment (as per the clone
91619 * flags). The actual kick-off is left to the caller.
91620 */
91621 -static struct task_struct *copy_process(unsigned long clone_flags,
91622 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
91623 unsigned long stack_start,
91624 unsigned long stack_size,
91625 int __user *child_tidptr,
91626 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
91627 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
91628 #endif
91629 retval = -EAGAIN;
91630 +
91631 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
91632 +
91633 if (atomic_read(&p->real_cred->user->processes) >=
91634 task_rlimit(p, RLIMIT_NPROC)) {
91635 if (p->real_cred->user != INIT_USER &&
91636 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
91637 goto bad_fork_free_pid;
91638 }
91639
91640 + /* synchronizes with gr_set_acls()
91641 + we need to call this past the point of no return for fork()
91642 + */
91643 + gr_copy_label(p);
91644 +
91645 if (likely(p->pid)) {
91646 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
91647
91648 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
91649 bad_fork_free:
91650 free_task(p);
91651 fork_out:
91652 + gr_log_forkfail(retval);
91653 +
91654 return ERR_PTR(retval);
91655 }
91656
91657 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
91658
91659 p = copy_process(clone_flags, stack_start, stack_size,
91660 child_tidptr, NULL, trace);
91661 + add_latent_entropy();
91662 /*
91663 * Do this prior waking up the new thread - the thread pointer
91664 * might get invalid after that point, if the thread exits quickly.
91665 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
91666 if (clone_flags & CLONE_PARENT_SETTID)
91667 put_user(nr, parent_tidptr);
91668
91669 + gr_handle_brute_check();
91670 +
91671 if (clone_flags & CLONE_VFORK) {
91672 p->vfork_done = &vfork;
91673 init_completion(&vfork);
91674 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
91675 mm_cachep = kmem_cache_create("mm_struct",
91676 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
91677 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
91678 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
91679 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
91680 mmap_init();
91681 nsproxy_cache_init();
91682 }
91683 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
91684 return 0;
91685
91686 /* don't need lock here; in the worst case we'll do useless copy */
91687 - if (fs->users == 1)
91688 + if (atomic_read(&fs->users) == 1)
91689 return 0;
91690
91691 *new_fsp = copy_fs_struct(fs);
91692 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
91693 fs = current->fs;
91694 spin_lock(&fs->lock);
91695 current->fs = new_fs;
91696 - if (--fs->users)
91697 + gr_set_chroot_entries(current, &current->fs->root);
91698 + if (atomic_dec_return(&fs->users))
91699 new_fs = NULL;
91700 else
91701 new_fs = fs;
91702 diff --git a/kernel/futex.c b/kernel/futex.c
91703 index b632b5f..0aa434d 100644
91704 --- a/kernel/futex.c
91705 +++ b/kernel/futex.c
91706 @@ -202,7 +202,7 @@ struct futex_pi_state {
91707 atomic_t refcount;
91708
91709 union futex_key key;
91710 -};
91711 +} __randomize_layout;
91712
91713 /**
91714 * struct futex_q - The hashed futex queue entry, one per waiting task
91715 @@ -236,7 +236,7 @@ struct futex_q {
91716 struct rt_mutex_waiter *rt_waiter;
91717 union futex_key *requeue_pi_key;
91718 u32 bitset;
91719 -};
91720 +} __randomize_layout;
91721
91722 static const struct futex_q futex_q_init = {
91723 /* list gets initialized in queue_me()*/
91724 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
91725 struct page *page, *page_head;
91726 int err, ro = 0;
91727
91728 +#ifdef CONFIG_PAX_SEGMEXEC
91729 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
91730 + return -EFAULT;
91731 +#endif
91732 +
91733 /*
91734 * The futex address must be "naturally" aligned.
91735 */
91736 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
91737
91738 static int get_futex_value_locked(u32 *dest, u32 __user *from)
91739 {
91740 - int ret;
91741 + unsigned long ret;
91742
91743 pagefault_disable();
91744 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
91745 @@ -2628,6 +2633,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
91746 * shared futexes. We need to compare the keys:
91747 */
91748 if (match_futex(&q.key, &key2)) {
91749 + queue_unlock(hb);
91750 ret = -EINVAL;
91751 goto out_put_keys;
91752 }
91753 @@ -3033,6 +3039,7 @@ static void __init futex_detect_cmpxchg(void)
91754 {
91755 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
91756 u32 curval;
91757 + mm_segment_t oldfs;
91758
91759 /*
91760 * This will fail and we want it. Some arch implementations do
91761 @@ -3044,8 +3051,11 @@ static void __init futex_detect_cmpxchg(void)
91762 * implementation, the non-functional ones will return
91763 * -ENOSYS.
91764 */
91765 + oldfs = get_fs();
91766 + set_fs(USER_DS);
91767 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
91768 futex_cmpxchg_enabled = 1;
91769 + set_fs(oldfs);
91770 #endif
91771 }
91772
91773 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
91774 index 55c8c93..9ba7ad6 100644
91775 --- a/kernel/futex_compat.c
91776 +++ b/kernel/futex_compat.c
91777 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
91778 return 0;
91779 }
91780
91781 -static void __user *futex_uaddr(struct robust_list __user *entry,
91782 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
91783 compat_long_t futex_offset)
91784 {
91785 compat_uptr_t base = ptr_to_compat(entry);
91786 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
91787 index b358a80..fc25240 100644
91788 --- a/kernel/gcov/base.c
91789 +++ b/kernel/gcov/base.c
91790 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
91791 }
91792
91793 #ifdef CONFIG_MODULES
91794 -static inline int within(void *addr, void *start, unsigned long size)
91795 -{
91796 - return ((addr >= start) && (addr < start + size));
91797 -}
91798 -
91799 /* Update list and generate events when modules are unloaded. */
91800 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
91801 void *data)
91802 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
91803
91804 /* Remove entries located in module from linked list. */
91805 while ((info = gcov_info_next(info))) {
91806 - if (within(info, mod->module_core, mod->core_size)) {
91807 + if (within_module_core_rw((unsigned long)info, mod)) {
91808 gcov_info_unlink(prev, info);
91809 if (gcov_events_enabled)
91810 gcov_event(GCOV_REMOVE, info);
91811 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
91812 index 3ab2899..c6ad010 100644
91813 --- a/kernel/hrtimer.c
91814 +++ b/kernel/hrtimer.c
91815 @@ -1449,7 +1449,7 @@ void hrtimer_peek_ahead_timers(void)
91816 local_irq_restore(flags);
91817 }
91818
91819 -static void run_hrtimer_softirq(struct softirq_action *h)
91820 +static __latent_entropy void run_hrtimer_softirq(void)
91821 {
91822 hrtimer_peek_ahead_timers();
91823 }
91824 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
91825 index a82170e..5b01e7f 100644
91826 --- a/kernel/irq_work.c
91827 +++ b/kernel/irq_work.c
91828 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
91829 return NOTIFY_OK;
91830 }
91831
91832 -static struct notifier_block cpu_notify;
91833 +static struct notifier_block cpu_notify = {
91834 + .notifier_call = irq_work_cpu_notify,
91835 + .priority = 0,
91836 +};
91837
91838 static __init int irq_work_init_cpu_notifier(void)
91839 {
91840 - cpu_notify.notifier_call = irq_work_cpu_notify;
91841 - cpu_notify.priority = 0;
91842 register_cpu_notifier(&cpu_notify);
91843 return 0;
91844 }
91845 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
91846 index 9019f15..9a3c42e 100644
91847 --- a/kernel/jump_label.c
91848 +++ b/kernel/jump_label.c
91849 @@ -14,6 +14,7 @@
91850 #include <linux/err.h>
91851 #include <linux/static_key.h>
91852 #include <linux/jump_label_ratelimit.h>
91853 +#include <linux/mm.h>
91854
91855 #ifdef HAVE_JUMP_LABEL
91856
91857 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
91858
91859 size = (((unsigned long)stop - (unsigned long)start)
91860 / sizeof(struct jump_entry));
91861 + pax_open_kernel();
91862 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
91863 + pax_close_kernel();
91864 }
91865
91866 static void jump_label_update(struct static_key *key, int enable);
91867 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
91868 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
91869 struct jump_entry *iter;
91870
91871 + pax_open_kernel();
91872 for (iter = iter_start; iter < iter_stop; iter++) {
91873 if (within_module_init(iter->code, mod))
91874 iter->code = 0;
91875 }
91876 + pax_close_kernel();
91877 }
91878
91879 static int
91880 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
91881 index cb0cf37..b69e161 100644
91882 --- a/kernel/kallsyms.c
91883 +++ b/kernel/kallsyms.c
91884 @@ -11,6 +11,9 @@
91885 * Changed the compression method from stem compression to "table lookup"
91886 * compression (see scripts/kallsyms.c for a more complete description)
91887 */
91888 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91889 +#define __INCLUDED_BY_HIDESYM 1
91890 +#endif
91891 #include <linux/kallsyms.h>
91892 #include <linux/module.h>
91893 #include <linux/init.h>
91894 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
91895
91896 static inline int is_kernel_inittext(unsigned long addr)
91897 {
91898 + if (system_state != SYSTEM_BOOTING)
91899 + return 0;
91900 +
91901 if (addr >= (unsigned long)_sinittext
91902 && addr <= (unsigned long)_einittext)
91903 return 1;
91904 return 0;
91905 }
91906
91907 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91908 +#ifdef CONFIG_MODULES
91909 +static inline int is_module_text(unsigned long addr)
91910 +{
91911 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
91912 + return 1;
91913 +
91914 + addr = ktla_ktva(addr);
91915 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
91916 +}
91917 +#else
91918 +static inline int is_module_text(unsigned long addr)
91919 +{
91920 + return 0;
91921 +}
91922 +#endif
91923 +#endif
91924 +
91925 static inline int is_kernel_text(unsigned long addr)
91926 {
91927 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
91928 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
91929
91930 static inline int is_kernel(unsigned long addr)
91931 {
91932 +
91933 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91934 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
91935 + return 1;
91936 +
91937 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
91938 +#else
91939 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
91940 +#endif
91941 +
91942 return 1;
91943 return in_gate_area_no_mm(addr);
91944 }
91945
91946 static int is_ksym_addr(unsigned long addr)
91947 {
91948 +
91949 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91950 + if (is_module_text(addr))
91951 + return 0;
91952 +#endif
91953 +
91954 if (all_var)
91955 return is_kernel(addr);
91956
91957 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
91958
91959 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
91960 {
91961 - iter->name[0] = '\0';
91962 iter->nameoff = get_symbol_offset(new_pos);
91963 iter->pos = new_pos;
91964 }
91965 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
91966 {
91967 struct kallsym_iter *iter = m->private;
91968
91969 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91970 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
91971 + return 0;
91972 +#endif
91973 +
91974 /* Some debugging symbols have no name. Ignore them. */
91975 if (!iter->name[0])
91976 return 0;
91977 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
91978 */
91979 type = iter->exported ? toupper(iter->type) :
91980 tolower(iter->type);
91981 +
91982 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
91983 type, iter->name, iter->module_name);
91984 } else
91985 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
91986 struct kallsym_iter *iter;
91987 int ret;
91988
91989 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
91990 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
91991 if (!iter)
91992 return -ENOMEM;
91993 reset_iter(iter, 0);
91994 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
91995 index e30ac0f..a7fcafb 100644
91996 --- a/kernel/kcmp.c
91997 +++ b/kernel/kcmp.c
91998 @@ -44,11 +44,12 @@ static long kptr_obfuscate(long v, int type)
91999 */
92000 static int kcmp_ptr(void *v1, void *v2, enum kcmp_type type)
92001 {
92002 - long ret;
92003 + long t1, t2;
92004
92005 - ret = kptr_obfuscate((long)v1, type) - kptr_obfuscate((long)v2, type);
92006 + t1 = kptr_obfuscate((long)v1, type);
92007 + t2 = kptr_obfuscate((long)v2, type);
92008
92009 - return (ret < 0) | ((ret > 0) << 1);
92010 + return (t1 < t2) | ((t1 > t2) << 1);
92011 }
92012
92013 /* The caller must have pinned the task */
92014 @@ -99,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
92015 struct task_struct *task1, *task2;
92016 int ret;
92017
92018 +#ifdef CONFIG_GRKERNSEC
92019 + return -ENOSYS;
92020 +#endif
92021 +
92022 rcu_read_lock();
92023
92024 /*
92025 diff --git a/kernel/kexec.c b/kernel/kexec.c
92026 index 4b8f0c9..fffd0df 100644
92027 --- a/kernel/kexec.c
92028 +++ b/kernel/kexec.c
92029 @@ -1045,7 +1045,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
92030 compat_ulong_t, flags)
92031 {
92032 struct compat_kexec_segment in;
92033 - struct kexec_segment out, __user *ksegments;
92034 + struct kexec_segment out;
92035 + struct kexec_segment __user *ksegments;
92036 unsigned long i, result;
92037
92038 /* Don't allow clients that don't understand the native
92039 diff --git a/kernel/kmod.c b/kernel/kmod.c
92040 index 8637e04..8b1d0d8 100644
92041 --- a/kernel/kmod.c
92042 +++ b/kernel/kmod.c
92043 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
92044 kfree(info->argv);
92045 }
92046
92047 -static int call_modprobe(char *module_name, int wait)
92048 +static int call_modprobe(char *module_name, char *module_param, int wait)
92049 {
92050 struct subprocess_info *info;
92051 static char *envp[] = {
92052 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
92053 NULL
92054 };
92055
92056 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
92057 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
92058 if (!argv)
92059 goto out;
92060
92061 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
92062 argv[1] = "-q";
92063 argv[2] = "--";
92064 argv[3] = module_name; /* check free_modprobe_argv() */
92065 - argv[4] = NULL;
92066 + argv[4] = module_param;
92067 + argv[5] = NULL;
92068
92069 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
92070 NULL, free_modprobe_argv, NULL);
92071 @@ -129,9 +130,8 @@ out:
92072 * If module auto-loading support is disabled then this function
92073 * becomes a no-operation.
92074 */
92075 -int __request_module(bool wait, const char *fmt, ...)
92076 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
92077 {
92078 - va_list args;
92079 char module_name[MODULE_NAME_LEN];
92080 unsigned int max_modprobes;
92081 int ret;
92082 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
92083 if (!modprobe_path[0])
92084 return 0;
92085
92086 - va_start(args, fmt);
92087 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
92088 - va_end(args);
92089 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
92090 if (ret >= MODULE_NAME_LEN)
92091 return -ENAMETOOLONG;
92092
92093 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
92094 if (ret)
92095 return ret;
92096
92097 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92098 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
92099 + /* hack to workaround consolekit/udisks stupidity */
92100 + read_lock(&tasklist_lock);
92101 + if (!strcmp(current->comm, "mount") &&
92102 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
92103 + read_unlock(&tasklist_lock);
92104 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
92105 + return -EPERM;
92106 + }
92107 + read_unlock(&tasklist_lock);
92108 + }
92109 +#endif
92110 +
92111 /* If modprobe needs a service that is in a module, we get a recursive
92112 * loop. Limit the number of running kmod threads to max_threads/2 or
92113 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
92114 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
92115
92116 trace_module_request(module_name, wait, _RET_IP_);
92117
92118 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
92119 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
92120
92121 atomic_dec(&kmod_concurrent);
92122 return ret;
92123 }
92124 +
92125 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
92126 +{
92127 + va_list args;
92128 + int ret;
92129 +
92130 + va_start(args, fmt);
92131 + ret = ____request_module(wait, module_param, fmt, args);
92132 + va_end(args);
92133 +
92134 + return ret;
92135 +}
92136 +
92137 +int __request_module(bool wait, const char *fmt, ...)
92138 +{
92139 + va_list args;
92140 + int ret;
92141 +
92142 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92143 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
92144 + char module_param[MODULE_NAME_LEN];
92145 +
92146 + memset(module_param, 0, sizeof(module_param));
92147 +
92148 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
92149 +
92150 + va_start(args, fmt);
92151 + ret = ____request_module(wait, module_param, fmt, args);
92152 + va_end(args);
92153 +
92154 + return ret;
92155 + }
92156 +#endif
92157 +
92158 + va_start(args, fmt);
92159 + ret = ____request_module(wait, NULL, fmt, args);
92160 + va_end(args);
92161 +
92162 + return ret;
92163 +}
92164 +
92165 EXPORT_SYMBOL(__request_module);
92166 #endif /* CONFIG_MODULES */
92167
92168 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
92169 */
92170 set_user_nice(current, 0);
92171
92172 +#ifdef CONFIG_GRKERNSEC
92173 + /* this is race-free as far as userland is concerned as we copied
92174 + out the path to be used prior to this point and are now operating
92175 + on that copy
92176 + */
92177 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
92178 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
92179 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
92180 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
92181 + retval = -EPERM;
92182 + goto fail;
92183 + }
92184 +#endif
92185 +
92186 retval = -ENOMEM;
92187 new = prepare_kernel_cred(current);
92188 if (!new)
92189 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
92190 commit_creds(new);
92191
92192 retval = do_execve(getname_kernel(sub_info->path),
92193 - (const char __user *const __user *)sub_info->argv,
92194 - (const char __user *const __user *)sub_info->envp);
92195 + (const char __user *const __force_user *)sub_info->argv,
92196 + (const char __user *const __force_user *)sub_info->envp);
92197 if (!retval)
92198 return 0;
92199
92200 @@ -260,6 +327,10 @@ static int call_helper(void *data)
92201
92202 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
92203 {
92204 +#ifdef CONFIG_GRKERNSEC
92205 + kfree(info->path);
92206 + info->path = info->origpath;
92207 +#endif
92208 if (info->cleanup)
92209 (*info->cleanup)(info);
92210 kfree(info);
92211 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
92212 *
92213 * Thus the __user pointer cast is valid here.
92214 */
92215 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
92216 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
92217
92218 /*
92219 * If ret is 0, either ____call_usermodehelper failed and the
92220 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
92221 goto out;
92222
92223 INIT_WORK(&sub_info->work, __call_usermodehelper);
92224 +#ifdef CONFIG_GRKERNSEC
92225 + sub_info->origpath = path;
92226 + sub_info->path = kstrdup(path, gfp_mask);
92227 +#else
92228 sub_info->path = path;
92229 +#endif
92230 sub_info->argv = argv;
92231 sub_info->envp = envp;
92232
92233 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
92234 static int proc_cap_handler(struct ctl_table *table, int write,
92235 void __user *buffer, size_t *lenp, loff_t *ppos)
92236 {
92237 - struct ctl_table t;
92238 + ctl_table_no_const t;
92239 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
92240 kernel_cap_t new_cap;
92241 int err, i;
92242 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
92243 index 734e9a7..0a313b8 100644
92244 --- a/kernel/kprobes.c
92245 +++ b/kernel/kprobes.c
92246 @@ -31,6 +31,9 @@
92247 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
92248 * <prasanna@in.ibm.com> added function-return probes.
92249 */
92250 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92251 +#define __INCLUDED_BY_HIDESYM 1
92252 +#endif
92253 #include <linux/kprobes.h>
92254 #include <linux/hash.h>
92255 #include <linux/init.h>
92256 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
92257
92258 static void *alloc_insn_page(void)
92259 {
92260 - return module_alloc(PAGE_SIZE);
92261 + return module_alloc_exec(PAGE_SIZE);
92262 }
92263
92264 static void free_insn_page(void *page)
92265 {
92266 - module_free(NULL, page);
92267 + module_free_exec(NULL, page);
92268 }
92269
92270 struct kprobe_insn_cache kprobe_insn_slots = {
92271 @@ -2176,11 +2179,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
92272 kprobe_type = "k";
92273
92274 if (sym)
92275 - seq_printf(pi, "%p %s %s+0x%x %s ",
92276 + seq_printf(pi, "%pK %s %s+0x%x %s ",
92277 p->addr, kprobe_type, sym, offset,
92278 (modname ? modname : " "));
92279 else
92280 - seq_printf(pi, "%p %s %p ",
92281 + seq_printf(pi, "%pK %s %pK ",
92282 p->addr, kprobe_type, p->addr);
92283
92284 if (!pp)
92285 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
92286 index 6683cce..daf8999 100644
92287 --- a/kernel/ksysfs.c
92288 +++ b/kernel/ksysfs.c
92289 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
92290 {
92291 if (count+1 > UEVENT_HELPER_PATH_LEN)
92292 return -ENOENT;
92293 + if (!capable(CAP_SYS_ADMIN))
92294 + return -EPERM;
92295 memcpy(uevent_helper, buf, count);
92296 uevent_helper[count] = '\0';
92297 if (count && uevent_helper[count-1] == '\n')
92298 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
92299 return count;
92300 }
92301
92302 -static struct bin_attribute notes_attr = {
92303 +static bin_attribute_no_const notes_attr __read_only = {
92304 .attr = {
92305 .name = "notes",
92306 .mode = S_IRUGO,
92307 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
92308 index d24e433..fa04fb8 100644
92309 --- a/kernel/locking/lockdep.c
92310 +++ b/kernel/locking/lockdep.c
92311 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
92312 end = (unsigned long) &_end,
92313 addr = (unsigned long) obj;
92314
92315 +#ifdef CONFIG_PAX_KERNEXEC
92316 + start = ktla_ktva(start);
92317 +#endif
92318 +
92319 /*
92320 * static variable?
92321 */
92322 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
92323 if (!static_obj(lock->key)) {
92324 debug_locks_off();
92325 printk("INFO: trying to register non-static key.\n");
92326 + printk("lock:%pS key:%pS.\n", lock, lock->key);
92327 printk("the code is fine but needs lockdep annotation.\n");
92328 printk("turning off the locking correctness validator.\n");
92329 dump_stack();
92330 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
92331 if (!class)
92332 return 0;
92333 }
92334 - atomic_inc((atomic_t *)&class->ops);
92335 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
92336 if (very_verbose(class)) {
92337 printk("\nacquire class [%p] %s", class->key, class->name);
92338 if (class->name_version > 1)
92339 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
92340 index ef43ac4..2720dfa 100644
92341 --- a/kernel/locking/lockdep_proc.c
92342 +++ b/kernel/locking/lockdep_proc.c
92343 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
92344 return 0;
92345 }
92346
92347 - seq_printf(m, "%p", class->key);
92348 + seq_printf(m, "%pK", class->key);
92349 #ifdef CONFIG_DEBUG_LOCKDEP
92350 seq_printf(m, " OPS:%8ld", class->ops);
92351 #endif
92352 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
92353
92354 list_for_each_entry(entry, &class->locks_after, entry) {
92355 if (entry->distance == 1) {
92356 - seq_printf(m, " -> [%p] ", entry->class->key);
92357 + seq_printf(m, " -> [%pK] ", entry->class->key);
92358 print_name(m, entry->class);
92359 seq_puts(m, "\n");
92360 }
92361 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
92362 if (!class->key)
92363 continue;
92364
92365 - seq_printf(m, "[%p] ", class->key);
92366 + seq_printf(m, "[%pK] ", class->key);
92367 print_name(m, class);
92368 seq_puts(m, "\n");
92369 }
92370 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
92371 if (!i)
92372 seq_line(m, '-', 40-namelen, namelen);
92373
92374 - snprintf(ip, sizeof(ip), "[<%p>]",
92375 + snprintf(ip, sizeof(ip), "[<%pK>]",
92376 (void *)class->contention_point[i]);
92377 seq_printf(m, "%40s %14lu %29s %pS\n",
92378 name, stats->contention_point[i],
92379 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
92380 if (!i)
92381 seq_line(m, '-', 40-namelen, namelen);
92382
92383 - snprintf(ip, sizeof(ip), "[<%p>]",
92384 + snprintf(ip, sizeof(ip), "[<%pK>]",
92385 (void *)class->contending_point[i]);
92386 seq_printf(m, "%40s %14lu %29s %pS\n",
92387 name, stats->contending_point[i],
92388 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
92389 index be9ee15..39d6233 100644
92390 --- a/kernel/locking/mcs_spinlock.c
92391 +++ b/kernel/locking/mcs_spinlock.c
92392 @@ -102,7 +102,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
92393
92394 prev = decode_cpu(old);
92395 node->prev = prev;
92396 - ACCESS_ONCE(prev->next) = node;
92397 + ACCESS_ONCE_RW(prev->next) = node;
92398
92399 /*
92400 * Normally @prev is untouchable after the above store; because at that
92401 @@ -174,8 +174,8 @@ unqueue:
92402 * it will wait in Step-A.
92403 */
92404
92405 - ACCESS_ONCE(next->prev) = prev;
92406 - ACCESS_ONCE(prev->next) = next;
92407 + ACCESS_ONCE_RW(next->prev) = prev;
92408 + ACCESS_ONCE_RW(prev->next) = next;
92409
92410 return false;
92411 }
92412 @@ -197,13 +197,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
92413 node = this_cpu_ptr(&osq_node);
92414 next = xchg(&node->next, NULL);
92415 if (next) {
92416 - ACCESS_ONCE(next->locked) = 1;
92417 + ACCESS_ONCE_RW(next->locked) = 1;
92418 return;
92419 }
92420
92421 next = osq_wait_next(lock, node, NULL);
92422 if (next)
92423 - ACCESS_ONCE(next->locked) = 1;
92424 + ACCESS_ONCE_RW(next->locked) = 1;
92425 }
92426
92427 #endif
92428 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
92429 index 74356dc..48dd5e1 100644
92430 --- a/kernel/locking/mcs_spinlock.h
92431 +++ b/kernel/locking/mcs_spinlock.h
92432 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
92433 */
92434 return;
92435 }
92436 - ACCESS_ONCE(prev->next) = node;
92437 + ACCESS_ONCE_RW(prev->next) = node;
92438
92439 /* Wait until the lock holder passes the lock down. */
92440 arch_mcs_spin_lock_contended(&node->locked);
92441 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
92442 index 5cf6731..ce3bc5a 100644
92443 --- a/kernel/locking/mutex-debug.c
92444 +++ b/kernel/locking/mutex-debug.c
92445 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
92446 }
92447
92448 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
92449 - struct thread_info *ti)
92450 + struct task_struct *task)
92451 {
92452 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
92453
92454 /* Mark the current thread as blocked on the lock: */
92455 - ti->task->blocked_on = waiter;
92456 + task->blocked_on = waiter;
92457 }
92458
92459 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
92460 - struct thread_info *ti)
92461 + struct task_struct *task)
92462 {
92463 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
92464 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
92465 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
92466 - ti->task->blocked_on = NULL;
92467 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
92468 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
92469 + task->blocked_on = NULL;
92470
92471 list_del_init(&waiter->list);
92472 waiter->task = NULL;
92473 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
92474 index 0799fd3..d06ae3b 100644
92475 --- a/kernel/locking/mutex-debug.h
92476 +++ b/kernel/locking/mutex-debug.h
92477 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
92478 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
92479 extern void debug_mutex_add_waiter(struct mutex *lock,
92480 struct mutex_waiter *waiter,
92481 - struct thread_info *ti);
92482 + struct task_struct *task);
92483 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
92484 - struct thread_info *ti);
92485 + struct task_struct *task);
92486 extern void debug_mutex_unlock(struct mutex *lock);
92487 extern void debug_mutex_init(struct mutex *lock, const char *name,
92488 struct lock_class_key *key);
92489 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
92490 index acca2c1..ddeaea8 100644
92491 --- a/kernel/locking/mutex.c
92492 +++ b/kernel/locking/mutex.c
92493 @@ -490,7 +490,7 @@ slowpath:
92494 goto skip_wait;
92495
92496 debug_mutex_lock_common(lock, &waiter);
92497 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
92498 + debug_mutex_add_waiter(lock, &waiter, task);
92499
92500 /* add waiting tasks to the end of the waitqueue (FIFO): */
92501 list_add_tail(&waiter.list, &lock->wait_list);
92502 @@ -534,7 +534,7 @@ slowpath:
92503 schedule_preempt_disabled();
92504 spin_lock_mutex(&lock->wait_lock, flags);
92505 }
92506 - mutex_remove_waiter(lock, &waiter, current_thread_info());
92507 + mutex_remove_waiter(lock, &waiter, task);
92508 /* set it to 0 if there are no waiters left: */
92509 if (likely(list_empty(&lock->wait_list)))
92510 atomic_set(&lock->count, 0);
92511 @@ -571,7 +571,7 @@ skip_wait:
92512 return 0;
92513
92514 err:
92515 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
92516 + mutex_remove_waiter(lock, &waiter, task);
92517 spin_unlock_mutex(&lock->wait_lock, flags);
92518 debug_mutex_free_waiter(&waiter);
92519 mutex_release(&lock->dep_map, 1, ip);
92520 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
92521 index 1d96dd0..994ff19 100644
92522 --- a/kernel/locking/rtmutex-tester.c
92523 +++ b/kernel/locking/rtmutex-tester.c
92524 @@ -22,7 +22,7 @@
92525 #define MAX_RT_TEST_MUTEXES 8
92526
92527 static spinlock_t rttest_lock;
92528 -static atomic_t rttest_event;
92529 +static atomic_unchecked_t rttest_event;
92530
92531 struct test_thread_data {
92532 int opcode;
92533 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
92534
92535 case RTTEST_LOCKCONT:
92536 td->mutexes[td->opdata] = 1;
92537 - td->event = atomic_add_return(1, &rttest_event);
92538 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92539 return 0;
92540
92541 case RTTEST_RESET:
92542 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
92543 return 0;
92544
92545 case RTTEST_RESETEVENT:
92546 - atomic_set(&rttest_event, 0);
92547 + atomic_set_unchecked(&rttest_event, 0);
92548 return 0;
92549
92550 default:
92551 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
92552 return ret;
92553
92554 td->mutexes[id] = 1;
92555 - td->event = atomic_add_return(1, &rttest_event);
92556 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92557 rt_mutex_lock(&mutexes[id]);
92558 - td->event = atomic_add_return(1, &rttest_event);
92559 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92560 td->mutexes[id] = 4;
92561 return 0;
92562
92563 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
92564 return ret;
92565
92566 td->mutexes[id] = 1;
92567 - td->event = atomic_add_return(1, &rttest_event);
92568 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92569 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
92570 - td->event = atomic_add_return(1, &rttest_event);
92571 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92572 td->mutexes[id] = ret ? 0 : 4;
92573 return ret ? -EINTR : 0;
92574
92575 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
92576 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
92577 return ret;
92578
92579 - td->event = atomic_add_return(1, &rttest_event);
92580 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92581 rt_mutex_unlock(&mutexes[id]);
92582 - td->event = atomic_add_return(1, &rttest_event);
92583 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92584 td->mutexes[id] = 0;
92585 return 0;
92586
92587 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
92588 break;
92589
92590 td->mutexes[dat] = 2;
92591 - td->event = atomic_add_return(1, &rttest_event);
92592 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92593 break;
92594
92595 default:
92596 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
92597 return;
92598
92599 td->mutexes[dat] = 3;
92600 - td->event = atomic_add_return(1, &rttest_event);
92601 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92602 break;
92603
92604 case RTTEST_LOCKNOWAIT:
92605 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
92606 return;
92607
92608 td->mutexes[dat] = 1;
92609 - td->event = atomic_add_return(1, &rttest_event);
92610 + td->event = atomic_add_return_unchecked(1, &rttest_event);
92611 return;
92612
92613 default:
92614 diff --git a/kernel/module.c b/kernel/module.c
92615 index 81e727c..a8ea6f9 100644
92616 --- a/kernel/module.c
92617 +++ b/kernel/module.c
92618 @@ -61,6 +61,7 @@
92619 #include <linux/pfn.h>
92620 #include <linux/bsearch.h>
92621 #include <linux/fips.h>
92622 +#include <linux/grsecurity.h>
92623 #include <uapi/linux/module.h>
92624 #include "module-internal.h"
92625
92626 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
92627
92628 /* Bounds of module allocation, for speeding __module_address.
92629 * Protected by module_mutex. */
92630 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
92631 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
92632 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
92633
92634 int register_module_notifier(struct notifier_block * nb)
92635 {
92636 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
92637 return true;
92638
92639 list_for_each_entry_rcu(mod, &modules, list) {
92640 - struct symsearch arr[] = {
92641 + struct symsearch modarr[] = {
92642 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
92643 NOT_GPL_ONLY, false },
92644 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
92645 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
92646 if (mod->state == MODULE_STATE_UNFORMED)
92647 continue;
92648
92649 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
92650 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
92651 return true;
92652 }
92653 return false;
92654 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
92655 if (!pcpusec->sh_size)
92656 return 0;
92657
92658 - if (align > PAGE_SIZE) {
92659 + if (align-1 >= PAGE_SIZE) {
92660 pr_warn("%s: per-cpu alignment %li > %li\n",
92661 mod->name, align, PAGE_SIZE);
92662 align = PAGE_SIZE;
92663 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
92664 static ssize_t show_coresize(struct module_attribute *mattr,
92665 struct module_kobject *mk, char *buffer)
92666 {
92667 - return sprintf(buffer, "%u\n", mk->mod->core_size);
92668 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
92669 }
92670
92671 static struct module_attribute modinfo_coresize =
92672 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
92673 static ssize_t show_initsize(struct module_attribute *mattr,
92674 struct module_kobject *mk, char *buffer)
92675 {
92676 - return sprintf(buffer, "%u\n", mk->mod->init_size);
92677 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
92678 }
92679
92680 static struct module_attribute modinfo_initsize =
92681 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
92682 goto bad_version;
92683 }
92684
92685 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
92686 + /*
92687 + * avoid potentially printing jibberish on attempted load
92688 + * of a module randomized with a different seed
92689 + */
92690 + pr_warn("no symbol version for %s\n", symname);
92691 +#else
92692 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
92693 +#endif
92694 return 0;
92695
92696 bad_version:
92697 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
92698 + /*
92699 + * avoid potentially printing jibberish on attempted load
92700 + * of a module randomized with a different seed
92701 + */
92702 + printk("attempted module disagrees about version of symbol %s\n",
92703 + symname);
92704 +#else
92705 printk("%s: disagrees about version of symbol %s\n",
92706 mod->name, symname);
92707 +#endif
92708 return 0;
92709 }
92710
92711 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
92712 */
92713 #ifdef CONFIG_SYSFS
92714
92715 -#ifdef CONFIG_KALLSYMS
92716 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
92717 static inline bool sect_empty(const Elf_Shdr *sect)
92718 {
92719 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
92720 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
92721 {
92722 unsigned int notes, loaded, i;
92723 struct module_notes_attrs *notes_attrs;
92724 - struct bin_attribute *nattr;
92725 + bin_attribute_no_const *nattr;
92726
92727 /* failed to create section attributes, so can't create notes */
92728 if (!mod->sect_attrs)
92729 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
92730 static int module_add_modinfo_attrs(struct module *mod)
92731 {
92732 struct module_attribute *attr;
92733 - struct module_attribute *temp_attr;
92734 + module_attribute_no_const *temp_attr;
92735 int error = 0;
92736 int i;
92737
92738 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
92739
92740 static void unset_module_core_ro_nx(struct module *mod)
92741 {
92742 - set_page_attributes(mod->module_core + mod->core_text_size,
92743 - mod->module_core + mod->core_size,
92744 + set_page_attributes(mod->module_core_rw,
92745 + mod->module_core_rw + mod->core_size_rw,
92746 set_memory_x);
92747 - set_page_attributes(mod->module_core,
92748 - mod->module_core + mod->core_ro_size,
92749 + set_page_attributes(mod->module_core_rx,
92750 + mod->module_core_rx + mod->core_size_rx,
92751 set_memory_rw);
92752 }
92753
92754 static void unset_module_init_ro_nx(struct module *mod)
92755 {
92756 - set_page_attributes(mod->module_init + mod->init_text_size,
92757 - mod->module_init + mod->init_size,
92758 + set_page_attributes(mod->module_init_rw,
92759 + mod->module_init_rw + mod->init_size_rw,
92760 set_memory_x);
92761 - set_page_attributes(mod->module_init,
92762 - mod->module_init + mod->init_ro_size,
92763 + set_page_attributes(mod->module_init_rx,
92764 + mod->module_init_rx + mod->init_size_rx,
92765 set_memory_rw);
92766 }
92767
92768 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
92769 list_for_each_entry_rcu(mod, &modules, list) {
92770 if (mod->state == MODULE_STATE_UNFORMED)
92771 continue;
92772 - if ((mod->module_core) && (mod->core_text_size)) {
92773 - set_page_attributes(mod->module_core,
92774 - mod->module_core + mod->core_text_size,
92775 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
92776 + set_page_attributes(mod->module_core_rx,
92777 + mod->module_core_rx + mod->core_size_rx,
92778 set_memory_rw);
92779 }
92780 - if ((mod->module_init) && (mod->init_text_size)) {
92781 - set_page_attributes(mod->module_init,
92782 - mod->module_init + mod->init_text_size,
92783 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
92784 + set_page_attributes(mod->module_init_rx,
92785 + mod->module_init_rx + mod->init_size_rx,
92786 set_memory_rw);
92787 }
92788 }
92789 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
92790 list_for_each_entry_rcu(mod, &modules, list) {
92791 if (mod->state == MODULE_STATE_UNFORMED)
92792 continue;
92793 - if ((mod->module_core) && (mod->core_text_size)) {
92794 - set_page_attributes(mod->module_core,
92795 - mod->module_core + mod->core_text_size,
92796 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
92797 + set_page_attributes(mod->module_core_rx,
92798 + mod->module_core_rx + mod->core_size_rx,
92799 set_memory_ro);
92800 }
92801 - if ((mod->module_init) && (mod->init_text_size)) {
92802 - set_page_attributes(mod->module_init,
92803 - mod->module_init + mod->init_text_size,
92804 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
92805 + set_page_attributes(mod->module_init_rx,
92806 + mod->module_init_rx + mod->init_size_rx,
92807 set_memory_ro);
92808 }
92809 }
92810 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
92811
92812 /* This may be NULL, but that's OK */
92813 unset_module_init_ro_nx(mod);
92814 - module_free(mod, mod->module_init);
92815 + module_free(mod, mod->module_init_rw);
92816 + module_free_exec(mod, mod->module_init_rx);
92817 kfree(mod->args);
92818 percpu_modfree(mod);
92819
92820 /* Free lock-classes: */
92821 - lockdep_free_key_range(mod->module_core, mod->core_size);
92822 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
92823 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
92824
92825 /* Finally, free the core (containing the module structure) */
92826 unset_module_core_ro_nx(mod);
92827 - module_free(mod, mod->module_core);
92828 + module_free_exec(mod, mod->module_core_rx);
92829 + module_free(mod, mod->module_core_rw);
92830
92831 #ifdef CONFIG_MPU
92832 update_protections(current->mm);
92833 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92834 int ret = 0;
92835 const struct kernel_symbol *ksym;
92836
92837 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92838 + int is_fs_load = 0;
92839 + int register_filesystem_found = 0;
92840 + char *p;
92841 +
92842 + p = strstr(mod->args, "grsec_modharden_fs");
92843 + if (p) {
92844 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
92845 + /* copy \0 as well */
92846 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
92847 + is_fs_load = 1;
92848 + }
92849 +#endif
92850 +
92851 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
92852 const char *name = info->strtab + sym[i].st_name;
92853
92854 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92855 + /* it's a real shame this will never get ripped and copied
92856 + upstream! ;(
92857 + */
92858 + if (is_fs_load && !strcmp(name, "register_filesystem"))
92859 + register_filesystem_found = 1;
92860 +#endif
92861 +
92862 switch (sym[i].st_shndx) {
92863 case SHN_COMMON:
92864 /* Ignore common symbols */
92865 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92866 ksym = resolve_symbol_wait(mod, info, name);
92867 /* Ok if resolved. */
92868 if (ksym && !IS_ERR(ksym)) {
92869 + pax_open_kernel();
92870 sym[i].st_value = ksym->value;
92871 + pax_close_kernel();
92872 break;
92873 }
92874
92875 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
92876 secbase = (unsigned long)mod_percpu(mod);
92877 else
92878 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
92879 + pax_open_kernel();
92880 sym[i].st_value += secbase;
92881 + pax_close_kernel();
92882 break;
92883 }
92884 }
92885
92886 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
92887 + if (is_fs_load && !register_filesystem_found) {
92888 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
92889 + ret = -EPERM;
92890 + }
92891 +#endif
92892 +
92893 return ret;
92894 }
92895
92896 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
92897 || s->sh_entsize != ~0UL
92898 || strstarts(sname, ".init"))
92899 continue;
92900 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
92901 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
92902 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
92903 + else
92904 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
92905 pr_debug("\t%s\n", sname);
92906 }
92907 - switch (m) {
92908 - case 0: /* executable */
92909 - mod->core_size = debug_align(mod->core_size);
92910 - mod->core_text_size = mod->core_size;
92911 - break;
92912 - case 1: /* RO: text and ro-data */
92913 - mod->core_size = debug_align(mod->core_size);
92914 - mod->core_ro_size = mod->core_size;
92915 - break;
92916 - case 3: /* whole core */
92917 - mod->core_size = debug_align(mod->core_size);
92918 - break;
92919 - }
92920 }
92921
92922 pr_debug("Init section allocation order:\n");
92923 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
92924 || s->sh_entsize != ~0UL
92925 || !strstarts(sname, ".init"))
92926 continue;
92927 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
92928 - | INIT_OFFSET_MASK);
92929 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
92930 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
92931 + else
92932 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
92933 + s->sh_entsize |= INIT_OFFSET_MASK;
92934 pr_debug("\t%s\n", sname);
92935 }
92936 - switch (m) {
92937 - case 0: /* executable */
92938 - mod->init_size = debug_align(mod->init_size);
92939 - mod->init_text_size = mod->init_size;
92940 - break;
92941 - case 1: /* RO: text and ro-data */
92942 - mod->init_size = debug_align(mod->init_size);
92943 - mod->init_ro_size = mod->init_size;
92944 - break;
92945 - case 3: /* whole init */
92946 - mod->init_size = debug_align(mod->init_size);
92947 - break;
92948 - }
92949 }
92950 }
92951
92952 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
92953
92954 /* Put symbol section at end of init part of module. */
92955 symsect->sh_flags |= SHF_ALLOC;
92956 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
92957 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
92958 info->index.sym) | INIT_OFFSET_MASK;
92959 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
92960
92961 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
92962 }
92963
92964 /* Append room for core symbols at end of core part. */
92965 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
92966 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
92967 - mod->core_size += strtab_size;
92968 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
92969 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
92970 + mod->core_size_rx += strtab_size;
92971
92972 /* Put string table section at end of init part of module. */
92973 strsect->sh_flags |= SHF_ALLOC;
92974 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
92975 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
92976 info->index.str) | INIT_OFFSET_MASK;
92977 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
92978 }
92979 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
92980 /* Make sure we get permanent strtab: don't use info->strtab. */
92981 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
92982
92983 + pax_open_kernel();
92984 +
92985 /* Set types up while we still have access to sections. */
92986 for (i = 0; i < mod->num_symtab; i++)
92987 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
92988
92989 - mod->core_symtab = dst = mod->module_core + info->symoffs;
92990 - mod->core_strtab = s = mod->module_core + info->stroffs;
92991 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
92992 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
92993 src = mod->symtab;
92994 for (ndst = i = 0; i < mod->num_symtab; i++) {
92995 if (i == 0 ||
92996 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
92997 }
92998 }
92999 mod->core_num_syms = ndst;
93000 +
93001 + pax_close_kernel();
93002 }
93003 #else
93004 static inline void layout_symtab(struct module *mod, struct load_info *info)
93005 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
93006 return vmalloc_exec(size);
93007 }
93008
93009 -static void *module_alloc_update_bounds(unsigned long size)
93010 +static void *module_alloc_update_bounds_rw(unsigned long size)
93011 {
93012 void *ret = module_alloc(size);
93013
93014 if (ret) {
93015 mutex_lock(&module_mutex);
93016 /* Update module bounds. */
93017 - if ((unsigned long)ret < module_addr_min)
93018 - module_addr_min = (unsigned long)ret;
93019 - if ((unsigned long)ret + size > module_addr_max)
93020 - module_addr_max = (unsigned long)ret + size;
93021 + if ((unsigned long)ret < module_addr_min_rw)
93022 + module_addr_min_rw = (unsigned long)ret;
93023 + if ((unsigned long)ret + size > module_addr_max_rw)
93024 + module_addr_max_rw = (unsigned long)ret + size;
93025 + mutex_unlock(&module_mutex);
93026 + }
93027 + return ret;
93028 +}
93029 +
93030 +static void *module_alloc_update_bounds_rx(unsigned long size)
93031 +{
93032 + void *ret = module_alloc_exec(size);
93033 +
93034 + if (ret) {
93035 + mutex_lock(&module_mutex);
93036 + /* Update module bounds. */
93037 + if ((unsigned long)ret < module_addr_min_rx)
93038 + module_addr_min_rx = (unsigned long)ret;
93039 + if ((unsigned long)ret + size > module_addr_max_rx)
93040 + module_addr_max_rx = (unsigned long)ret + size;
93041 mutex_unlock(&module_mutex);
93042 }
93043 return ret;
93044 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
93045 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
93046
93047 if (info->index.sym == 0) {
93048 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
93049 + /*
93050 + * avoid potentially printing jibberish on attempted load
93051 + * of a module randomized with a different seed
93052 + */
93053 + pr_warn("module has no symbols (stripped?)\n");
93054 +#else
93055 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
93056 +#endif
93057 return ERR_PTR(-ENOEXEC);
93058 }
93059
93060 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
93061 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
93062 {
93063 const char *modmagic = get_modinfo(info, "vermagic");
93064 + const char *license = get_modinfo(info, "license");
93065 int err;
93066
93067 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
93068 + if (!license || !license_is_gpl_compatible(license))
93069 + return -ENOEXEC;
93070 +#endif
93071 +
93072 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
93073 modmagic = NULL;
93074
93075 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
93076 }
93077
93078 /* Set up license info based on the info section */
93079 - set_license(mod, get_modinfo(info, "license"));
93080 + set_license(mod, license);
93081
93082 return 0;
93083 }
93084 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
93085 void *ptr;
93086
93087 /* Do the allocs. */
93088 - ptr = module_alloc_update_bounds(mod->core_size);
93089 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
93090 /*
93091 * The pointer to this block is stored in the module structure
93092 * which is inside the block. Just mark it as not being a
93093 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
93094 if (!ptr)
93095 return -ENOMEM;
93096
93097 - memset(ptr, 0, mod->core_size);
93098 - mod->module_core = ptr;
93099 + memset(ptr, 0, mod->core_size_rw);
93100 + mod->module_core_rw = ptr;
93101
93102 - if (mod->init_size) {
93103 - ptr = module_alloc_update_bounds(mod->init_size);
93104 + if (mod->init_size_rw) {
93105 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
93106 /*
93107 * The pointer to this block is stored in the module structure
93108 * which is inside the block. This block doesn't need to be
93109 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
93110 */
93111 kmemleak_ignore(ptr);
93112 if (!ptr) {
93113 - module_free(mod, mod->module_core);
93114 + module_free(mod, mod->module_core_rw);
93115 return -ENOMEM;
93116 }
93117 - memset(ptr, 0, mod->init_size);
93118 - mod->module_init = ptr;
93119 + memset(ptr, 0, mod->init_size_rw);
93120 + mod->module_init_rw = ptr;
93121 } else
93122 - mod->module_init = NULL;
93123 + mod->module_init_rw = NULL;
93124 +
93125 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
93126 + kmemleak_not_leak(ptr);
93127 + if (!ptr) {
93128 + if (mod->module_init_rw)
93129 + module_free(mod, mod->module_init_rw);
93130 + module_free(mod, mod->module_core_rw);
93131 + return -ENOMEM;
93132 + }
93133 +
93134 + pax_open_kernel();
93135 + memset(ptr, 0, mod->core_size_rx);
93136 + pax_close_kernel();
93137 + mod->module_core_rx = ptr;
93138 +
93139 + if (mod->init_size_rx) {
93140 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
93141 + kmemleak_ignore(ptr);
93142 + if (!ptr && mod->init_size_rx) {
93143 + module_free_exec(mod, mod->module_core_rx);
93144 + if (mod->module_init_rw)
93145 + module_free(mod, mod->module_init_rw);
93146 + module_free(mod, mod->module_core_rw);
93147 + return -ENOMEM;
93148 + }
93149 +
93150 + pax_open_kernel();
93151 + memset(ptr, 0, mod->init_size_rx);
93152 + pax_close_kernel();
93153 + mod->module_init_rx = ptr;
93154 + } else
93155 + mod->module_init_rx = NULL;
93156
93157 /* Transfer each section which specifies SHF_ALLOC */
93158 pr_debug("final section addresses:\n");
93159 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
93160 if (!(shdr->sh_flags & SHF_ALLOC))
93161 continue;
93162
93163 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
93164 - dest = mod->module_init
93165 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
93166 - else
93167 - dest = mod->module_core + shdr->sh_entsize;
93168 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
93169 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
93170 + dest = mod->module_init_rw
93171 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
93172 + else
93173 + dest = mod->module_init_rx
93174 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
93175 + } else {
93176 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
93177 + dest = mod->module_core_rw + shdr->sh_entsize;
93178 + else
93179 + dest = mod->module_core_rx + shdr->sh_entsize;
93180 + }
93181 +
93182 + if (shdr->sh_type != SHT_NOBITS) {
93183 +
93184 +#ifdef CONFIG_PAX_KERNEXEC
93185 +#ifdef CONFIG_X86_64
93186 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
93187 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
93188 +#endif
93189 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
93190 + pax_open_kernel();
93191 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
93192 + pax_close_kernel();
93193 + } else
93194 +#endif
93195
93196 - if (shdr->sh_type != SHT_NOBITS)
93197 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
93198 + }
93199 /* Update sh_addr to point to copy in image. */
93200 - shdr->sh_addr = (unsigned long)dest;
93201 +
93202 +#ifdef CONFIG_PAX_KERNEXEC
93203 + if (shdr->sh_flags & SHF_EXECINSTR)
93204 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
93205 + else
93206 +#endif
93207 +
93208 + shdr->sh_addr = (unsigned long)dest;
93209 pr_debug("\t0x%lx %s\n",
93210 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
93211 }
93212 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
93213 * Do it before processing of module parameters, so the module
93214 * can provide parameter accessor functions of its own.
93215 */
93216 - if (mod->module_init)
93217 - flush_icache_range((unsigned long)mod->module_init,
93218 - (unsigned long)mod->module_init
93219 - + mod->init_size);
93220 - flush_icache_range((unsigned long)mod->module_core,
93221 - (unsigned long)mod->module_core + mod->core_size);
93222 + if (mod->module_init_rx)
93223 + flush_icache_range((unsigned long)mod->module_init_rx,
93224 + (unsigned long)mod->module_init_rx
93225 + + mod->init_size_rx);
93226 + flush_icache_range((unsigned long)mod->module_core_rx,
93227 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
93228
93229 set_fs(old_fs);
93230 }
93231 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
93232 static void module_deallocate(struct module *mod, struct load_info *info)
93233 {
93234 percpu_modfree(mod);
93235 - module_free(mod, mod->module_init);
93236 - module_free(mod, mod->module_core);
93237 + module_free_exec(mod, mod->module_init_rx);
93238 + module_free_exec(mod, mod->module_core_rx);
93239 + module_free(mod, mod->module_init_rw);
93240 + module_free(mod, mod->module_core_rw);
93241 }
93242
93243 int __weak module_finalize(const Elf_Ehdr *hdr,
93244 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
93245 static int post_relocation(struct module *mod, const struct load_info *info)
93246 {
93247 /* Sort exception table now relocations are done. */
93248 + pax_open_kernel();
93249 sort_extable(mod->extable, mod->extable + mod->num_exentries);
93250 + pax_close_kernel();
93251
93252 /* Copy relocated percpu area over. */
93253 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
93254 @@ -3079,11 +3213,12 @@ static int do_init_module(struct module *mod)
93255 mod->strtab = mod->core_strtab;
93256 #endif
93257 unset_module_init_ro_nx(mod);
93258 - module_free(mod, mod->module_init);
93259 - mod->module_init = NULL;
93260 - mod->init_size = 0;
93261 - mod->init_ro_size = 0;
93262 - mod->init_text_size = 0;
93263 + module_free(mod, mod->module_init_rw);
93264 + module_free_exec(mod, mod->module_init_rx);
93265 + mod->module_init_rw = NULL;
93266 + mod->module_init_rx = NULL;
93267 + mod->init_size_rw = 0;
93268 + mod->init_size_rx = 0;
93269 mutex_unlock(&module_mutex);
93270 wake_up_all(&module_wq);
93271
93272 @@ -3151,16 +3286,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
93273 module_bug_finalize(info->hdr, info->sechdrs, mod);
93274
93275 /* Set RO and NX regions for core */
93276 - set_section_ro_nx(mod->module_core,
93277 - mod->core_text_size,
93278 - mod->core_ro_size,
93279 - mod->core_size);
93280 + set_section_ro_nx(mod->module_core_rx,
93281 + mod->core_size_rx,
93282 + mod->core_size_rx,
93283 + mod->core_size_rx);
93284
93285 /* Set RO and NX regions for init */
93286 - set_section_ro_nx(mod->module_init,
93287 - mod->init_text_size,
93288 - mod->init_ro_size,
93289 - mod->init_size);
93290 + set_section_ro_nx(mod->module_init_rx,
93291 + mod->init_size_rx,
93292 + mod->init_size_rx,
93293 + mod->init_size_rx);
93294
93295 /* Mark state as coming so strong_try_module_get() ignores us,
93296 * but kallsyms etc. can see us. */
93297 @@ -3244,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
93298 if (err)
93299 goto free_unload;
93300
93301 + /* Now copy in args */
93302 + mod->args = strndup_user(uargs, ~0UL >> 1);
93303 + if (IS_ERR(mod->args)) {
93304 + err = PTR_ERR(mod->args);
93305 + goto free_unload;
93306 + }
93307 +
93308 /* Set up MODINFO_ATTR fields */
93309 setup_modinfo(mod, info);
93310
93311 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
93312 + {
93313 + char *p, *p2;
93314 +
93315 + if (strstr(mod->args, "grsec_modharden_netdev")) {
93316 + 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);
93317 + err = -EPERM;
93318 + goto free_modinfo;
93319 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
93320 + p += sizeof("grsec_modharden_normal") - 1;
93321 + p2 = strstr(p, "_");
93322 + if (p2) {
93323 + *p2 = '\0';
93324 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
93325 + *p2 = '_';
93326 + }
93327 + err = -EPERM;
93328 + goto free_modinfo;
93329 + }
93330 + }
93331 +#endif
93332 +
93333 /* Fix up syms, so that st_value is a pointer to location. */
93334 err = simplify_symbols(mod, info);
93335 if (err < 0)
93336 @@ -3262,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
93337
93338 flush_module_icache(mod);
93339
93340 - /* Now copy in args */
93341 - mod->args = strndup_user(uargs, ~0UL >> 1);
93342 - if (IS_ERR(mod->args)) {
93343 - err = PTR_ERR(mod->args);
93344 - goto free_arch_cleanup;
93345 - }
93346 -
93347 dynamic_debug_setup(info->debug, info->num_debug);
93348
93349 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
93350 @@ -3311,11 +3468,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
93351 ddebug_cleanup:
93352 dynamic_debug_remove(info->debug);
93353 synchronize_sched();
93354 - kfree(mod->args);
93355 - free_arch_cleanup:
93356 module_arch_cleanup(mod);
93357 free_modinfo:
93358 free_modinfo(mod);
93359 + kfree(mod->args);
93360 free_unload:
93361 module_unload_free(mod);
93362 unlink_mod:
93363 @@ -3398,10 +3554,16 @@ static const char *get_ksymbol(struct module *mod,
93364 unsigned long nextval;
93365
93366 /* At worse, next value is at end of module */
93367 - if (within_module_init(addr, mod))
93368 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
93369 + if (within_module_init_rx(addr, mod))
93370 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
93371 + else if (within_module_init_rw(addr, mod))
93372 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
93373 + else if (within_module_core_rx(addr, mod))
93374 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
93375 + else if (within_module_core_rw(addr, mod))
93376 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
93377 else
93378 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
93379 + return NULL;
93380
93381 /* Scan for closest preceding symbol, and next symbol. (ELF
93382 starts real symbols at 1). */
93383 @@ -3652,7 +3814,7 @@ static int m_show(struct seq_file *m, void *p)
93384 return 0;
93385
93386 seq_printf(m, "%s %u",
93387 - mod->name, mod->init_size + mod->core_size);
93388 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
93389 print_unload_info(m, mod);
93390
93391 /* Informative for users. */
93392 @@ -3661,7 +3823,7 @@ static int m_show(struct seq_file *m, void *p)
93393 mod->state == MODULE_STATE_COMING ? "Loading":
93394 "Live");
93395 /* Used by oprofile and other similar tools. */
93396 - seq_printf(m, " 0x%pK", mod->module_core);
93397 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
93398
93399 /* Taints info */
93400 if (mod->taints)
93401 @@ -3697,7 +3859,17 @@ static const struct file_operations proc_modules_operations = {
93402
93403 static int __init proc_modules_init(void)
93404 {
93405 +#ifndef CONFIG_GRKERNSEC_HIDESYM
93406 +#ifdef CONFIG_GRKERNSEC_PROC_USER
93407 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
93408 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
93409 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
93410 +#else
93411 proc_create("modules", 0, NULL, &proc_modules_operations);
93412 +#endif
93413 +#else
93414 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
93415 +#endif
93416 return 0;
93417 }
93418 module_init(proc_modules_init);
93419 @@ -3758,14 +3930,14 @@ struct module *__module_address(unsigned long addr)
93420 {
93421 struct module *mod;
93422
93423 - if (addr < module_addr_min || addr > module_addr_max)
93424 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
93425 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
93426 return NULL;
93427
93428 list_for_each_entry_rcu(mod, &modules, list) {
93429 if (mod->state == MODULE_STATE_UNFORMED)
93430 continue;
93431 - if (within_module_core(addr, mod)
93432 - || within_module_init(addr, mod))
93433 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
93434 return mod;
93435 }
93436 return NULL;
93437 @@ -3800,11 +3972,20 @@ bool is_module_text_address(unsigned long addr)
93438 */
93439 struct module *__module_text_address(unsigned long addr)
93440 {
93441 - struct module *mod = __module_address(addr);
93442 + struct module *mod;
93443 +
93444 +#ifdef CONFIG_X86_32
93445 + addr = ktla_ktva(addr);
93446 +#endif
93447 +
93448 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
93449 + return NULL;
93450 +
93451 + mod = __module_address(addr);
93452 +
93453 if (mod) {
93454 /* Make sure it's within the text section. */
93455 - if (!within(addr, mod->module_init, mod->init_text_size)
93456 - && !within(addr, mod->module_core, mod->core_text_size))
93457 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
93458 mod = NULL;
93459 }
93460 return mod;
93461 diff --git a/kernel/notifier.c b/kernel/notifier.c
93462 index 4803da6..1c5eea6 100644
93463 --- a/kernel/notifier.c
93464 +++ b/kernel/notifier.c
93465 @@ -5,6 +5,7 @@
93466 #include <linux/rcupdate.h>
93467 #include <linux/vmalloc.h>
93468 #include <linux/reboot.h>
93469 +#include <linux/mm.h>
93470
93471 /*
93472 * Notifier list for kernel code which wants to be called
93473 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
93474 while ((*nl) != NULL) {
93475 if (n->priority > (*nl)->priority)
93476 break;
93477 - nl = &((*nl)->next);
93478 + nl = (struct notifier_block **)&((*nl)->next);
93479 }
93480 - n->next = *nl;
93481 + pax_open_kernel();
93482 + *(const void **)&n->next = *nl;
93483 rcu_assign_pointer(*nl, n);
93484 + pax_close_kernel();
93485 return 0;
93486 }
93487
93488 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
93489 return 0;
93490 if (n->priority > (*nl)->priority)
93491 break;
93492 - nl = &((*nl)->next);
93493 + nl = (struct notifier_block **)&((*nl)->next);
93494 }
93495 - n->next = *nl;
93496 + pax_open_kernel();
93497 + *(const void **)&n->next = *nl;
93498 rcu_assign_pointer(*nl, n);
93499 + pax_close_kernel();
93500 return 0;
93501 }
93502
93503 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
93504 {
93505 while ((*nl) != NULL) {
93506 if ((*nl) == n) {
93507 + pax_open_kernel();
93508 rcu_assign_pointer(*nl, n->next);
93509 + pax_close_kernel();
93510 return 0;
93511 }
93512 - nl = &((*nl)->next);
93513 + nl = (struct notifier_block **)&((*nl)->next);
93514 }
93515 return -ENOENT;
93516 }
93517 diff --git a/kernel/padata.c b/kernel/padata.c
93518 index 161402f..598814c 100644
93519 --- a/kernel/padata.c
93520 +++ b/kernel/padata.c
93521 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
93522 * seq_nr mod. number of cpus in use.
93523 */
93524
93525 - seq_nr = atomic_inc_return(&pd->seq_nr);
93526 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
93527 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
93528
93529 return padata_index_to_cpu(pd, cpu_index);
93530 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
93531 padata_init_pqueues(pd);
93532 padata_init_squeues(pd);
93533 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
93534 - atomic_set(&pd->seq_nr, -1);
93535 + atomic_set_unchecked(&pd->seq_nr, -1);
93536 atomic_set(&pd->reorder_objects, 0);
93537 atomic_set(&pd->refcnt, 0);
93538 pd->pinst = pinst;
93539 diff --git a/kernel/panic.c b/kernel/panic.c
93540 index 62e16ce..9db5047b 100644
93541 --- a/kernel/panic.c
93542 +++ b/kernel/panic.c
93543 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
93544 /*
93545 * Stop ourself in panic -- architecture code may override this
93546 */
93547 -void __weak panic_smp_self_stop(void)
93548 +void __weak __noreturn panic_smp_self_stop(void)
93549 {
93550 while (1)
93551 cpu_relax();
93552 @@ -420,7 +420,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
93553 disable_trace_on_warning();
93554
93555 pr_warn("------------[ cut here ]------------\n");
93556 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
93557 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
93558 raw_smp_processor_id(), current->pid, file, line, caller);
93559
93560 if (args)
93561 @@ -474,7 +474,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
93562 */
93563 __visible void __stack_chk_fail(void)
93564 {
93565 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
93566 + dump_stack();
93567 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
93568 __builtin_return_address(0));
93569 }
93570 EXPORT_SYMBOL(__stack_chk_fail);
93571 diff --git a/kernel/pid.c b/kernel/pid.c
93572 index 9b9a266..c20ef80 100644
93573 --- a/kernel/pid.c
93574 +++ b/kernel/pid.c
93575 @@ -33,6 +33,7 @@
93576 #include <linux/rculist.h>
93577 #include <linux/bootmem.h>
93578 #include <linux/hash.h>
93579 +#include <linux/security.h>
93580 #include <linux/pid_namespace.h>
93581 #include <linux/init_task.h>
93582 #include <linux/syscalls.h>
93583 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
93584
93585 int pid_max = PID_MAX_DEFAULT;
93586
93587 -#define RESERVED_PIDS 300
93588 +#define RESERVED_PIDS 500
93589
93590 int pid_max_min = RESERVED_PIDS + 1;
93591 int pid_max_max = PID_MAX_LIMIT;
93592 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
93593 */
93594 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
93595 {
93596 + struct task_struct *task;
93597 +
93598 rcu_lockdep_assert(rcu_read_lock_held(),
93599 "find_task_by_pid_ns() needs rcu_read_lock()"
93600 " protection");
93601 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
93602 +
93603 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
93604 +
93605 + if (gr_pid_is_chrooted(task))
93606 + return NULL;
93607 +
93608 + return task;
93609 }
93610
93611 struct task_struct *find_task_by_vpid(pid_t vnr)
93612 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
93613 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
93614 }
93615
93616 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
93617 +{
93618 + rcu_lockdep_assert(rcu_read_lock_held(),
93619 + "find_task_by_pid_ns() needs rcu_read_lock()"
93620 + " protection");
93621 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
93622 +}
93623 +
93624 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
93625 {
93626 struct pid *pid;
93627 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
93628 index db95d8e..a0ca23f 100644
93629 --- a/kernel/pid_namespace.c
93630 +++ b/kernel/pid_namespace.c
93631 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
93632 void __user *buffer, size_t *lenp, loff_t *ppos)
93633 {
93634 struct pid_namespace *pid_ns = task_active_pid_ns(current);
93635 - struct ctl_table tmp = *table;
93636 + ctl_table_no_const tmp = *table;
93637
93638 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
93639 return -EPERM;
93640 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
93641 index 3b89464..5e38379 100644
93642 --- a/kernel/posix-cpu-timers.c
93643 +++ b/kernel/posix-cpu-timers.c
93644 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93645
93646 static __init int init_posix_cpu_timers(void)
93647 {
93648 - struct k_clock process = {
93649 + static struct k_clock process = {
93650 .clock_getres = process_cpu_clock_getres,
93651 .clock_get = process_cpu_clock_get,
93652 .timer_create = process_cpu_timer_create,
93653 .nsleep = process_cpu_nsleep,
93654 .nsleep_restart = process_cpu_nsleep_restart,
93655 };
93656 - struct k_clock thread = {
93657 + static struct k_clock thread = {
93658 .clock_getres = thread_cpu_clock_getres,
93659 .clock_get = thread_cpu_clock_get,
93660 .timer_create = thread_cpu_timer_create,
93661 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
93662 index 424c2d4..679242f 100644
93663 --- a/kernel/posix-timers.c
93664 +++ b/kernel/posix-timers.c
93665 @@ -43,6 +43,7 @@
93666 #include <linux/hash.h>
93667 #include <linux/posix-clock.h>
93668 #include <linux/posix-timers.h>
93669 +#include <linux/grsecurity.h>
93670 #include <linux/syscalls.h>
93671 #include <linux/wait.h>
93672 #include <linux/workqueue.h>
93673 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
93674 * which we beg off on and pass to do_sys_settimeofday().
93675 */
93676
93677 -static struct k_clock posix_clocks[MAX_CLOCKS];
93678 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93679
93680 /*
93681 * These ones are defined below.
93682 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93683 */
93684 static __init int init_posix_timers(void)
93685 {
93686 - struct k_clock clock_realtime = {
93687 + static struct k_clock clock_realtime = {
93688 .clock_getres = hrtimer_get_res,
93689 .clock_get = posix_clock_realtime_get,
93690 .clock_set = posix_clock_realtime_set,
93691 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
93692 .timer_get = common_timer_get,
93693 .timer_del = common_timer_del,
93694 };
93695 - struct k_clock clock_monotonic = {
93696 + static struct k_clock clock_monotonic = {
93697 .clock_getres = hrtimer_get_res,
93698 .clock_get = posix_ktime_get_ts,
93699 .nsleep = common_nsleep,
93700 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
93701 .timer_get = common_timer_get,
93702 .timer_del = common_timer_del,
93703 };
93704 - struct k_clock clock_monotonic_raw = {
93705 + static struct k_clock clock_monotonic_raw = {
93706 .clock_getres = hrtimer_get_res,
93707 .clock_get = posix_get_monotonic_raw,
93708 };
93709 - struct k_clock clock_realtime_coarse = {
93710 + static struct k_clock clock_realtime_coarse = {
93711 .clock_getres = posix_get_coarse_res,
93712 .clock_get = posix_get_realtime_coarse,
93713 };
93714 - struct k_clock clock_monotonic_coarse = {
93715 + static struct k_clock clock_monotonic_coarse = {
93716 .clock_getres = posix_get_coarse_res,
93717 .clock_get = posix_get_monotonic_coarse,
93718 };
93719 - struct k_clock clock_tai = {
93720 + static struct k_clock clock_tai = {
93721 .clock_getres = hrtimer_get_res,
93722 .clock_get = posix_get_tai,
93723 .nsleep = common_nsleep,
93724 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
93725 .timer_get = common_timer_get,
93726 .timer_del = common_timer_del,
93727 };
93728 - struct k_clock clock_boottime = {
93729 + static struct k_clock clock_boottime = {
93730 .clock_getres = hrtimer_get_res,
93731 .clock_get = posix_get_boottime,
93732 .nsleep = common_nsleep,
93733 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93734 return;
93735 }
93736
93737 - posix_clocks[clock_id] = *new_clock;
93738 + posix_clocks[clock_id] = new_clock;
93739 }
93740 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93741
93742 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93743 return (id & CLOCKFD_MASK) == CLOCKFD ?
93744 &clock_posix_dynamic : &clock_posix_cpu;
93745
93746 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93747 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93748 return NULL;
93749 - return &posix_clocks[id];
93750 + return posix_clocks[id];
93751 }
93752
93753 static int common_timer_create(struct k_itimer *new_timer)
93754 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93755 struct k_clock *kc = clockid_to_kclock(which_clock);
93756 struct k_itimer *new_timer;
93757 int error, new_timer_id;
93758 - sigevent_t event;
93759 + sigevent_t event = { };
93760 int it_id_set = IT_ID_NOT_SET;
93761
93762 if (!kc)
93763 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93764 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93765 return -EFAULT;
93766
93767 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93768 + have their clock_set fptr set to a nosettime dummy function
93769 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93770 + call common_clock_set, which calls do_sys_settimeofday, which
93771 + we hook
93772 + */
93773 +
93774 return kc->clock_set(which_clock, &new_tp);
93775 }
93776
93777 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
93778 index 9a83d78..128bfc0 100644
93779 --- a/kernel/power/Kconfig
93780 +++ b/kernel/power/Kconfig
93781 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
93782 config HIBERNATION
93783 bool "Hibernation (aka 'suspend to disk')"
93784 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
93785 + depends on !GRKERNSEC_KMEM
93786 + depends on !PAX_MEMORY_SANITIZE
93787 select HIBERNATE_CALLBACKS
93788 select LZO_COMPRESS
93789 select LZO_DECOMPRESS
93790 diff --git a/kernel/power/process.c b/kernel/power/process.c
93791 index 4ee194e..925778f 100644
93792 --- a/kernel/power/process.c
93793 +++ b/kernel/power/process.c
93794 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
93795 unsigned int elapsed_msecs;
93796 bool wakeup = false;
93797 int sleep_usecs = USEC_PER_MSEC;
93798 + bool timedout = false;
93799
93800 do_gettimeofday(&start);
93801
93802 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
93803
93804 while (true) {
93805 todo = 0;
93806 + if (time_after(jiffies, end_time))
93807 + timedout = true;
93808 read_lock(&tasklist_lock);
93809 do_each_thread(g, p) {
93810 if (p == current || !freeze_task(p))
93811 continue;
93812
93813 - if (!freezer_should_skip(p))
93814 + if (!freezer_should_skip(p)) {
93815 todo++;
93816 + if (timedout) {
93817 + printk(KERN_ERR "Task refusing to freeze:\n");
93818 + sched_show_task(p);
93819 + }
93820 + }
93821 } while_each_thread(g, p);
93822 read_unlock(&tasklist_lock);
93823
93824 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
93825 todo += wq_busy;
93826 }
93827
93828 - if (!todo || time_after(jiffies, end_time))
93829 + if (!todo || timedout)
93830 break;
93831
93832 if (pm_wakeup_pending()) {
93833 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
93834 index 13e839d..8a71f12 100644
93835 --- a/kernel/printk/printk.c
93836 +++ b/kernel/printk/printk.c
93837 @@ -480,6 +480,11 @@ static int check_syslog_permissions(int type, bool from_file)
93838 if (from_file && type != SYSLOG_ACTION_OPEN)
93839 return 0;
93840
93841 +#ifdef CONFIG_GRKERNSEC_DMESG
93842 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
93843 + return -EPERM;
93844 +#endif
93845 +
93846 if (syslog_action_restricted(type)) {
93847 if (capable(CAP_SYSLOG))
93848 return 0;
93849 diff --git a/kernel/profile.c b/kernel/profile.c
93850 index 54bf5ba..df6e0a2 100644
93851 --- a/kernel/profile.c
93852 +++ b/kernel/profile.c
93853 @@ -37,7 +37,7 @@ struct profile_hit {
93854 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
93855 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
93856
93857 -static atomic_t *prof_buffer;
93858 +static atomic_unchecked_t *prof_buffer;
93859 static unsigned long prof_len, prof_shift;
93860
93861 int prof_on __read_mostly;
93862 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
93863 hits[i].pc = 0;
93864 continue;
93865 }
93866 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
93867 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
93868 hits[i].hits = hits[i].pc = 0;
93869 }
93870 }
93871 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
93872 * Add the current hit(s) and flush the write-queue out
93873 * to the global buffer:
93874 */
93875 - atomic_add(nr_hits, &prof_buffer[pc]);
93876 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
93877 for (i = 0; i < NR_PROFILE_HIT; ++i) {
93878 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
93879 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
93880 hits[i].pc = hits[i].hits = 0;
93881 }
93882 out:
93883 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
93884 {
93885 unsigned long pc;
93886 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
93887 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
93888 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
93889 }
93890 #endif /* !CONFIG_SMP */
93891
93892 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
93893 return -EFAULT;
93894 buf++; p++; count--; read++;
93895 }
93896 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
93897 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
93898 if (copy_to_user(buf, (void *)pnt, count))
93899 return -EFAULT;
93900 read += count;
93901 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
93902 }
93903 #endif
93904 profile_discard_flip_buffers();
93905 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
93906 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
93907 return count;
93908 }
93909
93910 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
93911 index adf9862..9d86345 100644
93912 --- a/kernel/ptrace.c
93913 +++ b/kernel/ptrace.c
93914 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
93915 if (seize)
93916 flags |= PT_SEIZED;
93917 rcu_read_lock();
93918 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
93919 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
93920 flags |= PT_PTRACE_CAP;
93921 rcu_read_unlock();
93922 task->ptrace = flags;
93923 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
93924 break;
93925 return -EIO;
93926 }
93927 - if (copy_to_user(dst, buf, retval))
93928 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
93929 return -EFAULT;
93930 copied += retval;
93931 src += retval;
93932 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
93933 bool seized = child->ptrace & PT_SEIZED;
93934 int ret = -EIO;
93935 siginfo_t siginfo, *si;
93936 - void __user *datavp = (void __user *) data;
93937 + void __user *datavp = (__force void __user *) data;
93938 unsigned long __user *datalp = datavp;
93939 unsigned long flags;
93940
93941 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
93942 goto out;
93943 }
93944
93945 + if (gr_handle_ptrace(child, request)) {
93946 + ret = -EPERM;
93947 + goto out_put_task_struct;
93948 + }
93949 +
93950 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
93951 ret = ptrace_attach(child, request, addr, data);
93952 /*
93953 * Some architectures need to do book-keeping after
93954 * a ptrace attach.
93955 */
93956 - if (!ret)
93957 + if (!ret) {
93958 arch_ptrace_attach(child);
93959 + gr_audit_ptrace(child);
93960 + }
93961 goto out_put_task_struct;
93962 }
93963
93964 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
93965 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
93966 if (copied != sizeof(tmp))
93967 return -EIO;
93968 - return put_user(tmp, (unsigned long __user *)data);
93969 + return put_user(tmp, (__force unsigned long __user *)data);
93970 }
93971
93972 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
93973 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
93974 }
93975
93976 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
93977 - compat_long_t, addr, compat_long_t, data)
93978 + compat_ulong_t, addr, compat_ulong_t, data)
93979 {
93980 struct task_struct *child;
93981 long ret;
93982 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
93983 goto out;
93984 }
93985
93986 + if (gr_handle_ptrace(child, request)) {
93987 + ret = -EPERM;
93988 + goto out_put_task_struct;
93989 + }
93990 +
93991 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
93992 ret = ptrace_attach(child, request, addr, data);
93993 /*
93994 * Some architectures need to do book-keeping after
93995 * a ptrace attach.
93996 */
93997 - if (!ret)
93998 + if (!ret) {
93999 arch_ptrace_attach(child);
94000 + gr_audit_ptrace(child);
94001 + }
94002 goto out_put_task_struct;
94003 }
94004
94005 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
94006 index 948a769..5ca842b 100644
94007 --- a/kernel/rcu/rcutorture.c
94008 +++ b/kernel/rcu/rcutorture.c
94009 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
94010 rcu_torture_count) = { 0 };
94011 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
94012 rcu_torture_batch) = { 0 };
94013 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
94014 -static atomic_t n_rcu_torture_alloc;
94015 -static atomic_t n_rcu_torture_alloc_fail;
94016 -static atomic_t n_rcu_torture_free;
94017 -static atomic_t n_rcu_torture_mberror;
94018 -static atomic_t n_rcu_torture_error;
94019 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
94020 +static atomic_unchecked_t n_rcu_torture_alloc;
94021 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
94022 +static atomic_unchecked_t n_rcu_torture_free;
94023 +static atomic_unchecked_t n_rcu_torture_mberror;
94024 +static atomic_unchecked_t n_rcu_torture_error;
94025 static long n_rcu_torture_barrier_error;
94026 static long n_rcu_torture_boost_ktrerror;
94027 static long n_rcu_torture_boost_rterror;
94028 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
94029
94030 spin_lock_bh(&rcu_torture_lock);
94031 if (list_empty(&rcu_torture_freelist)) {
94032 - atomic_inc(&n_rcu_torture_alloc_fail);
94033 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
94034 spin_unlock_bh(&rcu_torture_lock);
94035 return NULL;
94036 }
94037 - atomic_inc(&n_rcu_torture_alloc);
94038 + atomic_inc_unchecked(&n_rcu_torture_alloc);
94039 p = rcu_torture_freelist.next;
94040 list_del_init(p);
94041 spin_unlock_bh(&rcu_torture_lock);
94042 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
94043 static void
94044 rcu_torture_free(struct rcu_torture *p)
94045 {
94046 - atomic_inc(&n_rcu_torture_free);
94047 + atomic_inc_unchecked(&n_rcu_torture_free);
94048 spin_lock_bh(&rcu_torture_lock);
94049 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
94050 spin_unlock_bh(&rcu_torture_lock);
94051 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
94052 i = rp->rtort_pipe_count;
94053 if (i > RCU_TORTURE_PIPE_LEN)
94054 i = RCU_TORTURE_PIPE_LEN;
94055 - atomic_inc(&rcu_torture_wcount[i]);
94056 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
94057 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
94058 rp->rtort_mbtest = 0;
94059 return true;
94060 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
94061 i = old_rp->rtort_pipe_count;
94062 if (i > RCU_TORTURE_PIPE_LEN)
94063 i = RCU_TORTURE_PIPE_LEN;
94064 - atomic_inc(&rcu_torture_wcount[i]);
94065 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
94066 old_rp->rtort_pipe_count++;
94067 switch (synctype[torture_random(&rand) % nsynctypes]) {
94068 case RTWS_DEF_FREE:
94069 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
94070 return;
94071 }
94072 if (p->rtort_mbtest == 0)
94073 - atomic_inc(&n_rcu_torture_mberror);
94074 + atomic_inc_unchecked(&n_rcu_torture_mberror);
94075 spin_lock(&rand_lock);
94076 cur_ops->read_delay(&rand);
94077 n_rcu_torture_timers++;
94078 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
94079 continue;
94080 }
94081 if (p->rtort_mbtest == 0)
94082 - atomic_inc(&n_rcu_torture_mberror);
94083 + atomic_inc_unchecked(&n_rcu_torture_mberror);
94084 cur_ops->read_delay(&rand);
94085 preempt_disable();
94086 pipe_count = p->rtort_pipe_count;
94087 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
94088 }
94089 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
94090 page += sprintf(page,
94091 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
94092 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
94093 rcu_torture_current,
94094 rcu_torture_current_version,
94095 list_empty(&rcu_torture_freelist),
94096 - atomic_read(&n_rcu_torture_alloc),
94097 - atomic_read(&n_rcu_torture_alloc_fail),
94098 - atomic_read(&n_rcu_torture_free));
94099 + atomic_read_unchecked(&n_rcu_torture_alloc),
94100 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
94101 + atomic_read_unchecked(&n_rcu_torture_free));
94102 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
94103 - atomic_read(&n_rcu_torture_mberror),
94104 + atomic_read_unchecked(&n_rcu_torture_mberror),
94105 n_rcu_torture_boost_ktrerror,
94106 n_rcu_torture_boost_rterror);
94107 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
94108 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
94109 n_barrier_attempts,
94110 n_rcu_torture_barrier_error);
94111 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
94112 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
94113 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
94114 n_rcu_torture_barrier_error != 0 ||
94115 n_rcu_torture_boost_ktrerror != 0 ||
94116 n_rcu_torture_boost_rterror != 0 ||
94117 n_rcu_torture_boost_failure != 0 ||
94118 i > 1) {
94119 page += sprintf(page, "!!! ");
94120 - atomic_inc(&n_rcu_torture_error);
94121 + atomic_inc_unchecked(&n_rcu_torture_error);
94122 WARN_ON_ONCE(1);
94123 }
94124 page += sprintf(page, "Reader Pipe: ");
94125 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
94126 page += sprintf(page, "Free-Block Circulation: ");
94127 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
94128 page += sprintf(page, " %d",
94129 - atomic_read(&rcu_torture_wcount[i]));
94130 + atomic_read_unchecked(&rcu_torture_wcount[i]));
94131 }
94132 page += sprintf(page, "\n");
94133 if (cur_ops->stats)
94134 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
94135
94136 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
94137
94138 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
94139 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
94140 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
94141 else if (torture_onoff_failures())
94142 rcu_torture_print_module_parms(cur_ops,
94143 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
94144
94145 rcu_torture_current = NULL;
94146 rcu_torture_current_version = 0;
94147 - atomic_set(&n_rcu_torture_alloc, 0);
94148 - atomic_set(&n_rcu_torture_alloc_fail, 0);
94149 - atomic_set(&n_rcu_torture_free, 0);
94150 - atomic_set(&n_rcu_torture_mberror, 0);
94151 - atomic_set(&n_rcu_torture_error, 0);
94152 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
94153 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
94154 + atomic_set_unchecked(&n_rcu_torture_free, 0);
94155 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
94156 + atomic_set_unchecked(&n_rcu_torture_error, 0);
94157 n_rcu_torture_barrier_error = 0;
94158 n_rcu_torture_boost_ktrerror = 0;
94159 n_rcu_torture_boost_rterror = 0;
94160 n_rcu_torture_boost_failure = 0;
94161 n_rcu_torture_boosts = 0;
94162 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
94163 - atomic_set(&rcu_torture_wcount[i], 0);
94164 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
94165 for_each_possible_cpu(cpu) {
94166 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
94167 per_cpu(rcu_torture_count, cpu)[i] = 0;
94168 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
94169 index c639556..cf0a0d5 100644
94170 --- a/kernel/rcu/srcu.c
94171 +++ b/kernel/rcu/srcu.c
94172 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
94173
94174 idx = ACCESS_ONCE(sp->completed) & 0x1;
94175 preempt_disable();
94176 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
94177 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
94178 smp_mb(); /* B */ /* Avoid leaking the critical section. */
94179 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
94180 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
94181 preempt_enable();
94182 return idx;
94183 }
94184 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
94185 index d9efcc1..ea543e9 100644
94186 --- a/kernel/rcu/tiny.c
94187 +++ b/kernel/rcu/tiny.c
94188 @@ -42,7 +42,7 @@
94189 /* Forward declarations for tiny_plugin.h. */
94190 struct rcu_ctrlblk;
94191 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
94192 -static void rcu_process_callbacks(struct softirq_action *unused);
94193 +static void rcu_process_callbacks(void);
94194 static void __call_rcu(struct rcu_head *head,
94195 void (*func)(struct rcu_head *rcu),
94196 struct rcu_ctrlblk *rcp);
94197 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
94198 false));
94199 }
94200
94201 -static void rcu_process_callbacks(struct softirq_action *unused)
94202 +static __latent_entropy void rcu_process_callbacks(void)
94203 {
94204 __rcu_process_callbacks(&rcu_sched_ctrlblk);
94205 __rcu_process_callbacks(&rcu_bh_ctrlblk);
94206 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
94207 index 858c565..7efd915 100644
94208 --- a/kernel/rcu/tiny_plugin.h
94209 +++ b/kernel/rcu/tiny_plugin.h
94210 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
94211 dump_stack();
94212 }
94213 if (*rcp->curtail && ULONG_CMP_GE(j, js))
94214 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
94215 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
94216 3 * rcu_jiffies_till_stall_check() + 3;
94217 else if (ULONG_CMP_GE(j, js))
94218 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
94219 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
94220 }
94221
94222 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
94223 {
94224 rcp->ticks_this_gp = 0;
94225 rcp->gp_start = jiffies;
94226 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
94227 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
94228 }
94229
94230 static void check_cpu_stalls(void)
94231 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
94232 index 625d0b0..0bce4d6 100644
94233 --- a/kernel/rcu/tree.c
94234 +++ b/kernel/rcu/tree.c
94235 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
94236 */
94237 rdtp = this_cpu_ptr(&rcu_dynticks);
94238 smp_mb__before_atomic(); /* Earlier stuff before QS. */
94239 - atomic_add(2, &rdtp->dynticks); /* QS. */
94240 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
94241 smp_mb__after_atomic(); /* Later stuff after QS. */
94242 break;
94243 }
94244 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
94245 rcu_prepare_for_idle(smp_processor_id());
94246 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
94247 smp_mb__before_atomic(); /* See above. */
94248 - atomic_inc(&rdtp->dynticks);
94249 + atomic_inc_unchecked(&rdtp->dynticks);
94250 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
94251 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
94252 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
94253
94254 /*
94255 * It is illegal to enter an extended quiescent state while
94256 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
94257 int user)
94258 {
94259 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
94260 - atomic_inc(&rdtp->dynticks);
94261 + atomic_inc_unchecked(&rdtp->dynticks);
94262 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
94263 smp_mb__after_atomic(); /* See above. */
94264 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
94265 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
94266 rcu_cleanup_after_idle(smp_processor_id());
94267 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
94268 if (!user && !is_idle_task(current)) {
94269 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
94270 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
94271
94272 if (rdtp->dynticks_nmi_nesting == 0 &&
94273 - (atomic_read(&rdtp->dynticks) & 0x1))
94274 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
94275 return;
94276 rdtp->dynticks_nmi_nesting++;
94277 smp_mb__before_atomic(); /* Force delay from prior write. */
94278 - atomic_inc(&rdtp->dynticks);
94279 + atomic_inc_unchecked(&rdtp->dynticks);
94280 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
94281 smp_mb__after_atomic(); /* See above. */
94282 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
94283 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
94284 }
94285
94286 /**
94287 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
94288 return;
94289 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
94290 smp_mb__before_atomic(); /* See above. */
94291 - atomic_inc(&rdtp->dynticks);
94292 + atomic_inc_unchecked(&rdtp->dynticks);
94293 smp_mb__after_atomic(); /* Force delay to next write. */
94294 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
94295 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
94296 }
94297
94298 /**
94299 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
94300 */
94301 bool notrace __rcu_is_watching(void)
94302 {
94303 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
94304 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
94305 }
94306
94307 /**
94308 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
94309 static int dyntick_save_progress_counter(struct rcu_data *rdp,
94310 bool *isidle, unsigned long *maxj)
94311 {
94312 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
94313 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
94314 rcu_sysidle_check_cpu(rdp, isidle, maxj);
94315 if ((rdp->dynticks_snap & 0x1) == 0) {
94316 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
94317 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
94318 int *rcrmp;
94319 unsigned int snap;
94320
94321 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
94322 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
94323 snap = (unsigned int)rdp->dynticks_snap;
94324
94325 /*
94326 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
94327 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
94328 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
94329 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
94330 - ACCESS_ONCE(rdp->cond_resched_completed) =
94331 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
94332 ACCESS_ONCE(rdp->mynode->completed);
94333 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
94334 - ACCESS_ONCE(*rcrmp) =
94335 + ACCESS_ONCE_RW(*rcrmp) =
94336 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
94337 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
94338 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
94339 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
94340 rsp->gp_start = j;
94341 smp_wmb(); /* Record start time before stall time. */
94342 j1 = rcu_jiffies_till_stall_check();
94343 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
94344 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
94345 rsp->jiffies_resched = j + j1 / 2;
94346 }
94347
94348 @@ -1052,7 +1052,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
94349 raw_spin_unlock_irqrestore(&rnp->lock, flags);
94350 return;
94351 }
94352 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
94353 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
94354 raw_spin_unlock_irqrestore(&rnp->lock, flags);
94355
94356 /*
94357 @@ -1130,7 +1130,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
94358
94359 raw_spin_lock_irqsave(&rnp->lock, flags);
94360 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
94361 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
94362 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
94363 3 * rcu_jiffies_till_stall_check() + 3;
94364 raw_spin_unlock_irqrestore(&rnp->lock, flags);
94365
94366 @@ -1214,7 +1214,7 @@ void rcu_cpu_stall_reset(void)
94367 struct rcu_state *rsp;
94368
94369 for_each_rcu_flavor(rsp)
94370 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
94371 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
94372 }
94373
94374 /*
94375 @@ -1594,7 +1594,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
94376 raw_spin_unlock_irq(&rnp->lock);
94377 return 0;
94378 }
94379 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
94380 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
94381
94382 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
94383 /*
94384 @@ -1635,9 +1635,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
94385 rdp = this_cpu_ptr(rsp->rda);
94386 rcu_preempt_check_blocked_tasks(rnp);
94387 rnp->qsmask = rnp->qsmaskinit;
94388 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
94389 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
94390 WARN_ON_ONCE(rnp->completed != rsp->completed);
94391 - ACCESS_ONCE(rnp->completed) = rsp->completed;
94392 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
94393 if (rnp == rdp->mynode)
94394 (void)__note_gp_changes(rsp, rnp, rdp);
94395 rcu_preempt_boost_start_gp(rnp);
94396 @@ -1687,7 +1687,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
94397 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
94398 raw_spin_lock_irq(&rnp->lock);
94399 smp_mb__after_unlock_lock();
94400 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
94401 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
94402 raw_spin_unlock_irq(&rnp->lock);
94403 }
94404 return fqs_state;
94405 @@ -1732,7 +1732,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
94406 rcu_for_each_node_breadth_first(rsp, rnp) {
94407 raw_spin_lock_irq(&rnp->lock);
94408 smp_mb__after_unlock_lock();
94409 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
94410 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
94411 rdp = this_cpu_ptr(rsp->rda);
94412 if (rnp == rdp->mynode)
94413 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
94414 @@ -1747,14 +1747,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
94415 rcu_nocb_gp_set(rnp, nocb);
94416
94417 /* Declare grace period done. */
94418 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
94419 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
94420 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
94421 rsp->fqs_state = RCU_GP_IDLE;
94422 rdp = this_cpu_ptr(rsp->rda);
94423 /* Advance CBs to reduce false positives below. */
94424 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
94425 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
94426 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
94427 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
94428 trace_rcu_grace_period(rsp->name,
94429 ACCESS_ONCE(rsp->gpnum),
94430 TPS("newreq"));
94431 @@ -1879,7 +1879,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
94432 */
94433 return false;
94434 }
94435 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
94436 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
94437 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
94438 TPS("newreq"));
94439
94440 @@ -2100,7 +2100,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
94441 rsp->qlen += rdp->qlen;
94442 rdp->n_cbs_orphaned += rdp->qlen;
94443 rdp->qlen_lazy = 0;
94444 - ACCESS_ONCE(rdp->qlen) = 0;
94445 + ACCESS_ONCE_RW(rdp->qlen) = 0;
94446 }
94447
94448 /*
94449 @@ -2347,7 +2347,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
94450 }
94451 smp_mb(); /* List handling before counting for rcu_barrier(). */
94452 rdp->qlen_lazy -= count_lazy;
94453 - ACCESS_ONCE(rdp->qlen) -= count;
94454 + ACCESS_ONCE_RW(rdp->qlen) -= count;
94455 rdp->n_cbs_invoked += count;
94456
94457 /* Reinstate batch limit if we have worked down the excess. */
94458 @@ -2492,7 +2492,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
94459 if (rnp_old != NULL)
94460 raw_spin_unlock(&rnp_old->fqslock);
94461 if (ret) {
94462 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
94463 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
94464 return;
94465 }
94466 rnp_old = rnp;
94467 @@ -2504,11 +2504,11 @@ static void force_quiescent_state(struct rcu_state *rsp)
94468 smp_mb__after_unlock_lock();
94469 raw_spin_unlock(&rnp_old->fqslock);
94470 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
94471 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
94472 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
94473 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
94474 return; /* Someone beat us to it. */
94475 }
94476 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
94477 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
94478 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
94479 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
94480 }
94481 @@ -2553,7 +2553,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
94482 /*
94483 * Do RCU core processing for the current CPU.
94484 */
94485 -static void rcu_process_callbacks(struct softirq_action *unused)
94486 +static void rcu_process_callbacks(void)
94487 {
94488 struct rcu_state *rsp;
94489
94490 @@ -2665,7 +2665,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
94491 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
94492 if (debug_rcu_head_queue(head)) {
94493 /* Probable double call_rcu(), so leak the callback. */
94494 - ACCESS_ONCE(head->func) = rcu_leak_callback;
94495 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
94496 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
94497 return;
94498 }
94499 @@ -2693,7 +2693,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
94500 local_irq_restore(flags);
94501 return;
94502 }
94503 - ACCESS_ONCE(rdp->qlen)++;
94504 + ACCESS_ONCE_RW(rdp->qlen)++;
94505 if (lazy)
94506 rdp->qlen_lazy++;
94507 else
94508 @@ -2968,11 +2968,11 @@ void synchronize_sched_expedited(void)
94509 * counter wrap on a 32-bit system. Quite a few more CPUs would of
94510 * course be required on a 64-bit system.
94511 */
94512 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
94513 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
94514 (ulong)atomic_long_read(&rsp->expedited_done) +
94515 ULONG_MAX / 8)) {
94516 synchronize_sched();
94517 - atomic_long_inc(&rsp->expedited_wrap);
94518 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
94519 return;
94520 }
94521
94522 @@ -2980,7 +2980,7 @@ void synchronize_sched_expedited(void)
94523 * Take a ticket. Note that atomic_inc_return() implies a
94524 * full memory barrier.
94525 */
94526 - snap = atomic_long_inc_return(&rsp->expedited_start);
94527 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
94528 firstsnap = snap;
94529 get_online_cpus();
94530 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
94531 @@ -2993,14 +2993,14 @@ void synchronize_sched_expedited(void)
94532 synchronize_sched_expedited_cpu_stop,
94533 NULL) == -EAGAIN) {
94534 put_online_cpus();
94535 - atomic_long_inc(&rsp->expedited_tryfail);
94536 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
94537
94538 /* Check to see if someone else did our work for us. */
94539 s = atomic_long_read(&rsp->expedited_done);
94540 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
94541 /* ensure test happens before caller kfree */
94542 smp_mb__before_atomic(); /* ^^^ */
94543 - atomic_long_inc(&rsp->expedited_workdone1);
94544 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
94545 return;
94546 }
94547
94548 @@ -3009,7 +3009,7 @@ void synchronize_sched_expedited(void)
94549 udelay(trycount * num_online_cpus());
94550 } else {
94551 wait_rcu_gp(call_rcu_sched);
94552 - atomic_long_inc(&rsp->expedited_normal);
94553 + atomic_long_inc_unchecked(&rsp->expedited_normal);
94554 return;
94555 }
94556
94557 @@ -3018,7 +3018,7 @@ void synchronize_sched_expedited(void)
94558 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
94559 /* ensure test happens before caller kfree */
94560 smp_mb__before_atomic(); /* ^^^ */
94561 - atomic_long_inc(&rsp->expedited_workdone2);
94562 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
94563 return;
94564 }
94565
94566 @@ -3030,10 +3030,10 @@ void synchronize_sched_expedited(void)
94567 * period works for us.
94568 */
94569 get_online_cpus();
94570 - snap = atomic_long_read(&rsp->expedited_start);
94571 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
94572 smp_mb(); /* ensure read is before try_stop_cpus(). */
94573 }
94574 - atomic_long_inc(&rsp->expedited_stoppedcpus);
94575 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
94576
94577 /*
94578 * Everyone up to our most recent fetch is covered by our grace
94579 @@ -3042,16 +3042,16 @@ void synchronize_sched_expedited(void)
94580 * than we did already did their update.
94581 */
94582 do {
94583 - atomic_long_inc(&rsp->expedited_done_tries);
94584 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
94585 s = atomic_long_read(&rsp->expedited_done);
94586 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
94587 /* ensure test happens before caller kfree */
94588 smp_mb__before_atomic(); /* ^^^ */
94589 - atomic_long_inc(&rsp->expedited_done_lost);
94590 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
94591 break;
94592 }
94593 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
94594 - atomic_long_inc(&rsp->expedited_done_exit);
94595 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
94596
94597 put_online_cpus();
94598 }
94599 @@ -3257,7 +3257,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
94600 * ACCESS_ONCE() to prevent the compiler from speculating
94601 * the increment to precede the early-exit check.
94602 */
94603 - ACCESS_ONCE(rsp->n_barrier_done)++;
94604 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
94605 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
94606 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
94607 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
94608 @@ -3307,7 +3307,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
94609
94610 /* Increment ->n_barrier_done to prevent duplicate work. */
94611 smp_mb(); /* Keep increment after above mechanism. */
94612 - ACCESS_ONCE(rsp->n_barrier_done)++;
94613 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
94614 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
94615 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
94616 smp_mb(); /* Keep increment before caller's subsequent code. */
94617 @@ -3352,10 +3352,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
94618 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
94619 init_callback_list(rdp);
94620 rdp->qlen_lazy = 0;
94621 - ACCESS_ONCE(rdp->qlen) = 0;
94622 + ACCESS_ONCE_RW(rdp->qlen) = 0;
94623 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
94624 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
94625 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
94626 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
94627 rdp->cpu = cpu;
94628 rdp->rsp = rsp;
94629 rcu_boot_init_nocb_percpu_data(rdp);
94630 @@ -3388,8 +3388,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
94631 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
94632 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
94633 rcu_sysidle_init_percpu_data(rdp->dynticks);
94634 - atomic_set(&rdp->dynticks->dynticks,
94635 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
94636 + atomic_set_unchecked(&rdp->dynticks->dynticks,
94637 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
94638 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
94639
94640 /* Add CPU to rcu_node bitmasks. */
94641 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
94642 index 0f69a79..c85c2dc 100644
94643 --- a/kernel/rcu/tree.h
94644 +++ b/kernel/rcu/tree.h
94645 @@ -87,11 +87,11 @@ struct rcu_dynticks {
94646 long long dynticks_nesting; /* Track irq/process nesting level. */
94647 /* Process level is worth LLONG_MAX/2. */
94648 int dynticks_nmi_nesting; /* Track NMI nesting level. */
94649 - atomic_t dynticks; /* Even value for idle, else odd. */
94650 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
94651 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
94652 long long dynticks_idle_nesting;
94653 /* irq/process nesting level from idle. */
94654 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
94655 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
94656 /* "Idle" excludes userspace execution. */
94657 unsigned long dynticks_idle_jiffies;
94658 /* End of last non-NMI non-idle period. */
94659 @@ -435,17 +435,17 @@ struct rcu_state {
94660 /* _rcu_barrier(). */
94661 /* End of fields guarded by barrier_mutex. */
94662
94663 - atomic_long_t expedited_start; /* Starting ticket. */
94664 - atomic_long_t expedited_done; /* Done ticket. */
94665 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
94666 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
94667 - atomic_long_t expedited_workdone1; /* # done by others #1. */
94668 - atomic_long_t expedited_workdone2; /* # done by others #2. */
94669 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
94670 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
94671 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
94672 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
94673 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
94674 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
94675 + atomic_long_t expedited_done; /* Done ticket. */
94676 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
94677 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
94678 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
94679 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
94680 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
94681 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
94682 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
94683 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
94684 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
94685
94686 unsigned long jiffies_force_qs; /* Time at which to invoke */
94687 /* force_quiescent_state(). */
94688 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
94689 index 02ac0fb..4aa4a36 100644
94690 --- a/kernel/rcu/tree_plugin.h
94691 +++ b/kernel/rcu/tree_plugin.h
94692 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
94693 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
94694 {
94695 return !rcu_preempted_readers_exp(rnp) &&
94696 - ACCESS_ONCE(rnp->expmask) == 0;
94697 + ACCESS_ONCE_RW(rnp->expmask) == 0;
94698 }
94699
94700 /*
94701 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
94702
94703 /* Clean up and exit. */
94704 smp_mb(); /* ensure expedited GP seen before counter increment. */
94705 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
94706 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
94707 unlock_mb_ret:
94708 mutex_unlock(&sync_rcu_preempt_exp_mutex);
94709 mb_ret:
94710 @@ -1447,7 +1447,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
94711 free_cpumask_var(cm);
94712 }
94713
94714 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
94715 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
94716 .store = &rcu_cpu_kthread_task,
94717 .thread_should_run = rcu_cpu_kthread_should_run,
94718 .thread_fn = rcu_cpu_kthread,
94719 @@ -1926,7 +1926,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
94720 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
94721 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
94722 cpu, ticks_value, ticks_title,
94723 - atomic_read(&rdtp->dynticks) & 0xfff,
94724 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
94725 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
94726 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
94727 fast_no_hz);
94728 @@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
94729
94730 /* Enqueue the callback on the nocb list and update counts. */
94731 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
94732 - ACCESS_ONCE(*old_rhpp) = rhp;
94733 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
94734 atomic_long_add(rhcount, &rdp->nocb_q_count);
94735 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
94736
94737 @@ -2255,12 +2255,12 @@ static int rcu_nocb_kthread(void *arg)
94738 * Extract queued callbacks, update counts, and wait
94739 * for a grace period to elapse.
94740 */
94741 - ACCESS_ONCE(rdp->nocb_head) = NULL;
94742 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
94743 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
94744 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
94745 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
94746 - ACCESS_ONCE(rdp->nocb_p_count) += c;
94747 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
94748 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
94749 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
94750 rcu_nocb_wait_gp(rdp);
94751
94752 /* Each pass through the following loop invokes a callback. */
94753 @@ -2286,8 +2286,8 @@ static int rcu_nocb_kthread(void *arg)
94754 list = next;
94755 }
94756 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
94757 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
94758 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
94759 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
94760 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
94761 rdp->n_nocbs_invoked += c;
94762 }
94763 return 0;
94764 @@ -2304,7 +2304,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
94765 {
94766 if (!rcu_nocb_need_deferred_wakeup(rdp))
94767 return;
94768 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
94769 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
94770 wake_up(&rdp->nocb_wq);
94771 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
94772 }
94773 @@ -2330,7 +2330,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
94774 t = kthread_run(rcu_nocb_kthread, rdp,
94775 "rcuo%c/%d", rsp->abbr, cpu);
94776 BUG_ON(IS_ERR(t));
94777 - ACCESS_ONCE(rdp->nocb_kthread) = t;
94778 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
94779 }
94780 }
94781
94782 @@ -2461,11 +2461,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
94783
94784 /* Record start of fully idle period. */
94785 j = jiffies;
94786 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
94787 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
94788 smp_mb__before_atomic();
94789 - atomic_inc(&rdtp->dynticks_idle);
94790 + atomic_inc_unchecked(&rdtp->dynticks_idle);
94791 smp_mb__after_atomic();
94792 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
94793 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
94794 }
94795
94796 /*
94797 @@ -2530,9 +2530,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
94798
94799 /* Record end of idle period. */
94800 smp_mb__before_atomic();
94801 - atomic_inc(&rdtp->dynticks_idle);
94802 + atomic_inc_unchecked(&rdtp->dynticks_idle);
94803 smp_mb__after_atomic();
94804 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
94805 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
94806
94807 /*
94808 * If we are the timekeeping CPU, we are permitted to be non-idle
94809 @@ -2573,7 +2573,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
94810 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
94811
94812 /* Pick up current idle and NMI-nesting counter and check. */
94813 - cur = atomic_read(&rdtp->dynticks_idle);
94814 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
94815 if (cur & 0x1) {
94816 *isidle = false; /* We are not idle! */
94817 return;
94818 @@ -2622,7 +2622,7 @@ static void rcu_sysidle(unsigned long j)
94819 case RCU_SYSIDLE_NOT:
94820
94821 /* First time all are idle, so note a short idle period. */
94822 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
94823 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
94824 break;
94825
94826 case RCU_SYSIDLE_SHORT:
94827 @@ -2660,7 +2660,7 @@ static void rcu_sysidle_cancel(void)
94828 {
94829 smp_mb();
94830 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
94831 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
94832 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
94833 }
94834
94835 /*
94836 @@ -2708,7 +2708,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
94837 smp_mb(); /* grace period precedes setting inuse. */
94838
94839 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
94840 - ACCESS_ONCE(rshp->inuse) = 0;
94841 + ACCESS_ONCE_RW(rshp->inuse) = 0;
94842 }
94843
94844 /*
94845 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
94846 index 5cdc62e..cc52e88 100644
94847 --- a/kernel/rcu/tree_trace.c
94848 +++ b/kernel/rcu/tree_trace.c
94849 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
94850 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
94851 rdp->passed_quiesce, rdp->qs_pending);
94852 seq_printf(m, " dt=%d/%llx/%d df=%lu",
94853 - atomic_read(&rdp->dynticks->dynticks),
94854 + atomic_read_unchecked(&rdp->dynticks->dynticks),
94855 rdp->dynticks->dynticks_nesting,
94856 rdp->dynticks->dynticks_nmi_nesting,
94857 rdp->dynticks_fqs);
94858 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
94859 struct rcu_state *rsp = (struct rcu_state *)m->private;
94860
94861 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",
94862 - atomic_long_read(&rsp->expedited_start),
94863 + atomic_long_read_unchecked(&rsp->expedited_start),
94864 atomic_long_read(&rsp->expedited_done),
94865 - atomic_long_read(&rsp->expedited_wrap),
94866 - atomic_long_read(&rsp->expedited_tryfail),
94867 - atomic_long_read(&rsp->expedited_workdone1),
94868 - atomic_long_read(&rsp->expedited_workdone2),
94869 - atomic_long_read(&rsp->expedited_normal),
94870 - atomic_long_read(&rsp->expedited_stoppedcpus),
94871 - atomic_long_read(&rsp->expedited_done_tries),
94872 - atomic_long_read(&rsp->expedited_done_lost),
94873 - atomic_long_read(&rsp->expedited_done_exit));
94874 + atomic_long_read_unchecked(&rsp->expedited_wrap),
94875 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
94876 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
94877 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
94878 + atomic_long_read_unchecked(&rsp->expedited_normal),
94879 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
94880 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
94881 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
94882 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
94883 return 0;
94884 }
94885
94886 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
94887 index bc78835..7691a45 100644
94888 --- a/kernel/rcu/update.c
94889 +++ b/kernel/rcu/update.c
94890 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
94891 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
94892 */
94893 if (till_stall_check < 3) {
94894 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
94895 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
94896 till_stall_check = 3;
94897 } else if (till_stall_check > 300) {
94898 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
94899 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
94900 till_stall_check = 300;
94901 }
94902 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
94903 diff --git a/kernel/resource.c b/kernel/resource.c
94904 index 3c2237a..4568d96 100644
94905 --- a/kernel/resource.c
94906 +++ b/kernel/resource.c
94907 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
94908
94909 static int __init ioresources_init(void)
94910 {
94911 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94912 +#ifdef CONFIG_GRKERNSEC_PROC_USER
94913 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
94914 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
94915 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94916 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
94917 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
94918 +#endif
94919 +#else
94920 proc_create("ioports", 0, NULL, &proc_ioports_operations);
94921 proc_create("iomem", 0, NULL, &proc_iomem_operations);
94922 +#endif
94923 return 0;
94924 }
94925 __initcall(ioresources_init);
94926 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
94927 index e73efba..c9bfbd4 100644
94928 --- a/kernel/sched/auto_group.c
94929 +++ b/kernel/sched/auto_group.c
94930 @@ -11,7 +11,7 @@
94931
94932 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
94933 static struct autogroup autogroup_default;
94934 -static atomic_t autogroup_seq_nr;
94935 +static atomic_unchecked_t autogroup_seq_nr;
94936
94937 void __init autogroup_init(struct task_struct *init_task)
94938 {
94939 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
94940
94941 kref_init(&ag->kref);
94942 init_rwsem(&ag->lock);
94943 - ag->id = atomic_inc_return(&autogroup_seq_nr);
94944 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
94945 ag->tg = tg;
94946 #ifdef CONFIG_RT_GROUP_SCHED
94947 /*
94948 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
94949 index a63f4dc..349bbb0 100644
94950 --- a/kernel/sched/completion.c
94951 +++ b/kernel/sched/completion.c
94952 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
94953 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
94954 * or number of jiffies left till timeout) if completed.
94955 */
94956 -long __sched
94957 +long __sched __intentional_overflow(-1)
94958 wait_for_completion_interruptible_timeout(struct completion *x,
94959 unsigned long timeout)
94960 {
94961 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
94962 *
94963 * Return: -ERESTARTSYS if interrupted, 0 if completed.
94964 */
94965 -int __sched wait_for_completion_killable(struct completion *x)
94966 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
94967 {
94968 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
94969 if (t == -ERESTARTSYS)
94970 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
94971 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
94972 * or number of jiffies left till timeout) if completed.
94973 */
94974 -long __sched
94975 +long __sched __intentional_overflow(-1)
94976 wait_for_completion_killable_timeout(struct completion *x,
94977 unsigned long timeout)
94978 {
94979 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
94980 index 0acf96b..80ba955 100644
94981 --- a/kernel/sched/core.c
94982 +++ b/kernel/sched/core.c
94983 @@ -1849,7 +1849,7 @@ void set_numabalancing_state(bool enabled)
94984 int sysctl_numa_balancing(struct ctl_table *table, int write,
94985 void __user *buffer, size_t *lenp, loff_t *ppos)
94986 {
94987 - struct ctl_table t;
94988 + ctl_table_no_const t;
94989 int err;
94990 int state = numabalancing_enabled;
94991
94992 @@ -2312,8 +2312,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
94993 next->active_mm = oldmm;
94994 atomic_inc(&oldmm->mm_count);
94995 enter_lazy_tlb(oldmm, next);
94996 - } else
94997 + } else {
94998 switch_mm(oldmm, mm, next);
94999 + populate_stack();
95000 + }
95001
95002 if (!prev->mm) {
95003 prev->active_mm = NULL;
95004 @@ -3081,6 +3083,8 @@ int can_nice(const struct task_struct *p, const int nice)
95005 /* convert nice value [19,-20] to rlimit style value [1,40] */
95006 int nice_rlim = nice_to_rlimit(nice);
95007
95008 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
95009 +
95010 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
95011 capable(CAP_SYS_NICE));
95012 }
95013 @@ -3107,7 +3111,8 @@ SYSCALL_DEFINE1(nice, int, increment)
95014 nice = task_nice(current) + increment;
95015
95016 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
95017 - if (increment < 0 && !can_nice(current, nice))
95018 + if (increment < 0 && (!can_nice(current, nice) ||
95019 + gr_handle_chroot_nice()))
95020 return -EPERM;
95021
95022 retval = security_task_setnice(current, nice);
95023 @@ -3380,6 +3385,7 @@ recheck:
95024 if (policy != p->policy && !rlim_rtprio)
95025 return -EPERM;
95026
95027 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
95028 /* can't increase priority */
95029 if (attr->sched_priority > p->rt_priority &&
95030 attr->sched_priority > rlim_rtprio)
95031 @@ -4772,6 +4778,7 @@ void idle_task_exit(void)
95032
95033 if (mm != &init_mm) {
95034 switch_mm(mm, &init_mm, current);
95035 + populate_stack();
95036 finish_arch_post_lock_switch();
95037 }
95038 mmdrop(mm);
95039 @@ -4867,7 +4874,7 @@ static void migrate_tasks(unsigned int dead_cpu)
95040
95041 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
95042
95043 -static struct ctl_table sd_ctl_dir[] = {
95044 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
95045 {
95046 .procname = "sched_domain",
95047 .mode = 0555,
95048 @@ -4884,17 +4891,17 @@ static struct ctl_table sd_ctl_root[] = {
95049 {}
95050 };
95051
95052 -static struct ctl_table *sd_alloc_ctl_entry(int n)
95053 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
95054 {
95055 - struct ctl_table *entry =
95056 + ctl_table_no_const *entry =
95057 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
95058
95059 return entry;
95060 }
95061
95062 -static void sd_free_ctl_entry(struct ctl_table **tablep)
95063 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
95064 {
95065 - struct ctl_table *entry;
95066 + ctl_table_no_const *entry;
95067
95068 /*
95069 * In the intermediate directories, both the child directory and
95070 @@ -4902,22 +4909,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
95071 * will always be set. In the lowest directory the names are
95072 * static strings and all have proc handlers.
95073 */
95074 - for (entry = *tablep; entry->mode; entry++) {
95075 - if (entry->child)
95076 - sd_free_ctl_entry(&entry->child);
95077 + for (entry = tablep; entry->mode; entry++) {
95078 + if (entry->child) {
95079 + sd_free_ctl_entry(entry->child);
95080 + pax_open_kernel();
95081 + entry->child = NULL;
95082 + pax_close_kernel();
95083 + }
95084 if (entry->proc_handler == NULL)
95085 kfree(entry->procname);
95086 }
95087
95088 - kfree(*tablep);
95089 - *tablep = NULL;
95090 + kfree(tablep);
95091 }
95092
95093 static int min_load_idx = 0;
95094 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
95095
95096 static void
95097 -set_table_entry(struct ctl_table *entry,
95098 +set_table_entry(ctl_table_no_const *entry,
95099 const char *procname, void *data, int maxlen,
95100 umode_t mode, proc_handler *proc_handler,
95101 bool load_idx)
95102 @@ -4937,7 +4947,7 @@ set_table_entry(struct ctl_table *entry,
95103 static struct ctl_table *
95104 sd_alloc_ctl_domain_table(struct sched_domain *sd)
95105 {
95106 - struct ctl_table *table = sd_alloc_ctl_entry(14);
95107 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
95108
95109 if (table == NULL)
95110 return NULL;
95111 @@ -4975,9 +4985,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
95112 return table;
95113 }
95114
95115 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
95116 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
95117 {
95118 - struct ctl_table *entry, *table;
95119 + ctl_table_no_const *entry, *table;
95120 struct sched_domain *sd;
95121 int domain_num = 0, i;
95122 char buf[32];
95123 @@ -5004,11 +5014,13 @@ static struct ctl_table_header *sd_sysctl_header;
95124 static void register_sched_domain_sysctl(void)
95125 {
95126 int i, cpu_num = num_possible_cpus();
95127 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
95128 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
95129 char buf[32];
95130
95131 WARN_ON(sd_ctl_dir[0].child);
95132 + pax_open_kernel();
95133 sd_ctl_dir[0].child = entry;
95134 + pax_close_kernel();
95135
95136 if (entry == NULL)
95137 return;
95138 @@ -5031,8 +5043,12 @@ static void unregister_sched_domain_sysctl(void)
95139 if (sd_sysctl_header)
95140 unregister_sysctl_table(sd_sysctl_header);
95141 sd_sysctl_header = NULL;
95142 - if (sd_ctl_dir[0].child)
95143 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
95144 + if (sd_ctl_dir[0].child) {
95145 + sd_free_ctl_entry(sd_ctl_dir[0].child);
95146 + pax_open_kernel();
95147 + sd_ctl_dir[0].child = NULL;
95148 + pax_close_kernel();
95149 + }
95150 }
95151 #else
95152 static void register_sched_domain_sysctl(void)
95153 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
95154 index fea7d33..84faa94 100644
95155 --- a/kernel/sched/fair.c
95156 +++ b/kernel/sched/fair.c
95157 @@ -1857,7 +1857,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
95158
95159 static void reset_ptenuma_scan(struct task_struct *p)
95160 {
95161 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
95162 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
95163 p->mm->numa_scan_offset = 0;
95164 }
95165
95166 @@ -7289,7 +7289,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
95167 * run_rebalance_domains is triggered when needed from the scheduler tick.
95168 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
95169 */
95170 -static void run_rebalance_domains(struct softirq_action *h)
95171 +static __latent_entropy void run_rebalance_domains(void)
95172 {
95173 struct rq *this_rq = this_rq();
95174 enum cpu_idle_type idle = this_rq->idle_balance ?
95175 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
95176 index 31cc02e..734fb85 100644
95177 --- a/kernel/sched/sched.h
95178 +++ b/kernel/sched/sched.h
95179 @@ -1153,7 +1153,7 @@ struct sched_class {
95180 #ifdef CONFIG_FAIR_GROUP_SCHED
95181 void (*task_move_group) (struct task_struct *p, int on_rq);
95182 #endif
95183 -};
95184 +} __do_const;
95185
95186 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
95187 {
95188 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
95189 index 301bbc2..eda2da3 100644
95190 --- a/kernel/seccomp.c
95191 +++ b/kernel/seccomp.c
95192 @@ -39,7 +39,7 @@
95193 * is only needed for handling filters shared across tasks.
95194 * @prev: points to a previously installed, or inherited, filter
95195 * @len: the number of instructions in the program
95196 - * @insnsi: the BPF program instructions to evaluate
95197 + * @insns: the BPF program instructions to evaluate
95198 *
95199 * seccomp_filter objects are organized in a tree linked via the @prev
95200 * pointer. For any task, it appears to be a singly-linked list starting
95201 @@ -54,32 +54,61 @@
95202 struct seccomp_filter {
95203 atomic_t usage;
95204 struct seccomp_filter *prev;
95205 - struct sk_filter *prog;
95206 + unsigned short len; /* Instruction count */
95207 + struct sock_filter insns[];
95208 };
95209
95210 /* Limit any path through the tree to 256KB worth of instructions. */
95211 #define MAX_INSNS_PER_PATH ((1 << 18) / sizeof(struct sock_filter))
95212
95213 -/*
95214 +/**
95215 + * get_u32 - returns a u32 offset into data
95216 + * @data: a unsigned 64 bit value
95217 + * @index: 0 or 1 to return the first or second 32-bits
95218 + *
95219 + * This inline exists to hide the length of unsigned long. If a 32-bit
95220 + * unsigned long is passed in, it will be extended and the top 32-bits will be
95221 + * 0. If it is a 64-bit unsigned long, then whatever data is resident will be
95222 + * properly returned.
95223 + *
95224 * Endianness is explicitly ignored and left for BPF program authors to manage
95225 * as per the specific architecture.
95226 */
95227 -static void populate_seccomp_data(struct seccomp_data *sd)
95228 +static inline u32 get_u32(u64 data, int index)
95229 {
95230 - struct task_struct *task = current;
95231 - struct pt_regs *regs = task_pt_regs(task);
95232 - unsigned long args[6];
95233 + return ((u32 *)&data)[index];
95234 +}
95235
95236 - sd->nr = syscall_get_nr(task, regs);
95237 - sd->arch = syscall_get_arch();
95238 - syscall_get_arguments(task, regs, 0, 6, args);
95239 - sd->args[0] = args[0];
95240 - sd->args[1] = args[1];
95241 - sd->args[2] = args[2];
95242 - sd->args[3] = args[3];
95243 - sd->args[4] = args[4];
95244 - sd->args[5] = args[5];
95245 - sd->instruction_pointer = KSTK_EIP(task);
95246 +/* Helper for bpf_load below. */
95247 +#define BPF_DATA(_name) offsetof(struct seccomp_data, _name)
95248 +/**
95249 + * bpf_load: checks and returns a pointer to the requested offset
95250 + * @off: offset into struct seccomp_data to load from
95251 + *
95252 + * Returns the requested 32-bits of data.
95253 + * seccomp_check_filter() should assure that @off is 32-bit aligned
95254 + * and not out of bounds. Failure to do so is a BUG.
95255 + */
95256 +u32 seccomp_bpf_load(int off)
95257 +{
95258 + struct pt_regs *regs = task_pt_regs(current);
95259 + if (off == BPF_DATA(nr))
95260 + return syscall_get_nr(current, regs);
95261 + if (off == BPF_DATA(arch))
95262 + return syscall_get_arch();
95263 + if (off >= BPF_DATA(args[0]) && off < BPF_DATA(args[6])) {
95264 + unsigned long value;
95265 + int arg = (off - BPF_DATA(args[0])) / sizeof(u64);
95266 + int index = !!(off % sizeof(u64));
95267 + syscall_get_arguments(current, regs, arg, 1, &value);
95268 + return get_u32(value, index);
95269 + }
95270 + if (off == BPF_DATA(instruction_pointer))
95271 + return get_u32(KSTK_EIP(current), 0);
95272 + if (off == BPF_DATA(instruction_pointer) + sizeof(u32))
95273 + return get_u32(KSTK_EIP(current), 1);
95274 + /* seccomp_check_filter should make this impossible. */
95275 + BUG();
95276 }
95277
95278 /**
95279 @@ -103,59 +132,59 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
95280 u32 k = ftest->k;
95281
95282 switch (code) {
95283 - case BPF_LD | BPF_W | BPF_ABS:
95284 - ftest->code = BPF_LDX | BPF_W | BPF_ABS;
95285 + case BPF_S_LD_W_ABS:
95286 + ftest->code = BPF_S_ANC_SECCOMP_LD_W;
95287 /* 32-bit aligned and not out of bounds. */
95288 if (k >= sizeof(struct seccomp_data) || k & 3)
95289 return -EINVAL;
95290 continue;
95291 - case BPF_LD | BPF_W | BPF_LEN:
95292 - ftest->code = BPF_LD | BPF_IMM;
95293 + case BPF_S_LD_W_LEN:
95294 + ftest->code = BPF_S_LD_IMM;
95295 ftest->k = sizeof(struct seccomp_data);
95296 continue;
95297 - case BPF_LDX | BPF_W | BPF_LEN:
95298 - ftest->code = BPF_LDX | BPF_IMM;
95299 + case BPF_S_LDX_W_LEN:
95300 + ftest->code = BPF_S_LDX_IMM;
95301 ftest->k = sizeof(struct seccomp_data);
95302 continue;
95303 /* Explicitly include allowed calls. */
95304 - case BPF_RET | BPF_K:
95305 - case BPF_RET | BPF_A:
95306 - case BPF_ALU | BPF_ADD | BPF_K:
95307 - case BPF_ALU | BPF_ADD | BPF_X:
95308 - case BPF_ALU | BPF_SUB | BPF_K:
95309 - case BPF_ALU | BPF_SUB | BPF_X:
95310 - case BPF_ALU | BPF_MUL | BPF_K:
95311 - case BPF_ALU | BPF_MUL | BPF_X:
95312 - case BPF_ALU | BPF_DIV | BPF_K:
95313 - case BPF_ALU | BPF_DIV | BPF_X:
95314 - case BPF_ALU | BPF_AND | BPF_K:
95315 - case BPF_ALU | BPF_AND | BPF_X:
95316 - case BPF_ALU | BPF_OR | BPF_K:
95317 - case BPF_ALU | BPF_OR | BPF_X:
95318 - case BPF_ALU | BPF_XOR | BPF_K:
95319 - case BPF_ALU | BPF_XOR | BPF_X:
95320 - case BPF_ALU | BPF_LSH | BPF_K:
95321 - case BPF_ALU | BPF_LSH | BPF_X:
95322 - case BPF_ALU | BPF_RSH | BPF_K:
95323 - case BPF_ALU | BPF_RSH | BPF_X:
95324 - case BPF_ALU | BPF_NEG:
95325 - case BPF_LD | BPF_IMM:
95326 - case BPF_LDX | BPF_IMM:
95327 - case BPF_MISC | BPF_TAX:
95328 - case BPF_MISC | BPF_TXA:
95329 - case BPF_LD | BPF_MEM:
95330 - case BPF_LDX | BPF_MEM:
95331 - case BPF_ST:
95332 - case BPF_STX:
95333 - case BPF_JMP | BPF_JA:
95334 - case BPF_JMP | BPF_JEQ | BPF_K:
95335 - case BPF_JMP | BPF_JEQ | BPF_X:
95336 - case BPF_JMP | BPF_JGE | BPF_K:
95337 - case BPF_JMP | BPF_JGE | BPF_X:
95338 - case BPF_JMP | BPF_JGT | BPF_K:
95339 - case BPF_JMP | BPF_JGT | BPF_X:
95340 - case BPF_JMP | BPF_JSET | BPF_K:
95341 - case BPF_JMP | BPF_JSET | BPF_X:
95342 + case BPF_S_RET_K:
95343 + case BPF_S_RET_A:
95344 + case BPF_S_ALU_ADD_K:
95345 + case BPF_S_ALU_ADD_X:
95346 + case BPF_S_ALU_SUB_K:
95347 + case BPF_S_ALU_SUB_X:
95348 + case BPF_S_ALU_MUL_K:
95349 + case BPF_S_ALU_MUL_X:
95350 + case BPF_S_ALU_DIV_X:
95351 + case BPF_S_ALU_AND_K:
95352 + case BPF_S_ALU_AND_X:
95353 + case BPF_S_ALU_OR_K:
95354 + case BPF_S_ALU_OR_X:
95355 + case BPF_S_ALU_XOR_K:
95356 + case BPF_S_ALU_XOR_X:
95357 + case BPF_S_ALU_LSH_K:
95358 + case BPF_S_ALU_LSH_X:
95359 + case BPF_S_ALU_RSH_K:
95360 + case BPF_S_ALU_RSH_X:
95361 + case BPF_S_ALU_NEG:
95362 + case BPF_S_LD_IMM:
95363 + case BPF_S_LDX_IMM:
95364 + case BPF_S_MISC_TAX:
95365 + case BPF_S_MISC_TXA:
95366 + case BPF_S_ALU_DIV_K:
95367 + case BPF_S_LD_MEM:
95368 + case BPF_S_LDX_MEM:
95369 + case BPF_S_ST:
95370 + case BPF_S_STX:
95371 + case BPF_S_JMP_JA:
95372 + case BPF_S_JMP_JEQ_K:
95373 + case BPF_S_JMP_JEQ_X:
95374 + case BPF_S_JMP_JGE_K:
95375 + case BPF_S_JMP_JGE_X:
95376 + case BPF_S_JMP_JGT_K:
95377 + case BPF_S_JMP_JGT_X:
95378 + case BPF_S_JMP_JSET_K:
95379 + case BPF_S_JMP_JSET_X:
95380 continue;
95381 default:
95382 return -EINVAL;
95383 @@ -173,22 +202,18 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
95384 static u32 seccomp_run_filters(int syscall)
95385 {
95386 struct seccomp_filter *f;
95387 - struct seccomp_data sd;
95388 u32 ret = SECCOMP_RET_ALLOW;
95389
95390 /* Ensure unexpected behavior doesn't result in failing open. */
95391 if (WARN_ON(current->seccomp.filter == NULL))
95392 return SECCOMP_RET_KILL;
95393
95394 - populate_seccomp_data(&sd);
95395 -
95396 /*
95397 * All filters in the list are evaluated and the lowest BPF return
95398 * value always takes priority (ignoring the DATA).
95399 */
95400 for (f = current->seccomp.filter; f; f = f->prev) {
95401 - u32 cur_ret = SK_RUN_FILTER(f->prog, (void *)&sd);
95402 -
95403 + u32 cur_ret = sk_run_filter(NULL, f->insns);
95404 if ((cur_ret & SECCOMP_RET_ACTION) < (ret & SECCOMP_RET_ACTION))
95405 ret = cur_ret;
95406 }
95407 @@ -206,20 +231,18 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
95408 struct seccomp_filter *filter;
95409 unsigned long fp_size = fprog->len * sizeof(struct sock_filter);
95410 unsigned long total_insns = fprog->len;
95411 - struct sock_filter *fp;
95412 - int new_len;
95413 long ret;
95414
95415 if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
95416 return -EINVAL;
95417
95418 for (filter = current->seccomp.filter; filter; filter = filter->prev)
95419 - total_insns += filter->prog->len + 4; /* include a 4 instr penalty */
95420 + total_insns += filter->len + 4; /* include a 4 instr penalty */
95421 if (total_insns > MAX_INSNS_PER_PATH)
95422 return -ENOMEM;
95423
95424 /*
95425 - * Installing a seccomp filter requires that the task has
95426 + * Installing a seccomp filter requires that the task have
95427 * CAP_SYS_ADMIN in its namespace or be running with no_new_privs.
95428 * This avoids scenarios where unprivileged tasks can affect the
95429 * behavior of privileged children.
95430 @@ -229,51 +252,28 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
95431 CAP_SYS_ADMIN) != 0)
95432 return -EACCES;
95433
95434 - fp = kzalloc(fp_size, GFP_KERNEL|__GFP_NOWARN);
95435 - if (!fp)
95436 - return -ENOMEM;
95437 -
95438 - /* Copy the instructions from fprog. */
95439 - ret = -EFAULT;
95440 - if (copy_from_user(fp, fprog->filter, fp_size))
95441 - goto free_prog;
95442 -
95443 - /* Check and rewrite the fprog via the skb checker */
95444 - ret = sk_chk_filter(fp, fprog->len);
95445 - if (ret)
95446 - goto free_prog;
95447 -
95448 - /* Check and rewrite the fprog for seccomp use */
95449 - ret = seccomp_check_filter(fp, fprog->len);
95450 - if (ret)
95451 - goto free_prog;
95452 -
95453 - /* Convert 'sock_filter' insns to 'sock_filter_int' insns */
95454 - ret = sk_convert_filter(fp, fprog->len, NULL, &new_len);
95455 - if (ret)
95456 - goto free_prog;
95457 -
95458 /* Allocate a new seccomp_filter */
95459 - ret = -ENOMEM;
95460 - filter = kzalloc(sizeof(struct seccomp_filter),
95461 + filter = kzalloc(sizeof(struct seccomp_filter) + fp_size,
95462 GFP_KERNEL|__GFP_NOWARN);
95463 if (!filter)
95464 - goto free_prog;
95465 -
95466 - filter->prog = kzalloc(sk_filter_size(new_len),
95467 - GFP_KERNEL|__GFP_NOWARN);
95468 - if (!filter->prog)
95469 - goto free_filter;
95470 -
95471 - ret = sk_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
95472 - if (ret)
95473 - goto free_filter_prog;
95474 - kfree(fp);
95475 -
95476 + return -ENOMEM;
95477 atomic_set(&filter->usage, 1);
95478 - filter->prog->len = new_len;
95479 + filter->len = fprog->len;
95480
95481 - sk_filter_select_runtime(filter->prog);
95482 + /* Copy the instructions from fprog. */
95483 + ret = -EFAULT;
95484 + if (copy_from_user(filter->insns, fprog->filter, fp_size))
95485 + goto fail;
95486 +
95487 + /* Check and rewrite the fprog via the skb checker */
95488 + ret = sk_chk_filter(filter->insns, filter->len);
95489 + if (ret)
95490 + goto fail;
95491 +
95492 + /* Check and rewrite the fprog for seccomp use */
95493 + ret = seccomp_check_filter(filter->insns, filter->len);
95494 + if (ret)
95495 + goto fail;
95496
95497 /*
95498 * If there is an existing filter, make it the prev and don't drop its
95499 @@ -282,13 +282,8 @@ static long seccomp_attach_filter(struct sock_fprog *fprog)
95500 filter->prev = current->seccomp.filter;
95501 current->seccomp.filter = filter;
95502 return 0;
95503 -
95504 -free_filter_prog:
95505 - kfree(filter->prog);
95506 -free_filter:
95507 +fail:
95508 kfree(filter);
95509 -free_prog:
95510 - kfree(fp);
95511 return ret;
95512 }
95513
95514 @@ -298,7 +293,7 @@ free_prog:
95515 *
95516 * Returns 0 on success and non-zero otherwise.
95517 */
95518 -static long seccomp_attach_user_filter(char __user *user_filter)
95519 +long seccomp_attach_user_filter(char __user *user_filter)
95520 {
95521 struct sock_fprog fprog;
95522 long ret = -EFAULT;
95523 @@ -337,7 +332,6 @@ void put_seccomp_filter(struct task_struct *tsk)
95524 while (orig && atomic_dec_and_test(&orig->usage)) {
95525 struct seccomp_filter *freeme = orig;
95526 orig = orig->prev;
95527 - sk_filter_free(freeme->prog);
95528 kfree(freeme);
95529 }
95530 }
95531 diff --git a/kernel/signal.c b/kernel/signal.c
95532 index a4077e9..f0d4e5c 100644
95533 --- a/kernel/signal.c
95534 +++ b/kernel/signal.c
95535 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
95536
95537 int print_fatal_signals __read_mostly;
95538
95539 -static void __user *sig_handler(struct task_struct *t, int sig)
95540 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
95541 {
95542 return t->sighand->action[sig - 1].sa.sa_handler;
95543 }
95544
95545 -static int sig_handler_ignored(void __user *handler, int sig)
95546 +static int sig_handler_ignored(__sighandler_t handler, int sig)
95547 {
95548 /* Is it explicitly or implicitly ignored? */
95549 return handler == SIG_IGN ||
95550 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
95551
95552 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
95553 {
95554 - void __user *handler;
95555 + __sighandler_t handler;
95556
95557 handler = sig_handler(t, sig);
95558
95559 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
95560 atomic_inc(&user->sigpending);
95561 rcu_read_unlock();
95562
95563 + if (!override_rlimit)
95564 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
95565 +
95566 if (override_rlimit ||
95567 atomic_read(&user->sigpending) <=
95568 task_rlimit(t, RLIMIT_SIGPENDING)) {
95569 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
95570
95571 int unhandled_signal(struct task_struct *tsk, int sig)
95572 {
95573 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
95574 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
95575 if (is_global_init(tsk))
95576 return 1;
95577 if (handler != SIG_IGN && handler != SIG_DFL)
95578 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
95579 }
95580 }
95581
95582 + /* allow glibc communication via tgkill to other threads in our
95583 + thread group */
95584 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
95585 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
95586 + && gr_handle_signal(t, sig))
95587 + return -EPERM;
95588 +
95589 return security_task_kill(t, info, sig, 0);
95590 }
95591
95592 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
95593 return send_signal(sig, info, p, 1);
95594 }
95595
95596 -static int
95597 +int
95598 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
95599 {
95600 return send_signal(sig, info, t, 0);
95601 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
95602 unsigned long int flags;
95603 int ret, blocked, ignored;
95604 struct k_sigaction *action;
95605 + int is_unhandled = 0;
95606
95607 spin_lock_irqsave(&t->sighand->siglock, flags);
95608 action = &t->sighand->action[sig-1];
95609 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
95610 }
95611 if (action->sa.sa_handler == SIG_DFL)
95612 t->signal->flags &= ~SIGNAL_UNKILLABLE;
95613 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
95614 + is_unhandled = 1;
95615 ret = specific_send_sig_info(sig, info, t);
95616 spin_unlock_irqrestore(&t->sighand->siglock, flags);
95617
95618 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
95619 + normal operation */
95620 + if (is_unhandled) {
95621 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
95622 + gr_handle_crash(t, sig);
95623 + }
95624 +
95625 return ret;
95626 }
95627
95628 @@ -1296,8 +1316,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
95629 ret = check_kill_permission(sig, info, p);
95630 rcu_read_unlock();
95631
95632 - if (!ret && sig)
95633 + if (!ret && sig) {
95634 ret = do_send_sig_info(sig, info, p, true);
95635 + if (!ret)
95636 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
95637 + }
95638
95639 return ret;
95640 }
95641 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
95642 int error = -ESRCH;
95643
95644 rcu_read_lock();
95645 - p = find_task_by_vpid(pid);
95646 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
95647 + /* allow glibc communication via tgkill to other threads in our
95648 + thread group */
95649 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
95650 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
95651 + p = find_task_by_vpid_unrestricted(pid);
95652 + else
95653 +#endif
95654 + p = find_task_by_vpid(pid);
95655 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
95656 error = check_kill_permission(sig, info, p);
95657 /*
95658 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
95659 }
95660 seg = get_fs();
95661 set_fs(KERNEL_DS);
95662 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
95663 - (stack_t __force __user *) &uoss,
95664 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
95665 + (stack_t __force_user *) &uoss,
95666 compat_user_stack_pointer());
95667 set_fs(seg);
95668 if (ret >= 0 && uoss_ptr) {
95669 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
95670 index eb89e18..a4e6792 100644
95671 --- a/kernel/smpboot.c
95672 +++ b/kernel/smpboot.c
95673 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
95674 }
95675 smpboot_unpark_thread(plug_thread, cpu);
95676 }
95677 - list_add(&plug_thread->list, &hotplug_threads);
95678 + pax_list_add(&plug_thread->list, &hotplug_threads);
95679 out:
95680 mutex_unlock(&smpboot_threads_lock);
95681 return ret;
95682 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
95683 {
95684 get_online_cpus();
95685 mutex_lock(&smpboot_threads_lock);
95686 - list_del(&plug_thread->list);
95687 + pax_list_del(&plug_thread->list);
95688 smpboot_destroy_threads(plug_thread);
95689 mutex_unlock(&smpboot_threads_lock);
95690 put_online_cpus();
95691 diff --git a/kernel/softirq.c b/kernel/softirq.c
95692 index 5918d22..e95d1926 100644
95693 --- a/kernel/softirq.c
95694 +++ b/kernel/softirq.c
95695 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
95696 EXPORT_SYMBOL(irq_stat);
95697 #endif
95698
95699 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
95700 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
95701
95702 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
95703
95704 @@ -266,7 +266,7 @@ restart:
95705 kstat_incr_softirqs_this_cpu(vec_nr);
95706
95707 trace_softirq_entry(vec_nr);
95708 - h->action(h);
95709 + h->action();
95710 trace_softirq_exit(vec_nr);
95711 if (unlikely(prev_count != preempt_count())) {
95712 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
95713 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
95714 or_softirq_pending(1UL << nr);
95715 }
95716
95717 -void open_softirq(int nr, void (*action)(struct softirq_action *))
95718 +void __init open_softirq(int nr, void (*action)(void))
95719 {
95720 softirq_vec[nr].action = action;
95721 }
95722 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
95723 }
95724 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
95725
95726 -static void tasklet_action(struct softirq_action *a)
95727 +static void tasklet_action(void)
95728 {
95729 struct tasklet_struct *list;
95730
95731 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
95732 }
95733 }
95734
95735 -static void tasklet_hi_action(struct softirq_action *a)
95736 +static __latent_entropy void tasklet_hi_action(void)
95737 {
95738 struct tasklet_struct *list;
95739
95740 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
95741 .notifier_call = cpu_callback
95742 };
95743
95744 -static struct smp_hotplug_thread softirq_threads = {
95745 +static struct smp_hotplug_thread softirq_threads __read_only = {
95746 .store = &ksoftirqd,
95747 .thread_should_run = ksoftirqd_should_run,
95748 .thread_fn = run_ksoftirqd,
95749 diff --git a/kernel/sys.c b/kernel/sys.c
95750 index 66a751e..a42497e 100644
95751 --- a/kernel/sys.c
95752 +++ b/kernel/sys.c
95753 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
95754 error = -EACCES;
95755 goto out;
95756 }
95757 +
95758 + if (gr_handle_chroot_setpriority(p, niceval)) {
95759 + error = -EACCES;
95760 + goto out;
95761 + }
95762 +
95763 no_nice = security_task_setnice(p, niceval);
95764 if (no_nice) {
95765 error = no_nice;
95766 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
95767 goto error;
95768 }
95769
95770 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
95771 + goto error;
95772 +
95773 + if (!gid_eq(new->gid, old->gid)) {
95774 + /* make sure we generate a learn log for what will
95775 + end up being a role transition after a full-learning
95776 + policy is generated
95777 + CAP_SETGID is required to perform a transition
95778 + we may not log a CAP_SETGID check above, e.g.
95779 + in the case where new rgid = old egid
95780 + */
95781 + gr_learn_cap(current, new, CAP_SETGID);
95782 + }
95783 +
95784 if (rgid != (gid_t) -1 ||
95785 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
95786 new->sgid = new->egid;
95787 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
95788 old = current_cred();
95789
95790 retval = -EPERM;
95791 +
95792 + if (gr_check_group_change(kgid, kgid, kgid))
95793 + goto error;
95794 +
95795 if (ns_capable(old->user_ns, CAP_SETGID))
95796 new->gid = new->egid = new->sgid = new->fsgid = kgid;
95797 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
95798 @@ -403,7 +427,7 @@ error:
95799 /*
95800 * change the user struct in a credentials set to match the new UID
95801 */
95802 -static int set_user(struct cred *new)
95803 +int set_user(struct cred *new)
95804 {
95805 struct user_struct *new_user;
95806
95807 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
95808 goto error;
95809 }
95810
95811 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
95812 + goto error;
95813 +
95814 if (!uid_eq(new->uid, old->uid)) {
95815 + /* make sure we generate a learn log for what will
95816 + end up being a role transition after a full-learning
95817 + policy is generated
95818 + CAP_SETUID is required to perform a transition
95819 + we may not log a CAP_SETUID check above, e.g.
95820 + in the case where new ruid = old euid
95821 + */
95822 + gr_learn_cap(current, new, CAP_SETUID);
95823 retval = set_user(new);
95824 if (retval < 0)
95825 goto error;
95826 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
95827 old = current_cred();
95828
95829 retval = -EPERM;
95830 +
95831 + if (gr_check_crash_uid(kuid))
95832 + goto error;
95833 + if (gr_check_user_change(kuid, kuid, kuid))
95834 + goto error;
95835 +
95836 if (ns_capable(old->user_ns, CAP_SETUID)) {
95837 new->suid = new->uid = kuid;
95838 if (!uid_eq(kuid, old->uid)) {
95839 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
95840 goto error;
95841 }
95842
95843 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
95844 + goto error;
95845 +
95846 if (ruid != (uid_t) -1) {
95847 new->uid = kruid;
95848 if (!uid_eq(kruid, old->uid)) {
95849 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
95850 goto error;
95851 }
95852
95853 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
95854 + goto error;
95855 +
95856 if (rgid != (gid_t) -1)
95857 new->gid = krgid;
95858 if (egid != (gid_t) -1)
95859 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
95860 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
95861 ns_capable(old->user_ns, CAP_SETUID)) {
95862 if (!uid_eq(kuid, old->fsuid)) {
95863 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
95864 + goto error;
95865 +
95866 new->fsuid = kuid;
95867 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
95868 goto change_okay;
95869 }
95870 }
95871
95872 +error:
95873 abort_creds(new);
95874 return old_fsuid;
95875
95876 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
95877 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
95878 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
95879 ns_capable(old->user_ns, CAP_SETGID)) {
95880 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
95881 + goto error;
95882 +
95883 if (!gid_eq(kgid, old->fsgid)) {
95884 new->fsgid = kgid;
95885 goto change_okay;
95886 }
95887 }
95888
95889 +error:
95890 abort_creds(new);
95891 return old_fsgid;
95892
95893 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
95894 return -EFAULT;
95895
95896 down_read(&uts_sem);
95897 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
95898 + error = __copy_to_user(name->sysname, &utsname()->sysname,
95899 __OLD_UTS_LEN);
95900 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
95901 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
95902 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
95903 __OLD_UTS_LEN);
95904 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
95905 - error |= __copy_to_user(&name->release, &utsname()->release,
95906 + error |= __copy_to_user(name->release, &utsname()->release,
95907 __OLD_UTS_LEN);
95908 error |= __put_user(0, name->release + __OLD_UTS_LEN);
95909 - error |= __copy_to_user(&name->version, &utsname()->version,
95910 + error |= __copy_to_user(name->version, &utsname()->version,
95911 __OLD_UTS_LEN);
95912 error |= __put_user(0, name->version + __OLD_UTS_LEN);
95913 - error |= __copy_to_user(&name->machine, &utsname()->machine,
95914 + error |= __copy_to_user(name->machine, &utsname()->machine,
95915 __OLD_UTS_LEN);
95916 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
95917 up_read(&uts_sem);
95918 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
95919 */
95920 new_rlim->rlim_cur = 1;
95921 }
95922 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
95923 + is changed to a lower value. Since tasks can be created by the same
95924 + user in between this limit change and an execve by this task, force
95925 + a recheck only for this task by setting PF_NPROC_EXCEEDED
95926 + */
95927 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
95928 + tsk->flags |= PF_NPROC_EXCEEDED;
95929 }
95930 if (!retval) {
95931 if (old_rlim)
95932 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
95933 index 75b22e2..65c0ac8 100644
95934 --- a/kernel/sysctl.c
95935 +++ b/kernel/sysctl.c
95936 @@ -94,7 +94,6 @@
95937
95938
95939 #if defined(CONFIG_SYSCTL)
95940 -
95941 /* External variables not in a header file. */
95942 extern int max_threads;
95943 extern int suid_dumpable;
95944 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
95945
95946 /* Constants used for minimum and maximum */
95947 #ifdef CONFIG_LOCKUP_DETECTOR
95948 -static int sixty = 60;
95949 +static int sixty __read_only = 60;
95950 #endif
95951
95952 -static int __maybe_unused neg_one = -1;
95953 +static int __maybe_unused neg_one __read_only = -1;
95954
95955 -static int zero;
95956 -static int __maybe_unused one = 1;
95957 -static int __maybe_unused two = 2;
95958 -static int __maybe_unused four = 4;
95959 -static unsigned long one_ul = 1;
95960 -static int one_hundred = 100;
95961 +static int zero __read_only = 0;
95962 +static int __maybe_unused one __read_only = 1;
95963 +static int __maybe_unused two __read_only = 2;
95964 +static int __maybe_unused three __read_only = 3;
95965 +static int __maybe_unused four __read_only = 4;
95966 +static unsigned long one_ul __read_only = 1;
95967 +static int one_hundred __read_only = 100;
95968 #ifdef CONFIG_PRINTK
95969 -static int ten_thousand = 10000;
95970 +static int ten_thousand __read_only = 10000;
95971 #endif
95972
95973 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
95974 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
95975 void __user *buffer, size_t *lenp, loff_t *ppos);
95976 #endif
95977
95978 -#ifdef CONFIG_PRINTK
95979 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
95980 void __user *buffer, size_t *lenp, loff_t *ppos);
95981 -#endif
95982
95983 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
95984 void __user *buffer, size_t *lenp, loff_t *ppos);
95985 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
95986
95987 #endif
95988
95989 +extern struct ctl_table grsecurity_table[];
95990 +
95991 static struct ctl_table kern_table[];
95992 static struct ctl_table vm_table[];
95993 static struct ctl_table fs_table[];
95994 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
95995 int sysctl_legacy_va_layout;
95996 #endif
95997
95998 +#ifdef CONFIG_PAX_SOFTMODE
95999 +static ctl_table pax_table[] = {
96000 + {
96001 + .procname = "softmode",
96002 + .data = &pax_softmode,
96003 + .maxlen = sizeof(unsigned int),
96004 + .mode = 0600,
96005 + .proc_handler = &proc_dointvec,
96006 + },
96007 +
96008 + { }
96009 +};
96010 +#endif
96011 +
96012 /* The default sysctl tables: */
96013
96014 static struct ctl_table sysctl_base_table[] = {
96015 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
96016 #endif
96017
96018 static struct ctl_table kern_table[] = {
96019 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
96020 + {
96021 + .procname = "grsecurity",
96022 + .mode = 0500,
96023 + .child = grsecurity_table,
96024 + },
96025 +#endif
96026 +
96027 +#ifdef CONFIG_PAX_SOFTMODE
96028 + {
96029 + .procname = "pax",
96030 + .mode = 0500,
96031 + .child = pax_table,
96032 + },
96033 +#endif
96034 +
96035 {
96036 .procname = "sched_child_runs_first",
96037 .data = &sysctl_sched_child_runs_first,
96038 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
96039 .data = &modprobe_path,
96040 .maxlen = KMOD_PATH_LEN,
96041 .mode = 0644,
96042 - .proc_handler = proc_dostring,
96043 + .proc_handler = proc_dostring_modpriv,
96044 },
96045 {
96046 .procname = "modules_disabled",
96047 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
96048 .extra1 = &zero,
96049 .extra2 = &one,
96050 },
96051 +#endif
96052 {
96053 .procname = "kptr_restrict",
96054 .data = &kptr_restrict,
96055 .maxlen = sizeof(int),
96056 .mode = 0644,
96057 .proc_handler = proc_dointvec_minmax_sysadmin,
96058 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96059 + .extra1 = &two,
96060 +#else
96061 .extra1 = &zero,
96062 +#endif
96063 .extra2 = &two,
96064 },
96065 -#endif
96066 {
96067 .procname = "ngroups_max",
96068 .data = &ngroups_max,
96069 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
96070 */
96071 {
96072 .procname = "perf_event_paranoid",
96073 - .data = &sysctl_perf_event_paranoid,
96074 - .maxlen = sizeof(sysctl_perf_event_paranoid),
96075 + .data = &sysctl_perf_event_legitimately_concerned,
96076 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
96077 .mode = 0644,
96078 - .proc_handler = proc_dointvec,
96079 + /* go ahead, be a hero */
96080 + .proc_handler = proc_dointvec_minmax_sysadmin,
96081 + .extra1 = &neg_one,
96082 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
96083 + .extra2 = &three,
96084 +#else
96085 + .extra2 = &two,
96086 +#endif
96087 },
96088 {
96089 .procname = "perf_event_mlock_kb",
96090 @@ -1338,6 +1379,13 @@ static struct ctl_table vm_table[] = {
96091 .proc_handler = proc_dointvec_minmax,
96092 .extra1 = &zero,
96093 },
96094 + {
96095 + .procname = "heap_stack_gap",
96096 + .data = &sysctl_heap_stack_gap,
96097 + .maxlen = sizeof(sysctl_heap_stack_gap),
96098 + .mode = 0644,
96099 + .proc_handler = proc_doulongvec_minmax,
96100 + },
96101 #else
96102 {
96103 .procname = "nr_trim_pages",
96104 @@ -1827,6 +1875,16 @@ int proc_dostring(struct ctl_table *table, int write,
96105 (char __user *)buffer, lenp, ppos);
96106 }
96107
96108 +int proc_dostring_modpriv(struct ctl_table *table, int write,
96109 + void __user *buffer, size_t *lenp, loff_t *ppos)
96110 +{
96111 + if (write && !capable(CAP_SYS_MODULE))
96112 + return -EPERM;
96113 +
96114 + return _proc_do_string(table->data, table->maxlen, write,
96115 + buffer, lenp, ppos);
96116 +}
96117 +
96118 static size_t proc_skip_spaces(char **buf)
96119 {
96120 size_t ret;
96121 @@ -1932,6 +1990,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
96122 len = strlen(tmp);
96123 if (len > *size)
96124 len = *size;
96125 + if (len > sizeof(tmp))
96126 + len = sizeof(tmp);
96127 if (copy_to_user(*buf, tmp, len))
96128 return -EFAULT;
96129 *size -= len;
96130 @@ -2109,7 +2169,7 @@ int proc_dointvec(struct ctl_table *table, int write,
96131 static int proc_taint(struct ctl_table *table, int write,
96132 void __user *buffer, size_t *lenp, loff_t *ppos)
96133 {
96134 - struct ctl_table t;
96135 + ctl_table_no_const t;
96136 unsigned long tmptaint = get_taint();
96137 int err;
96138
96139 @@ -2137,7 +2197,6 @@ static int proc_taint(struct ctl_table *table, int write,
96140 return err;
96141 }
96142
96143 -#ifdef CONFIG_PRINTK
96144 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
96145 void __user *buffer, size_t *lenp, loff_t *ppos)
96146 {
96147 @@ -2146,7 +2205,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
96148
96149 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
96150 }
96151 -#endif
96152
96153 struct do_proc_dointvec_minmax_conv_param {
96154 int *min;
96155 @@ -2706,6 +2764,12 @@ int proc_dostring(struct ctl_table *table, int write,
96156 return -ENOSYS;
96157 }
96158
96159 +int proc_dostring_modpriv(struct ctl_table *table, int write,
96160 + void __user *buffer, size_t *lenp, loff_t *ppos)
96161 +{
96162 + return -ENOSYS;
96163 +}
96164 +
96165 int proc_dointvec(struct ctl_table *table, int write,
96166 void __user *buffer, size_t *lenp, loff_t *ppos)
96167 {
96168 @@ -2762,5 +2826,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
96169 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
96170 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
96171 EXPORT_SYMBOL(proc_dostring);
96172 +EXPORT_SYMBOL(proc_dostring_modpriv);
96173 EXPORT_SYMBOL(proc_doulongvec_minmax);
96174 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
96175 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
96176 index 13d2f7c..c93d0b0 100644
96177 --- a/kernel/taskstats.c
96178 +++ b/kernel/taskstats.c
96179 @@ -28,9 +28,12 @@
96180 #include <linux/fs.h>
96181 #include <linux/file.h>
96182 #include <linux/pid_namespace.h>
96183 +#include <linux/grsecurity.h>
96184 #include <net/genetlink.h>
96185 #include <linux/atomic.h>
96186
96187 +extern int gr_is_taskstats_denied(int pid);
96188 +
96189 /*
96190 * Maximum length of a cpumask that can be specified in
96191 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
96192 @@ -576,6 +579,9 @@ err:
96193
96194 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
96195 {
96196 + if (gr_is_taskstats_denied(current->pid))
96197 + return -EACCES;
96198 +
96199 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
96200 return cmd_attr_register_cpumask(info);
96201 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
96202 diff --git a/kernel/time.c b/kernel/time.c
96203 index 7c7964c..2a0d412 100644
96204 --- a/kernel/time.c
96205 +++ b/kernel/time.c
96206 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
96207 return error;
96208
96209 if (tz) {
96210 + /* we log in do_settimeofday called below, so don't log twice
96211 + */
96212 + if (!tv)
96213 + gr_log_timechange();
96214 +
96215 sys_tz = *tz;
96216 update_vsyscall_tz();
96217 if (firsttime) {
96218 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
96219 index fe75444..b8a1463 100644
96220 --- a/kernel/time/alarmtimer.c
96221 +++ b/kernel/time/alarmtimer.c
96222 @@ -464,18 +464,26 @@ static enum alarmtimer_type clock2alarm(clockid_t clockid)
96223 static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
96224 ktime_t now)
96225 {
96226 + unsigned long flags;
96227 struct k_itimer *ptr = container_of(alarm, struct k_itimer,
96228 it.alarm.alarmtimer);
96229 - if (posix_timer_event(ptr, 0) != 0)
96230 - ptr->it_overrun++;
96231 + enum alarmtimer_restart result = ALARMTIMER_NORESTART;
96232 +
96233 + spin_lock_irqsave(&ptr->it_lock, flags);
96234 + if ((ptr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) {
96235 + if (posix_timer_event(ptr, 0) != 0)
96236 + ptr->it_overrun++;
96237 + }
96238
96239 /* Re-add periodic timers */
96240 if (ptr->it.alarm.interval.tv64) {
96241 ptr->it_overrun += alarm_forward(alarm, now,
96242 ptr->it.alarm.interval);
96243 - return ALARMTIMER_RESTART;
96244 + result = ALARMTIMER_RESTART;
96245 }
96246 - return ALARMTIMER_NORESTART;
96247 + spin_unlock_irqrestore(&ptr->it_lock, flags);
96248 +
96249 + return result;
96250 }
96251
96252 /**
96253 @@ -541,18 +549,22 @@ static int alarm_timer_create(struct k_itimer *new_timer)
96254 * @new_timer: k_itimer pointer
96255 * @cur_setting: itimerspec data to fill
96256 *
96257 - * Copies the itimerspec data out from the k_itimer
96258 + * Copies out the current itimerspec data
96259 */
96260 static void alarm_timer_get(struct k_itimer *timr,
96261 struct itimerspec *cur_setting)
96262 {
96263 - memset(cur_setting, 0, sizeof(struct itimerspec));
96264 + ktime_t relative_expiry_time =
96265 + alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
96266
96267 - cur_setting->it_interval =
96268 - ktime_to_timespec(timr->it.alarm.interval);
96269 - cur_setting->it_value =
96270 - ktime_to_timespec(timr->it.alarm.alarmtimer.node.expires);
96271 - return;
96272 + if (ktime_to_ns(relative_expiry_time) > 0) {
96273 + cur_setting->it_value = ktime_to_timespec(relative_expiry_time);
96274 + } else {
96275 + cur_setting->it_value.tv_sec = 0;
96276 + cur_setting->it_value.tv_nsec = 0;
96277 + }
96278 +
96279 + cur_setting->it_interval = ktime_to_timespec(timr->it.alarm.interval);
96280 }
96281
96282 /**
96283 @@ -811,7 +823,7 @@ static int __init alarmtimer_init(void)
96284 struct platform_device *pdev;
96285 int error = 0;
96286 int i;
96287 - struct k_clock alarm_clock = {
96288 + static struct k_clock alarm_clock = {
96289 .clock_getres = alarm_clock_getres,
96290 .clock_get = alarm_clock_get,
96291 .timer_create = alarm_timer_create,
96292 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
96293 index 32d8d6a..11486af 100644
96294 --- a/kernel/time/timekeeping.c
96295 +++ b/kernel/time/timekeeping.c
96296 @@ -15,6 +15,7 @@
96297 #include <linux/init.h>
96298 #include <linux/mm.h>
96299 #include <linux/sched.h>
96300 +#include <linux/grsecurity.h>
96301 #include <linux/syscore_ops.h>
96302 #include <linux/clocksource.h>
96303 #include <linux/jiffies.h>
96304 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
96305 if (!timespec_valid_strict(tv))
96306 return -EINVAL;
96307
96308 + gr_log_timechange();
96309 +
96310 raw_spin_lock_irqsave(&timekeeper_lock, flags);
96311 write_seqcount_begin(&timekeeper_seq);
96312
96313 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
96314 index 61ed862..3b52c65 100644
96315 --- a/kernel/time/timer_list.c
96316 +++ b/kernel/time/timer_list.c
96317 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
96318
96319 static void print_name_offset(struct seq_file *m, void *sym)
96320 {
96321 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96322 + SEQ_printf(m, "<%p>", NULL);
96323 +#else
96324 char symname[KSYM_NAME_LEN];
96325
96326 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
96327 SEQ_printf(m, "<%pK>", sym);
96328 else
96329 SEQ_printf(m, "%s", symname);
96330 +#endif
96331 }
96332
96333 static void
96334 @@ -119,7 +123,11 @@ next_one:
96335 static void
96336 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
96337 {
96338 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96339 + SEQ_printf(m, " .base: %p\n", NULL);
96340 +#else
96341 SEQ_printf(m, " .base: %pK\n", base);
96342 +#endif
96343 SEQ_printf(m, " .index: %d\n",
96344 base->index);
96345 SEQ_printf(m, " .resolution: %Lu nsecs\n",
96346 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
96347 {
96348 struct proc_dir_entry *pe;
96349
96350 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96351 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
96352 +#else
96353 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
96354 +#endif
96355 if (!pe)
96356 return -ENOMEM;
96357 return 0;
96358 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
96359 index 1fb08f2..ca4bb1e 100644
96360 --- a/kernel/time/timer_stats.c
96361 +++ b/kernel/time/timer_stats.c
96362 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
96363 static unsigned long nr_entries;
96364 static struct entry entries[MAX_ENTRIES];
96365
96366 -static atomic_t overflow_count;
96367 +static atomic_unchecked_t overflow_count;
96368
96369 /*
96370 * The entries are in a hash-table, for fast lookup:
96371 @@ -140,7 +140,7 @@ static void reset_entries(void)
96372 nr_entries = 0;
96373 memset(entries, 0, sizeof(entries));
96374 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
96375 - atomic_set(&overflow_count, 0);
96376 + atomic_set_unchecked(&overflow_count, 0);
96377 }
96378
96379 static struct entry *alloc_entry(void)
96380 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
96381 if (likely(entry))
96382 entry->count++;
96383 else
96384 - atomic_inc(&overflow_count);
96385 + atomic_inc_unchecked(&overflow_count);
96386
96387 out_unlock:
96388 raw_spin_unlock_irqrestore(lock, flags);
96389 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
96390
96391 static void print_name_offset(struct seq_file *m, unsigned long addr)
96392 {
96393 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96394 + seq_printf(m, "<%p>", NULL);
96395 +#else
96396 char symname[KSYM_NAME_LEN];
96397
96398 if (lookup_symbol_name(addr, symname) < 0)
96399 - seq_printf(m, "<%p>", (void *)addr);
96400 + seq_printf(m, "<%pK>", (void *)addr);
96401 else
96402 seq_printf(m, "%s", symname);
96403 +#endif
96404 }
96405
96406 static int tstats_show(struct seq_file *m, void *v)
96407 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
96408
96409 seq_puts(m, "Timer Stats Version: v0.3\n");
96410 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
96411 - if (atomic_read(&overflow_count))
96412 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
96413 + if (atomic_read_unchecked(&overflow_count))
96414 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
96415 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
96416
96417 for (i = 0; i < nr_entries; i++) {
96418 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
96419 {
96420 struct proc_dir_entry *pe;
96421
96422 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96423 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
96424 +#else
96425 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
96426 +#endif
96427 if (!pe)
96428 return -ENOMEM;
96429 return 0;
96430 diff --git a/kernel/timer.c b/kernel/timer.c
96431 index 3bb01a3..0e7760e 100644
96432 --- a/kernel/timer.c
96433 +++ b/kernel/timer.c
96434 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
96435 /*
96436 * This function runs timers and the timer-tq in bottom half context.
96437 */
96438 -static void run_timer_softirq(struct softirq_action *h)
96439 +static __latent_entropy void run_timer_softirq(void)
96440 {
96441 struct tvec_base *base = __this_cpu_read(tvec_bases);
96442
96443 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
96444 *
96445 * In all cases the return value is guaranteed to be non-negative.
96446 */
96447 -signed long __sched schedule_timeout(signed long timeout)
96448 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
96449 {
96450 struct timer_list timer;
96451 unsigned long expire;
96452 diff --git a/kernel/torture.c b/kernel/torture.c
96453 index 40bb511..91190b9 100644
96454 --- a/kernel/torture.c
96455 +++ b/kernel/torture.c
96456 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
96457 mutex_lock(&fullstop_mutex);
96458 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
96459 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
96460 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
96461 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
96462 } else {
96463 pr_warn("Concurrent rmmod and shutdown illegal!\n");
96464 }
96465 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
96466 if (!torture_must_stop()) {
96467 if (stutter > 1) {
96468 schedule_timeout_interruptible(stutter - 1);
96469 - ACCESS_ONCE(stutter_pause_test) = 2;
96470 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
96471 }
96472 schedule_timeout_interruptible(1);
96473 - ACCESS_ONCE(stutter_pause_test) = 1;
96474 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
96475 }
96476 if (!torture_must_stop())
96477 schedule_timeout_interruptible(stutter);
96478 - ACCESS_ONCE(stutter_pause_test) = 0;
96479 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
96480 torture_shutdown_absorb("torture_stutter");
96481 } while (!torture_must_stop());
96482 torture_kthread_stopping("torture_stutter");
96483 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
96484 schedule_timeout_uninterruptible(10);
96485 return true;
96486 }
96487 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
96488 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
96489 mutex_unlock(&fullstop_mutex);
96490 torture_shutdown_cleanup();
96491 torture_shuffle_cleanup();
96492 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
96493 index c1bd4ad..4b861dc 100644
96494 --- a/kernel/trace/blktrace.c
96495 +++ b/kernel/trace/blktrace.c
96496 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
96497 struct blk_trace *bt = filp->private_data;
96498 char buf[16];
96499
96500 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
96501 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
96502
96503 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
96504 }
96505 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
96506 return 1;
96507
96508 bt = buf->chan->private_data;
96509 - atomic_inc(&bt->dropped);
96510 + atomic_inc_unchecked(&bt->dropped);
96511 return 0;
96512 }
96513
96514 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
96515
96516 bt->dir = dir;
96517 bt->dev = dev;
96518 - atomic_set(&bt->dropped, 0);
96519 + atomic_set_unchecked(&bt->dropped, 0);
96520 INIT_LIST_HEAD(&bt->running_list);
96521
96522 ret = -EIO;
96523 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
96524 index ac9d1da..ce98b35 100644
96525 --- a/kernel/trace/ftrace.c
96526 +++ b/kernel/trace/ftrace.c
96527 @@ -1920,12 +1920,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
96528 if (unlikely(ftrace_disabled))
96529 return 0;
96530
96531 + ret = ftrace_arch_code_modify_prepare();
96532 + FTRACE_WARN_ON(ret);
96533 + if (ret)
96534 + return 0;
96535 +
96536 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
96537 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
96538 if (ret) {
96539 ftrace_bug(ret, ip);
96540 - return 0;
96541 }
96542 - return 1;
96543 + return ret ? 0 : 1;
96544 }
96545
96546 /*
96547 @@ -4126,8 +4131,10 @@ static int ftrace_process_locs(struct module *mod,
96548 if (!count)
96549 return 0;
96550
96551 + pax_open_kernel();
96552 sort(start, count, sizeof(*start),
96553 ftrace_cmp_ips, ftrace_swap_ips);
96554 + pax_close_kernel();
96555
96556 start_pg = ftrace_allocate_pages(count);
96557 if (!start_pg)
96558 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
96559 index ff70271..4242e69 100644
96560 --- a/kernel/trace/ring_buffer.c
96561 +++ b/kernel/trace/ring_buffer.c
96562 @@ -352,9 +352,9 @@ struct buffer_data_page {
96563 */
96564 struct buffer_page {
96565 struct list_head list; /* list of buffer pages */
96566 - local_t write; /* index for next write */
96567 + local_unchecked_t write; /* index for next write */
96568 unsigned read; /* index for next read */
96569 - local_t entries; /* entries on this page */
96570 + local_unchecked_t entries; /* entries on this page */
96571 unsigned long real_end; /* real end of data */
96572 struct buffer_data_page *page; /* Actual data page */
96573 };
96574 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
96575 unsigned long last_overrun;
96576 local_t entries_bytes;
96577 local_t entries;
96578 - local_t overrun;
96579 - local_t commit_overrun;
96580 + local_unchecked_t overrun;
96581 + local_unchecked_t commit_overrun;
96582 local_t dropped_events;
96583 local_t committing;
96584 local_t commits;
96585 @@ -626,8 +626,22 @@ int ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
96586 work = &cpu_buffer->irq_work;
96587 }
96588
96589 - work->waiters_pending = true;
96590 poll_wait(filp, &work->waiters, poll_table);
96591 + work->waiters_pending = true;
96592 + /*
96593 + * There's a tight race between setting the waiters_pending and
96594 + * checking if the ring buffer is empty. Once the waiters_pending bit
96595 + * is set, the next event will wake the task up, but we can get stuck
96596 + * if there's only a single event in.
96597 + *
96598 + * FIXME: Ideally, we need a memory barrier on the writer side as well,
96599 + * but adding a memory barrier to all events will cause too much of a
96600 + * performance hit in the fast path. We only need a memory barrier when
96601 + * the buffer goes from empty to having content. But as this race is
96602 + * extremely small, and it's not a problem if another event comes in, we
96603 + * will fix it later.
96604 + */
96605 + smp_mb();
96606
96607 if ((cpu == RING_BUFFER_ALL_CPUS && !ring_buffer_empty(buffer)) ||
96608 (cpu != RING_BUFFER_ALL_CPUS && !ring_buffer_empty_cpu(buffer, cpu)))
96609 @@ -991,8 +1005,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
96610 *
96611 * We add a counter to the write field to denote this.
96612 */
96613 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
96614 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
96615 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
96616 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
96617
96618 /*
96619 * Just make sure we have seen our old_write and synchronize
96620 @@ -1020,8 +1034,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
96621 * cmpxchg to only update if an interrupt did not already
96622 * do it for us. If the cmpxchg fails, we don't care.
96623 */
96624 - (void)local_cmpxchg(&next_page->write, old_write, val);
96625 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
96626 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
96627 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
96628
96629 /*
96630 * No need to worry about races with clearing out the commit.
96631 @@ -1388,12 +1402,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
96632
96633 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
96634 {
96635 - return local_read(&bpage->entries) & RB_WRITE_MASK;
96636 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
96637 }
96638
96639 static inline unsigned long rb_page_write(struct buffer_page *bpage)
96640 {
96641 - return local_read(&bpage->write) & RB_WRITE_MASK;
96642 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
96643 }
96644
96645 static int
96646 @@ -1488,7 +1502,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
96647 * bytes consumed in ring buffer from here.
96648 * Increment overrun to account for the lost events.
96649 */
96650 - local_add(page_entries, &cpu_buffer->overrun);
96651 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
96652 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
96653 }
96654
96655 @@ -2066,7 +2080,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
96656 * it is our responsibility to update
96657 * the counters.
96658 */
96659 - local_add(entries, &cpu_buffer->overrun);
96660 + local_add_unchecked(entries, &cpu_buffer->overrun);
96661 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
96662
96663 /*
96664 @@ -2216,7 +2230,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
96665 if (tail == BUF_PAGE_SIZE)
96666 tail_page->real_end = 0;
96667
96668 - local_sub(length, &tail_page->write);
96669 + local_sub_unchecked(length, &tail_page->write);
96670 return;
96671 }
96672
96673 @@ -2251,7 +2265,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
96674 rb_event_set_padding(event);
96675
96676 /* Set the write back to the previous setting */
96677 - local_sub(length, &tail_page->write);
96678 + local_sub_unchecked(length, &tail_page->write);
96679 return;
96680 }
96681
96682 @@ -2263,7 +2277,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
96683
96684 /* Set write to end of buffer */
96685 length = (tail + length) - BUF_PAGE_SIZE;
96686 - local_sub(length, &tail_page->write);
96687 + local_sub_unchecked(length, &tail_page->write);
96688 }
96689
96690 /*
96691 @@ -2289,7 +2303,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
96692 * about it.
96693 */
96694 if (unlikely(next_page == commit_page)) {
96695 - local_inc(&cpu_buffer->commit_overrun);
96696 + local_inc_unchecked(&cpu_buffer->commit_overrun);
96697 goto out_reset;
96698 }
96699
96700 @@ -2345,7 +2359,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
96701 cpu_buffer->tail_page) &&
96702 (cpu_buffer->commit_page ==
96703 cpu_buffer->reader_page))) {
96704 - local_inc(&cpu_buffer->commit_overrun);
96705 + local_inc_unchecked(&cpu_buffer->commit_overrun);
96706 goto out_reset;
96707 }
96708 }
96709 @@ -2393,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
96710 length += RB_LEN_TIME_EXTEND;
96711
96712 tail_page = cpu_buffer->tail_page;
96713 - write = local_add_return(length, &tail_page->write);
96714 + write = local_add_return_unchecked(length, &tail_page->write);
96715
96716 /* set write to only the index of the write */
96717 write &= RB_WRITE_MASK;
96718 @@ -2417,7 +2431,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
96719 kmemcheck_annotate_bitfield(event, bitfield);
96720 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
96721
96722 - local_inc(&tail_page->entries);
96723 + local_inc_unchecked(&tail_page->entries);
96724
96725 /*
96726 * If this is the first commit on the page, then update
96727 @@ -2450,7 +2464,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
96728
96729 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
96730 unsigned long write_mask =
96731 - local_read(&bpage->write) & ~RB_WRITE_MASK;
96732 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
96733 unsigned long event_length = rb_event_length(event);
96734 /*
96735 * This is on the tail page. It is possible that
96736 @@ -2460,7 +2474,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
96737 */
96738 old_index += write_mask;
96739 new_index += write_mask;
96740 - index = local_cmpxchg(&bpage->write, old_index, new_index);
96741 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
96742 if (index == old_index) {
96743 /* update counters */
96744 local_sub(event_length, &cpu_buffer->entries_bytes);
96745 @@ -2852,7 +2866,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
96746
96747 /* Do the likely case first */
96748 if (likely(bpage->page == (void *)addr)) {
96749 - local_dec(&bpage->entries);
96750 + local_dec_unchecked(&bpage->entries);
96751 return;
96752 }
96753
96754 @@ -2864,7 +2878,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
96755 start = bpage;
96756 do {
96757 if (bpage->page == (void *)addr) {
96758 - local_dec(&bpage->entries);
96759 + local_dec_unchecked(&bpage->entries);
96760 return;
96761 }
96762 rb_inc_page(cpu_buffer, &bpage);
96763 @@ -3148,7 +3162,7 @@ static inline unsigned long
96764 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
96765 {
96766 return local_read(&cpu_buffer->entries) -
96767 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
96768 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
96769 }
96770
96771 /**
96772 @@ -3237,7 +3251,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
96773 return 0;
96774
96775 cpu_buffer = buffer->buffers[cpu];
96776 - ret = local_read(&cpu_buffer->overrun);
96777 + ret = local_read_unchecked(&cpu_buffer->overrun);
96778
96779 return ret;
96780 }
96781 @@ -3260,7 +3274,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
96782 return 0;
96783
96784 cpu_buffer = buffer->buffers[cpu];
96785 - ret = local_read(&cpu_buffer->commit_overrun);
96786 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
96787
96788 return ret;
96789 }
96790 @@ -3345,7 +3359,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
96791 /* if you care about this being correct, lock the buffer */
96792 for_each_buffer_cpu(buffer, cpu) {
96793 cpu_buffer = buffer->buffers[cpu];
96794 - overruns += local_read(&cpu_buffer->overrun);
96795 + overruns += local_read_unchecked(&cpu_buffer->overrun);
96796 }
96797
96798 return overruns;
96799 @@ -3521,8 +3535,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
96800 /*
96801 * Reset the reader page to size zero.
96802 */
96803 - local_set(&cpu_buffer->reader_page->write, 0);
96804 - local_set(&cpu_buffer->reader_page->entries, 0);
96805 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
96806 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
96807 local_set(&cpu_buffer->reader_page->page->commit, 0);
96808 cpu_buffer->reader_page->real_end = 0;
96809
96810 @@ -3556,7 +3570,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
96811 * want to compare with the last_overrun.
96812 */
96813 smp_mb();
96814 - overwrite = local_read(&(cpu_buffer->overrun));
96815 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
96816
96817 /*
96818 * Here's the tricky part.
96819 @@ -4126,8 +4140,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
96820
96821 cpu_buffer->head_page
96822 = list_entry(cpu_buffer->pages, struct buffer_page, list);
96823 - local_set(&cpu_buffer->head_page->write, 0);
96824 - local_set(&cpu_buffer->head_page->entries, 0);
96825 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
96826 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
96827 local_set(&cpu_buffer->head_page->page->commit, 0);
96828
96829 cpu_buffer->head_page->read = 0;
96830 @@ -4137,14 +4151,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
96831
96832 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
96833 INIT_LIST_HEAD(&cpu_buffer->new_pages);
96834 - local_set(&cpu_buffer->reader_page->write, 0);
96835 - local_set(&cpu_buffer->reader_page->entries, 0);
96836 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
96837 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
96838 local_set(&cpu_buffer->reader_page->page->commit, 0);
96839 cpu_buffer->reader_page->read = 0;
96840
96841 local_set(&cpu_buffer->entries_bytes, 0);
96842 - local_set(&cpu_buffer->overrun, 0);
96843 - local_set(&cpu_buffer->commit_overrun, 0);
96844 + local_set_unchecked(&cpu_buffer->overrun, 0);
96845 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
96846 local_set(&cpu_buffer->dropped_events, 0);
96847 local_set(&cpu_buffer->entries, 0);
96848 local_set(&cpu_buffer->committing, 0);
96849 @@ -4549,8 +4563,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
96850 rb_init_page(bpage);
96851 bpage = reader->page;
96852 reader->page = *data_page;
96853 - local_set(&reader->write, 0);
96854 - local_set(&reader->entries, 0);
96855 + local_set_unchecked(&reader->write, 0);
96856 + local_set_unchecked(&reader->entries, 0);
96857 reader->read = 0;
96858 *data_page = bpage;
96859
96860 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
96861 index 291397e..db3836d 100644
96862 --- a/kernel/trace/trace.c
96863 +++ b/kernel/trace/trace.c
96864 @@ -3510,7 +3510,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
96865 return 0;
96866 }
96867
96868 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
96869 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
96870 {
96871 /* do nothing if flag is already set */
96872 if (!!(trace_flags & mask) == !!enabled)
96873 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
96874 index 9258f5a..9b1e41e 100644
96875 --- a/kernel/trace/trace.h
96876 +++ b/kernel/trace/trace.h
96877 @@ -1278,7 +1278,7 @@ extern const char *__stop___tracepoint_str[];
96878 void trace_printk_init_buffers(void);
96879 void trace_printk_start_comm(void);
96880 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
96881 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
96882 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
96883
96884 /*
96885 * Normal trace_printk() and friends allocates special buffers
96886 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
96887 index 57b67b1..66082a9 100644
96888 --- a/kernel/trace/trace_clock.c
96889 +++ b/kernel/trace/trace_clock.c
96890 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
96891 return now;
96892 }
96893
96894 -static atomic64_t trace_counter;
96895 +static atomic64_unchecked_t trace_counter;
96896
96897 /*
96898 * trace_clock_counter(): simply an atomic counter.
96899 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
96900 */
96901 u64 notrace trace_clock_counter(void)
96902 {
96903 - return atomic64_add_return(1, &trace_counter);
96904 + return atomic64_inc_return_unchecked(&trace_counter);
96905 }
96906 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
96907 index 2de5362..c4c7003 100644
96908 --- a/kernel/trace/trace_events.c
96909 +++ b/kernel/trace/trace_events.c
96910 @@ -1722,7 +1722,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
96911 return 0;
96912 }
96913
96914 -struct ftrace_module_file_ops;
96915 static void __add_event_to_tracers(struct ftrace_event_call *call);
96916
96917 /* Add an additional event_call dynamically */
96918 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
96919 index 0abd9b8..6a663a2 100644
96920 --- a/kernel/trace/trace_mmiotrace.c
96921 +++ b/kernel/trace/trace_mmiotrace.c
96922 @@ -24,7 +24,7 @@ struct header_iter {
96923 static struct trace_array *mmio_trace_array;
96924 static bool overrun_detected;
96925 static unsigned long prev_overruns;
96926 -static atomic_t dropped_count;
96927 +static atomic_unchecked_t dropped_count;
96928
96929 static void mmio_reset_data(struct trace_array *tr)
96930 {
96931 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
96932
96933 static unsigned long count_overruns(struct trace_iterator *iter)
96934 {
96935 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
96936 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
96937 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
96938
96939 if (over > prev_overruns)
96940 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
96941 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
96942 sizeof(*entry), 0, pc);
96943 if (!event) {
96944 - atomic_inc(&dropped_count);
96945 + atomic_inc_unchecked(&dropped_count);
96946 return;
96947 }
96948 entry = ring_buffer_event_data(event);
96949 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
96950 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
96951 sizeof(*entry), 0, pc);
96952 if (!event) {
96953 - atomic_inc(&dropped_count);
96954 + atomic_inc_unchecked(&dropped_count);
96955 return;
96956 }
96957 entry = ring_buffer_event_data(event);
96958 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
96959 index f3dad80..d291d61 100644
96960 --- a/kernel/trace/trace_output.c
96961 +++ b/kernel/trace/trace_output.c
96962 @@ -322,7 +322,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
96963
96964 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
96965 if (!IS_ERR(p)) {
96966 - p = mangle_path(s->buffer + s->len, p, "\n");
96967 + p = mangle_path(s->buffer + s->len, p, "\n\\");
96968 if (p) {
96969 s->len = p - s->buffer;
96970 return 1;
96971 @@ -980,14 +980,16 @@ int register_ftrace_event(struct trace_event *event)
96972 goto out;
96973 }
96974
96975 + pax_open_kernel();
96976 if (event->funcs->trace == NULL)
96977 - event->funcs->trace = trace_nop_print;
96978 + *(void **)&event->funcs->trace = trace_nop_print;
96979 if (event->funcs->raw == NULL)
96980 - event->funcs->raw = trace_nop_print;
96981 + *(void **)&event->funcs->raw = trace_nop_print;
96982 if (event->funcs->hex == NULL)
96983 - event->funcs->hex = trace_nop_print;
96984 + *(void **)&event->funcs->hex = trace_nop_print;
96985 if (event->funcs->binary == NULL)
96986 - event->funcs->binary = trace_nop_print;
96987 + *(void **)&event->funcs->binary = trace_nop_print;
96988 + pax_close_kernel();
96989
96990 key = event->type & (EVENT_HASHSIZE - 1);
96991
96992 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
96993 index 8a4e5cb..64f270d 100644
96994 --- a/kernel/trace/trace_stack.c
96995 +++ b/kernel/trace/trace_stack.c
96996 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
96997 return;
96998
96999 /* we do not handle interrupt stacks yet */
97000 - if (!object_is_on_stack(stack))
97001 + if (!object_starts_on_stack(stack))
97002 return;
97003
97004 local_irq_save(flags);
97005 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
97006 index fcc0256..aee880f 100644
97007 --- a/kernel/user_namespace.c
97008 +++ b/kernel/user_namespace.c
97009 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
97010 !kgid_has_mapping(parent_ns, group))
97011 return -EPERM;
97012
97013 +#ifdef CONFIG_GRKERNSEC
97014 + /*
97015 + * This doesn't really inspire confidence:
97016 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
97017 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
97018 + * Increases kernel attack surface in areas developers
97019 + * previously cared little about ("low importance due
97020 + * to requiring "root" capability")
97021 + * To be removed when this code receives *proper* review
97022 + */
97023 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
97024 + !capable(CAP_SETGID))
97025 + return -EPERM;
97026 +#endif
97027 +
97028 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
97029 if (!ns)
97030 return -ENOMEM;
97031 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
97032 if (atomic_read(&current->mm->mm_users) > 1)
97033 return -EINVAL;
97034
97035 - if (current->fs->users != 1)
97036 + if (atomic_read(&current->fs->users) != 1)
97037 return -EINVAL;
97038
97039 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
97040 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
97041 index c8eac43..4b5f08f 100644
97042 --- a/kernel/utsname_sysctl.c
97043 +++ b/kernel/utsname_sysctl.c
97044 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
97045 static int proc_do_uts_string(struct ctl_table *table, int write,
97046 void __user *buffer, size_t *lenp, loff_t *ppos)
97047 {
97048 - struct ctl_table uts_table;
97049 + ctl_table_no_const uts_table;
97050 int r;
97051 memcpy(&uts_table, table, sizeof(uts_table));
97052 uts_table.data = get_uts(table, write);
97053 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
97054 index c3319bd..67efc3c 100644
97055 --- a/kernel/watchdog.c
97056 +++ b/kernel/watchdog.c
97057 @@ -518,7 +518,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
97058 static void watchdog_nmi_disable(unsigned int cpu) { return; }
97059 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
97060
97061 -static struct smp_hotplug_thread watchdog_threads = {
97062 +static struct smp_hotplug_thread watchdog_threads __read_only = {
97063 .store = &softlockup_watchdog,
97064 .thread_should_run = watchdog_should_run,
97065 .thread_fn = watchdog,
97066 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
97067 index 35974ac..43c9e87 100644
97068 --- a/kernel/workqueue.c
97069 +++ b/kernel/workqueue.c
97070 @@ -4576,7 +4576,7 @@ static void rebind_workers(struct worker_pool *pool)
97071 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
97072 worker_flags |= WORKER_REBOUND;
97073 worker_flags &= ~WORKER_UNBOUND;
97074 - ACCESS_ONCE(worker->flags) = worker_flags;
97075 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
97076 }
97077
97078 spin_unlock_irq(&pool->lock);
97079 diff --git a/lib/Kconfig b/lib/Kconfig
97080 index 334f772..74b8ec3 100644
97081 --- a/lib/Kconfig
97082 +++ b/lib/Kconfig
97083 @@ -51,6 +51,9 @@ config PERCPU_RWSEM
97084 config ARCH_USE_CMPXCHG_LOCKREF
97085 bool
97086
97087 +config ARCH_HAS_FAST_MULTIPLIER
97088 + bool
97089 +
97090 config CRC_CCITT
97091 tristate "CRC-CCITT functions"
97092 help
97093 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
97094 index 7a638aa..20db901 100644
97095 --- a/lib/Kconfig.debug
97096 +++ b/lib/Kconfig.debug
97097 @@ -858,7 +858,7 @@ config DEBUG_MUTEXES
97098
97099 config DEBUG_WW_MUTEX_SLOWPATH
97100 bool "Wait/wound mutex debugging: Slowpath testing"
97101 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
97102 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
97103 select DEBUG_LOCK_ALLOC
97104 select DEBUG_SPINLOCK
97105 select DEBUG_MUTEXES
97106 @@ -871,7 +871,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
97107
97108 config DEBUG_LOCK_ALLOC
97109 bool "Lock debugging: detect incorrect freeing of live locks"
97110 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
97111 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
97112 select DEBUG_SPINLOCK
97113 select DEBUG_MUTEXES
97114 select LOCKDEP
97115 @@ -885,7 +885,7 @@ config DEBUG_LOCK_ALLOC
97116
97117 config PROVE_LOCKING
97118 bool "Lock debugging: prove locking correctness"
97119 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
97120 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
97121 select LOCKDEP
97122 select DEBUG_SPINLOCK
97123 select DEBUG_MUTEXES
97124 @@ -936,7 +936,7 @@ config LOCKDEP
97125
97126 config LOCK_STAT
97127 bool "Lock usage statistics"
97128 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
97129 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
97130 select LOCKDEP
97131 select DEBUG_SPINLOCK
97132 select DEBUG_MUTEXES
97133 @@ -1418,6 +1418,7 @@ config LATENCYTOP
97134 depends on DEBUG_KERNEL
97135 depends on STACKTRACE_SUPPORT
97136 depends on PROC_FS
97137 + depends on !GRKERNSEC_HIDESYM
97138 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
97139 select KALLSYMS
97140 select KALLSYMS_ALL
97141 @@ -1434,7 +1435,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
97142 config DEBUG_STRICT_USER_COPY_CHECKS
97143 bool "Strict user copy size checks"
97144 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
97145 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
97146 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
97147 help
97148 Enabling this option turns a certain set of sanity checks for user
97149 copy operations into compile time failures.
97150 @@ -1554,7 +1555,7 @@ endmenu # runtime tests
97151
97152 config PROVIDE_OHCI1394_DMA_INIT
97153 bool "Remote debugging over FireWire early on boot"
97154 - depends on PCI && X86
97155 + depends on PCI && X86 && !GRKERNSEC
97156 help
97157 If you want to debug problems which hang or crash the kernel early
97158 on boot and the crashing machine has a FireWire port, you can use
97159 diff --git a/lib/Makefile b/lib/Makefile
97160 index ba967a1..2cc869a 100644
97161 --- a/lib/Makefile
97162 +++ b/lib/Makefile
97163 @@ -33,7 +33,6 @@ obj-y += kstrtox.o
97164 obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
97165 obj-$(CONFIG_TEST_MODULE) += test_module.o
97166 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
97167 -obj-$(CONFIG_TEST_BPF) += test_bpf.o
97168
97169 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
97170 CFLAGS_kobject.o += -DDEBUG
97171 @@ -54,7 +53,7 @@ obj-$(CONFIG_BTREE) += btree.o
97172 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
97173 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
97174 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
97175 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
97176 +obj-y += list_debug.o
97177 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
97178
97179 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
97180 diff --git a/lib/assoc_array.c b/lib/assoc_array.c
97181 index c0b1007..2404d03 100644
97182 --- a/lib/assoc_array.c
97183 +++ b/lib/assoc_array.c
97184 @@ -1723,11 +1723,13 @@ ascend_old_tree:
97185 shortcut = assoc_array_ptr_to_shortcut(ptr);
97186 slot = shortcut->parent_slot;
97187 cursor = shortcut->back_pointer;
97188 + if (!cursor)
97189 + goto gc_complete;
97190 } else {
97191 slot = node->parent_slot;
97192 cursor = ptr;
97193 }
97194 - BUG_ON(!ptr);
97195 + BUG_ON(!cursor);
97196 node = assoc_array_ptr_to_node(cursor);
97197 slot++;
97198 goto continue_node;
97199 @@ -1735,7 +1737,7 @@ ascend_old_tree:
97200 gc_complete:
97201 edit->set[0].to = new_root;
97202 assoc_array_apply_edit(edit);
97203 - edit->array->nr_leaves_on_tree = nr_leaves_on_tree;
97204 + array->nr_leaves_on_tree = nr_leaves_on_tree;
97205 return 0;
97206
97207 enomem:
97208 diff --git a/lib/average.c b/lib/average.c
97209 index 114d1be..ab0350c 100644
97210 --- a/lib/average.c
97211 +++ b/lib/average.c
97212 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
97213 {
97214 unsigned long internal = ACCESS_ONCE(avg->internal);
97215
97216 - ACCESS_ONCE(avg->internal) = internal ?
97217 + ACCESS_ONCE_RW(avg->internal) = internal ?
97218 (((internal << avg->weight) - internal) +
97219 (val << avg->factor)) >> avg->weight :
97220 (val << avg->factor);
97221 diff --git a/lib/bitmap.c b/lib/bitmap.c
97222 index 06f7e4f..f3cf2b0 100644
97223 --- a/lib/bitmap.c
97224 +++ b/lib/bitmap.c
97225 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
97226 {
97227 int c, old_c, totaldigits, ndigits, nchunks, nbits;
97228 u32 chunk;
97229 - const char __user __force *ubuf = (const char __user __force *)buf;
97230 + const char __user *ubuf = (const char __force_user *)buf;
97231
97232 bitmap_zero(maskp, nmaskbits);
97233
97234 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
97235 {
97236 if (!access_ok(VERIFY_READ, ubuf, ulen))
97237 return -EFAULT;
97238 - return __bitmap_parse((const char __force *)ubuf,
97239 + return __bitmap_parse((const char __force_kernel *)ubuf,
97240 ulen, 1, maskp, nmaskbits);
97241
97242 }
97243 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
97244 {
97245 unsigned a, b;
97246 int c, old_c, totaldigits;
97247 - const char __user __force *ubuf = (const char __user __force *)buf;
97248 + const char __user *ubuf = (const char __force_user *)buf;
97249 int exp_digit, in_range;
97250
97251 totaldigits = c = 0;
97252 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
97253 {
97254 if (!access_ok(VERIFY_READ, ubuf, ulen))
97255 return -EFAULT;
97256 - return __bitmap_parselist((const char __force *)ubuf,
97257 + return __bitmap_parselist((const char __force_kernel *)ubuf,
97258 ulen, 1, maskp, nmaskbits);
97259 }
97260 EXPORT_SYMBOL(bitmap_parselist_user);
97261 diff --git a/lib/bug.c b/lib/bug.c
97262 index d1d7c78..b354235 100644
97263 --- a/lib/bug.c
97264 +++ b/lib/bug.c
97265 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
97266 return BUG_TRAP_TYPE_NONE;
97267
97268 bug = find_bug(bugaddr);
97269 + if (!bug)
97270 + return BUG_TRAP_TYPE_NONE;
97271
97272 file = NULL;
97273 line = 0;
97274 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
97275 index 547f7f9..a6d4ba0 100644
97276 --- a/lib/debugobjects.c
97277 +++ b/lib/debugobjects.c
97278 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
97279 if (limit > 4)
97280 return;
97281
97282 - is_on_stack = object_is_on_stack(addr);
97283 + is_on_stack = object_starts_on_stack(addr);
97284 if (is_on_stack == onstack)
97285 return;
97286
97287 diff --git a/lib/div64.c b/lib/div64.c
97288 index 4382ad7..08aa558 100644
97289 --- a/lib/div64.c
97290 +++ b/lib/div64.c
97291 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
97292 EXPORT_SYMBOL(__div64_32);
97293
97294 #ifndef div_s64_rem
97295 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
97296 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
97297 {
97298 u64 quotient;
97299
97300 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
97301 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
97302 */
97303 #ifndef div64_u64
97304 -u64 div64_u64(u64 dividend, u64 divisor)
97305 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
97306 {
97307 u32 high = divisor >> 32;
97308 u64 quot;
97309 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
97310 index 98f2d7e..899da5c 100644
97311 --- a/lib/dma-debug.c
97312 +++ b/lib/dma-debug.c
97313 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
97314
97315 void dma_debug_add_bus(struct bus_type *bus)
97316 {
97317 - struct notifier_block *nb;
97318 + notifier_block_no_const *nb;
97319
97320 if (global_disable)
97321 return;
97322 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
97323
97324 static void check_for_stack(struct device *dev, void *addr)
97325 {
97326 - if (object_is_on_stack(addr))
97327 + if (object_starts_on_stack(addr))
97328 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
97329 "stack [addr=%p]\n", addr);
97330 }
97331 diff --git a/lib/hash.c b/lib/hash.c
97332 index fea973f..386626f 100644
97333 --- a/lib/hash.c
97334 +++ b/lib/hash.c
97335 @@ -14,7 +14,7 @@
97336 #include <linux/hash.h>
97337 #include <linux/cache.h>
97338
97339 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
97340 +static struct fast_hash_ops arch_hash_ops __read_only = {
97341 .hash = jhash,
97342 .hash2 = jhash2,
97343 };
97344 diff --git a/lib/hweight.c b/lib/hweight.c
97345 index b7d81ba..9a5c1f2 100644
97346 --- a/lib/hweight.c
97347 +++ b/lib/hweight.c
97348 @@ -11,7 +11,7 @@
97349
97350 unsigned int __sw_hweight32(unsigned int w)
97351 {
97352 -#ifdef ARCH_HAS_FAST_MULTIPLIER
97353 +#ifdef CONFIG_ARCH_HAS_FAST_MULTIPLIER
97354 w -= (w >> 1) & 0x55555555;
97355 w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
97356 w = (w + (w >> 4)) & 0x0f0f0f0f;
97357 @@ -49,7 +49,7 @@ unsigned long __sw_hweight64(__u64 w)
97358 return __sw_hweight32((unsigned int)(w >> 32)) +
97359 __sw_hweight32((unsigned int)w);
97360 #elif BITS_PER_LONG == 64
97361 -#ifdef ARCH_HAS_FAST_MULTIPLIER
97362 +#ifdef CONFIG_ARCH_HAS_FAST_MULTIPLIER
97363 w -= (w >> 1) & 0x5555555555555555ul;
97364 w = (w & 0x3333333333333333ul) + ((w >> 2) & 0x3333333333333333ul);
97365 w = (w + (w >> 4)) & 0x0f0f0f0f0f0f0f0ful;
97366 diff --git a/lib/inflate.c b/lib/inflate.c
97367 index 013a761..c28f3fc 100644
97368 --- a/lib/inflate.c
97369 +++ b/lib/inflate.c
97370 @@ -269,7 +269,7 @@ static void free(void *where)
97371 malloc_ptr = free_mem_ptr;
97372 }
97373 #else
97374 -#define malloc(a) kmalloc(a, GFP_KERNEL)
97375 +#define malloc(a) kmalloc((a), GFP_KERNEL)
97376 #define free(a) kfree(a)
97377 #endif
97378
97379 diff --git a/lib/ioremap.c b/lib/ioremap.c
97380 index 0c9216c..863bd89 100644
97381 --- a/lib/ioremap.c
97382 +++ b/lib/ioremap.c
97383 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
97384 unsigned long next;
97385
97386 phys_addr -= addr;
97387 - pmd = pmd_alloc(&init_mm, pud, addr);
97388 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97389 if (!pmd)
97390 return -ENOMEM;
97391 do {
97392 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
97393 unsigned long next;
97394
97395 phys_addr -= addr;
97396 - pud = pud_alloc(&init_mm, pgd, addr);
97397 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
97398 if (!pud)
97399 return -ENOMEM;
97400 do {
97401 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
97402 index bd2bea9..6b3c95e 100644
97403 --- a/lib/is_single_threaded.c
97404 +++ b/lib/is_single_threaded.c
97405 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
97406 struct task_struct *p, *t;
97407 bool ret;
97408
97409 + if (!mm)
97410 + return true;
97411 +
97412 if (atomic_read(&task->signal->live) != 1)
97413 return false;
97414
97415 diff --git a/lib/kobject.c b/lib/kobject.c
97416 index 58751bb..93a1853 100644
97417 --- a/lib/kobject.c
97418 +++ b/lib/kobject.c
97419 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
97420
97421
97422 static DEFINE_SPINLOCK(kobj_ns_type_lock);
97423 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
97424 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
97425
97426 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
97427 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
97428 {
97429 enum kobj_ns_type type = ops->type;
97430 int error;
97431 diff --git a/lib/list_debug.c b/lib/list_debug.c
97432 index c24c2f7..f0296f4 100644
97433 --- a/lib/list_debug.c
97434 +++ b/lib/list_debug.c
97435 @@ -11,7 +11,9 @@
97436 #include <linux/bug.h>
97437 #include <linux/kernel.h>
97438 #include <linux/rculist.h>
97439 +#include <linux/mm.h>
97440
97441 +#ifdef CONFIG_DEBUG_LIST
97442 /*
97443 * Insert a new entry between two known consecutive entries.
97444 *
97445 @@ -19,21 +21,40 @@
97446 * the prev/next entries already!
97447 */
97448
97449 +static bool __list_add_debug(struct list_head *new,
97450 + struct list_head *prev,
97451 + struct list_head *next)
97452 +{
97453 + if (unlikely(next->prev != prev)) {
97454 + printk(KERN_ERR "list_add corruption. next->prev should be "
97455 + "prev (%p), but was %p. (next=%p).\n",
97456 + prev, next->prev, next);
97457 + BUG();
97458 + return false;
97459 + }
97460 + if (unlikely(prev->next != next)) {
97461 + printk(KERN_ERR "list_add corruption. prev->next should be "
97462 + "next (%p), but was %p. (prev=%p).\n",
97463 + next, prev->next, prev);
97464 + BUG();
97465 + return false;
97466 + }
97467 + if (unlikely(new == prev || new == next)) {
97468 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
97469 + new, prev, next);
97470 + BUG();
97471 + return false;
97472 + }
97473 + return true;
97474 +}
97475 +
97476 void __list_add(struct list_head *new,
97477 - struct list_head *prev,
97478 - struct list_head *next)
97479 + struct list_head *prev,
97480 + struct list_head *next)
97481 {
97482 - WARN(next->prev != prev,
97483 - "list_add corruption. next->prev should be "
97484 - "prev (%p), but was %p. (next=%p).\n",
97485 - prev, next->prev, next);
97486 - WARN(prev->next != next,
97487 - "list_add corruption. prev->next should be "
97488 - "next (%p), but was %p. (prev=%p).\n",
97489 - next, prev->next, prev);
97490 - WARN(new == prev || new == next,
97491 - "list_add double add: new=%p, prev=%p, next=%p.\n",
97492 - new, prev, next);
97493 + if (!__list_add_debug(new, prev, next))
97494 + return;
97495 +
97496 next->prev = new;
97497 new->next = next;
97498 new->prev = prev;
97499 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
97500 }
97501 EXPORT_SYMBOL(__list_add);
97502
97503 -void __list_del_entry(struct list_head *entry)
97504 +static bool __list_del_entry_debug(struct list_head *entry)
97505 {
97506 struct list_head *prev, *next;
97507
97508 prev = entry->prev;
97509 next = entry->next;
97510
97511 - if (WARN(next == LIST_POISON1,
97512 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
97513 - entry, LIST_POISON1) ||
97514 - WARN(prev == LIST_POISON2,
97515 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
97516 - entry, LIST_POISON2) ||
97517 - WARN(prev->next != entry,
97518 - "list_del corruption. prev->next should be %p, "
97519 - "but was %p\n", entry, prev->next) ||
97520 - WARN(next->prev != entry,
97521 - "list_del corruption. next->prev should be %p, "
97522 - "but was %p\n", entry, next->prev))
97523 + if (unlikely(next == LIST_POISON1)) {
97524 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
97525 + entry, LIST_POISON1);
97526 + BUG();
97527 + return false;
97528 + }
97529 + if (unlikely(prev == LIST_POISON2)) {
97530 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
97531 + entry, LIST_POISON2);
97532 + BUG();
97533 + return false;
97534 + }
97535 + if (unlikely(entry->prev->next != entry)) {
97536 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
97537 + "but was %p\n", entry, prev->next);
97538 + BUG();
97539 + return false;
97540 + }
97541 + if (unlikely(entry->next->prev != entry)) {
97542 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
97543 + "but was %p\n", entry, next->prev);
97544 + BUG();
97545 + return false;
97546 + }
97547 + return true;
97548 +}
97549 +
97550 +void __list_del_entry(struct list_head *entry)
97551 +{
97552 + if (!__list_del_entry_debug(entry))
97553 return;
97554
97555 - __list_del(prev, next);
97556 + __list_del(entry->prev, entry->next);
97557 }
97558 EXPORT_SYMBOL(__list_del_entry);
97559
97560 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
97561 void __list_add_rcu(struct list_head *new,
97562 struct list_head *prev, struct list_head *next)
97563 {
97564 - WARN(next->prev != prev,
97565 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
97566 - prev, next->prev, next);
97567 - WARN(prev->next != next,
97568 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
97569 - next, prev->next, prev);
97570 + if (!__list_add_debug(new, prev, next))
97571 + return;
97572 +
97573 new->next = next;
97574 new->prev = prev;
97575 rcu_assign_pointer(list_next_rcu(prev), new);
97576 next->prev = new;
97577 }
97578 EXPORT_SYMBOL(__list_add_rcu);
97579 +#endif
97580 +
97581 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
97582 +{
97583 +#ifdef CONFIG_DEBUG_LIST
97584 + if (!__list_add_debug(new, prev, next))
97585 + return;
97586 +#endif
97587 +
97588 + pax_open_kernel();
97589 + next->prev = new;
97590 + new->next = next;
97591 + new->prev = prev;
97592 + prev->next = new;
97593 + pax_close_kernel();
97594 +}
97595 +EXPORT_SYMBOL(__pax_list_add);
97596 +
97597 +void pax_list_del(struct list_head *entry)
97598 +{
97599 +#ifdef CONFIG_DEBUG_LIST
97600 + if (!__list_del_entry_debug(entry))
97601 + return;
97602 +#endif
97603 +
97604 + pax_open_kernel();
97605 + __list_del(entry->prev, entry->next);
97606 + entry->next = LIST_POISON1;
97607 + entry->prev = LIST_POISON2;
97608 + pax_close_kernel();
97609 +}
97610 +EXPORT_SYMBOL(pax_list_del);
97611 +
97612 +void pax_list_del_init(struct list_head *entry)
97613 +{
97614 + pax_open_kernel();
97615 + __list_del(entry->prev, entry->next);
97616 + INIT_LIST_HEAD(entry);
97617 + pax_close_kernel();
97618 +}
97619 +EXPORT_SYMBOL(pax_list_del_init);
97620 +
97621 +void __pax_list_add_rcu(struct list_head *new,
97622 + struct list_head *prev, struct list_head *next)
97623 +{
97624 +#ifdef CONFIG_DEBUG_LIST
97625 + if (!__list_add_debug(new, prev, next))
97626 + return;
97627 +#endif
97628 +
97629 + pax_open_kernel();
97630 + new->next = next;
97631 + new->prev = prev;
97632 + rcu_assign_pointer(list_next_rcu(prev), new);
97633 + next->prev = new;
97634 + pax_close_kernel();
97635 +}
97636 +EXPORT_SYMBOL(__pax_list_add_rcu);
97637 +
97638 +void pax_list_del_rcu(struct list_head *entry)
97639 +{
97640 +#ifdef CONFIG_DEBUG_LIST
97641 + if (!__list_del_entry_debug(entry))
97642 + return;
97643 +#endif
97644 +
97645 + pax_open_kernel();
97646 + __list_del(entry->prev, entry->next);
97647 + entry->next = LIST_POISON1;
97648 + entry->prev = LIST_POISON2;
97649 + pax_close_kernel();
97650 +}
97651 +EXPORT_SYMBOL(pax_list_del_rcu);
97652 diff --git a/lib/lockref.c b/lib/lockref.c
97653 index f07a40d..0a445a7 100644
97654 --- a/lib/lockref.c
97655 +++ b/lib/lockref.c
97656 @@ -49,13 +49,13 @@
97657 void lockref_get(struct lockref *lockref)
97658 {
97659 CMPXCHG_LOOP(
97660 - new.count++;
97661 + __lockref_inc(&new);
97662 ,
97663 return;
97664 );
97665
97666 spin_lock(&lockref->lock);
97667 - lockref->count++;
97668 + __lockref_inc(lockref);
97669 spin_unlock(&lockref->lock);
97670 }
97671 EXPORT_SYMBOL(lockref_get);
97672 @@ -70,7 +70,7 @@ int lockref_get_not_zero(struct lockref *lockref)
97673 int retval;
97674
97675 CMPXCHG_LOOP(
97676 - new.count++;
97677 + __lockref_inc(&new);
97678 if (!old.count)
97679 return 0;
97680 ,
97681 @@ -80,7 +80,7 @@ int lockref_get_not_zero(struct lockref *lockref)
97682 spin_lock(&lockref->lock);
97683 retval = 0;
97684 if (lockref->count) {
97685 - lockref->count++;
97686 + __lockref_inc(lockref);
97687 retval = 1;
97688 }
97689 spin_unlock(&lockref->lock);
97690 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
97691 int lockref_get_or_lock(struct lockref *lockref)
97692 {
97693 CMPXCHG_LOOP(
97694 - new.count++;
97695 + __lockref_inc(&new);
97696 if (!old.count)
97697 break;
97698 ,
97699 @@ -107,7 +107,7 @@ int lockref_get_or_lock(struct lockref *lockref)
97700 spin_lock(&lockref->lock);
97701 if (!lockref->count)
97702 return 0;
97703 - lockref->count++;
97704 + __lockref_inc(lockref);
97705 spin_unlock(&lockref->lock);
97706 return 1;
97707 }
97708 @@ -121,7 +121,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
97709 int lockref_put_or_lock(struct lockref *lockref)
97710 {
97711 CMPXCHG_LOOP(
97712 - new.count--;
97713 + __lockref_dec(&new);
97714 if (old.count <= 1)
97715 break;
97716 ,
97717 @@ -131,7 +131,7 @@ int lockref_put_or_lock(struct lockref *lockref)
97718 spin_lock(&lockref->lock);
97719 if (lockref->count <= 1)
97720 return 0;
97721 - lockref->count--;
97722 + __lockref_dec(lockref);
97723 spin_unlock(&lockref->lock);
97724 return 1;
97725 }
97726 @@ -158,7 +158,7 @@ int lockref_get_not_dead(struct lockref *lockref)
97727 int retval;
97728
97729 CMPXCHG_LOOP(
97730 - new.count++;
97731 + __lockref_inc(&new);
97732 if ((int)old.count < 0)
97733 return 0;
97734 ,
97735 @@ -168,7 +168,7 @@ int lockref_get_not_dead(struct lockref *lockref)
97736 spin_lock(&lockref->lock);
97737 retval = 0;
97738 if ((int) lockref->count >= 0) {
97739 - lockref->count++;
97740 + __lockref_inc(lockref);
97741 retval = 1;
97742 }
97743 spin_unlock(&lockref->lock);
97744 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
97745 index 963b703..438bc51 100644
97746 --- a/lib/percpu-refcount.c
97747 +++ b/lib/percpu-refcount.c
97748 @@ -29,7 +29,7 @@
97749 * can't hit 0 before we've added up all the percpu refs.
97750 */
97751
97752 -#define PCPU_COUNT_BIAS (1U << 31)
97753 +#define PCPU_COUNT_BIAS (1U << 30)
97754
97755 /**
97756 * percpu_ref_init - initialize a percpu refcount
97757 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
97758 index 3291a8e..346a91e 100644
97759 --- a/lib/radix-tree.c
97760 +++ b/lib/radix-tree.c
97761 @@ -67,7 +67,7 @@ struct radix_tree_preload {
97762 int nr;
97763 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
97764 };
97765 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
97766 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
97767
97768 static inline void *ptr_to_indirect(void *ptr)
97769 {
97770 diff --git a/lib/random32.c b/lib/random32.c
97771 index fa5da61..35fe9af 100644
97772 --- a/lib/random32.c
97773 +++ b/lib/random32.c
97774 @@ -42,7 +42,7 @@
97775 static void __init prandom_state_selftest(void);
97776 #endif
97777
97778 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
97779 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
97780
97781 /**
97782 * prandom_u32_state - seeded pseudo-random number generator.
97783 diff --git a/lib/rbtree.c b/lib/rbtree.c
97784 index 65f4eff..2cfa167 100644
97785 --- a/lib/rbtree.c
97786 +++ b/lib/rbtree.c
97787 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
97788 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
97789
97790 static const struct rb_augment_callbacks dummy_callbacks = {
97791 - dummy_propagate, dummy_copy, dummy_rotate
97792 + .propagate = dummy_propagate,
97793 + .copy = dummy_copy,
97794 + .rotate = dummy_rotate
97795 };
97796
97797 void rb_insert_color(struct rb_node *node, struct rb_root *root)
97798 diff --git a/lib/show_mem.c b/lib/show_mem.c
97799 index 0922579..9d7adb9 100644
97800 --- a/lib/show_mem.c
97801 +++ b/lib/show_mem.c
97802 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
97803 quicklist_total_size());
97804 #endif
97805 #ifdef CONFIG_MEMORY_FAILURE
97806 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
97807 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
97808 #endif
97809 }
97810 diff --git a/lib/string.c b/lib/string.c
97811 index 992bf30..f3c6ff5 100644
97812 --- a/lib/string.c
97813 +++ b/lib/string.c
97814 @@ -807,9 +807,9 @@ void *memchr_inv(const void *start, int c, size_t bytes)
97815 return check_bytes8(start, value, bytes);
97816
97817 value64 = value;
97818 -#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
97819 +#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
97820 value64 *= 0x0101010101010101;
97821 -#elif defined(ARCH_HAS_FAST_MULTIPLIER)
97822 +#elif defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER)
97823 value64 *= 0x01010101;
97824 value64 |= value64 << 32;
97825 #else
97826 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
97827 index bb2b201..46abaf9 100644
97828 --- a/lib/strncpy_from_user.c
97829 +++ b/lib/strncpy_from_user.c
97830 @@ -21,7 +21,7 @@
97831 */
97832 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
97833 {
97834 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
97835 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
97836 long res = 0;
97837
97838 /*
97839 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
97840 index a28df52..3d55877 100644
97841 --- a/lib/strnlen_user.c
97842 +++ b/lib/strnlen_user.c
97843 @@ -26,7 +26,7 @@
97844 */
97845 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
97846 {
97847 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
97848 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
97849 long align, res = 0;
97850 unsigned long c;
97851
97852 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
97853 index 4abda07..b9d3765 100644
97854 --- a/lib/swiotlb.c
97855 +++ b/lib/swiotlb.c
97856 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
97857
97858 void
97859 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
97860 - dma_addr_t dev_addr)
97861 + dma_addr_t dev_addr, struct dma_attrs *attrs)
97862 {
97863 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
97864
97865 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
97866 deleted file mode 100644
97867 index c579e0f..0000000
97868 --- a/lib/test_bpf.c
97869 +++ /dev/null
97870 @@ -1,1929 +0,0 @@
97871 -/*
97872 - * Testsuite for BPF interpreter and BPF JIT compiler
97873 - *
97874 - * Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
97875 - *
97876 - * This program is free software; you can redistribute it and/or
97877 - * modify it under the terms of version 2 of the GNU General Public
97878 - * License as published by the Free Software Foundation.
97879 - *
97880 - * This program is distributed in the hope that it will be useful, but
97881 - * WITHOUT ANY WARRANTY; without even the implied warranty of
97882 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97883 - * General Public License for more details.
97884 - */
97885 -
97886 -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
97887 -
97888 -#include <linux/init.h>
97889 -#include <linux/module.h>
97890 -#include <linux/filter.h>
97891 -#include <linux/skbuff.h>
97892 -#include <linux/netdevice.h>
97893 -#include <linux/if_vlan.h>
97894 -
97895 -/* General test specific settings */
97896 -#define MAX_SUBTESTS 3
97897 -#define MAX_TESTRUNS 10000
97898 -#define MAX_DATA 128
97899 -#define MAX_INSNS 512
97900 -#define MAX_K 0xffffFFFF
97901 -
97902 -/* Few constants used to init test 'skb' */
97903 -#define SKB_TYPE 3
97904 -#define SKB_MARK 0x1234aaaa
97905 -#define SKB_HASH 0x1234aaab
97906 -#define SKB_QUEUE_MAP 123
97907 -#define SKB_VLAN_TCI 0xffff
97908 -#define SKB_DEV_IFINDEX 577
97909 -#define SKB_DEV_TYPE 588
97910 -
97911 -/* Redefine REGs to make tests less verbose */
97912 -#define R0 BPF_REG_0
97913 -#define R1 BPF_REG_1
97914 -#define R2 BPF_REG_2
97915 -#define R3 BPF_REG_3
97916 -#define R4 BPF_REG_4
97917 -#define R5 BPF_REG_5
97918 -#define R6 BPF_REG_6
97919 -#define R7 BPF_REG_7
97920 -#define R8 BPF_REG_8
97921 -#define R9 BPF_REG_9
97922 -#define R10 BPF_REG_10
97923 -
97924 -/* Flags that can be passed to test cases */
97925 -#define FLAG_NO_DATA BIT(0)
97926 -#define FLAG_EXPECTED_FAIL BIT(1)
97927 -
97928 -enum {
97929 - CLASSIC = BIT(6), /* Old BPF instructions only. */
97930 - INTERNAL = BIT(7), /* Extended instruction set. */
97931 -};
97932 -
97933 -#define TEST_TYPE_MASK (CLASSIC | INTERNAL)
97934 -
97935 -struct bpf_test {
97936 - const char *descr;
97937 - union {
97938 - struct sock_filter insns[MAX_INSNS];
97939 - struct sock_filter_int insns_int[MAX_INSNS];
97940 - } u;
97941 - __u8 aux;
97942 - __u8 data[MAX_DATA];
97943 - struct {
97944 - int data_size;
97945 - __u32 result;
97946 - } test[MAX_SUBTESTS];
97947 -};
97948 -
97949 -static struct bpf_test tests[] = {
97950 - {
97951 - "TAX",
97952 - .u.insns = {
97953 - BPF_STMT(BPF_LD | BPF_IMM, 1),
97954 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97955 - BPF_STMT(BPF_LD | BPF_IMM, 2),
97956 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97957 - BPF_STMT(BPF_ALU | BPF_NEG, 0), /* A == -3 */
97958 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
97959 - BPF_STMT(BPF_LD | BPF_LEN, 0),
97960 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97961 - BPF_STMT(BPF_MISC | BPF_TAX, 0), /* X == len - 3 */
97962 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1),
97963 - BPF_STMT(BPF_RET | BPF_A, 0)
97964 - },
97965 - CLASSIC,
97966 - { 10, 20, 30, 40, 50 },
97967 - { { 2, 10 }, { 3, 20 }, { 4, 30 } },
97968 - },
97969 - {
97970 - "TXA",
97971 - .u.insns = {
97972 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
97973 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
97974 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
97975 - BPF_STMT(BPF_RET | BPF_A, 0) /* A == len * 2 */
97976 - },
97977 - CLASSIC,
97978 - { 10, 20, 30, 40, 50 },
97979 - { { 1, 2 }, { 3, 6 }, { 4, 8 } },
97980 - },
97981 - {
97982 - "ADD_SUB_MUL_K",
97983 - .u.insns = {
97984 - BPF_STMT(BPF_LD | BPF_IMM, 1),
97985 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 2),
97986 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
97987 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
97988 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 0xffffffff),
97989 - BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 3),
97990 - BPF_STMT(BPF_RET | BPF_A, 0)
97991 - },
97992 - CLASSIC | FLAG_NO_DATA,
97993 - { },
97994 - { { 0, 0xfffffffd } }
97995 - },
97996 - {
97997 - "DIV_KX",
97998 - .u.insns = {
97999 - BPF_STMT(BPF_LD | BPF_IMM, 8),
98000 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 2),
98001 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98002 - BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
98003 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_X, 0),
98004 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98005 - BPF_STMT(BPF_LD | BPF_IMM, 0xffffffff),
98006 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0x70000000),
98007 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98008 - BPF_STMT(BPF_RET | BPF_A, 0)
98009 - },
98010 - CLASSIC | FLAG_NO_DATA,
98011 - { },
98012 - { { 0, 0x40000001 } }
98013 - },
98014 - {
98015 - "AND_OR_LSH_K",
98016 - .u.insns = {
98017 - BPF_STMT(BPF_LD | BPF_IMM, 0xff),
98018 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
98019 - BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 27),
98020 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98021 - BPF_STMT(BPF_LD | BPF_IMM, 0xf),
98022 - BPF_STMT(BPF_ALU | BPF_OR | BPF_K, 0xf0),
98023 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98024 - BPF_STMT(BPF_RET | BPF_A, 0)
98025 - },
98026 - CLASSIC | FLAG_NO_DATA,
98027 - { },
98028 - { { 0, 0x800000ff }, { 1, 0x800000ff } },
98029 - },
98030 - {
98031 - "LD_IMM_0",
98032 - .u.insns = {
98033 - BPF_STMT(BPF_LD | BPF_IMM, 0), /* ld #0 */
98034 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
98035 - BPF_STMT(BPF_RET | BPF_K, 0),
98036 - BPF_STMT(BPF_RET | BPF_K, 1),
98037 - },
98038 - CLASSIC,
98039 - { },
98040 - { { 1, 1 } },
98041 - },
98042 - {
98043 - "LD_IND",
98044 - .u.insns = {
98045 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98046 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, MAX_K),
98047 - BPF_STMT(BPF_RET | BPF_K, 1)
98048 - },
98049 - CLASSIC,
98050 - { },
98051 - { { 1, 0 }, { 10, 0 }, { 60, 0 } },
98052 - },
98053 - {
98054 - "LD_ABS",
98055 - .u.insns = {
98056 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS, 1000),
98057 - BPF_STMT(BPF_RET | BPF_K, 1)
98058 - },
98059 - CLASSIC,
98060 - { },
98061 - { { 1, 0 }, { 10, 0 }, { 60, 0 } },
98062 - },
98063 - {
98064 - "LD_ABS_LL",
98065 - .u.insns = {
98066 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF),
98067 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98068 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_LL_OFF + 1),
98069 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98070 - BPF_STMT(BPF_RET | BPF_A, 0)
98071 - },
98072 - CLASSIC,
98073 - { 1, 2, 3 },
98074 - { { 1, 0 }, { 2, 3 } },
98075 - },
98076 - {
98077 - "LD_IND_LL",
98078 - .u.insns = {
98079 - BPF_STMT(BPF_LD | BPF_IMM, SKF_LL_OFF - 1),
98080 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98081 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98082 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98083 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
98084 - BPF_STMT(BPF_RET | BPF_A, 0)
98085 - },
98086 - CLASSIC,
98087 - { 1, 2, 3, 0xff },
98088 - { { 1, 1 }, { 3, 3 }, { 4, 0xff } },
98089 - },
98090 - {
98091 - "LD_ABS_NET",
98092 - .u.insns = {
98093 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF),
98094 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98095 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, SKF_NET_OFF + 1),
98096 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98097 - BPF_STMT(BPF_RET | BPF_A, 0)
98098 - },
98099 - CLASSIC,
98100 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
98101 - { { 15, 0 }, { 16, 3 } },
98102 - },
98103 - {
98104 - "LD_IND_NET",
98105 - .u.insns = {
98106 - BPF_STMT(BPF_LD | BPF_IMM, SKF_NET_OFF - 15),
98107 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98108 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
98109 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98110 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
98111 - BPF_STMT(BPF_RET | BPF_A, 0)
98112 - },
98113 - CLASSIC,
98114 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 },
98115 - { { 14, 0 }, { 15, 1 }, { 17, 3 } },
98116 - },
98117 - {
98118 - "LD_PKTTYPE",
98119 - .u.insns = {
98120 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98121 - SKF_AD_OFF + SKF_AD_PKTTYPE),
98122 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
98123 - BPF_STMT(BPF_RET | BPF_K, 1),
98124 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98125 - SKF_AD_OFF + SKF_AD_PKTTYPE),
98126 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
98127 - BPF_STMT(BPF_RET | BPF_K, 1),
98128 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98129 - SKF_AD_OFF + SKF_AD_PKTTYPE),
98130 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SKB_TYPE, 1, 0),
98131 - BPF_STMT(BPF_RET | BPF_K, 1),
98132 - BPF_STMT(BPF_RET | BPF_A, 0)
98133 - },
98134 - CLASSIC,
98135 - { },
98136 - { { 1, 3 }, { 10, 3 } },
98137 - },
98138 - {
98139 - "LD_MARK",
98140 - .u.insns = {
98141 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98142 - SKF_AD_OFF + SKF_AD_MARK),
98143 - BPF_STMT(BPF_RET | BPF_A, 0)
98144 - },
98145 - CLASSIC,
98146 - { },
98147 - { { 1, SKB_MARK}, { 10, SKB_MARK} },
98148 - },
98149 - {
98150 - "LD_RXHASH",
98151 - .u.insns = {
98152 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98153 - SKF_AD_OFF + SKF_AD_RXHASH),
98154 - BPF_STMT(BPF_RET | BPF_A, 0)
98155 - },
98156 - CLASSIC,
98157 - { },
98158 - { { 1, SKB_HASH}, { 10, SKB_HASH} },
98159 - },
98160 - {
98161 - "LD_QUEUE",
98162 - .u.insns = {
98163 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98164 - SKF_AD_OFF + SKF_AD_QUEUE),
98165 - BPF_STMT(BPF_RET | BPF_A, 0)
98166 - },
98167 - CLASSIC,
98168 - { },
98169 - { { 1, SKB_QUEUE_MAP }, { 10, SKB_QUEUE_MAP } },
98170 - },
98171 - {
98172 - "LD_PROTOCOL",
98173 - .u.insns = {
98174 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 1),
98175 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 20, 1, 0),
98176 - BPF_STMT(BPF_RET | BPF_K, 0),
98177 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98178 - SKF_AD_OFF + SKF_AD_PROTOCOL),
98179 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98180 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
98181 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 30, 1, 0),
98182 - BPF_STMT(BPF_RET | BPF_K, 0),
98183 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98184 - BPF_STMT(BPF_RET | BPF_A, 0)
98185 - },
98186 - CLASSIC,
98187 - { 10, 20, 30 },
98188 - { { 10, ETH_P_IP }, { 100, ETH_P_IP } },
98189 - },
98190 - {
98191 - "LD_VLAN_TAG",
98192 - .u.insns = {
98193 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98194 - SKF_AD_OFF + SKF_AD_VLAN_TAG),
98195 - BPF_STMT(BPF_RET | BPF_A, 0)
98196 - },
98197 - CLASSIC,
98198 - { },
98199 - {
98200 - { 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT },
98201 - { 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }
98202 - },
98203 - },
98204 - {
98205 - "LD_VLAN_TAG_PRESENT",
98206 - .u.insns = {
98207 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98208 - SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT),
98209 - BPF_STMT(BPF_RET | BPF_A, 0)
98210 - },
98211 - CLASSIC,
98212 - { },
98213 - {
98214 - { 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
98215 - { 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
98216 - },
98217 - },
98218 - {
98219 - "LD_IFINDEX",
98220 - .u.insns = {
98221 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98222 - SKF_AD_OFF + SKF_AD_IFINDEX),
98223 - BPF_STMT(BPF_RET | BPF_A, 0)
98224 - },
98225 - CLASSIC,
98226 - { },
98227 - { { 1, SKB_DEV_IFINDEX }, { 10, SKB_DEV_IFINDEX } },
98228 - },
98229 - {
98230 - "LD_HATYPE",
98231 - .u.insns = {
98232 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98233 - SKF_AD_OFF + SKF_AD_HATYPE),
98234 - BPF_STMT(BPF_RET | BPF_A, 0)
98235 - },
98236 - CLASSIC,
98237 - { },
98238 - { { 1, SKB_DEV_TYPE }, { 10, SKB_DEV_TYPE } },
98239 - },
98240 - {
98241 - "LD_CPU",
98242 - .u.insns = {
98243 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98244 - SKF_AD_OFF + SKF_AD_CPU),
98245 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98246 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98247 - SKF_AD_OFF + SKF_AD_CPU),
98248 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
98249 - BPF_STMT(BPF_RET | BPF_A, 0)
98250 - },
98251 - CLASSIC,
98252 - { },
98253 - { { 1, 0 }, { 10, 0 } },
98254 - },
98255 - {
98256 - "LD_NLATTR",
98257 - .u.insns = {
98258 - BPF_STMT(BPF_LDX | BPF_IMM, 2),
98259 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98260 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
98261 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98262 - SKF_AD_OFF + SKF_AD_NLATTR),
98263 - BPF_STMT(BPF_RET | BPF_A, 0)
98264 - },
98265 - CLASSIC,
98266 -#ifdef __BIG_ENDIAN
98267 - { 0xff, 0xff, 0, 4, 0, 2, 0, 4, 0, 3 },
98268 -#else
98269 - { 0xff, 0xff, 4, 0, 2, 0, 4, 0, 3, 0 },
98270 -#endif
98271 - { { 4, 0 }, { 20, 6 } },
98272 - },
98273 - {
98274 - "LD_NLATTR_NEST",
98275 - .u.insns = {
98276 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98277 - BPF_STMT(BPF_LDX | BPF_IMM, 3),
98278 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98279 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98280 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98281 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98282 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98283 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98284 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98285 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98286 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98287 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98288 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98289 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98290 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98291 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98292 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98293 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98294 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98295 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98296 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98297 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98298 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98299 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98300 - SKF_AD_OFF + SKF_AD_NLATTR_NEST),
98301 - BPF_STMT(BPF_RET | BPF_A, 0)
98302 - },
98303 - CLASSIC,
98304 -#ifdef __BIG_ENDIAN
98305 - { 0xff, 0xff, 0, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3 },
98306 -#else
98307 - { 0xff, 0xff, 12, 0, 1, 0, 4, 0, 2, 0, 4, 0, 3, 0 },
98308 -#endif
98309 - { { 4, 0 }, { 20, 10 } },
98310 - },
98311 - {
98312 - "LD_PAYLOAD_OFF",
98313 - .u.insns = {
98314 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98315 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
98316 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98317 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
98318 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98319 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
98320 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98321 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
98322 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98323 - SKF_AD_OFF + SKF_AD_PAY_OFFSET),
98324 - BPF_STMT(BPF_RET | BPF_A, 0)
98325 - },
98326 - CLASSIC,
98327 - /* 00:00:00:00:00:00 > 00:00:00:00:00:00, ethtype IPv4 (0x0800),
98328 - * length 98: 127.0.0.1 > 127.0.0.1: ICMP echo request,
98329 - * id 9737, seq 1, length 64
98330 - */
98331 - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98332 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98333 - 0x08, 0x00,
98334 - 0x45, 0x00, 0x00, 0x54, 0xac, 0x8b, 0x40, 0x00, 0x40,
98335 - 0x01, 0x90, 0x1b, 0x7f, 0x00, 0x00, 0x01 },
98336 - { { 30, 0 }, { 100, 42 } },
98337 - },
98338 - {
98339 - "LD_ANC_XOR",
98340 - .u.insns = {
98341 - BPF_STMT(BPF_LD | BPF_IMM, 10),
98342 - BPF_STMT(BPF_LDX | BPF_IMM, 300),
98343 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
98344 - SKF_AD_OFF + SKF_AD_ALU_XOR_X),
98345 - BPF_STMT(BPF_RET | BPF_A, 0)
98346 - },
98347 - CLASSIC,
98348 - { },
98349 - { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
98350 - },
98351 - {
98352 - "SPILL_FILL",
98353 - .u.insns = {
98354 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98355 - BPF_STMT(BPF_LD | BPF_IMM, 2),
98356 - BPF_STMT(BPF_ALU | BPF_RSH, 1),
98357 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
98358 - BPF_STMT(BPF_ST, 1), /* M1 = 1 ^ len */
98359 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_K, 0x80000000),
98360 - BPF_STMT(BPF_ST, 2), /* M2 = 1 ^ len ^ 0x80000000 */
98361 - BPF_STMT(BPF_STX, 15), /* M3 = len */
98362 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
98363 - BPF_STMT(BPF_LD | BPF_MEM, 2),
98364 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
98365 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
98366 - BPF_STMT(BPF_ALU | BPF_XOR | BPF_X, 0),
98367 - BPF_STMT(BPF_RET | BPF_A, 0)
98368 - },
98369 - CLASSIC,
98370 - { },
98371 - { { 1, 0x80000001 }, { 2, 0x80000002 }, { 60, 0x80000000 ^ 60 } }
98372 - },
98373 - {
98374 - "JEQ",
98375 - .u.insns = {
98376 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98377 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
98378 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
98379 - BPF_STMT(BPF_RET | BPF_K, 1),
98380 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
98381 - },
98382 - CLASSIC,
98383 - { 3, 3, 3, 3, 3 },
98384 - { { 1, 0 }, { 3, 1 }, { 4, MAX_K } },
98385 - },
98386 - {
98387 - "JGT",
98388 - .u.insns = {
98389 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98390 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2),
98391 - BPF_JUMP(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 1),
98392 - BPF_STMT(BPF_RET | BPF_K, 1),
98393 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
98394 - },
98395 - CLASSIC,
98396 - { 4, 4, 4, 3, 3 },
98397 - { { 2, 0 }, { 3, 1 }, { 4, MAX_K } },
98398 - },
98399 - {
98400 - "JGE",
98401 - .u.insns = {
98402 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98403 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, MAX_K),
98404 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 1, 1, 0),
98405 - BPF_STMT(BPF_RET | BPF_K, 10),
98406 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 2, 1, 0),
98407 - BPF_STMT(BPF_RET | BPF_K, 20),
98408 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 3, 1, 0),
98409 - BPF_STMT(BPF_RET | BPF_K, 30),
98410 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 4, 1, 0),
98411 - BPF_STMT(BPF_RET | BPF_K, 40),
98412 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
98413 - },
98414 - CLASSIC,
98415 - { 1, 2, 3, 4, 5 },
98416 - { { 1, 20 }, { 3, 40 }, { 5, MAX_K } },
98417 - },
98418 - {
98419 - "JSET",
98420 - .u.insns = {
98421 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
98422 - BPF_JUMP(BPF_JMP | BPF_JA, 1, 1, 1),
98423 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
98424 - BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0),
98425 - BPF_STMT(BPF_LDX | BPF_LEN, 0),
98426 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98427 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_K, 4),
98428 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
98429 - BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0),
98430 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 1, 0, 1),
98431 - BPF_STMT(BPF_RET | BPF_K, 10),
98432 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x80000000, 0, 1),
98433 - BPF_STMT(BPF_RET | BPF_K, 20),
98434 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
98435 - BPF_STMT(BPF_RET | BPF_K, 30),
98436 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
98437 - BPF_STMT(BPF_RET | BPF_K, 30),
98438 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
98439 - BPF_STMT(BPF_RET | BPF_K, 30),
98440 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
98441 - BPF_STMT(BPF_RET | BPF_K, 30),
98442 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0xffffff, 1, 0),
98443 - BPF_STMT(BPF_RET | BPF_K, 30),
98444 - BPF_STMT(BPF_RET | BPF_K, MAX_K)
98445 - },
98446 - CLASSIC,
98447 - { 0, 0xAA, 0x55, 1 },
98448 - { { 4, 10 }, { 5, 20 }, { 6, MAX_K } },
98449 - },
98450 - {
98451 - "tcpdump port 22",
98452 - .u.insns = {
98453 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
98454 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
98455 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
98456 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
98457 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
98458 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
98459 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
98460 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
98461 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
98462 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
98463 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
98464 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
98465 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
98466 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
98467 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
98468 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
98469 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
98470 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
98471 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
98472 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
98473 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
98474 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
98475 - BPF_STMT(BPF_RET | BPF_K, 0xffff),
98476 - BPF_STMT(BPF_RET | BPF_K, 0),
98477 - },
98478 - CLASSIC,
98479 - /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
98480 - * length 114: 10.1.1.149.49700 > 10.1.2.10.22: Flags [P.],
98481 - * seq 1305692979:1305693027, ack 3650467037, win 65535,
98482 - * options [nop,nop,TS val 2502645400 ecr 3971138], length 48
98483 - */
98484 - { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
98485 - 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
98486 - 0x08, 0x00,
98487 - 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
98488 - 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
98489 - 0x0a, 0x01, 0x01, 0x95, /* ip src */
98490 - 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
98491 - 0xc2, 0x24,
98492 - 0x00, 0x16 /* dst port */ },
98493 - { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
98494 - },
98495 - {
98496 - "tcpdump complex",
98497 - .u.insns = {
98498 - /* tcpdump -nei eth0 'tcp port 22 and (((ip[2:2] -
98499 - * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
98500 - * (len > 115 or len < 30000000000)' -d
98501 - */
98502 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
98503 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
98504 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
98505 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
98506 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
98507 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
98508 - BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
98509 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
98510 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
98511 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
98512 - BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
98513 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
98514 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
98515 - BPF_STMT(BPF_ST, 1),
98516 - BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
98517 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
98518 - BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
98519 - BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
98520 - BPF_STMT(BPF_LD | BPF_MEM, 1),
98521 - BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
98522 - BPF_STMT(BPF_ST, 5),
98523 - BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
98524 - BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
98525 - BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
98526 - BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
98527 - BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
98528 - BPF_STMT(BPF_LD | BPF_MEM, 5),
98529 - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
98530 - BPF_STMT(BPF_LD | BPF_LEN, 0),
98531 - BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
98532 - BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
98533 - BPF_STMT(BPF_RET | BPF_K, 0xffff),
98534 - BPF_STMT(BPF_RET | BPF_K, 0),
98535 - },
98536 - CLASSIC,
98537 - { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
98538 - 0x3c, 0x07, 0x54, 0x43, 0xe5, 0x76,
98539 - 0x08, 0x00,
98540 - 0x45, 0x10, 0x00, 0x64, 0x75, 0xb5,
98541 - 0x40, 0x00, 0x40, 0x06, 0xad, 0x2e, /* IP header */
98542 - 0x0a, 0x01, 0x01, 0x95, /* ip src */
98543 - 0x0a, 0x01, 0x02, 0x0a, /* ip dst */
98544 - 0xc2, 0x24,
98545 - 0x00, 0x16 /* dst port */ },
98546 - { { 10, 0 }, { 30, 0 }, { 100, 65535 } },
98547 - },
98548 - {
98549 - "RET_A",
98550 - .u.insns = {
98551 - /* check that unitialized X and A contain zeros */
98552 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
98553 - BPF_STMT(BPF_RET | BPF_A, 0)
98554 - },
98555 - CLASSIC,
98556 - { },
98557 - { {1, 0}, {2, 0} },
98558 - },
98559 - {
98560 - "INT: ADD trivial",
98561 - .u.insns_int = {
98562 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
98563 - BPF_ALU64_IMM(BPF_ADD, R1, 2),
98564 - BPF_ALU64_IMM(BPF_MOV, R2, 3),
98565 - BPF_ALU64_REG(BPF_SUB, R1, R2),
98566 - BPF_ALU64_IMM(BPF_ADD, R1, -1),
98567 - BPF_ALU64_IMM(BPF_MUL, R1, 3),
98568 - BPF_ALU64_REG(BPF_MOV, R0, R1),
98569 - BPF_EXIT_INSN(),
98570 - },
98571 - INTERNAL,
98572 - { },
98573 - { { 0, 0xfffffffd } }
98574 - },
98575 - {
98576 - "INT: MUL_X",
98577 - .u.insns_int = {
98578 - BPF_ALU64_IMM(BPF_MOV, R0, -1),
98579 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
98580 - BPF_ALU64_IMM(BPF_MOV, R2, 3),
98581 - BPF_ALU64_REG(BPF_MUL, R1, R2),
98582 - BPF_JMP_IMM(BPF_JEQ, R1, 0xfffffffd, 1),
98583 - BPF_EXIT_INSN(),
98584 - BPF_ALU64_IMM(BPF_MOV, R0, 1),
98585 - BPF_EXIT_INSN(),
98586 - },
98587 - INTERNAL,
98588 - { },
98589 - { { 0, 1 } }
98590 - },
98591 - {
98592 - "INT: MUL_X2",
98593 - .u.insns_int = {
98594 - BPF_ALU32_IMM(BPF_MOV, R0, -1),
98595 - BPF_ALU32_IMM(BPF_MOV, R1, -1),
98596 - BPF_ALU32_IMM(BPF_MOV, R2, 3),
98597 - BPF_ALU64_REG(BPF_MUL, R1, R2),
98598 - BPF_ALU64_IMM(BPF_RSH, R1, 8),
98599 - BPF_JMP_IMM(BPF_JEQ, R1, 0x2ffffff, 1),
98600 - BPF_EXIT_INSN(),
98601 - BPF_ALU32_IMM(BPF_MOV, R0, 1),
98602 - BPF_EXIT_INSN(),
98603 - },
98604 - INTERNAL,
98605 - { },
98606 - { { 0, 1 } }
98607 - },
98608 - {
98609 - "INT: MUL32_X",
98610 - .u.insns_int = {
98611 - BPF_ALU32_IMM(BPF_MOV, R0, -1),
98612 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
98613 - BPF_ALU32_IMM(BPF_MOV, R2, 3),
98614 - BPF_ALU32_REG(BPF_MUL, R1, R2),
98615 - BPF_ALU64_IMM(BPF_RSH, R1, 8),
98616 - BPF_JMP_IMM(BPF_JEQ, R1, 0xffffff, 1),
98617 - BPF_EXIT_INSN(),
98618 - BPF_ALU32_IMM(BPF_MOV, R0, 1),
98619 - BPF_EXIT_INSN(),
98620 - },
98621 - INTERNAL,
98622 - { },
98623 - { { 0, 1 } }
98624 - },
98625 - {
98626 - /* Have to test all register combinations, since
98627 - * JITing of different registers will produce
98628 - * different asm code.
98629 - */
98630 - "INT: ADD 64-bit",
98631 - .u.insns_int = {
98632 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
98633 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
98634 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
98635 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
98636 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
98637 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
98638 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
98639 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
98640 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
98641 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
98642 - BPF_ALU64_IMM(BPF_ADD, R0, 20),
98643 - BPF_ALU64_IMM(BPF_ADD, R1, 20),
98644 - BPF_ALU64_IMM(BPF_ADD, R2, 20),
98645 - BPF_ALU64_IMM(BPF_ADD, R3, 20),
98646 - BPF_ALU64_IMM(BPF_ADD, R4, 20),
98647 - BPF_ALU64_IMM(BPF_ADD, R5, 20),
98648 - BPF_ALU64_IMM(BPF_ADD, R6, 20),
98649 - BPF_ALU64_IMM(BPF_ADD, R7, 20),
98650 - BPF_ALU64_IMM(BPF_ADD, R8, 20),
98651 - BPF_ALU64_IMM(BPF_ADD, R9, 20),
98652 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
98653 - BPF_ALU64_IMM(BPF_SUB, R1, 10),
98654 - BPF_ALU64_IMM(BPF_SUB, R2, 10),
98655 - BPF_ALU64_IMM(BPF_SUB, R3, 10),
98656 - BPF_ALU64_IMM(BPF_SUB, R4, 10),
98657 - BPF_ALU64_IMM(BPF_SUB, R5, 10),
98658 - BPF_ALU64_IMM(BPF_SUB, R6, 10),
98659 - BPF_ALU64_IMM(BPF_SUB, R7, 10),
98660 - BPF_ALU64_IMM(BPF_SUB, R8, 10),
98661 - BPF_ALU64_IMM(BPF_SUB, R9, 10),
98662 - BPF_ALU64_REG(BPF_ADD, R0, R0),
98663 - BPF_ALU64_REG(BPF_ADD, R0, R1),
98664 - BPF_ALU64_REG(BPF_ADD, R0, R2),
98665 - BPF_ALU64_REG(BPF_ADD, R0, R3),
98666 - BPF_ALU64_REG(BPF_ADD, R0, R4),
98667 - BPF_ALU64_REG(BPF_ADD, R0, R5),
98668 - BPF_ALU64_REG(BPF_ADD, R0, R6),
98669 - BPF_ALU64_REG(BPF_ADD, R0, R7),
98670 - BPF_ALU64_REG(BPF_ADD, R0, R8),
98671 - BPF_ALU64_REG(BPF_ADD, R0, R9), /* R0 == 155 */
98672 - BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
98673 - BPF_EXIT_INSN(),
98674 - BPF_ALU64_REG(BPF_ADD, R1, R0),
98675 - BPF_ALU64_REG(BPF_ADD, R1, R1),
98676 - BPF_ALU64_REG(BPF_ADD, R1, R2),
98677 - BPF_ALU64_REG(BPF_ADD, R1, R3),
98678 - BPF_ALU64_REG(BPF_ADD, R1, R4),
98679 - BPF_ALU64_REG(BPF_ADD, R1, R5),
98680 - BPF_ALU64_REG(BPF_ADD, R1, R6),
98681 - BPF_ALU64_REG(BPF_ADD, R1, R7),
98682 - BPF_ALU64_REG(BPF_ADD, R1, R8),
98683 - BPF_ALU64_REG(BPF_ADD, R1, R9), /* R1 == 456 */
98684 - BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
98685 - BPF_EXIT_INSN(),
98686 - BPF_ALU64_REG(BPF_ADD, R2, R0),
98687 - BPF_ALU64_REG(BPF_ADD, R2, R1),
98688 - BPF_ALU64_REG(BPF_ADD, R2, R2),
98689 - BPF_ALU64_REG(BPF_ADD, R2, R3),
98690 - BPF_ALU64_REG(BPF_ADD, R2, R4),
98691 - BPF_ALU64_REG(BPF_ADD, R2, R5),
98692 - BPF_ALU64_REG(BPF_ADD, R2, R6),
98693 - BPF_ALU64_REG(BPF_ADD, R2, R7),
98694 - BPF_ALU64_REG(BPF_ADD, R2, R8),
98695 - BPF_ALU64_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
98696 - BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
98697 - BPF_EXIT_INSN(),
98698 - BPF_ALU64_REG(BPF_ADD, R3, R0),
98699 - BPF_ALU64_REG(BPF_ADD, R3, R1),
98700 - BPF_ALU64_REG(BPF_ADD, R3, R2),
98701 - BPF_ALU64_REG(BPF_ADD, R3, R3),
98702 - BPF_ALU64_REG(BPF_ADD, R3, R4),
98703 - BPF_ALU64_REG(BPF_ADD, R3, R5),
98704 - BPF_ALU64_REG(BPF_ADD, R3, R6),
98705 - BPF_ALU64_REG(BPF_ADD, R3, R7),
98706 - BPF_ALU64_REG(BPF_ADD, R3, R8),
98707 - BPF_ALU64_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
98708 - BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
98709 - BPF_EXIT_INSN(),
98710 - BPF_ALU64_REG(BPF_ADD, R4, R0),
98711 - BPF_ALU64_REG(BPF_ADD, R4, R1),
98712 - BPF_ALU64_REG(BPF_ADD, R4, R2),
98713 - BPF_ALU64_REG(BPF_ADD, R4, R3),
98714 - BPF_ALU64_REG(BPF_ADD, R4, R4),
98715 - BPF_ALU64_REG(BPF_ADD, R4, R5),
98716 - BPF_ALU64_REG(BPF_ADD, R4, R6),
98717 - BPF_ALU64_REG(BPF_ADD, R4, R7),
98718 - BPF_ALU64_REG(BPF_ADD, R4, R8),
98719 - BPF_ALU64_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
98720 - BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
98721 - BPF_EXIT_INSN(),
98722 - BPF_ALU64_REG(BPF_ADD, R5, R0),
98723 - BPF_ALU64_REG(BPF_ADD, R5, R1),
98724 - BPF_ALU64_REG(BPF_ADD, R5, R2),
98725 - BPF_ALU64_REG(BPF_ADD, R5, R3),
98726 - BPF_ALU64_REG(BPF_ADD, R5, R4),
98727 - BPF_ALU64_REG(BPF_ADD, R5, R5),
98728 - BPF_ALU64_REG(BPF_ADD, R5, R6),
98729 - BPF_ALU64_REG(BPF_ADD, R5, R7),
98730 - BPF_ALU64_REG(BPF_ADD, R5, R8),
98731 - BPF_ALU64_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
98732 - BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
98733 - BPF_EXIT_INSN(),
98734 - BPF_ALU64_REG(BPF_ADD, R6, R0),
98735 - BPF_ALU64_REG(BPF_ADD, R6, R1),
98736 - BPF_ALU64_REG(BPF_ADD, R6, R2),
98737 - BPF_ALU64_REG(BPF_ADD, R6, R3),
98738 - BPF_ALU64_REG(BPF_ADD, R6, R4),
98739 - BPF_ALU64_REG(BPF_ADD, R6, R5),
98740 - BPF_ALU64_REG(BPF_ADD, R6, R6),
98741 - BPF_ALU64_REG(BPF_ADD, R6, R7),
98742 - BPF_ALU64_REG(BPF_ADD, R6, R8),
98743 - BPF_ALU64_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
98744 - BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
98745 - BPF_EXIT_INSN(),
98746 - BPF_ALU64_REG(BPF_ADD, R7, R0),
98747 - BPF_ALU64_REG(BPF_ADD, R7, R1),
98748 - BPF_ALU64_REG(BPF_ADD, R7, R2),
98749 - BPF_ALU64_REG(BPF_ADD, R7, R3),
98750 - BPF_ALU64_REG(BPF_ADD, R7, R4),
98751 - BPF_ALU64_REG(BPF_ADD, R7, R5),
98752 - BPF_ALU64_REG(BPF_ADD, R7, R6),
98753 - BPF_ALU64_REG(BPF_ADD, R7, R7),
98754 - BPF_ALU64_REG(BPF_ADD, R7, R8),
98755 - BPF_ALU64_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
98756 - BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
98757 - BPF_EXIT_INSN(),
98758 - BPF_ALU64_REG(BPF_ADD, R8, R0),
98759 - BPF_ALU64_REG(BPF_ADD, R8, R1),
98760 - BPF_ALU64_REG(BPF_ADD, R8, R2),
98761 - BPF_ALU64_REG(BPF_ADD, R8, R3),
98762 - BPF_ALU64_REG(BPF_ADD, R8, R4),
98763 - BPF_ALU64_REG(BPF_ADD, R8, R5),
98764 - BPF_ALU64_REG(BPF_ADD, R8, R6),
98765 - BPF_ALU64_REG(BPF_ADD, R8, R7),
98766 - BPF_ALU64_REG(BPF_ADD, R8, R8),
98767 - BPF_ALU64_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
98768 - BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
98769 - BPF_EXIT_INSN(),
98770 - BPF_ALU64_REG(BPF_ADD, R9, R0),
98771 - BPF_ALU64_REG(BPF_ADD, R9, R1),
98772 - BPF_ALU64_REG(BPF_ADD, R9, R2),
98773 - BPF_ALU64_REG(BPF_ADD, R9, R3),
98774 - BPF_ALU64_REG(BPF_ADD, R9, R4),
98775 - BPF_ALU64_REG(BPF_ADD, R9, R5),
98776 - BPF_ALU64_REG(BPF_ADD, R9, R6),
98777 - BPF_ALU64_REG(BPF_ADD, R9, R7),
98778 - BPF_ALU64_REG(BPF_ADD, R9, R8),
98779 - BPF_ALU64_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
98780 - BPF_ALU64_REG(BPF_MOV, R0, R9),
98781 - BPF_EXIT_INSN(),
98782 - },
98783 - INTERNAL,
98784 - { },
98785 - { { 0, 2957380 } }
98786 - },
98787 - {
98788 - "INT: ADD 32-bit",
98789 - .u.insns_int = {
98790 - BPF_ALU32_IMM(BPF_MOV, R0, 20),
98791 - BPF_ALU32_IMM(BPF_MOV, R1, 1),
98792 - BPF_ALU32_IMM(BPF_MOV, R2, 2),
98793 - BPF_ALU32_IMM(BPF_MOV, R3, 3),
98794 - BPF_ALU32_IMM(BPF_MOV, R4, 4),
98795 - BPF_ALU32_IMM(BPF_MOV, R5, 5),
98796 - BPF_ALU32_IMM(BPF_MOV, R6, 6),
98797 - BPF_ALU32_IMM(BPF_MOV, R7, 7),
98798 - BPF_ALU32_IMM(BPF_MOV, R8, 8),
98799 - BPF_ALU32_IMM(BPF_MOV, R9, 9),
98800 - BPF_ALU64_IMM(BPF_ADD, R1, 10),
98801 - BPF_ALU64_IMM(BPF_ADD, R2, 10),
98802 - BPF_ALU64_IMM(BPF_ADD, R3, 10),
98803 - BPF_ALU64_IMM(BPF_ADD, R4, 10),
98804 - BPF_ALU64_IMM(BPF_ADD, R5, 10),
98805 - BPF_ALU64_IMM(BPF_ADD, R6, 10),
98806 - BPF_ALU64_IMM(BPF_ADD, R7, 10),
98807 - BPF_ALU64_IMM(BPF_ADD, R8, 10),
98808 - BPF_ALU64_IMM(BPF_ADD, R9, 10),
98809 - BPF_ALU32_REG(BPF_ADD, R0, R1),
98810 - BPF_ALU32_REG(BPF_ADD, R0, R2),
98811 - BPF_ALU32_REG(BPF_ADD, R0, R3),
98812 - BPF_ALU32_REG(BPF_ADD, R0, R4),
98813 - BPF_ALU32_REG(BPF_ADD, R0, R5),
98814 - BPF_ALU32_REG(BPF_ADD, R0, R6),
98815 - BPF_ALU32_REG(BPF_ADD, R0, R7),
98816 - BPF_ALU32_REG(BPF_ADD, R0, R8),
98817 - BPF_ALU32_REG(BPF_ADD, R0, R9), /* R0 == 155 */
98818 - BPF_JMP_IMM(BPF_JEQ, R0, 155, 1),
98819 - BPF_EXIT_INSN(),
98820 - BPF_ALU32_REG(BPF_ADD, R1, R0),
98821 - BPF_ALU32_REG(BPF_ADD, R1, R1),
98822 - BPF_ALU32_REG(BPF_ADD, R1, R2),
98823 - BPF_ALU32_REG(BPF_ADD, R1, R3),
98824 - BPF_ALU32_REG(BPF_ADD, R1, R4),
98825 - BPF_ALU32_REG(BPF_ADD, R1, R5),
98826 - BPF_ALU32_REG(BPF_ADD, R1, R6),
98827 - BPF_ALU32_REG(BPF_ADD, R1, R7),
98828 - BPF_ALU32_REG(BPF_ADD, R1, R8),
98829 - BPF_ALU32_REG(BPF_ADD, R1, R9), /* R1 == 456 */
98830 - BPF_JMP_IMM(BPF_JEQ, R1, 456, 1),
98831 - BPF_EXIT_INSN(),
98832 - BPF_ALU32_REG(BPF_ADD, R2, R0),
98833 - BPF_ALU32_REG(BPF_ADD, R2, R1),
98834 - BPF_ALU32_REG(BPF_ADD, R2, R2),
98835 - BPF_ALU32_REG(BPF_ADD, R2, R3),
98836 - BPF_ALU32_REG(BPF_ADD, R2, R4),
98837 - BPF_ALU32_REG(BPF_ADD, R2, R5),
98838 - BPF_ALU32_REG(BPF_ADD, R2, R6),
98839 - BPF_ALU32_REG(BPF_ADD, R2, R7),
98840 - BPF_ALU32_REG(BPF_ADD, R2, R8),
98841 - BPF_ALU32_REG(BPF_ADD, R2, R9), /* R2 == 1358 */
98842 - BPF_JMP_IMM(BPF_JEQ, R2, 1358, 1),
98843 - BPF_EXIT_INSN(),
98844 - BPF_ALU32_REG(BPF_ADD, R3, R0),
98845 - BPF_ALU32_REG(BPF_ADD, R3, R1),
98846 - BPF_ALU32_REG(BPF_ADD, R3, R2),
98847 - BPF_ALU32_REG(BPF_ADD, R3, R3),
98848 - BPF_ALU32_REG(BPF_ADD, R3, R4),
98849 - BPF_ALU32_REG(BPF_ADD, R3, R5),
98850 - BPF_ALU32_REG(BPF_ADD, R3, R6),
98851 - BPF_ALU32_REG(BPF_ADD, R3, R7),
98852 - BPF_ALU32_REG(BPF_ADD, R3, R8),
98853 - BPF_ALU32_REG(BPF_ADD, R3, R9), /* R3 == 4063 */
98854 - BPF_JMP_IMM(BPF_JEQ, R3, 4063, 1),
98855 - BPF_EXIT_INSN(),
98856 - BPF_ALU32_REG(BPF_ADD, R4, R0),
98857 - BPF_ALU32_REG(BPF_ADD, R4, R1),
98858 - BPF_ALU32_REG(BPF_ADD, R4, R2),
98859 - BPF_ALU32_REG(BPF_ADD, R4, R3),
98860 - BPF_ALU32_REG(BPF_ADD, R4, R4),
98861 - BPF_ALU32_REG(BPF_ADD, R4, R5),
98862 - BPF_ALU32_REG(BPF_ADD, R4, R6),
98863 - BPF_ALU32_REG(BPF_ADD, R4, R7),
98864 - BPF_ALU32_REG(BPF_ADD, R4, R8),
98865 - BPF_ALU32_REG(BPF_ADD, R4, R9), /* R4 == 12177 */
98866 - BPF_JMP_IMM(BPF_JEQ, R4, 12177, 1),
98867 - BPF_EXIT_INSN(),
98868 - BPF_ALU32_REG(BPF_ADD, R5, R0),
98869 - BPF_ALU32_REG(BPF_ADD, R5, R1),
98870 - BPF_ALU32_REG(BPF_ADD, R5, R2),
98871 - BPF_ALU32_REG(BPF_ADD, R5, R3),
98872 - BPF_ALU32_REG(BPF_ADD, R5, R4),
98873 - BPF_ALU32_REG(BPF_ADD, R5, R5),
98874 - BPF_ALU32_REG(BPF_ADD, R5, R6),
98875 - BPF_ALU32_REG(BPF_ADD, R5, R7),
98876 - BPF_ALU32_REG(BPF_ADD, R5, R8),
98877 - BPF_ALU32_REG(BPF_ADD, R5, R9), /* R5 == 36518 */
98878 - BPF_JMP_IMM(BPF_JEQ, R5, 36518, 1),
98879 - BPF_EXIT_INSN(),
98880 - BPF_ALU32_REG(BPF_ADD, R6, R0),
98881 - BPF_ALU32_REG(BPF_ADD, R6, R1),
98882 - BPF_ALU32_REG(BPF_ADD, R6, R2),
98883 - BPF_ALU32_REG(BPF_ADD, R6, R3),
98884 - BPF_ALU32_REG(BPF_ADD, R6, R4),
98885 - BPF_ALU32_REG(BPF_ADD, R6, R5),
98886 - BPF_ALU32_REG(BPF_ADD, R6, R6),
98887 - BPF_ALU32_REG(BPF_ADD, R6, R7),
98888 - BPF_ALU32_REG(BPF_ADD, R6, R8),
98889 - BPF_ALU32_REG(BPF_ADD, R6, R9), /* R6 == 109540 */
98890 - BPF_JMP_IMM(BPF_JEQ, R6, 109540, 1),
98891 - BPF_EXIT_INSN(),
98892 - BPF_ALU32_REG(BPF_ADD, R7, R0),
98893 - BPF_ALU32_REG(BPF_ADD, R7, R1),
98894 - BPF_ALU32_REG(BPF_ADD, R7, R2),
98895 - BPF_ALU32_REG(BPF_ADD, R7, R3),
98896 - BPF_ALU32_REG(BPF_ADD, R7, R4),
98897 - BPF_ALU32_REG(BPF_ADD, R7, R5),
98898 - BPF_ALU32_REG(BPF_ADD, R7, R6),
98899 - BPF_ALU32_REG(BPF_ADD, R7, R7),
98900 - BPF_ALU32_REG(BPF_ADD, R7, R8),
98901 - BPF_ALU32_REG(BPF_ADD, R7, R9), /* R7 == 328605 */
98902 - BPF_JMP_IMM(BPF_JEQ, R7, 328605, 1),
98903 - BPF_EXIT_INSN(),
98904 - BPF_ALU32_REG(BPF_ADD, R8, R0),
98905 - BPF_ALU32_REG(BPF_ADD, R8, R1),
98906 - BPF_ALU32_REG(BPF_ADD, R8, R2),
98907 - BPF_ALU32_REG(BPF_ADD, R8, R3),
98908 - BPF_ALU32_REG(BPF_ADD, R8, R4),
98909 - BPF_ALU32_REG(BPF_ADD, R8, R5),
98910 - BPF_ALU32_REG(BPF_ADD, R8, R6),
98911 - BPF_ALU32_REG(BPF_ADD, R8, R7),
98912 - BPF_ALU32_REG(BPF_ADD, R8, R8),
98913 - BPF_ALU32_REG(BPF_ADD, R8, R9), /* R8 == 985799 */
98914 - BPF_JMP_IMM(BPF_JEQ, R8, 985799, 1),
98915 - BPF_EXIT_INSN(),
98916 - BPF_ALU32_REG(BPF_ADD, R9, R0),
98917 - BPF_ALU32_REG(BPF_ADD, R9, R1),
98918 - BPF_ALU32_REG(BPF_ADD, R9, R2),
98919 - BPF_ALU32_REG(BPF_ADD, R9, R3),
98920 - BPF_ALU32_REG(BPF_ADD, R9, R4),
98921 - BPF_ALU32_REG(BPF_ADD, R9, R5),
98922 - BPF_ALU32_REG(BPF_ADD, R9, R6),
98923 - BPF_ALU32_REG(BPF_ADD, R9, R7),
98924 - BPF_ALU32_REG(BPF_ADD, R9, R8),
98925 - BPF_ALU32_REG(BPF_ADD, R9, R9), /* R9 == 2957380 */
98926 - BPF_ALU32_REG(BPF_MOV, R0, R9),
98927 - BPF_EXIT_INSN(),
98928 - },
98929 - INTERNAL,
98930 - { },
98931 - { { 0, 2957380 } }
98932 - },
98933 - { /* Mainly checking JIT here. */
98934 - "INT: SUB",
98935 - .u.insns_int = {
98936 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
98937 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
98938 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
98939 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
98940 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
98941 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
98942 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
98943 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
98944 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
98945 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
98946 - BPF_ALU64_REG(BPF_SUB, R0, R0),
98947 - BPF_ALU64_REG(BPF_SUB, R0, R1),
98948 - BPF_ALU64_REG(BPF_SUB, R0, R2),
98949 - BPF_ALU64_REG(BPF_SUB, R0, R3),
98950 - BPF_ALU64_REG(BPF_SUB, R0, R4),
98951 - BPF_ALU64_REG(BPF_SUB, R0, R5),
98952 - BPF_ALU64_REG(BPF_SUB, R0, R6),
98953 - BPF_ALU64_REG(BPF_SUB, R0, R7),
98954 - BPF_ALU64_REG(BPF_SUB, R0, R8),
98955 - BPF_ALU64_REG(BPF_SUB, R0, R9),
98956 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
98957 - BPF_JMP_IMM(BPF_JEQ, R0, -55, 1),
98958 - BPF_EXIT_INSN(),
98959 - BPF_ALU64_REG(BPF_SUB, R1, R0),
98960 - BPF_ALU64_REG(BPF_SUB, R1, R2),
98961 - BPF_ALU64_REG(BPF_SUB, R1, R3),
98962 - BPF_ALU64_REG(BPF_SUB, R1, R4),
98963 - BPF_ALU64_REG(BPF_SUB, R1, R5),
98964 - BPF_ALU64_REG(BPF_SUB, R1, R6),
98965 - BPF_ALU64_REG(BPF_SUB, R1, R7),
98966 - BPF_ALU64_REG(BPF_SUB, R1, R8),
98967 - BPF_ALU64_REG(BPF_SUB, R1, R9),
98968 - BPF_ALU64_IMM(BPF_SUB, R1, 10),
98969 - BPF_ALU64_REG(BPF_SUB, R2, R0),
98970 - BPF_ALU64_REG(BPF_SUB, R2, R1),
98971 - BPF_ALU64_REG(BPF_SUB, R2, R3),
98972 - BPF_ALU64_REG(BPF_SUB, R2, R4),
98973 - BPF_ALU64_REG(BPF_SUB, R2, R5),
98974 - BPF_ALU64_REG(BPF_SUB, R2, R6),
98975 - BPF_ALU64_REG(BPF_SUB, R2, R7),
98976 - BPF_ALU64_REG(BPF_SUB, R2, R8),
98977 - BPF_ALU64_REG(BPF_SUB, R2, R9),
98978 - BPF_ALU64_IMM(BPF_SUB, R2, 10),
98979 - BPF_ALU64_REG(BPF_SUB, R3, R0),
98980 - BPF_ALU64_REG(BPF_SUB, R3, R1),
98981 - BPF_ALU64_REG(BPF_SUB, R3, R2),
98982 - BPF_ALU64_REG(BPF_SUB, R3, R4),
98983 - BPF_ALU64_REG(BPF_SUB, R3, R5),
98984 - BPF_ALU64_REG(BPF_SUB, R3, R6),
98985 - BPF_ALU64_REG(BPF_SUB, R3, R7),
98986 - BPF_ALU64_REG(BPF_SUB, R3, R8),
98987 - BPF_ALU64_REG(BPF_SUB, R3, R9),
98988 - BPF_ALU64_IMM(BPF_SUB, R3, 10),
98989 - BPF_ALU64_REG(BPF_SUB, R4, R0),
98990 - BPF_ALU64_REG(BPF_SUB, R4, R1),
98991 - BPF_ALU64_REG(BPF_SUB, R4, R2),
98992 - BPF_ALU64_REG(BPF_SUB, R4, R3),
98993 - BPF_ALU64_REG(BPF_SUB, R4, R5),
98994 - BPF_ALU64_REG(BPF_SUB, R4, R6),
98995 - BPF_ALU64_REG(BPF_SUB, R4, R7),
98996 - BPF_ALU64_REG(BPF_SUB, R4, R8),
98997 - BPF_ALU64_REG(BPF_SUB, R4, R9),
98998 - BPF_ALU64_IMM(BPF_SUB, R4, 10),
98999 - BPF_ALU64_REG(BPF_SUB, R5, R0),
99000 - BPF_ALU64_REG(BPF_SUB, R5, R1),
99001 - BPF_ALU64_REG(BPF_SUB, R5, R2),
99002 - BPF_ALU64_REG(BPF_SUB, R5, R3),
99003 - BPF_ALU64_REG(BPF_SUB, R5, R4),
99004 - BPF_ALU64_REG(BPF_SUB, R5, R6),
99005 - BPF_ALU64_REG(BPF_SUB, R5, R7),
99006 - BPF_ALU64_REG(BPF_SUB, R5, R8),
99007 - BPF_ALU64_REG(BPF_SUB, R5, R9),
99008 - BPF_ALU64_IMM(BPF_SUB, R5, 10),
99009 - BPF_ALU64_REG(BPF_SUB, R6, R0),
99010 - BPF_ALU64_REG(BPF_SUB, R6, R1),
99011 - BPF_ALU64_REG(BPF_SUB, R6, R2),
99012 - BPF_ALU64_REG(BPF_SUB, R6, R3),
99013 - BPF_ALU64_REG(BPF_SUB, R6, R4),
99014 - BPF_ALU64_REG(BPF_SUB, R6, R5),
99015 - BPF_ALU64_REG(BPF_SUB, R6, R7),
99016 - BPF_ALU64_REG(BPF_SUB, R6, R8),
99017 - BPF_ALU64_REG(BPF_SUB, R6, R9),
99018 - BPF_ALU64_IMM(BPF_SUB, R6, 10),
99019 - BPF_ALU64_REG(BPF_SUB, R7, R0),
99020 - BPF_ALU64_REG(BPF_SUB, R7, R1),
99021 - BPF_ALU64_REG(BPF_SUB, R7, R2),
99022 - BPF_ALU64_REG(BPF_SUB, R7, R3),
99023 - BPF_ALU64_REG(BPF_SUB, R7, R4),
99024 - BPF_ALU64_REG(BPF_SUB, R7, R5),
99025 - BPF_ALU64_REG(BPF_SUB, R7, R6),
99026 - BPF_ALU64_REG(BPF_SUB, R7, R8),
99027 - BPF_ALU64_REG(BPF_SUB, R7, R9),
99028 - BPF_ALU64_IMM(BPF_SUB, R7, 10),
99029 - BPF_ALU64_REG(BPF_SUB, R8, R0),
99030 - BPF_ALU64_REG(BPF_SUB, R8, R1),
99031 - BPF_ALU64_REG(BPF_SUB, R8, R2),
99032 - BPF_ALU64_REG(BPF_SUB, R8, R3),
99033 - BPF_ALU64_REG(BPF_SUB, R8, R4),
99034 - BPF_ALU64_REG(BPF_SUB, R8, R5),
99035 - BPF_ALU64_REG(BPF_SUB, R8, R6),
99036 - BPF_ALU64_REG(BPF_SUB, R8, R7),
99037 - BPF_ALU64_REG(BPF_SUB, R8, R9),
99038 - BPF_ALU64_IMM(BPF_SUB, R8, 10),
99039 - BPF_ALU64_REG(BPF_SUB, R9, R0),
99040 - BPF_ALU64_REG(BPF_SUB, R9, R1),
99041 - BPF_ALU64_REG(BPF_SUB, R9, R2),
99042 - BPF_ALU64_REG(BPF_SUB, R9, R3),
99043 - BPF_ALU64_REG(BPF_SUB, R9, R4),
99044 - BPF_ALU64_REG(BPF_SUB, R9, R5),
99045 - BPF_ALU64_REG(BPF_SUB, R9, R6),
99046 - BPF_ALU64_REG(BPF_SUB, R9, R7),
99047 - BPF_ALU64_REG(BPF_SUB, R9, R8),
99048 - BPF_ALU64_IMM(BPF_SUB, R9, 10),
99049 - BPF_ALU64_IMM(BPF_SUB, R0, 10),
99050 - BPF_ALU64_IMM(BPF_NEG, R0, 0),
99051 - BPF_ALU64_REG(BPF_SUB, R0, R1),
99052 - BPF_ALU64_REG(BPF_SUB, R0, R2),
99053 - BPF_ALU64_REG(BPF_SUB, R0, R3),
99054 - BPF_ALU64_REG(BPF_SUB, R0, R4),
99055 - BPF_ALU64_REG(BPF_SUB, R0, R5),
99056 - BPF_ALU64_REG(BPF_SUB, R0, R6),
99057 - BPF_ALU64_REG(BPF_SUB, R0, R7),
99058 - BPF_ALU64_REG(BPF_SUB, R0, R8),
99059 - BPF_ALU64_REG(BPF_SUB, R0, R9),
99060 - BPF_EXIT_INSN(),
99061 - },
99062 - INTERNAL,
99063 - { },
99064 - { { 0, 11 } }
99065 - },
99066 - { /* Mainly checking JIT here. */
99067 - "INT: XOR",
99068 - .u.insns_int = {
99069 - BPF_ALU64_REG(BPF_SUB, R0, R0),
99070 - BPF_ALU64_REG(BPF_XOR, R1, R1),
99071 - BPF_JMP_REG(BPF_JEQ, R0, R1, 1),
99072 - BPF_EXIT_INSN(),
99073 - BPF_ALU64_IMM(BPF_MOV, R0, 10),
99074 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
99075 - BPF_ALU64_REG(BPF_SUB, R1, R1),
99076 - BPF_ALU64_REG(BPF_XOR, R2, R2),
99077 - BPF_JMP_REG(BPF_JEQ, R1, R2, 1),
99078 - BPF_EXIT_INSN(),
99079 - BPF_ALU64_REG(BPF_SUB, R2, R2),
99080 - BPF_ALU64_REG(BPF_XOR, R3, R3),
99081 - BPF_ALU64_IMM(BPF_MOV, R0, 10),
99082 - BPF_ALU64_IMM(BPF_MOV, R1, -1),
99083 - BPF_JMP_REG(BPF_JEQ, R2, R3, 1),
99084 - BPF_EXIT_INSN(),
99085 - BPF_ALU64_REG(BPF_SUB, R3, R3),
99086 - BPF_ALU64_REG(BPF_XOR, R4, R4),
99087 - BPF_ALU64_IMM(BPF_MOV, R2, 1),
99088 - BPF_ALU64_IMM(BPF_MOV, R5, -1),
99089 - BPF_JMP_REG(BPF_JEQ, R3, R4, 1),
99090 - BPF_EXIT_INSN(),
99091 - BPF_ALU64_REG(BPF_SUB, R4, R4),
99092 - BPF_ALU64_REG(BPF_XOR, R5, R5),
99093 - BPF_ALU64_IMM(BPF_MOV, R3, 1),
99094 - BPF_ALU64_IMM(BPF_MOV, R7, -1),
99095 - BPF_JMP_REG(BPF_JEQ, R5, R4, 1),
99096 - BPF_EXIT_INSN(),
99097 - BPF_ALU64_IMM(BPF_MOV, R5, 1),
99098 - BPF_ALU64_REG(BPF_SUB, R5, R5),
99099 - BPF_ALU64_REG(BPF_XOR, R6, R6),
99100 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
99101 - BPF_ALU64_IMM(BPF_MOV, R8, -1),
99102 - BPF_JMP_REG(BPF_JEQ, R5, R6, 1),
99103 - BPF_EXIT_INSN(),
99104 - BPF_ALU64_REG(BPF_SUB, R6, R6),
99105 - BPF_ALU64_REG(BPF_XOR, R7, R7),
99106 - BPF_JMP_REG(BPF_JEQ, R7, R6, 1),
99107 - BPF_EXIT_INSN(),
99108 - BPF_ALU64_REG(BPF_SUB, R7, R7),
99109 - BPF_ALU64_REG(BPF_XOR, R8, R8),
99110 - BPF_JMP_REG(BPF_JEQ, R7, R8, 1),
99111 - BPF_EXIT_INSN(),
99112 - BPF_ALU64_REG(BPF_SUB, R8, R8),
99113 - BPF_ALU64_REG(BPF_XOR, R9, R9),
99114 - BPF_JMP_REG(BPF_JEQ, R9, R8, 1),
99115 - BPF_EXIT_INSN(),
99116 - BPF_ALU64_REG(BPF_SUB, R9, R9),
99117 - BPF_ALU64_REG(BPF_XOR, R0, R0),
99118 - BPF_JMP_REG(BPF_JEQ, R9, R0, 1),
99119 - BPF_EXIT_INSN(),
99120 - BPF_ALU64_REG(BPF_SUB, R1, R1),
99121 - BPF_ALU64_REG(BPF_XOR, R0, R0),
99122 - BPF_JMP_REG(BPF_JEQ, R9, R0, 2),
99123 - BPF_ALU64_IMM(BPF_MOV, R0, 0),
99124 - BPF_EXIT_INSN(),
99125 - BPF_ALU64_IMM(BPF_MOV, R0, 1),
99126 - BPF_EXIT_INSN(),
99127 - },
99128 - INTERNAL,
99129 - { },
99130 - { { 0, 1 } }
99131 - },
99132 - { /* Mainly checking JIT here. */
99133 - "INT: MUL",
99134 - .u.insns_int = {
99135 - BPF_ALU64_IMM(BPF_MOV, R0, 11),
99136 - BPF_ALU64_IMM(BPF_MOV, R1, 1),
99137 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
99138 - BPF_ALU64_IMM(BPF_MOV, R3, 3),
99139 - BPF_ALU64_IMM(BPF_MOV, R4, 4),
99140 - BPF_ALU64_IMM(BPF_MOV, R5, 5),
99141 - BPF_ALU64_IMM(BPF_MOV, R6, 6),
99142 - BPF_ALU64_IMM(BPF_MOV, R7, 7),
99143 - BPF_ALU64_IMM(BPF_MOV, R8, 8),
99144 - BPF_ALU64_IMM(BPF_MOV, R9, 9),
99145 - BPF_ALU64_REG(BPF_MUL, R0, R0),
99146 - BPF_ALU64_REG(BPF_MUL, R0, R1),
99147 - BPF_ALU64_REG(BPF_MUL, R0, R2),
99148 - BPF_ALU64_REG(BPF_MUL, R0, R3),
99149 - BPF_ALU64_REG(BPF_MUL, R0, R4),
99150 - BPF_ALU64_REG(BPF_MUL, R0, R5),
99151 - BPF_ALU64_REG(BPF_MUL, R0, R6),
99152 - BPF_ALU64_REG(BPF_MUL, R0, R7),
99153 - BPF_ALU64_REG(BPF_MUL, R0, R8),
99154 - BPF_ALU64_REG(BPF_MUL, R0, R9),
99155 - BPF_ALU64_IMM(BPF_MUL, R0, 10),
99156 - BPF_JMP_IMM(BPF_JEQ, R0, 439084800, 1),
99157 - BPF_EXIT_INSN(),
99158 - BPF_ALU64_REG(BPF_MUL, R1, R0),
99159 - BPF_ALU64_REG(BPF_MUL, R1, R2),
99160 - BPF_ALU64_REG(BPF_MUL, R1, R3),
99161 - BPF_ALU64_REG(BPF_MUL, R1, R4),
99162 - BPF_ALU64_REG(BPF_MUL, R1, R5),
99163 - BPF_ALU64_REG(BPF_MUL, R1, R6),
99164 - BPF_ALU64_REG(BPF_MUL, R1, R7),
99165 - BPF_ALU64_REG(BPF_MUL, R1, R8),
99166 - BPF_ALU64_REG(BPF_MUL, R1, R9),
99167 - BPF_ALU64_IMM(BPF_MUL, R1, 10),
99168 - BPF_ALU64_REG(BPF_MOV, R2, R1),
99169 - BPF_ALU64_IMM(BPF_RSH, R2, 32),
99170 - BPF_JMP_IMM(BPF_JEQ, R2, 0x5a924, 1),
99171 - BPF_EXIT_INSN(),
99172 - BPF_ALU64_IMM(BPF_LSH, R1, 32),
99173 - BPF_ALU64_IMM(BPF_ARSH, R1, 32),
99174 - BPF_JMP_IMM(BPF_JEQ, R1, 0xebb90000, 1),
99175 - BPF_EXIT_INSN(),
99176 - BPF_ALU64_REG(BPF_MUL, R2, R0),
99177 - BPF_ALU64_REG(BPF_MUL, R2, R1),
99178 - BPF_ALU64_REG(BPF_MUL, R2, R3),
99179 - BPF_ALU64_REG(BPF_MUL, R2, R4),
99180 - BPF_ALU64_REG(BPF_MUL, R2, R5),
99181 - BPF_ALU64_REG(BPF_MUL, R2, R6),
99182 - BPF_ALU64_REG(BPF_MUL, R2, R7),
99183 - BPF_ALU64_REG(BPF_MUL, R2, R8),
99184 - BPF_ALU64_REG(BPF_MUL, R2, R9),
99185 - BPF_ALU64_IMM(BPF_MUL, R2, 10),
99186 - BPF_ALU64_IMM(BPF_RSH, R2, 32),
99187 - BPF_ALU64_REG(BPF_MOV, R0, R2),
99188 - BPF_EXIT_INSN(),
99189 - },
99190 - INTERNAL,
99191 - { },
99192 - { { 0, 0x35d97ef2 } }
99193 - },
99194 - {
99195 - "INT: ALU MIX",
99196 - .u.insns_int = {
99197 - BPF_ALU64_IMM(BPF_MOV, R0, 11),
99198 - BPF_ALU64_IMM(BPF_ADD, R0, -1),
99199 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
99200 - BPF_ALU64_IMM(BPF_XOR, R2, 3),
99201 - BPF_ALU64_REG(BPF_DIV, R0, R2),
99202 - BPF_JMP_IMM(BPF_JEQ, R0, 10, 1),
99203 - BPF_EXIT_INSN(),
99204 - BPF_ALU64_IMM(BPF_MOD, R0, 3),
99205 - BPF_JMP_IMM(BPF_JEQ, R0, 1, 1),
99206 - BPF_EXIT_INSN(),
99207 - BPF_ALU64_IMM(BPF_MOV, R0, -1),
99208 - BPF_EXIT_INSN(),
99209 - },
99210 - INTERNAL,
99211 - { },
99212 - { { 0, -1 } }
99213 - },
99214 - {
99215 - "INT: DIV + ABS",
99216 - .u.insns_int = {
99217 - BPF_ALU64_REG(BPF_MOV, R6, R1),
99218 - BPF_LD_ABS(BPF_B, 3),
99219 - BPF_ALU64_IMM(BPF_MOV, R2, 2),
99220 - BPF_ALU32_REG(BPF_DIV, R0, R2),
99221 - BPF_ALU64_REG(BPF_MOV, R8, R0),
99222 - BPF_LD_ABS(BPF_B, 4),
99223 - BPF_ALU64_REG(BPF_ADD, R8, R0),
99224 - BPF_LD_IND(BPF_B, R8, -70),
99225 - BPF_EXIT_INSN(),
99226 - },
99227 - INTERNAL,
99228 - { 10, 20, 30, 40, 50 },
99229 - { { 4, 0 }, { 5, 10 } }
99230 - },
99231 - {
99232 - "INT: DIV by zero",
99233 - .u.insns_int = {
99234 - BPF_ALU64_REG(BPF_MOV, R6, R1),
99235 - BPF_ALU64_IMM(BPF_MOV, R7, 0),
99236 - BPF_LD_ABS(BPF_B, 3),
99237 - BPF_ALU32_REG(BPF_DIV, R0, R7),
99238 - BPF_EXIT_INSN(),
99239 - },
99240 - INTERNAL,
99241 - { 10, 20, 30, 40, 50 },
99242 - { { 3, 0 }, { 4, 0 } }
99243 - },
99244 - {
99245 - "check: missing ret",
99246 - .u.insns = {
99247 - BPF_STMT(BPF_LD | BPF_IMM, 1),
99248 - },
99249 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
99250 - { },
99251 - { }
99252 - },
99253 - {
99254 - "check: div_k_0",
99255 - .u.insns = {
99256 - BPF_STMT(BPF_ALU | BPF_DIV | BPF_K, 0),
99257 - BPF_STMT(BPF_RET | BPF_K, 0)
99258 - },
99259 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
99260 - { },
99261 - { }
99262 - },
99263 - {
99264 - "check: unknown insn",
99265 - .u.insns = {
99266 - /* seccomp insn, rejected in socket filter */
99267 - BPF_STMT(BPF_LDX | BPF_W | BPF_ABS, 0),
99268 - BPF_STMT(BPF_RET | BPF_K, 0)
99269 - },
99270 - CLASSIC | FLAG_EXPECTED_FAIL,
99271 - { },
99272 - { }
99273 - },
99274 - {
99275 - "check: out of range spill/fill",
99276 - .u.insns = {
99277 - BPF_STMT(BPF_STX, 16),
99278 - BPF_STMT(BPF_RET | BPF_K, 0)
99279 - },
99280 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
99281 - { },
99282 - { }
99283 - },
99284 - {
99285 - "JUMPS + HOLES",
99286 - .u.insns = {
99287 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99288 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 15),
99289 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99290 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99291 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99292 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99293 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99294 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99295 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99296 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99297 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99298 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99299 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99300 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99301 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99302 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 3, 4),
99303 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99304 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90c2894d, 1, 2),
99305 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99306 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
99307 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
99308 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99309 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99310 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99311 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99312 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99313 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99314 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99315 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99316 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99317 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99318 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99319 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99320 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99321 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 2, 3),
99322 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x2ac28349, 1, 2),
99323 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99324 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 14, 15),
99325 - BPF_JUMP(BPF_JMP | BPF_JGE, 0, 13, 14),
99326 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99327 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99328 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99329 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99330 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99331 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99332 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99333 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99334 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99335 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99336 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99337 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99338 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99339 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 2, 3),
99340 - BPF_JUMP(BPF_JMP | BPF_JEQ, 0x90d2ff41, 1, 2),
99341 - BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 0),
99342 - BPF_STMT(BPF_RET | BPF_A, 0),
99343 - BPF_STMT(BPF_RET | BPF_A, 0),
99344 - },
99345 - CLASSIC,
99346 - { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
99347 - 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
99348 - 0x08, 0x00,
99349 - 0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
99350 - 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
99351 - 0xc0, 0xa8, 0x33, 0x01,
99352 - 0xc0, 0xa8, 0x33, 0x02,
99353 - 0xbb, 0xb6,
99354 - 0xa9, 0xfa,
99355 - 0x00, 0x14, 0x00, 0x00,
99356 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99357 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99358 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99359 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99360 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99361 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99362 - 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
99363 - 0xcc, 0xcc, 0xcc, 0xcc },
99364 - { { 88, 0x001b } }
99365 - },
99366 - {
99367 - "check: RET X",
99368 - .u.insns = {
99369 - BPF_STMT(BPF_RET | BPF_X, 0),
99370 - },
99371 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
99372 - { },
99373 - { },
99374 - },
99375 - {
99376 - "check: LDX + RET X",
99377 - .u.insns = {
99378 - BPF_STMT(BPF_LDX | BPF_IMM, 42),
99379 - BPF_STMT(BPF_RET | BPF_X, 0),
99380 - },
99381 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
99382 - { },
99383 - { },
99384 - },
99385 - { /* Mainly checking JIT here. */
99386 - "M[]: alt STX + LDX",
99387 - .u.insns = {
99388 - BPF_STMT(BPF_LDX | BPF_IMM, 100),
99389 - BPF_STMT(BPF_STX, 0),
99390 - BPF_STMT(BPF_LDX | BPF_MEM, 0),
99391 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99392 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99393 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99394 - BPF_STMT(BPF_STX, 1),
99395 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
99396 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99397 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99398 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99399 - BPF_STMT(BPF_STX, 2),
99400 - BPF_STMT(BPF_LDX | BPF_MEM, 2),
99401 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99402 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99403 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99404 - BPF_STMT(BPF_STX, 3),
99405 - BPF_STMT(BPF_LDX | BPF_MEM, 3),
99406 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99407 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99408 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99409 - BPF_STMT(BPF_STX, 4),
99410 - BPF_STMT(BPF_LDX | BPF_MEM, 4),
99411 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99412 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99413 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99414 - BPF_STMT(BPF_STX, 5),
99415 - BPF_STMT(BPF_LDX | BPF_MEM, 5),
99416 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99417 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99418 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99419 - BPF_STMT(BPF_STX, 6),
99420 - BPF_STMT(BPF_LDX | BPF_MEM, 6),
99421 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99422 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99423 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99424 - BPF_STMT(BPF_STX, 7),
99425 - BPF_STMT(BPF_LDX | BPF_MEM, 7),
99426 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99427 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99428 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99429 - BPF_STMT(BPF_STX, 8),
99430 - BPF_STMT(BPF_LDX | BPF_MEM, 8),
99431 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99432 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99433 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99434 - BPF_STMT(BPF_STX, 9),
99435 - BPF_STMT(BPF_LDX | BPF_MEM, 9),
99436 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99437 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99438 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99439 - BPF_STMT(BPF_STX, 10),
99440 - BPF_STMT(BPF_LDX | BPF_MEM, 10),
99441 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99442 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99443 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99444 - BPF_STMT(BPF_STX, 11),
99445 - BPF_STMT(BPF_LDX | BPF_MEM, 11),
99446 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99447 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99448 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99449 - BPF_STMT(BPF_STX, 12),
99450 - BPF_STMT(BPF_LDX | BPF_MEM, 12),
99451 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99452 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99453 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99454 - BPF_STMT(BPF_STX, 13),
99455 - BPF_STMT(BPF_LDX | BPF_MEM, 13),
99456 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99457 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99458 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99459 - BPF_STMT(BPF_STX, 14),
99460 - BPF_STMT(BPF_LDX | BPF_MEM, 14),
99461 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99462 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99463 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99464 - BPF_STMT(BPF_STX, 15),
99465 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
99466 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99467 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 1),
99468 - BPF_STMT(BPF_MISC | BPF_TAX, 0),
99469 - BPF_STMT(BPF_RET | BPF_A, 0),
99470 - },
99471 - CLASSIC | FLAG_NO_DATA,
99472 - { },
99473 - { { 0, 116 } },
99474 - },
99475 - { /* Mainly checking JIT here. */
99476 - "M[]: full STX + full LDX",
99477 - .u.insns = {
99478 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbadfeedb),
99479 - BPF_STMT(BPF_STX, 0),
99480 - BPF_STMT(BPF_LDX | BPF_IMM, 0xecabedae),
99481 - BPF_STMT(BPF_STX, 1),
99482 - BPF_STMT(BPF_LDX | BPF_IMM, 0xafccfeaf),
99483 - BPF_STMT(BPF_STX, 2),
99484 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbffdcedc),
99485 - BPF_STMT(BPF_STX, 3),
99486 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfbbbdccb),
99487 - BPF_STMT(BPF_STX, 4),
99488 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfbabcbda),
99489 - BPF_STMT(BPF_STX, 5),
99490 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaedecbdb),
99491 - BPF_STMT(BPF_STX, 6),
99492 - BPF_STMT(BPF_LDX | BPF_IMM, 0xadebbade),
99493 - BPF_STMT(BPF_STX, 7),
99494 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfcfcfaec),
99495 - BPF_STMT(BPF_STX, 8),
99496 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbcdddbdc),
99497 - BPF_STMT(BPF_STX, 9),
99498 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfeefdfac),
99499 - BPF_STMT(BPF_STX, 10),
99500 - BPF_STMT(BPF_LDX | BPF_IMM, 0xcddcdeea),
99501 - BPF_STMT(BPF_STX, 11),
99502 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaccfaebb),
99503 - BPF_STMT(BPF_STX, 12),
99504 - BPF_STMT(BPF_LDX | BPF_IMM, 0xbdcccdcf),
99505 - BPF_STMT(BPF_STX, 13),
99506 - BPF_STMT(BPF_LDX | BPF_IMM, 0xaaedecde),
99507 - BPF_STMT(BPF_STX, 14),
99508 - BPF_STMT(BPF_LDX | BPF_IMM, 0xfaeacdad),
99509 - BPF_STMT(BPF_STX, 15),
99510 - BPF_STMT(BPF_LDX | BPF_MEM, 0),
99511 - BPF_STMT(BPF_MISC | BPF_TXA, 0),
99512 - BPF_STMT(BPF_LDX | BPF_MEM, 1),
99513 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99514 - BPF_STMT(BPF_LDX | BPF_MEM, 2),
99515 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99516 - BPF_STMT(BPF_LDX | BPF_MEM, 3),
99517 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99518 - BPF_STMT(BPF_LDX | BPF_MEM, 4),
99519 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99520 - BPF_STMT(BPF_LDX | BPF_MEM, 5),
99521 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99522 - BPF_STMT(BPF_LDX | BPF_MEM, 6),
99523 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99524 - BPF_STMT(BPF_LDX | BPF_MEM, 7),
99525 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99526 - BPF_STMT(BPF_LDX | BPF_MEM, 8),
99527 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99528 - BPF_STMT(BPF_LDX | BPF_MEM, 9),
99529 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99530 - BPF_STMT(BPF_LDX | BPF_MEM, 10),
99531 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99532 - BPF_STMT(BPF_LDX | BPF_MEM, 11),
99533 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99534 - BPF_STMT(BPF_LDX | BPF_MEM, 12),
99535 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99536 - BPF_STMT(BPF_LDX | BPF_MEM, 13),
99537 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99538 - BPF_STMT(BPF_LDX | BPF_MEM, 14),
99539 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99540 - BPF_STMT(BPF_LDX | BPF_MEM, 15),
99541 - BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
99542 - BPF_STMT(BPF_RET | BPF_A, 0),
99543 - },
99544 - CLASSIC | FLAG_NO_DATA,
99545 - { },
99546 - { { 0, 0x2a5a5e5 } },
99547 - },
99548 - {
99549 - "check: SKF_AD_MAX",
99550 - .u.insns = {
99551 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
99552 - SKF_AD_OFF + SKF_AD_MAX),
99553 - BPF_STMT(BPF_RET | BPF_A, 0),
99554 - },
99555 - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
99556 - { },
99557 - { },
99558 - },
99559 - { /* Passes checker but fails during runtime. */
99560 - "LD [SKF_AD_OFF-1]",
99561 - .u.insns = {
99562 - BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
99563 - SKF_AD_OFF - 1),
99564 - BPF_STMT(BPF_RET | BPF_K, 1),
99565 - },
99566 - CLASSIC,
99567 - { },
99568 - { { 1, 0 } },
99569 - },
99570 -};
99571 -
99572 -static struct net_device dev;
99573 -
99574 -static struct sk_buff *populate_skb(char *buf, int size)
99575 -{
99576 - struct sk_buff *skb;
99577 -
99578 - if (size >= MAX_DATA)
99579 - return NULL;
99580 -
99581 - skb = alloc_skb(MAX_DATA, GFP_KERNEL);
99582 - if (!skb)
99583 - return NULL;
99584 -
99585 - memcpy(__skb_put(skb, size), buf, size);
99586 -
99587 - /* Initialize a fake skb with test pattern. */
99588 - skb_reset_mac_header(skb);
99589 - skb->protocol = htons(ETH_P_IP);
99590 - skb->pkt_type = SKB_TYPE;
99591 - skb->mark = SKB_MARK;
99592 - skb->hash = SKB_HASH;
99593 - skb->queue_mapping = SKB_QUEUE_MAP;
99594 - skb->vlan_tci = SKB_VLAN_TCI;
99595 - skb->dev = &dev;
99596 - skb->dev->ifindex = SKB_DEV_IFINDEX;
99597 - skb->dev->type = SKB_DEV_TYPE;
99598 - skb_set_network_header(skb, min(size, ETH_HLEN));
99599 -
99600 - return skb;
99601 -}
99602 -
99603 -static void *generate_test_data(struct bpf_test *test, int sub)
99604 -{
99605 - if (test->aux & FLAG_NO_DATA)
99606 - return NULL;
99607 -
99608 - /* Test case expects an skb, so populate one. Various
99609 - * subtests generate skbs of different sizes based on
99610 - * the same data.
99611 - */
99612 - return populate_skb(test->data, test->test[sub].data_size);
99613 -}
99614 -
99615 -static void release_test_data(const struct bpf_test *test, void *data)
99616 -{
99617 - if (test->aux & FLAG_NO_DATA)
99618 - return;
99619 -
99620 - kfree_skb(data);
99621 -}
99622 -
99623 -static int probe_filter_length(struct sock_filter *fp)
99624 -{
99625 - int len = 0;
99626 -
99627 - for (len = MAX_INSNS - 1; len > 0; --len)
99628 - if (fp[len].code != 0 || fp[len].k != 0)
99629 - break;
99630 -
99631 - return len + 1;
99632 -}
99633 -
99634 -static struct sk_filter *generate_filter(int which, int *err)
99635 -{
99636 - struct sk_filter *fp;
99637 - struct sock_fprog_kern fprog;
99638 - unsigned int flen = probe_filter_length(tests[which].u.insns);
99639 - __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
99640 -
99641 - switch (test_type) {
99642 - case CLASSIC:
99643 - fprog.filter = tests[which].u.insns;
99644 - fprog.len = flen;
99645 -
99646 - *err = sk_unattached_filter_create(&fp, &fprog);
99647 - if (tests[which].aux & FLAG_EXPECTED_FAIL) {
99648 - if (*err == -EINVAL) {
99649 - pr_cont("PASS\n");
99650 - /* Verifier rejected filter as expected. */
99651 - *err = 0;
99652 - return NULL;
99653 - } else {
99654 - pr_cont("UNEXPECTED_PASS\n");
99655 - /* Verifier didn't reject the test that's
99656 - * bad enough, just return!
99657 - */
99658 - *err = -EINVAL;
99659 - return NULL;
99660 - }
99661 - }
99662 - /* We don't expect to fail. */
99663 - if (*err) {
99664 - pr_cont("FAIL to attach err=%d len=%d\n",
99665 - *err, fprog.len);
99666 - return NULL;
99667 - }
99668 - break;
99669 -
99670 - case INTERNAL:
99671 - fp = kzalloc(sk_filter_size(flen), GFP_KERNEL);
99672 - if (fp == NULL) {
99673 - pr_cont("UNEXPECTED_FAIL no memory left\n");
99674 - *err = -ENOMEM;
99675 - return NULL;
99676 - }
99677 -
99678 - fp->len = flen;
99679 - memcpy(fp->insnsi, tests[which].u.insns_int,
99680 - fp->len * sizeof(struct sock_filter_int));
99681 -
99682 - sk_filter_select_runtime(fp);
99683 - break;
99684 - }
99685 -
99686 - *err = 0;
99687 - return fp;
99688 -}
99689 -
99690 -static void release_filter(struct sk_filter *fp, int which)
99691 -{
99692 - __u8 test_type = tests[which].aux & TEST_TYPE_MASK;
99693 -
99694 - switch (test_type) {
99695 - case CLASSIC:
99696 - sk_unattached_filter_destroy(fp);
99697 - break;
99698 - case INTERNAL:
99699 - sk_filter_free(fp);
99700 - break;
99701 - }
99702 -}
99703 -
99704 -static int __run_one(const struct sk_filter *fp, const void *data,
99705 - int runs, u64 *duration)
99706 -{
99707 - u64 start, finish;
99708 - int ret, i;
99709 -
99710 - start = ktime_to_us(ktime_get());
99711 -
99712 - for (i = 0; i < runs; i++)
99713 - ret = SK_RUN_FILTER(fp, data);
99714 -
99715 - finish = ktime_to_us(ktime_get());
99716 -
99717 - *duration = (finish - start) * 1000ULL;
99718 - do_div(*duration, runs);
99719 -
99720 - return ret;
99721 -}
99722 -
99723 -static int run_one(const struct sk_filter *fp, struct bpf_test *test)
99724 -{
99725 - int err_cnt = 0, i, runs = MAX_TESTRUNS;
99726 -
99727 - for (i = 0; i < MAX_SUBTESTS; i++) {
99728 - void *data;
99729 - u64 duration;
99730 - u32 ret;
99731 -
99732 - if (test->test[i].data_size == 0 &&
99733 - test->test[i].result == 0)
99734 - break;
99735 -
99736 - data = generate_test_data(test, i);
99737 - ret = __run_one(fp, data, runs, &duration);
99738 - release_test_data(test, data);
99739 -
99740 - if (ret == test->test[i].result) {
99741 - pr_cont("%lld ", duration);
99742 - } else {
99743 - pr_cont("ret %d != %d ", ret,
99744 - test->test[i].result);
99745 - err_cnt++;
99746 - }
99747 - }
99748 -
99749 - return err_cnt;
99750 -}
99751 -
99752 -static __init int test_bpf(void)
99753 -{
99754 - int i, err_cnt = 0, pass_cnt = 0;
99755 -
99756 - for (i = 0; i < ARRAY_SIZE(tests); i++) {
99757 - struct sk_filter *fp;
99758 - int err;
99759 -
99760 - pr_info("#%d %s ", i, tests[i].descr);
99761 -
99762 - fp = generate_filter(i, &err);
99763 - if (fp == NULL) {
99764 - if (err == 0) {
99765 - pass_cnt++;
99766 - continue;
99767 - }
99768 -
99769 - return err;
99770 - }
99771 - err = run_one(fp, &tests[i]);
99772 - release_filter(fp, i);
99773 -
99774 - if (err) {
99775 - pr_cont("FAIL (%d times)\n", err);
99776 - err_cnt++;
99777 - } else {
99778 - pr_cont("PASS\n");
99779 - pass_cnt++;
99780 - }
99781 - }
99782 -
99783 - pr_info("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt);
99784 - return err_cnt ? -EINVAL : 0;
99785 -}
99786 -
99787 -static int __init test_bpf_init(void)
99788 -{
99789 - return test_bpf();
99790 -}
99791 -
99792 -static void __exit test_bpf_exit(void)
99793 -{
99794 -}
99795 -
99796 -module_init(test_bpf_init);
99797 -module_exit(test_bpf_exit);
99798 -
99799 -MODULE_LICENSE("GPL");
99800 diff --git a/lib/usercopy.c b/lib/usercopy.c
99801 index 4f5b1dd..7cab418 100644
99802 --- a/lib/usercopy.c
99803 +++ b/lib/usercopy.c
99804 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
99805 WARN(1, "Buffer overflow detected!\n");
99806 }
99807 EXPORT_SYMBOL(copy_from_user_overflow);
99808 +
99809 +void copy_to_user_overflow(void)
99810 +{
99811 + WARN(1, "Buffer overflow detected!\n");
99812 +}
99813 +EXPORT_SYMBOL(copy_to_user_overflow);
99814 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
99815 index 6fe2c84..2fe5ec6 100644
99816 --- a/lib/vsprintf.c
99817 +++ b/lib/vsprintf.c
99818 @@ -16,6 +16,9 @@
99819 * - scnprintf and vscnprintf
99820 */
99821
99822 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99823 +#define __INCLUDED_BY_HIDESYM 1
99824 +#endif
99825 #include <stdarg.h>
99826 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
99827 #include <linux/types.h>
99828 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
99829 #ifdef CONFIG_KALLSYMS
99830 if (*fmt == 'B')
99831 sprint_backtrace(sym, value);
99832 - else if (*fmt != 'f' && *fmt != 's')
99833 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
99834 sprint_symbol(sym, value);
99835 else
99836 sprint_symbol_no_offset(sym, value);
99837 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
99838 return number(buf, end, num, spec);
99839 }
99840
99841 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99842 +int kptr_restrict __read_mostly = 2;
99843 +#else
99844 int kptr_restrict __read_mostly;
99845 +#endif
99846
99847 /*
99848 * Show a '%p' thing. A kernel extension is that the '%p' is followed
99849 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
99850 *
99851 * - 'F' For symbolic function descriptor pointers with offset
99852 * - 'f' For simple symbolic function names without offset
99853 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
99854 * - 'S' For symbolic direct pointers with offset
99855 * - 's' For symbolic direct pointers without offset
99856 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
99857 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
99858 * - 'B' For backtraced symbolic direct pointers with offset
99859 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
99860 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
99861
99862 if (!ptr && *fmt != 'K') {
99863 /*
99864 - * Print (null) with the same width as a pointer so it makes
99865 + * Print (nil) with the same width as a pointer so it makes
99866 * tabular output look nice.
99867 */
99868 if (spec.field_width == -1)
99869 spec.field_width = default_width;
99870 - return string(buf, end, "(null)", spec);
99871 + return string(buf, end, "(nil)", spec);
99872 }
99873
99874 switch (*fmt) {
99875 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
99876 /* Fallthrough */
99877 case 'S':
99878 case 's':
99879 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99880 + break;
99881 +#else
99882 + return symbol_string(buf, end, ptr, spec, fmt);
99883 +#endif
99884 + case 'X':
99885 + ptr = dereference_function_descriptor(ptr);
99886 + case 'A':
99887 case 'B':
99888 return symbol_string(buf, end, ptr, spec, fmt);
99889 case 'R':
99890 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
99891 va_end(va);
99892 return buf;
99893 }
99894 + case 'P':
99895 + break;
99896 case 'K':
99897 /*
99898 * %pK cannot be used in IRQ context because its test
99899 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
99900 ((const struct file *)ptr)->f_path.dentry,
99901 spec, fmt);
99902 }
99903 +
99904 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99905 + /* 'P' = approved pointers to copy to userland,
99906 + as in the /proc/kallsyms case, as we make it display nothing
99907 + for non-root users, and the real contents for root users
99908 + 'X' = approved simple symbols
99909 + Also ignore 'K' pointers, since we force their NULLing for non-root users
99910 + above
99911 + */
99912 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
99913 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
99914 + dump_stack();
99915 + ptr = NULL;
99916 + }
99917 +#endif
99918 +
99919 spec.flags |= SMALL;
99920 if (spec.field_width == -1) {
99921 spec.field_width = default_width;
99922 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
99923 typeof(type) value; \
99924 if (sizeof(type) == 8) { \
99925 args = PTR_ALIGN(args, sizeof(u32)); \
99926 - *(u32 *)&value = *(u32 *)args; \
99927 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
99928 + *(u32 *)&value = *(const u32 *)args; \
99929 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
99930 } else { \
99931 args = PTR_ALIGN(args, sizeof(type)); \
99932 - value = *(typeof(type) *)args; \
99933 + value = *(const typeof(type) *)args; \
99934 } \
99935 args += sizeof(type); \
99936 value; \
99937 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
99938 case FORMAT_TYPE_STR: {
99939 const char *str_arg = args;
99940 args += strlen(str_arg) + 1;
99941 - str = string(str, end, (char *)str_arg, spec);
99942 + str = string(str, end, str_arg, spec);
99943 break;
99944 }
99945
99946 diff --git a/localversion-grsec b/localversion-grsec
99947 new file mode 100644
99948 index 0000000..7cd6065
99949 --- /dev/null
99950 +++ b/localversion-grsec
99951 @@ -0,0 +1 @@
99952 +-grsec
99953 diff --git a/mm/Kconfig b/mm/Kconfig
99954 index 3e9977a..205074f 100644
99955 --- a/mm/Kconfig
99956 +++ b/mm/Kconfig
99957 @@ -333,10 +333,11 @@ config KSM
99958 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
99959
99960 config DEFAULT_MMAP_MIN_ADDR
99961 - int "Low address space to protect from user allocation"
99962 + int "Low address space to protect from user allocation"
99963 depends on MMU
99964 - default 4096
99965 - help
99966 + default 32768 if ALPHA || ARM || PARISC || SPARC32
99967 + default 65536
99968 + help
99969 This is the portion of low virtual memory which should be protected
99970 from userspace allocation. Keeping a user from writing to low pages
99971 can help reduce the impact of kernel NULL pointer bugs.
99972 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
99973
99974 config HWPOISON_INJECT
99975 tristate "HWPoison pages injector"
99976 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
99977 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
99978 select PROC_PAGE_MONITOR
99979
99980 config NOMMU_INITIAL_TRIM_EXCESS
99981 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
99982 index 1706cbb..f89dbca 100644
99983 --- a/mm/backing-dev.c
99984 +++ b/mm/backing-dev.c
99985 @@ -12,7 +12,7 @@
99986 #include <linux/device.h>
99987 #include <trace/events/writeback.h>
99988
99989 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
99990 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
99991
99992 struct backing_dev_info default_backing_dev_info = {
99993 .name = "default",
99994 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
99995 return err;
99996
99997 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
99998 - atomic_long_inc_return(&bdi_seq));
99999 + atomic_long_inc_return_unchecked(&bdi_seq));
100000 if (err) {
100001 bdi_destroy(bdi);
100002 return err;
100003 diff --git a/mm/filemap.c b/mm/filemap.c
100004 index 900edfa..ff056b1 100644
100005 --- a/mm/filemap.c
100006 +++ b/mm/filemap.c
100007 @@ -2074,7 +2074,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
100008 struct address_space *mapping = file->f_mapping;
100009
100010 if (!mapping->a_ops->readpage)
100011 - return -ENOEXEC;
100012 + return -ENODEV;
100013 file_accessed(file);
100014 vma->vm_ops = &generic_file_vm_ops;
100015 return 0;
100016 @@ -2252,6 +2252,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
100017 *pos = i_size_read(inode);
100018
100019 if (limit != RLIM_INFINITY) {
100020 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
100021 if (*pos >= limit) {
100022 send_sig(SIGXFSZ, current, 0);
100023 return -EFBIG;
100024 diff --git a/mm/fremap.c b/mm/fremap.c
100025 index 72b8fa3..c5b39f1 100644
100026 --- a/mm/fremap.c
100027 +++ b/mm/fremap.c
100028 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
100029 retry:
100030 vma = find_vma(mm, start);
100031
100032 +#ifdef CONFIG_PAX_SEGMEXEC
100033 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
100034 + goto out;
100035 +#endif
100036 +
100037 /*
100038 * Make sure the vma is shared, that it supports prefaulting,
100039 * and that the remapped range is valid and fully within
100040 diff --git a/mm/gup.c b/mm/gup.c
100041 index cc5a9e7..d496acf 100644
100042 --- a/mm/gup.c
100043 +++ b/mm/gup.c
100044 @@ -265,11 +265,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
100045 unsigned int fault_flags = 0;
100046 int ret;
100047
100048 - /* For mlock, just skip the stack guard page. */
100049 - if ((*flags & FOLL_MLOCK) &&
100050 - (stack_guard_page_start(vma, address) ||
100051 - stack_guard_page_end(vma, address + PAGE_SIZE)))
100052 - return -ENOENT;
100053 if (*flags & FOLL_WRITE)
100054 fault_flags |= FAULT_FLAG_WRITE;
100055 if (nonblocking)
100056 @@ -424,14 +419,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
100057 if (!(gup_flags & FOLL_FORCE))
100058 gup_flags |= FOLL_NUMA;
100059
100060 - do {
100061 + while (nr_pages) {
100062 struct page *page;
100063 unsigned int foll_flags = gup_flags;
100064 unsigned int page_increm;
100065
100066 /* first iteration or cross vma bound */
100067 if (!vma || start >= vma->vm_end) {
100068 - vma = find_extend_vma(mm, start);
100069 + vma = find_vma(mm, start);
100070 if (!vma && in_gate_area(mm, start)) {
100071 int ret;
100072 ret = get_gate_page(mm, start & PAGE_MASK,
100073 @@ -443,7 +438,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
100074 goto next_page;
100075 }
100076
100077 - if (!vma || check_vma_flags(vma, gup_flags))
100078 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
100079 return i ? : -EFAULT;
100080 if (is_vm_hugetlb_page(vma)) {
100081 i = follow_hugetlb_page(mm, vma, pages, vmas,
100082 @@ -498,7 +493,7 @@ next_page:
100083 i += page_increm;
100084 start += page_increm * PAGE_SIZE;
100085 nr_pages -= page_increm;
100086 - } while (nr_pages);
100087 + }
100088 return i;
100089 }
100090 EXPORT_SYMBOL(__get_user_pages);
100091 diff --git a/mm/highmem.c b/mm/highmem.c
100092 index b32b70c..e512eb0 100644
100093 --- a/mm/highmem.c
100094 +++ b/mm/highmem.c
100095 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
100096 * So no dangers, even with speculative execution.
100097 */
100098 page = pte_page(pkmap_page_table[i]);
100099 + pax_open_kernel();
100100 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
100101 -
100102 + pax_close_kernel();
100103 set_page_address(page, NULL);
100104 need_flush = 1;
100105 }
100106 @@ -198,9 +199,11 @@ start:
100107 }
100108 }
100109 vaddr = PKMAP_ADDR(last_pkmap_nr);
100110 +
100111 + pax_open_kernel();
100112 set_pte_at(&init_mm, vaddr,
100113 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
100114 -
100115 + pax_close_kernel();
100116 pkmap_count[last_pkmap_nr] = 1;
100117 set_page_address(page, (void *)vaddr);
100118
100119 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
100120 index 7a0a73d..d583cca 100644
100121 --- a/mm/hugetlb.c
100122 +++ b/mm/hugetlb.c
100123 @@ -2250,6 +2250,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
100124 struct hstate *h = &default_hstate;
100125 unsigned long tmp;
100126 int ret;
100127 + ctl_table_no_const hugetlb_table;
100128
100129 if (!hugepages_supported())
100130 return -ENOTSUPP;
100131 @@ -2259,9 +2260,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
100132 if (write && hstate_is_gigantic(h) && !gigantic_page_supported())
100133 return -EINVAL;
100134
100135 - table->data = &tmp;
100136 - table->maxlen = sizeof(unsigned long);
100137 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
100138 + hugetlb_table = *table;
100139 + hugetlb_table.data = &tmp;
100140 + hugetlb_table.maxlen = sizeof(unsigned long);
100141 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
100142 if (ret)
100143 goto out;
100144
100145 @@ -2306,6 +2308,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
100146 struct hstate *h = &default_hstate;
100147 unsigned long tmp;
100148 int ret;
100149 + ctl_table_no_const hugetlb_table;
100150
100151 if (!hugepages_supported())
100152 return -ENOTSUPP;
100153 @@ -2315,9 +2318,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
100154 if (write && hstate_is_gigantic(h))
100155 return -EINVAL;
100156
100157 - table->data = &tmp;
100158 - table->maxlen = sizeof(unsigned long);
100159 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
100160 + hugetlb_table = *table;
100161 + hugetlb_table.data = &tmp;
100162 + hugetlb_table.maxlen = sizeof(unsigned long);
100163 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
100164 if (ret)
100165 goto out;
100166
100167 @@ -2798,6 +2802,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
100168 return 1;
100169 }
100170
100171 +#ifdef CONFIG_PAX_SEGMEXEC
100172 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
100173 +{
100174 + struct mm_struct *mm = vma->vm_mm;
100175 + struct vm_area_struct *vma_m;
100176 + unsigned long address_m;
100177 + pte_t *ptep_m;
100178 +
100179 + vma_m = pax_find_mirror_vma(vma);
100180 + if (!vma_m)
100181 + return;
100182 +
100183 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
100184 + address_m = address + SEGMEXEC_TASK_SIZE;
100185 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
100186 + get_page(page_m);
100187 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
100188 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
100189 +}
100190 +#endif
100191 +
100192 /*
100193 * Hugetlb_cow() should be called with page lock of the original hugepage held.
100194 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
100195 @@ -2915,6 +2940,11 @@ retry_avoidcopy:
100196 make_huge_pte(vma, new_page, 1));
100197 page_remove_rmap(old_page);
100198 hugepage_add_new_anon_rmap(new_page, vma, address);
100199 +
100200 +#ifdef CONFIG_PAX_SEGMEXEC
100201 + pax_mirror_huge_pte(vma, address, new_page);
100202 +#endif
100203 +
100204 /* Make the old page be freed below */
100205 new_page = old_page;
100206 }
100207 @@ -3074,6 +3104,10 @@ retry:
100208 && (vma->vm_flags & VM_SHARED)));
100209 set_huge_pte_at(mm, address, ptep, new_pte);
100210
100211 +#ifdef CONFIG_PAX_SEGMEXEC
100212 + pax_mirror_huge_pte(vma, address, page);
100213 +#endif
100214 +
100215 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
100216 /* Optimization, do the COW without a second fault */
100217 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
100218 @@ -3140,6 +3174,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100219 struct hstate *h = hstate_vma(vma);
100220 struct address_space *mapping;
100221
100222 +#ifdef CONFIG_PAX_SEGMEXEC
100223 + struct vm_area_struct *vma_m;
100224 +#endif
100225 +
100226 address &= huge_page_mask(h);
100227
100228 ptep = huge_pte_offset(mm, address);
100229 @@ -3153,6 +3191,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100230 VM_FAULT_SET_HINDEX(hstate_index(h));
100231 }
100232
100233 +#ifdef CONFIG_PAX_SEGMEXEC
100234 + vma_m = pax_find_mirror_vma(vma);
100235 + if (vma_m) {
100236 + unsigned long address_m;
100237 +
100238 + if (vma->vm_start > vma_m->vm_start) {
100239 + address_m = address;
100240 + address -= SEGMEXEC_TASK_SIZE;
100241 + vma = vma_m;
100242 + h = hstate_vma(vma);
100243 + } else
100244 + address_m = address + SEGMEXEC_TASK_SIZE;
100245 +
100246 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
100247 + return VM_FAULT_OOM;
100248 + address_m &= HPAGE_MASK;
100249 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
100250 + }
100251 +#endif
100252 +
100253 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
100254 if (!ptep)
100255 return VM_FAULT_OOM;
100256 diff --git a/mm/internal.h b/mm/internal.h
100257 index 7f22a11f..f3c207f 100644
100258 --- a/mm/internal.h
100259 +++ b/mm/internal.h
100260 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
100261 * in mm/page_alloc.c
100262 */
100263 extern void __free_pages_bootmem(struct page *page, unsigned int order);
100264 +extern void free_compound_page(struct page *page);
100265 extern void prep_compound_page(struct page *page, unsigned long order);
100266 #ifdef CONFIG_MEMORY_FAILURE
100267 extern bool is_free_buddy_page(struct page *page);
100268 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
100269
100270 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
100271 unsigned long, unsigned long,
100272 - unsigned long, unsigned long);
100273 + unsigned long, unsigned long) __intentional_overflow(-1);
100274
100275 extern void set_pageblock_order(void);
100276 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
100277 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
100278 index 7b5dbd1..af0e329 100644
100279 --- a/mm/iov_iter.c
100280 +++ b/mm/iov_iter.c
100281 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
100282
100283 while (bytes) {
100284 char __user *buf = iov->iov_base + base;
100285 - int copy = min(bytes, iov->iov_len - base);
100286 + size_t copy = min(bytes, iov->iov_len - base);
100287
100288 base = 0;
100289 left = __copy_from_user_inatomic(vaddr, buf, copy);
100290 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
100291
100292 kaddr = kmap_atomic(page);
100293 if (likely(i->nr_segs == 1)) {
100294 - int left;
100295 + size_t left;
100296 char __user *buf = i->iov->iov_base + i->iov_offset;
100297 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
100298 copied = bytes - left;
100299 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
100300 * zero-length segments (without overruning the iovec).
100301 */
100302 while (bytes || unlikely(i->count && !iov->iov_len)) {
100303 - int copy;
100304 + size_t copy;
100305
100306 copy = min(bytes, iov->iov_len - base);
100307 BUG_ON(!i->count || i->count < copy);
100308 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
100309 index 3cda50c..032ba634 100644
100310 --- a/mm/kmemleak.c
100311 +++ b/mm/kmemleak.c
100312 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
100313
100314 for (i = 0; i < object->trace_len; i++) {
100315 void *ptr = (void *)object->trace[i];
100316 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
100317 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
100318 }
100319 }
100320
100321 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
100322 return -ENOMEM;
100323 }
100324
100325 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
100326 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
100327 &kmemleak_fops);
100328 if (!dentry)
100329 pr_warning("Failed to create the debugfs kmemleak file\n");
100330 diff --git a/mm/maccess.c b/mm/maccess.c
100331 index d53adf9..03a24bf 100644
100332 --- a/mm/maccess.c
100333 +++ b/mm/maccess.c
100334 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
100335 set_fs(KERNEL_DS);
100336 pagefault_disable();
100337 ret = __copy_from_user_inatomic(dst,
100338 - (__force const void __user *)src, size);
100339 + (const void __force_user *)src, size);
100340 pagefault_enable();
100341 set_fs(old_fs);
100342
100343 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
100344
100345 set_fs(KERNEL_DS);
100346 pagefault_disable();
100347 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
100348 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
100349 pagefault_enable();
100350 set_fs(old_fs);
100351
100352 diff --git a/mm/madvise.c b/mm/madvise.c
100353 index a402f8f..f5e5daa 100644
100354 --- a/mm/madvise.c
100355 +++ b/mm/madvise.c
100356 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
100357 pgoff_t pgoff;
100358 unsigned long new_flags = vma->vm_flags;
100359
100360 +#ifdef CONFIG_PAX_SEGMEXEC
100361 + struct vm_area_struct *vma_m;
100362 +#endif
100363 +
100364 switch (behavior) {
100365 case MADV_NORMAL:
100366 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
100367 @@ -126,6 +130,13 @@ success:
100368 /*
100369 * vm_flags is protected by the mmap_sem held in write mode.
100370 */
100371 +
100372 +#ifdef CONFIG_PAX_SEGMEXEC
100373 + vma_m = pax_find_mirror_vma(vma);
100374 + if (vma_m)
100375 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
100376 +#endif
100377 +
100378 vma->vm_flags = new_flags;
100379
100380 out:
100381 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
100382 struct vm_area_struct **prev,
100383 unsigned long start, unsigned long end)
100384 {
100385 +
100386 +#ifdef CONFIG_PAX_SEGMEXEC
100387 + struct vm_area_struct *vma_m;
100388 +#endif
100389 +
100390 *prev = vma;
100391 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
100392 return -EINVAL;
100393 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
100394 zap_page_range(vma, start, end - start, &details);
100395 } else
100396 zap_page_range(vma, start, end - start, NULL);
100397 +
100398 +#ifdef CONFIG_PAX_SEGMEXEC
100399 + vma_m = pax_find_mirror_vma(vma);
100400 + if (vma_m) {
100401 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
100402 + struct zap_details details = {
100403 + .nonlinear_vma = vma_m,
100404 + .last_index = ULONG_MAX,
100405 + };
100406 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
100407 + } else
100408 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
100409 + }
100410 +#endif
100411 +
100412 return 0;
100413 }
100414
100415 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
100416 if (end < start)
100417 return error;
100418
100419 +#ifdef CONFIG_PAX_SEGMEXEC
100420 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
100421 + if (end > SEGMEXEC_TASK_SIZE)
100422 + return error;
100423 + } else
100424 +#endif
100425 +
100426 + if (end > TASK_SIZE)
100427 + return error;
100428 +
100429 error = 0;
100430 if (end == start)
100431 return error;
100432 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
100433 index a013bc9..a897a14 100644
100434 --- a/mm/memory-failure.c
100435 +++ b/mm/memory-failure.c
100436 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
100437
100438 int sysctl_memory_failure_recovery __read_mostly = 1;
100439
100440 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
100441 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
100442
100443 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
100444
100445 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
100446 pfn, t->comm, t->pid);
100447 si.si_signo = SIGBUS;
100448 si.si_errno = 0;
100449 - si.si_addr = (void *)addr;
100450 + si.si_addr = (void __user *)addr;
100451 #ifdef __ARCH_SI_TRAPNO
100452 si.si_trapno = trapno;
100453 #endif
100454 @@ -791,7 +791,7 @@ static struct page_state {
100455 unsigned long res;
100456 char *msg;
100457 int (*action)(struct page *p, unsigned long pfn);
100458 -} error_states[] = {
100459 +} __do_const error_states[] = {
100460 { reserved, reserved, "reserved kernel", me_kernel },
100461 /*
100462 * free pages are specially detected outside this table:
100463 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
100464 nr_pages = 1 << compound_order(hpage);
100465 else /* normal page or thp */
100466 nr_pages = 1;
100467 - atomic_long_add(nr_pages, &num_poisoned_pages);
100468 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
100469
100470 /*
100471 * We need/can do nothing about count=0 pages.
100472 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
100473 if (PageHWPoison(hpage)) {
100474 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
100475 || (p != hpage && TestSetPageHWPoison(hpage))) {
100476 - atomic_long_sub(nr_pages, &num_poisoned_pages);
100477 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
100478 unlock_page(hpage);
100479 return 0;
100480 }
100481 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
100482 */
100483 if (!PageHWPoison(p)) {
100484 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
100485 - atomic_long_sub(nr_pages, &num_poisoned_pages);
100486 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
100487 put_page(hpage);
100488 res = 0;
100489 goto out;
100490 }
100491 if (hwpoison_filter(p)) {
100492 if (TestClearPageHWPoison(p))
100493 - atomic_long_sub(nr_pages, &num_poisoned_pages);
100494 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
100495 unlock_page(hpage);
100496 put_page(hpage);
100497 return 0;
100498 @@ -1423,7 +1423,7 @@ int unpoison_memory(unsigned long pfn)
100499 return 0;
100500 }
100501 if (TestClearPageHWPoison(p))
100502 - atomic_long_dec(&num_poisoned_pages);
100503 + atomic_long_dec_unchecked(&num_poisoned_pages);
100504 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
100505 return 0;
100506 }
100507 @@ -1437,7 +1437,7 @@ int unpoison_memory(unsigned long pfn)
100508 */
100509 if (TestClearPageHWPoison(page)) {
100510 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
100511 - atomic_long_sub(nr_pages, &num_poisoned_pages);
100512 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
100513 freeit = 1;
100514 if (PageHuge(page))
100515 clear_page_hwpoison_huge_page(page);
100516 @@ -1562,11 +1562,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
100517 if (PageHuge(page)) {
100518 set_page_hwpoison_huge_page(hpage);
100519 dequeue_hwpoisoned_huge_page(hpage);
100520 - atomic_long_add(1 << compound_order(hpage),
100521 + atomic_long_add_unchecked(1 << compound_order(hpage),
100522 &num_poisoned_pages);
100523 } else {
100524 SetPageHWPoison(page);
100525 - atomic_long_inc(&num_poisoned_pages);
100526 + atomic_long_inc_unchecked(&num_poisoned_pages);
100527 }
100528 }
100529 return ret;
100530 @@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
100531 put_page(page);
100532 pr_info("soft_offline: %#lx: invalidated\n", pfn);
100533 SetPageHWPoison(page);
100534 - atomic_long_inc(&num_poisoned_pages);
100535 + atomic_long_inc_unchecked(&num_poisoned_pages);
100536 return 0;
100537 }
100538
100539 @@ -1656,7 +1656,7 @@ static int __soft_offline_page(struct page *page, int flags)
100540 if (!is_free_buddy_page(page))
100541 pr_info("soft offline: %#lx: page leaked\n",
100542 pfn);
100543 - atomic_long_inc(&num_poisoned_pages);
100544 + atomic_long_inc_unchecked(&num_poisoned_pages);
100545 }
100546 } else {
100547 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
100548 @@ -1726,11 +1726,11 @@ int soft_offline_page(struct page *page, int flags)
100549 if (PageHuge(page)) {
100550 set_page_hwpoison_huge_page(hpage);
100551 dequeue_hwpoisoned_huge_page(hpage);
100552 - atomic_long_add(1 << compound_order(hpage),
100553 + atomic_long_add_unchecked(1 << compound_order(hpage),
100554 &num_poisoned_pages);
100555 } else {
100556 SetPageHWPoison(page);
100557 - atomic_long_inc(&num_poisoned_pages);
100558 + atomic_long_inc_unchecked(&num_poisoned_pages);
100559 }
100560 }
100561 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
100562 diff --git a/mm/memory.c b/mm/memory.c
100563 index 0a21f3d..babeaec 100644
100564 --- a/mm/memory.c
100565 +++ b/mm/memory.c
100566 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
100567 free_pte_range(tlb, pmd, addr);
100568 } while (pmd++, addr = next, addr != end);
100569
100570 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
100571 start &= PUD_MASK;
100572 if (start < floor)
100573 return;
100574 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
100575 pmd = pmd_offset(pud, start);
100576 pud_clear(pud);
100577 pmd_free_tlb(tlb, pmd, start);
100578 +#endif
100579 +
100580 }
100581
100582 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
100583 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
100584 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
100585 } while (pud++, addr = next, addr != end);
100586
100587 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
100588 start &= PGDIR_MASK;
100589 if (start < floor)
100590 return;
100591 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
100592 pud = pud_offset(pgd, start);
100593 pgd_clear(pgd);
100594 pud_free_tlb(tlb, pud, start);
100595 +#endif
100596 +
100597 }
100598
100599 /*
100600 @@ -1500,6 +1506,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
100601 page_add_file_rmap(page);
100602 set_pte_at(mm, addr, pte, mk_pte(page, prot));
100603
100604 +#ifdef CONFIG_PAX_SEGMEXEC
100605 + pax_mirror_file_pte(vma, addr, page, ptl);
100606 +#endif
100607 +
100608 retval = 0;
100609 pte_unmap_unlock(pte, ptl);
100610 return retval;
100611 @@ -1544,9 +1554,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
100612 if (!page_count(page))
100613 return -EINVAL;
100614 if (!(vma->vm_flags & VM_MIXEDMAP)) {
100615 +
100616 +#ifdef CONFIG_PAX_SEGMEXEC
100617 + struct vm_area_struct *vma_m;
100618 +#endif
100619 +
100620 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
100621 BUG_ON(vma->vm_flags & VM_PFNMAP);
100622 vma->vm_flags |= VM_MIXEDMAP;
100623 +
100624 +#ifdef CONFIG_PAX_SEGMEXEC
100625 + vma_m = pax_find_mirror_vma(vma);
100626 + if (vma_m)
100627 + vma_m->vm_flags |= VM_MIXEDMAP;
100628 +#endif
100629 +
100630 }
100631 return insert_page(vma, addr, page, vma->vm_page_prot);
100632 }
100633 @@ -1629,6 +1651,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
100634 unsigned long pfn)
100635 {
100636 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
100637 + BUG_ON(vma->vm_mirror);
100638
100639 if (addr < vma->vm_start || addr >= vma->vm_end)
100640 return -EFAULT;
100641 @@ -1876,7 +1899,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
100642
100643 BUG_ON(pud_huge(*pud));
100644
100645 - pmd = pmd_alloc(mm, pud, addr);
100646 + pmd = (mm == &init_mm) ?
100647 + pmd_alloc_kernel(mm, pud, addr) :
100648 + pmd_alloc(mm, pud, addr);
100649 if (!pmd)
100650 return -ENOMEM;
100651 do {
100652 @@ -1896,7 +1921,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
100653 unsigned long next;
100654 int err;
100655
100656 - pud = pud_alloc(mm, pgd, addr);
100657 + pud = (mm == &init_mm) ?
100658 + pud_alloc_kernel(mm, pgd, addr) :
100659 + pud_alloc(mm, pgd, addr);
100660 if (!pud)
100661 return -ENOMEM;
100662 do {
100663 @@ -2018,6 +2045,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
100664 return ret;
100665 }
100666
100667 +#ifdef CONFIG_PAX_SEGMEXEC
100668 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
100669 +{
100670 + struct mm_struct *mm = vma->vm_mm;
100671 + spinlock_t *ptl;
100672 + pte_t *pte, entry;
100673 +
100674 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
100675 + entry = *pte;
100676 + if (!pte_present(entry)) {
100677 + if (!pte_none(entry)) {
100678 + BUG_ON(pte_file(entry));
100679 + free_swap_and_cache(pte_to_swp_entry(entry));
100680 + pte_clear_not_present_full(mm, address, pte, 0);
100681 + }
100682 + } else {
100683 + struct page *page;
100684 +
100685 + flush_cache_page(vma, address, pte_pfn(entry));
100686 + entry = ptep_clear_flush(vma, address, pte);
100687 + BUG_ON(pte_dirty(entry));
100688 + page = vm_normal_page(vma, address, entry);
100689 + if (page) {
100690 + update_hiwater_rss(mm);
100691 + if (PageAnon(page))
100692 + dec_mm_counter_fast(mm, MM_ANONPAGES);
100693 + else
100694 + dec_mm_counter_fast(mm, MM_FILEPAGES);
100695 + page_remove_rmap(page);
100696 + page_cache_release(page);
100697 + }
100698 + }
100699 + pte_unmap_unlock(pte, ptl);
100700 +}
100701 +
100702 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
100703 + *
100704 + * the ptl of the lower mapped page is held on entry and is not released on exit
100705 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
100706 + */
100707 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
100708 +{
100709 + struct mm_struct *mm = vma->vm_mm;
100710 + unsigned long address_m;
100711 + spinlock_t *ptl_m;
100712 + struct vm_area_struct *vma_m;
100713 + pmd_t *pmd_m;
100714 + pte_t *pte_m, entry_m;
100715 +
100716 + BUG_ON(!page_m || !PageAnon(page_m));
100717 +
100718 + vma_m = pax_find_mirror_vma(vma);
100719 + if (!vma_m)
100720 + return;
100721 +
100722 + BUG_ON(!PageLocked(page_m));
100723 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
100724 + address_m = address + SEGMEXEC_TASK_SIZE;
100725 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
100726 + pte_m = pte_offset_map(pmd_m, address_m);
100727 + ptl_m = pte_lockptr(mm, pmd_m);
100728 + if (ptl != ptl_m) {
100729 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
100730 + if (!pte_none(*pte_m))
100731 + goto out;
100732 + }
100733 +
100734 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
100735 + page_cache_get(page_m);
100736 + page_add_anon_rmap(page_m, vma_m, address_m);
100737 + inc_mm_counter_fast(mm, MM_ANONPAGES);
100738 + set_pte_at(mm, address_m, pte_m, entry_m);
100739 + update_mmu_cache(vma_m, address_m, pte_m);
100740 +out:
100741 + if (ptl != ptl_m)
100742 + spin_unlock(ptl_m);
100743 + pte_unmap(pte_m);
100744 + unlock_page(page_m);
100745 +}
100746 +
100747 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
100748 +{
100749 + struct mm_struct *mm = vma->vm_mm;
100750 + unsigned long address_m;
100751 + spinlock_t *ptl_m;
100752 + struct vm_area_struct *vma_m;
100753 + pmd_t *pmd_m;
100754 + pte_t *pte_m, entry_m;
100755 +
100756 + BUG_ON(!page_m || PageAnon(page_m));
100757 +
100758 + vma_m = pax_find_mirror_vma(vma);
100759 + if (!vma_m)
100760 + return;
100761 +
100762 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
100763 + address_m = address + SEGMEXEC_TASK_SIZE;
100764 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
100765 + pte_m = pte_offset_map(pmd_m, address_m);
100766 + ptl_m = pte_lockptr(mm, pmd_m);
100767 + if (ptl != ptl_m) {
100768 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
100769 + if (!pte_none(*pte_m))
100770 + goto out;
100771 + }
100772 +
100773 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
100774 + page_cache_get(page_m);
100775 + page_add_file_rmap(page_m);
100776 + inc_mm_counter_fast(mm, MM_FILEPAGES);
100777 + set_pte_at(mm, address_m, pte_m, entry_m);
100778 + update_mmu_cache(vma_m, address_m, pte_m);
100779 +out:
100780 + if (ptl != ptl_m)
100781 + spin_unlock(ptl_m);
100782 + pte_unmap(pte_m);
100783 +}
100784 +
100785 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
100786 +{
100787 + struct mm_struct *mm = vma->vm_mm;
100788 + unsigned long address_m;
100789 + spinlock_t *ptl_m;
100790 + struct vm_area_struct *vma_m;
100791 + pmd_t *pmd_m;
100792 + pte_t *pte_m, entry_m;
100793 +
100794 + vma_m = pax_find_mirror_vma(vma);
100795 + if (!vma_m)
100796 + return;
100797 +
100798 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
100799 + address_m = address + SEGMEXEC_TASK_SIZE;
100800 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
100801 + pte_m = pte_offset_map(pmd_m, address_m);
100802 + ptl_m = pte_lockptr(mm, pmd_m);
100803 + if (ptl != ptl_m) {
100804 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
100805 + if (!pte_none(*pte_m))
100806 + goto out;
100807 + }
100808 +
100809 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
100810 + set_pte_at(mm, address_m, pte_m, entry_m);
100811 +out:
100812 + if (ptl != ptl_m)
100813 + spin_unlock(ptl_m);
100814 + pte_unmap(pte_m);
100815 +}
100816 +
100817 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
100818 +{
100819 + struct page *page_m;
100820 + pte_t entry;
100821 +
100822 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
100823 + goto out;
100824 +
100825 + entry = *pte;
100826 + page_m = vm_normal_page(vma, address, entry);
100827 + if (!page_m)
100828 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
100829 + else if (PageAnon(page_m)) {
100830 + if (pax_find_mirror_vma(vma)) {
100831 + pte_unmap_unlock(pte, ptl);
100832 + lock_page(page_m);
100833 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
100834 + if (pte_same(entry, *pte))
100835 + pax_mirror_anon_pte(vma, address, page_m, ptl);
100836 + else
100837 + unlock_page(page_m);
100838 + }
100839 + } else
100840 + pax_mirror_file_pte(vma, address, page_m, ptl);
100841 +
100842 +out:
100843 + pte_unmap_unlock(pte, ptl);
100844 +}
100845 +#endif
100846 +
100847 /*
100848 * This routine handles present pages, when users try to write
100849 * to a shared page. It is done by copying the page to a new address
100850 @@ -2215,6 +2422,12 @@ gotten:
100851 */
100852 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
100853 if (likely(pte_same(*page_table, orig_pte))) {
100854 +
100855 +#ifdef CONFIG_PAX_SEGMEXEC
100856 + if (pax_find_mirror_vma(vma))
100857 + BUG_ON(!trylock_page(new_page));
100858 +#endif
100859 +
100860 if (old_page) {
100861 if (!PageAnon(old_page)) {
100862 dec_mm_counter_fast(mm, MM_FILEPAGES);
100863 @@ -2266,6 +2479,10 @@ gotten:
100864 page_remove_rmap(old_page);
100865 }
100866
100867 +#ifdef CONFIG_PAX_SEGMEXEC
100868 + pax_mirror_anon_pte(vma, address, new_page, ptl);
100869 +#endif
100870 +
100871 /* Free the old page.. */
100872 new_page = old_page;
100873 ret |= VM_FAULT_WRITE;
100874 @@ -2539,6 +2756,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
100875 swap_free(entry);
100876 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
100877 try_to_free_swap(page);
100878 +
100879 +#ifdef CONFIG_PAX_SEGMEXEC
100880 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
100881 +#endif
100882 +
100883 unlock_page(page);
100884 if (page != swapcache) {
100885 /*
100886 @@ -2562,6 +2784,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
100887
100888 /* No need to invalidate - it was non-present before */
100889 update_mmu_cache(vma, address, page_table);
100890 +
100891 +#ifdef CONFIG_PAX_SEGMEXEC
100892 + pax_mirror_anon_pte(vma, address, page, ptl);
100893 +#endif
100894 +
100895 unlock:
100896 pte_unmap_unlock(page_table, ptl);
100897 out:
100898 @@ -2581,40 +2808,6 @@ out_release:
100899 }
100900
100901 /*
100902 - * This is like a special single-page "expand_{down|up}wards()",
100903 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
100904 - * doesn't hit another vma.
100905 - */
100906 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
100907 -{
100908 - address &= PAGE_MASK;
100909 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
100910 - struct vm_area_struct *prev = vma->vm_prev;
100911 -
100912 - /*
100913 - * Is there a mapping abutting this one below?
100914 - *
100915 - * That's only ok if it's the same stack mapping
100916 - * that has gotten split..
100917 - */
100918 - if (prev && prev->vm_end == address)
100919 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
100920 -
100921 - expand_downwards(vma, address - PAGE_SIZE);
100922 - }
100923 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
100924 - struct vm_area_struct *next = vma->vm_next;
100925 -
100926 - /* As VM_GROWSDOWN but s/below/above/ */
100927 - if (next && next->vm_start == address + PAGE_SIZE)
100928 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
100929 -
100930 - expand_upwards(vma, address + PAGE_SIZE);
100931 - }
100932 - return 0;
100933 -}
100934 -
100935 -/*
100936 * We enter with non-exclusive mmap_sem (to exclude vma changes,
100937 * but allow concurrent faults), and pte mapped but not yet locked.
100938 * We return with mmap_sem still held, but pte unmapped and unlocked.
100939 @@ -2623,27 +2816,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
100940 unsigned long address, pte_t *page_table, pmd_t *pmd,
100941 unsigned int flags)
100942 {
100943 - struct page *page;
100944 + struct page *page = NULL;
100945 spinlock_t *ptl;
100946 pte_t entry;
100947
100948 - pte_unmap(page_table);
100949 -
100950 - /* Check if we need to add a guard page to the stack */
100951 - if (check_stack_guard_page(vma, address) < 0)
100952 - return VM_FAULT_SIGBUS;
100953 -
100954 - /* Use the zero-page for reads */
100955 if (!(flags & FAULT_FLAG_WRITE)) {
100956 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
100957 vma->vm_page_prot));
100958 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
100959 + ptl = pte_lockptr(mm, pmd);
100960 + spin_lock(ptl);
100961 if (!pte_none(*page_table))
100962 goto unlock;
100963 goto setpte;
100964 }
100965
100966 /* Allocate our own private page. */
100967 + pte_unmap(page_table);
100968 +
100969 if (unlikely(anon_vma_prepare(vma)))
100970 goto oom;
100971 page = alloc_zeroed_user_highpage_movable(vma, address);
100972 @@ -2667,6 +2856,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
100973 if (!pte_none(*page_table))
100974 goto release;
100975
100976 +#ifdef CONFIG_PAX_SEGMEXEC
100977 + if (pax_find_mirror_vma(vma))
100978 + BUG_ON(!trylock_page(page));
100979 +#endif
100980 +
100981 inc_mm_counter_fast(mm, MM_ANONPAGES);
100982 page_add_new_anon_rmap(page, vma, address);
100983 setpte:
100984 @@ -2674,6 +2868,12 @@ setpte:
100985
100986 /* No need to invalidate - it was non-present before */
100987 update_mmu_cache(vma, address, page_table);
100988 +
100989 +#ifdef CONFIG_PAX_SEGMEXEC
100990 + if (page)
100991 + pax_mirror_anon_pte(vma, address, page, ptl);
100992 +#endif
100993 +
100994 unlock:
100995 pte_unmap_unlock(page_table, ptl);
100996 return 0;
100997 @@ -2905,6 +3105,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
100998 return ret;
100999 }
101000 do_set_pte(vma, address, fault_page, pte, false, false);
101001 +
101002 +#ifdef CONFIG_PAX_SEGMEXEC
101003 + pax_mirror_file_pte(vma, address, fault_page, ptl);
101004 +#endif
101005 +
101006 unlock_page(fault_page);
101007 unlock_out:
101008 pte_unmap_unlock(pte, ptl);
101009 @@ -2946,7 +3151,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
101010 page_cache_release(fault_page);
101011 goto uncharge_out;
101012 }
101013 +
101014 +#ifdef CONFIG_PAX_SEGMEXEC
101015 + if (pax_find_mirror_vma(vma))
101016 + BUG_ON(!trylock_page(new_page));
101017 +#endif
101018 +
101019 do_set_pte(vma, address, new_page, pte, true, true);
101020 +
101021 +#ifdef CONFIG_PAX_SEGMEXEC
101022 + pax_mirror_anon_pte(vma, address, new_page, ptl);
101023 +#endif
101024 +
101025 pte_unmap_unlock(pte, ptl);
101026 unlock_page(fault_page);
101027 page_cache_release(fault_page);
101028 @@ -2994,6 +3210,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
101029 return ret;
101030 }
101031 do_set_pte(vma, address, fault_page, pte, true, false);
101032 +
101033 +#ifdef CONFIG_PAX_SEGMEXEC
101034 + pax_mirror_file_pte(vma, address, fault_page, ptl);
101035 +#endif
101036 +
101037 pte_unmap_unlock(pte, ptl);
101038
101039 if (set_page_dirty(fault_page))
101040 @@ -3224,6 +3445,12 @@ static int handle_pte_fault(struct mm_struct *mm,
101041 if (flags & FAULT_FLAG_WRITE)
101042 flush_tlb_fix_spurious_fault(vma, address);
101043 }
101044 +
101045 +#ifdef CONFIG_PAX_SEGMEXEC
101046 + pax_mirror_pte(vma, address, pte, pmd, ptl);
101047 + return 0;
101048 +#endif
101049 +
101050 unlock:
101051 pte_unmap_unlock(pte, ptl);
101052 return 0;
101053 @@ -3240,9 +3467,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
101054 pmd_t *pmd;
101055 pte_t *pte;
101056
101057 +#ifdef CONFIG_PAX_SEGMEXEC
101058 + struct vm_area_struct *vma_m;
101059 +#endif
101060 +
101061 if (unlikely(is_vm_hugetlb_page(vma)))
101062 return hugetlb_fault(mm, vma, address, flags);
101063
101064 +#ifdef CONFIG_PAX_SEGMEXEC
101065 + vma_m = pax_find_mirror_vma(vma);
101066 + if (vma_m) {
101067 + unsigned long address_m;
101068 + pgd_t *pgd_m;
101069 + pud_t *pud_m;
101070 + pmd_t *pmd_m;
101071 +
101072 + if (vma->vm_start > vma_m->vm_start) {
101073 + address_m = address;
101074 + address -= SEGMEXEC_TASK_SIZE;
101075 + vma = vma_m;
101076 + } else
101077 + address_m = address + SEGMEXEC_TASK_SIZE;
101078 +
101079 + pgd_m = pgd_offset(mm, address_m);
101080 + pud_m = pud_alloc(mm, pgd_m, address_m);
101081 + if (!pud_m)
101082 + return VM_FAULT_OOM;
101083 + pmd_m = pmd_alloc(mm, pud_m, address_m);
101084 + if (!pmd_m)
101085 + return VM_FAULT_OOM;
101086 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
101087 + return VM_FAULT_OOM;
101088 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
101089 + }
101090 +#endif
101091 +
101092 pgd = pgd_offset(mm, address);
101093 pud = pud_alloc(mm, pgd, address);
101094 if (!pud)
101095 @@ -3370,6 +3629,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
101096 spin_unlock(&mm->page_table_lock);
101097 return 0;
101098 }
101099 +
101100 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
101101 +{
101102 + pud_t *new = pud_alloc_one(mm, address);
101103 + if (!new)
101104 + return -ENOMEM;
101105 +
101106 + smp_wmb(); /* See comment in __pte_alloc */
101107 +
101108 + spin_lock(&mm->page_table_lock);
101109 + if (pgd_present(*pgd)) /* Another has populated it */
101110 + pud_free(mm, new);
101111 + else
101112 + pgd_populate_kernel(mm, pgd, new);
101113 + spin_unlock(&mm->page_table_lock);
101114 + return 0;
101115 +}
101116 #endif /* __PAGETABLE_PUD_FOLDED */
101117
101118 #ifndef __PAGETABLE_PMD_FOLDED
101119 @@ -3400,6 +3676,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
101120 spin_unlock(&mm->page_table_lock);
101121 return 0;
101122 }
101123 +
101124 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
101125 +{
101126 + pmd_t *new = pmd_alloc_one(mm, address);
101127 + if (!new)
101128 + return -ENOMEM;
101129 +
101130 + smp_wmb(); /* See comment in __pte_alloc */
101131 +
101132 + spin_lock(&mm->page_table_lock);
101133 +#ifndef __ARCH_HAS_4LEVEL_HACK
101134 + if (pud_present(*pud)) /* Another has populated it */
101135 + pmd_free(mm, new);
101136 + else
101137 + pud_populate_kernel(mm, pud, new);
101138 +#else
101139 + if (pgd_present(*pud)) /* Another has populated it */
101140 + pmd_free(mm, new);
101141 + else
101142 + pgd_populate_kernel(mm, pud, new);
101143 +#endif /* __ARCH_HAS_4LEVEL_HACK */
101144 + spin_unlock(&mm->page_table_lock);
101145 + return 0;
101146 +}
101147 #endif /* __PAGETABLE_PMD_FOLDED */
101148
101149 #if !defined(__HAVE_ARCH_GATE_AREA)
101150 @@ -3413,7 +3713,7 @@ static int __init gate_vma_init(void)
101151 gate_vma.vm_start = FIXADDR_USER_START;
101152 gate_vma.vm_end = FIXADDR_USER_END;
101153 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
101154 - gate_vma.vm_page_prot = __P101;
101155 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
101156
101157 return 0;
101158 }
101159 @@ -3547,8 +3847,8 @@ out:
101160 return ret;
101161 }
101162
101163 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
101164 - void *buf, int len, int write)
101165 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
101166 + void *buf, size_t len, int write)
101167 {
101168 resource_size_t phys_addr;
101169 unsigned long prot = 0;
101170 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
101171 * Access another process' address space as given in mm. If non-NULL, use the
101172 * given task for page fault accounting.
101173 */
101174 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101175 - unsigned long addr, void *buf, int len, int write)
101176 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101177 + unsigned long addr, void *buf, size_t len, int write)
101178 {
101179 struct vm_area_struct *vma;
101180 void *old_buf = buf;
101181 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101182 down_read(&mm->mmap_sem);
101183 /* ignore errors, just check how much was successfully transferred */
101184 while (len) {
101185 - int bytes, ret, offset;
101186 + ssize_t bytes, ret, offset;
101187 void *maddr;
101188 struct page *page = NULL;
101189
101190 @@ -3642,8 +3942,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
101191 *
101192 * The caller must hold a reference on @mm.
101193 */
101194 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
101195 - void *buf, int len, int write)
101196 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
101197 + void *buf, size_t len, int write)
101198 {
101199 return __access_remote_vm(NULL, mm, addr, buf, len, write);
101200 }
101201 @@ -3653,11 +3953,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
101202 * Source/target buffer must be kernel space,
101203 * Do not walk the page table directly, use get_user_pages
101204 */
101205 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
101206 - void *buf, int len, int write)
101207 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
101208 + void *buf, size_t len, int write)
101209 {
101210 struct mm_struct *mm;
101211 - int ret;
101212 + ssize_t ret;
101213
101214 mm = get_task_mm(tsk);
101215 if (!mm)
101216 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
101217 index 8f5330d..b41914b 100644
101218 --- a/mm/mempolicy.c
101219 +++ b/mm/mempolicy.c
101220 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
101221 unsigned long vmstart;
101222 unsigned long vmend;
101223
101224 +#ifdef CONFIG_PAX_SEGMEXEC
101225 + struct vm_area_struct *vma_m;
101226 +#endif
101227 +
101228 vma = find_vma(mm, start);
101229 if (!vma || vma->vm_start > start)
101230 return -EFAULT;
101231 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
101232 err = vma_replace_policy(vma, new_pol);
101233 if (err)
101234 goto out;
101235 +
101236 +#ifdef CONFIG_PAX_SEGMEXEC
101237 + vma_m = pax_find_mirror_vma(vma);
101238 + if (vma_m) {
101239 + err = vma_replace_policy(vma_m, new_pol);
101240 + if (err)
101241 + goto out;
101242 + }
101243 +#endif
101244 +
101245 }
101246
101247 out:
101248 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
101249
101250 if (end < start)
101251 return -EINVAL;
101252 +
101253 +#ifdef CONFIG_PAX_SEGMEXEC
101254 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
101255 + if (end > SEGMEXEC_TASK_SIZE)
101256 + return -EINVAL;
101257 + } else
101258 +#endif
101259 +
101260 + if (end > TASK_SIZE)
101261 + return -EINVAL;
101262 +
101263 if (end == start)
101264 return 0;
101265
101266 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
101267 */
101268 tcred = __task_cred(task);
101269 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
101270 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
101271 - !capable(CAP_SYS_NICE)) {
101272 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
101273 rcu_read_unlock();
101274 err = -EPERM;
101275 goto out_put;
101276 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
101277 goto out;
101278 }
101279
101280 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
101281 + if (mm != current->mm &&
101282 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
101283 + mmput(mm);
101284 + err = -EPERM;
101285 + goto out;
101286 + }
101287 +#endif
101288 +
101289 err = do_migrate_pages(mm, old, new,
101290 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
101291
101292 diff --git a/mm/migrate.c b/mm/migrate.c
101293 index be6dbf9..febb8ec 100644
101294 --- a/mm/migrate.c
101295 +++ b/mm/migrate.c
101296 @@ -1506,8 +1506,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
101297 */
101298 tcred = __task_cred(task);
101299 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
101300 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
101301 - !capable(CAP_SYS_NICE)) {
101302 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
101303 rcu_read_unlock();
101304 err = -EPERM;
101305 goto out;
101306 diff --git a/mm/mlock.c b/mm/mlock.c
101307 index b1eb536..091d154 100644
101308 --- a/mm/mlock.c
101309 +++ b/mm/mlock.c
101310 @@ -14,6 +14,7 @@
101311 #include <linux/pagevec.h>
101312 #include <linux/mempolicy.h>
101313 #include <linux/syscalls.h>
101314 +#include <linux/security.h>
101315 #include <linux/sched.h>
101316 #include <linux/export.h>
101317 #include <linux/rmap.h>
101318 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
101319 {
101320 unsigned long nstart, end, tmp;
101321 struct vm_area_struct * vma, * prev;
101322 - int error;
101323 + int error = 0;
101324
101325 VM_BUG_ON(start & ~PAGE_MASK);
101326 VM_BUG_ON(len != PAGE_ALIGN(len));
101327 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
101328 return -EINVAL;
101329 if (end == start)
101330 return 0;
101331 + if (end > TASK_SIZE)
101332 + return -EINVAL;
101333 +
101334 vma = find_vma(current->mm, start);
101335 if (!vma || vma->vm_start > start)
101336 return -ENOMEM;
101337 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
101338 for (nstart = start ; ; ) {
101339 vm_flags_t newflags;
101340
101341 +#ifdef CONFIG_PAX_SEGMEXEC
101342 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
101343 + break;
101344 +#endif
101345 +
101346 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
101347
101348 newflags = vma->vm_flags & ~VM_LOCKED;
101349 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
101350 locked += current->mm->locked_vm;
101351
101352 /* check against resource limits */
101353 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
101354 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
101355 error = do_mlock(start, len, 1);
101356
101357 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
101358 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
101359 vm_flags_t newflags;
101360
101361 +#ifdef CONFIG_PAX_SEGMEXEC
101362 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
101363 + break;
101364 +#endif
101365 +
101366 newflags = vma->vm_flags & ~VM_LOCKED;
101367 if (flags & MCL_CURRENT)
101368 newflags |= VM_LOCKED;
101369 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
101370 lock_limit >>= PAGE_SHIFT;
101371
101372 ret = -ENOMEM;
101373 +
101374 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
101375 +
101376 down_write(&current->mm->mmap_sem);
101377 -
101378 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
101379 capable(CAP_IPC_LOCK))
101380 ret = do_mlockall(flags);
101381 diff --git a/mm/mmap.c b/mm/mmap.c
101382 index 129b847..fbed804 100644
101383 --- a/mm/mmap.c
101384 +++ b/mm/mmap.c
101385 @@ -40,6 +40,7 @@
101386 #include <linux/notifier.h>
101387 #include <linux/memory.h>
101388 #include <linux/printk.h>
101389 +#include <linux/random.h>
101390
101391 #include <asm/uaccess.h>
101392 #include <asm/cacheflush.h>
101393 @@ -56,6 +57,16 @@
101394 #define arch_rebalance_pgtables(addr, len) (addr)
101395 #endif
101396
101397 +static inline void verify_mm_writelocked(struct mm_struct *mm)
101398 +{
101399 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
101400 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
101401 + up_read(&mm->mmap_sem);
101402 + BUG();
101403 + }
101404 +#endif
101405 +}
101406 +
101407 static void unmap_region(struct mm_struct *mm,
101408 struct vm_area_struct *vma, struct vm_area_struct *prev,
101409 unsigned long start, unsigned long end);
101410 @@ -75,16 +86,25 @@ static void unmap_region(struct mm_struct *mm,
101411 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
101412 *
101413 */
101414 -pgprot_t protection_map[16] = {
101415 +pgprot_t protection_map[16] __read_only = {
101416 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
101417 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
101418 };
101419
101420 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
101421 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
101422 {
101423 - return __pgprot(pgprot_val(protection_map[vm_flags &
101424 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
101425 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
101426 pgprot_val(arch_vm_get_page_prot(vm_flags)));
101427 +
101428 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
101429 + if (!(__supported_pte_mask & _PAGE_NX) &&
101430 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
101431 + (vm_flags & (VM_READ | VM_WRITE)))
101432 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
101433 +#endif
101434 +
101435 + return prot;
101436 }
101437 EXPORT_SYMBOL(vm_get_page_prot);
101438
101439 @@ -94,6 +114,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
101440 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
101441 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
101442 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
101443 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
101444 /*
101445 * Make sure vm_committed_as in one cacheline and not cacheline shared with
101446 * other variables. It can be updated by several CPUs frequently.
101447 @@ -250,6 +271,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
101448 struct vm_area_struct *next = vma->vm_next;
101449
101450 might_sleep();
101451 + BUG_ON(vma->vm_mirror);
101452 if (vma->vm_ops && vma->vm_ops->close)
101453 vma->vm_ops->close(vma);
101454 if (vma->vm_file)
101455 @@ -294,6 +316,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
101456 * not page aligned -Ram Gupta
101457 */
101458 rlim = rlimit(RLIMIT_DATA);
101459 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
101460 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
101461 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
101462 + rlim = 4096 * PAGE_SIZE;
101463 +#endif
101464 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
101465 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
101466 (mm->end_data - mm->start_data) > rlim)
101467 goto out;
101468 @@ -944,6 +972,12 @@ static int
101469 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
101470 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
101471 {
101472 +
101473 +#ifdef CONFIG_PAX_SEGMEXEC
101474 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
101475 + return 0;
101476 +#endif
101477 +
101478 if (is_mergeable_vma(vma, file, vm_flags) &&
101479 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
101480 if (vma->vm_pgoff == vm_pgoff)
101481 @@ -963,6 +997,12 @@ static int
101482 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
101483 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
101484 {
101485 +
101486 +#ifdef CONFIG_PAX_SEGMEXEC
101487 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
101488 + return 0;
101489 +#endif
101490 +
101491 if (is_mergeable_vma(vma, file, vm_flags) &&
101492 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
101493 pgoff_t vm_pglen;
101494 @@ -1005,13 +1045,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
101495 struct vm_area_struct *vma_merge(struct mm_struct *mm,
101496 struct vm_area_struct *prev, unsigned long addr,
101497 unsigned long end, unsigned long vm_flags,
101498 - struct anon_vma *anon_vma, struct file *file,
101499 + struct anon_vma *anon_vma, struct file *file,
101500 pgoff_t pgoff, struct mempolicy *policy)
101501 {
101502 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
101503 struct vm_area_struct *area, *next;
101504 int err;
101505
101506 +#ifdef CONFIG_PAX_SEGMEXEC
101507 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
101508 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
101509 +
101510 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
101511 +#endif
101512 +
101513 /*
101514 * We later require that vma->vm_flags == vm_flags,
101515 * so this tests vma->vm_flags & VM_SPECIAL, too.
101516 @@ -1027,6 +1074,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
101517 if (next && next->vm_end == end) /* cases 6, 7, 8 */
101518 next = next->vm_next;
101519
101520 +#ifdef CONFIG_PAX_SEGMEXEC
101521 + if (prev)
101522 + prev_m = pax_find_mirror_vma(prev);
101523 + if (area)
101524 + area_m = pax_find_mirror_vma(area);
101525 + if (next)
101526 + next_m = pax_find_mirror_vma(next);
101527 +#endif
101528 +
101529 /*
101530 * Can it merge with the predecessor?
101531 */
101532 @@ -1046,9 +1102,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
101533 /* cases 1, 6 */
101534 err = vma_adjust(prev, prev->vm_start,
101535 next->vm_end, prev->vm_pgoff, NULL);
101536 - } else /* cases 2, 5, 7 */
101537 +
101538 +#ifdef CONFIG_PAX_SEGMEXEC
101539 + if (!err && prev_m)
101540 + err = vma_adjust(prev_m, prev_m->vm_start,
101541 + next_m->vm_end, prev_m->vm_pgoff, NULL);
101542 +#endif
101543 +
101544 + } else { /* cases 2, 5, 7 */
101545 err = vma_adjust(prev, prev->vm_start,
101546 end, prev->vm_pgoff, NULL);
101547 +
101548 +#ifdef CONFIG_PAX_SEGMEXEC
101549 + if (!err && prev_m)
101550 + err = vma_adjust(prev_m, prev_m->vm_start,
101551 + end_m, prev_m->vm_pgoff, NULL);
101552 +#endif
101553 +
101554 + }
101555 if (err)
101556 return NULL;
101557 khugepaged_enter_vma_merge(prev);
101558 @@ -1062,12 +1133,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
101559 mpol_equal(policy, vma_policy(next)) &&
101560 can_vma_merge_before(next, vm_flags,
101561 anon_vma, file, pgoff+pglen)) {
101562 - if (prev && addr < prev->vm_end) /* case 4 */
101563 + if (prev && addr < prev->vm_end) { /* case 4 */
101564 err = vma_adjust(prev, prev->vm_start,
101565 addr, prev->vm_pgoff, NULL);
101566 - else /* cases 3, 8 */
101567 +
101568 +#ifdef CONFIG_PAX_SEGMEXEC
101569 + if (!err && prev_m)
101570 + err = vma_adjust(prev_m, prev_m->vm_start,
101571 + addr_m, prev_m->vm_pgoff, NULL);
101572 +#endif
101573 +
101574 + } else { /* cases 3, 8 */
101575 err = vma_adjust(area, addr, next->vm_end,
101576 next->vm_pgoff - pglen, NULL);
101577 +
101578 +#ifdef CONFIG_PAX_SEGMEXEC
101579 + if (!err && area_m)
101580 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
101581 + next_m->vm_pgoff - pglen, NULL);
101582 +#endif
101583 +
101584 + }
101585 if (err)
101586 return NULL;
101587 khugepaged_enter_vma_merge(area);
101588 @@ -1176,8 +1262,10 @@ none:
101589 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
101590 struct file *file, long pages)
101591 {
101592 - const unsigned long stack_flags
101593 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
101594 +
101595 +#ifdef CONFIG_PAX_RANDMMAP
101596 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
101597 +#endif
101598
101599 mm->total_vm += pages;
101600
101601 @@ -1185,7 +1273,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
101602 mm->shared_vm += pages;
101603 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
101604 mm->exec_vm += pages;
101605 - } else if (flags & stack_flags)
101606 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
101607 mm->stack_vm += pages;
101608 }
101609 #endif /* CONFIG_PROC_FS */
101610 @@ -1215,6 +1303,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
101611 locked += mm->locked_vm;
101612 lock_limit = rlimit(RLIMIT_MEMLOCK);
101613 lock_limit >>= PAGE_SHIFT;
101614 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
101615 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
101616 return -EAGAIN;
101617 }
101618 @@ -1241,7 +1330,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
101619 * (the exception is when the underlying filesystem is noexec
101620 * mounted, in which case we dont add PROT_EXEC.)
101621 */
101622 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
101623 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
101624 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
101625 prot |= PROT_EXEC;
101626
101627 @@ -1267,7 +1356,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
101628 /* Obtain the address to map to. we verify (or select) it and ensure
101629 * that it represents a valid section of the address space.
101630 */
101631 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
101632 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
101633 if (addr & ~PAGE_MASK)
101634 return addr;
101635
101636 @@ -1278,6 +1367,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
101637 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
101638 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
101639
101640 +#ifdef CONFIG_PAX_MPROTECT
101641 + if (mm->pax_flags & MF_PAX_MPROTECT) {
101642 +
101643 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
101644 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
101645 + mm->binfmt->handle_mmap)
101646 + mm->binfmt->handle_mmap(file);
101647 +#endif
101648 +
101649 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
101650 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
101651 + gr_log_rwxmmap(file);
101652 +
101653 +#ifdef CONFIG_PAX_EMUPLT
101654 + vm_flags &= ~VM_EXEC;
101655 +#else
101656 + return -EPERM;
101657 +#endif
101658 +
101659 + }
101660 +
101661 + if (!(vm_flags & VM_EXEC))
101662 + vm_flags &= ~VM_MAYEXEC;
101663 +#else
101664 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
101665 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
101666 +#endif
101667 + else
101668 + vm_flags &= ~VM_MAYWRITE;
101669 + }
101670 +#endif
101671 +
101672 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
101673 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
101674 + vm_flags &= ~VM_PAGEEXEC;
101675 +#endif
101676 +
101677 if (flags & MAP_LOCKED)
101678 if (!can_do_mlock())
101679 return -EPERM;
101680 @@ -1365,6 +1491,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
101681 vm_flags |= VM_NORESERVE;
101682 }
101683
101684 + if (!gr_acl_handle_mmap(file, prot))
101685 + return -EACCES;
101686 +
101687 addr = mmap_region(file, addr, len, vm_flags, pgoff);
101688 if (!IS_ERR_VALUE(addr) &&
101689 ((vm_flags & VM_LOCKED) ||
101690 @@ -1458,7 +1587,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
101691 vm_flags_t vm_flags = vma->vm_flags;
101692
101693 /* If it was private or non-writable, the write bit is already clear */
101694 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
101695 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
101696 return 0;
101697
101698 /* The backer wishes to know when pages are first written to? */
101699 @@ -1504,7 +1633,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
101700 struct rb_node **rb_link, *rb_parent;
101701 unsigned long charged = 0;
101702
101703 +#ifdef CONFIG_PAX_SEGMEXEC
101704 + struct vm_area_struct *vma_m = NULL;
101705 +#endif
101706 +
101707 + /*
101708 + * mm->mmap_sem is required to protect against another thread
101709 + * changing the mappings in case we sleep.
101710 + */
101711 + verify_mm_writelocked(mm);
101712 +
101713 /* Check against address space limit. */
101714 +
101715 +#ifdef CONFIG_PAX_RANDMMAP
101716 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
101717 +#endif
101718 +
101719 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
101720 unsigned long nr_pages;
101721
101722 @@ -1523,11 +1667,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
101723
101724 /* Clear old maps */
101725 error = -ENOMEM;
101726 -munmap_back:
101727 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
101728 if (do_munmap(mm, addr, len))
101729 return -ENOMEM;
101730 - goto munmap_back;
101731 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
101732 }
101733
101734 /*
101735 @@ -1558,6 +1701,16 @@ munmap_back:
101736 goto unacct_error;
101737 }
101738
101739 +#ifdef CONFIG_PAX_SEGMEXEC
101740 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
101741 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
101742 + if (!vma_m) {
101743 + error = -ENOMEM;
101744 + goto free_vma;
101745 + }
101746 + }
101747 +#endif
101748 +
101749 vma->vm_mm = mm;
101750 vma->vm_start = addr;
101751 vma->vm_end = addr + len;
101752 @@ -1577,6 +1730,13 @@ munmap_back:
101753 if (error)
101754 goto unmap_and_free_vma;
101755
101756 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
101757 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
101758 + vma->vm_flags |= VM_PAGEEXEC;
101759 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
101760 + }
101761 +#endif
101762 +
101763 /* Can addr have changed??
101764 *
101765 * Answer: Yes, several device drivers can do it in their
101766 @@ -1610,6 +1770,12 @@ munmap_back:
101767 }
101768
101769 vma_link(mm, vma, prev, rb_link, rb_parent);
101770 +
101771 +#ifdef CONFIG_PAX_SEGMEXEC
101772 + if (vma_m)
101773 + BUG_ON(pax_mirror_vma(vma_m, vma));
101774 +#endif
101775 +
101776 /* Once vma denies write, undo our temporary denial count */
101777 if (vm_flags & VM_DENYWRITE)
101778 allow_write_access(file);
101779 @@ -1618,6 +1784,7 @@ out:
101780 perf_event_mmap(vma);
101781
101782 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
101783 + track_exec_limit(mm, addr, addr + len, vm_flags);
101784 if (vm_flags & VM_LOCKED) {
101785 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
101786 vma == get_gate_vma(current->mm)))
101787 @@ -1650,6 +1817,12 @@ unmap_and_free_vma:
101788 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
101789 charged = 0;
101790 free_vma:
101791 +
101792 +#ifdef CONFIG_PAX_SEGMEXEC
101793 + if (vma_m)
101794 + kmem_cache_free(vm_area_cachep, vma_m);
101795 +#endif
101796 +
101797 kmem_cache_free(vm_area_cachep, vma);
101798 unacct_error:
101799 if (charged)
101800 @@ -1657,7 +1830,63 @@ unacct_error:
101801 return error;
101802 }
101803
101804 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
101805 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
101806 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
101807 +{
101808 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
101809 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
101810 +
101811 + return 0;
101812 +}
101813 +#endif
101814 +
101815 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
101816 +{
101817 + if (!vma) {
101818 +#ifdef CONFIG_STACK_GROWSUP
101819 + if (addr > sysctl_heap_stack_gap)
101820 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
101821 + else
101822 + vma = find_vma(current->mm, 0);
101823 + if (vma && (vma->vm_flags & VM_GROWSUP))
101824 + return false;
101825 +#endif
101826 + return true;
101827 + }
101828 +
101829 + if (addr + len > vma->vm_start)
101830 + return false;
101831 +
101832 + if (vma->vm_flags & VM_GROWSDOWN)
101833 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
101834 +#ifdef CONFIG_STACK_GROWSUP
101835 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
101836 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
101837 +#endif
101838 + else if (offset)
101839 + return offset <= vma->vm_start - addr - len;
101840 +
101841 + return true;
101842 +}
101843 +
101844 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
101845 +{
101846 + if (vma->vm_start < len)
101847 + return -ENOMEM;
101848 +
101849 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
101850 + if (offset <= vma->vm_start - len)
101851 + return vma->vm_start - len - offset;
101852 + else
101853 + return -ENOMEM;
101854 + }
101855 +
101856 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
101857 + return vma->vm_start - len - sysctl_heap_stack_gap;
101858 + return -ENOMEM;
101859 +}
101860 +
101861 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
101862 {
101863 /*
101864 * We implement the search by looking for an rbtree node that
101865 @@ -1705,11 +1934,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
101866 }
101867 }
101868
101869 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
101870 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
101871 check_current:
101872 /* Check if current node has a suitable gap */
101873 if (gap_start > high_limit)
101874 return -ENOMEM;
101875 +
101876 + if (gap_end - gap_start > info->threadstack_offset)
101877 + gap_start += info->threadstack_offset;
101878 + else
101879 + gap_start = gap_end;
101880 +
101881 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
101882 + if (gap_end - gap_start > sysctl_heap_stack_gap)
101883 + gap_start += sysctl_heap_stack_gap;
101884 + else
101885 + gap_start = gap_end;
101886 + }
101887 + if (vma->vm_flags & VM_GROWSDOWN) {
101888 + if (gap_end - gap_start > sysctl_heap_stack_gap)
101889 + gap_end -= sysctl_heap_stack_gap;
101890 + else
101891 + gap_end = gap_start;
101892 + }
101893 if (gap_end >= low_limit && gap_end - gap_start >= length)
101894 goto found;
101895
101896 @@ -1759,7 +2006,7 @@ found:
101897 return gap_start;
101898 }
101899
101900 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
101901 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
101902 {
101903 struct mm_struct *mm = current->mm;
101904 struct vm_area_struct *vma;
101905 @@ -1813,6 +2060,24 @@ check_current:
101906 gap_end = vma->vm_start;
101907 if (gap_end < low_limit)
101908 return -ENOMEM;
101909 +
101910 + if (gap_end - gap_start > info->threadstack_offset)
101911 + gap_end -= info->threadstack_offset;
101912 + else
101913 + gap_end = gap_start;
101914 +
101915 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
101916 + if (gap_end - gap_start > sysctl_heap_stack_gap)
101917 + gap_start += sysctl_heap_stack_gap;
101918 + else
101919 + gap_start = gap_end;
101920 + }
101921 + if (vma->vm_flags & VM_GROWSDOWN) {
101922 + if (gap_end - gap_start > sysctl_heap_stack_gap)
101923 + gap_end -= sysctl_heap_stack_gap;
101924 + else
101925 + gap_end = gap_start;
101926 + }
101927 if (gap_start <= high_limit && gap_end - gap_start >= length)
101928 goto found;
101929
101930 @@ -1876,6 +2141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
101931 struct mm_struct *mm = current->mm;
101932 struct vm_area_struct *vma;
101933 struct vm_unmapped_area_info info;
101934 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
101935
101936 if (len > TASK_SIZE - mmap_min_addr)
101937 return -ENOMEM;
101938 @@ -1883,11 +2149,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
101939 if (flags & MAP_FIXED)
101940 return addr;
101941
101942 +#ifdef CONFIG_PAX_RANDMMAP
101943 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
101944 +#endif
101945 +
101946 if (addr) {
101947 addr = PAGE_ALIGN(addr);
101948 vma = find_vma(mm, addr);
101949 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
101950 - (!vma || addr + len <= vma->vm_start))
101951 + check_heap_stack_gap(vma, addr, len, offset))
101952 return addr;
101953 }
101954
101955 @@ -1896,6 +2166,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
101956 info.low_limit = mm->mmap_base;
101957 info.high_limit = TASK_SIZE;
101958 info.align_mask = 0;
101959 + info.threadstack_offset = offset;
101960 return vm_unmapped_area(&info);
101961 }
101962 #endif
101963 @@ -1914,6 +2185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
101964 struct mm_struct *mm = current->mm;
101965 unsigned long addr = addr0;
101966 struct vm_unmapped_area_info info;
101967 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
101968
101969 /* requested length too big for entire address space */
101970 if (len > TASK_SIZE - mmap_min_addr)
101971 @@ -1922,12 +2194,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
101972 if (flags & MAP_FIXED)
101973 return addr;
101974
101975 +#ifdef CONFIG_PAX_RANDMMAP
101976 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
101977 +#endif
101978 +
101979 /* requesting a specific address */
101980 if (addr) {
101981 addr = PAGE_ALIGN(addr);
101982 vma = find_vma(mm, addr);
101983 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
101984 - (!vma || addr + len <= vma->vm_start))
101985 + check_heap_stack_gap(vma, addr, len, offset))
101986 return addr;
101987 }
101988
101989 @@ -1936,6 +2212,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
101990 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
101991 info.high_limit = mm->mmap_base;
101992 info.align_mask = 0;
101993 + info.threadstack_offset = offset;
101994 addr = vm_unmapped_area(&info);
101995
101996 /*
101997 @@ -1948,6 +2225,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
101998 VM_BUG_ON(addr != -ENOMEM);
101999 info.flags = 0;
102000 info.low_limit = TASK_UNMAPPED_BASE;
102001 +
102002 +#ifdef CONFIG_PAX_RANDMMAP
102003 + if (mm->pax_flags & MF_PAX_RANDMMAP)
102004 + info.low_limit += mm->delta_mmap;
102005 +#endif
102006 +
102007 info.high_limit = TASK_SIZE;
102008 addr = vm_unmapped_area(&info);
102009 }
102010 @@ -2048,6 +2331,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
102011 return vma;
102012 }
102013
102014 +#ifdef CONFIG_PAX_SEGMEXEC
102015 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
102016 +{
102017 + struct vm_area_struct *vma_m;
102018 +
102019 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
102020 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
102021 + BUG_ON(vma->vm_mirror);
102022 + return NULL;
102023 + }
102024 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
102025 + vma_m = vma->vm_mirror;
102026 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
102027 + BUG_ON(vma->vm_file != vma_m->vm_file);
102028 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
102029 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
102030 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
102031 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
102032 + return vma_m;
102033 +}
102034 +#endif
102035 +
102036 /*
102037 * Verify that the stack growth is acceptable and
102038 * update accounting. This is shared with both the
102039 @@ -2064,6 +2369,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
102040 return -ENOMEM;
102041
102042 /* Stack limit test */
102043 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
102044 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
102045 return -ENOMEM;
102046
102047 @@ -2074,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
102048 locked = mm->locked_vm + grow;
102049 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
102050 limit >>= PAGE_SHIFT;
102051 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
102052 if (locked > limit && !capable(CAP_IPC_LOCK))
102053 return -ENOMEM;
102054 }
102055 @@ -2103,37 +2410,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
102056 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
102057 * vma is the last one with address > vma->vm_end. Have to extend vma.
102058 */
102059 +#ifndef CONFIG_IA64
102060 +static
102061 +#endif
102062 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
102063 {
102064 int error;
102065 + bool locknext;
102066
102067 if (!(vma->vm_flags & VM_GROWSUP))
102068 return -EFAULT;
102069
102070 + /* Also guard against wrapping around to address 0. */
102071 + if (address < PAGE_ALIGN(address+1))
102072 + address = PAGE_ALIGN(address+1);
102073 + else
102074 + return -ENOMEM;
102075 +
102076 /*
102077 * We must make sure the anon_vma is allocated
102078 * so that the anon_vma locking is not a noop.
102079 */
102080 if (unlikely(anon_vma_prepare(vma)))
102081 return -ENOMEM;
102082 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
102083 + if (locknext && anon_vma_prepare(vma->vm_next))
102084 + return -ENOMEM;
102085 vma_lock_anon_vma(vma);
102086 + if (locknext)
102087 + vma_lock_anon_vma(vma->vm_next);
102088
102089 /*
102090 * vma->vm_start/vm_end cannot change under us because the caller
102091 * is required to hold the mmap_sem in read mode. We need the
102092 - * anon_vma lock to serialize against concurrent expand_stacks.
102093 - * Also guard against wrapping around to address 0.
102094 + * anon_vma locks to serialize against concurrent expand_stacks
102095 + * and expand_upwards.
102096 */
102097 - if (address < PAGE_ALIGN(address+4))
102098 - address = PAGE_ALIGN(address+4);
102099 - else {
102100 - vma_unlock_anon_vma(vma);
102101 - return -ENOMEM;
102102 - }
102103 error = 0;
102104
102105 /* Somebody else might have raced and expanded it already */
102106 - if (address > vma->vm_end) {
102107 + 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)
102108 + error = -ENOMEM;
102109 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
102110 unsigned long size, grow;
102111
102112 size = address - vma->vm_start;
102113 @@ -2168,6 +2486,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
102114 }
102115 }
102116 }
102117 + if (locknext)
102118 + vma_unlock_anon_vma(vma->vm_next);
102119 vma_unlock_anon_vma(vma);
102120 khugepaged_enter_vma_merge(vma);
102121 validate_mm(vma->vm_mm);
102122 @@ -2182,6 +2502,8 @@ int expand_downwards(struct vm_area_struct *vma,
102123 unsigned long address)
102124 {
102125 int error;
102126 + bool lockprev = false;
102127 + struct vm_area_struct *prev;
102128
102129 /*
102130 * We must make sure the anon_vma is allocated
102131 @@ -2195,6 +2517,15 @@ int expand_downwards(struct vm_area_struct *vma,
102132 if (error)
102133 return error;
102134
102135 + prev = vma->vm_prev;
102136 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
102137 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
102138 +#endif
102139 + if (lockprev && anon_vma_prepare(prev))
102140 + return -ENOMEM;
102141 + if (lockprev)
102142 + vma_lock_anon_vma(prev);
102143 +
102144 vma_lock_anon_vma(vma);
102145
102146 /*
102147 @@ -2204,9 +2535,17 @@ int expand_downwards(struct vm_area_struct *vma,
102148 */
102149
102150 /* Somebody else might have raced and expanded it already */
102151 - if (address < vma->vm_start) {
102152 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
102153 + error = -ENOMEM;
102154 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
102155 unsigned long size, grow;
102156
102157 +#ifdef CONFIG_PAX_SEGMEXEC
102158 + struct vm_area_struct *vma_m;
102159 +
102160 + vma_m = pax_find_mirror_vma(vma);
102161 +#endif
102162 +
102163 size = vma->vm_end - address;
102164 grow = (vma->vm_start - address) >> PAGE_SHIFT;
102165
102166 @@ -2231,13 +2570,27 @@ int expand_downwards(struct vm_area_struct *vma,
102167 vma->vm_pgoff -= grow;
102168 anon_vma_interval_tree_post_update_vma(vma);
102169 vma_gap_update(vma);
102170 +
102171 +#ifdef CONFIG_PAX_SEGMEXEC
102172 + if (vma_m) {
102173 + anon_vma_interval_tree_pre_update_vma(vma_m);
102174 + vma_m->vm_start -= grow << PAGE_SHIFT;
102175 + vma_m->vm_pgoff -= grow;
102176 + anon_vma_interval_tree_post_update_vma(vma_m);
102177 + vma_gap_update(vma_m);
102178 + }
102179 +#endif
102180 +
102181 spin_unlock(&vma->vm_mm->page_table_lock);
102182
102183 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
102184 perf_event_mmap(vma);
102185 }
102186 }
102187 }
102188 vma_unlock_anon_vma(vma);
102189 + if (lockprev)
102190 + vma_unlock_anon_vma(prev);
102191 khugepaged_enter_vma_merge(vma);
102192 validate_mm(vma->vm_mm);
102193 return error;
102194 @@ -2335,6 +2688,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
102195 do {
102196 long nrpages = vma_pages(vma);
102197
102198 +#ifdef CONFIG_PAX_SEGMEXEC
102199 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
102200 + vma = remove_vma(vma);
102201 + continue;
102202 + }
102203 +#endif
102204 +
102205 if (vma->vm_flags & VM_ACCOUNT)
102206 nr_accounted += nrpages;
102207 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
102208 @@ -2379,6 +2739,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
102209 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
102210 vma->vm_prev = NULL;
102211 do {
102212 +
102213 +#ifdef CONFIG_PAX_SEGMEXEC
102214 + if (vma->vm_mirror) {
102215 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
102216 + vma->vm_mirror->vm_mirror = NULL;
102217 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
102218 + vma->vm_mirror = NULL;
102219 + }
102220 +#endif
102221 +
102222 vma_rb_erase(vma, &mm->mm_rb);
102223 mm->map_count--;
102224 tail_vma = vma;
102225 @@ -2406,14 +2776,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
102226 struct vm_area_struct *new;
102227 int err = -ENOMEM;
102228
102229 +#ifdef CONFIG_PAX_SEGMEXEC
102230 + struct vm_area_struct *vma_m, *new_m = NULL;
102231 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
102232 +#endif
102233 +
102234 if (is_vm_hugetlb_page(vma) && (addr &
102235 ~(huge_page_mask(hstate_vma(vma)))))
102236 return -EINVAL;
102237
102238 +#ifdef CONFIG_PAX_SEGMEXEC
102239 + vma_m = pax_find_mirror_vma(vma);
102240 +#endif
102241 +
102242 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
102243 if (!new)
102244 goto out_err;
102245
102246 +#ifdef CONFIG_PAX_SEGMEXEC
102247 + if (vma_m) {
102248 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
102249 + if (!new_m) {
102250 + kmem_cache_free(vm_area_cachep, new);
102251 + goto out_err;
102252 + }
102253 + }
102254 +#endif
102255 +
102256 /* most fields are the same, copy all, and then fixup */
102257 *new = *vma;
102258
102259 @@ -2426,6 +2815,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
102260 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
102261 }
102262
102263 +#ifdef CONFIG_PAX_SEGMEXEC
102264 + if (vma_m) {
102265 + *new_m = *vma_m;
102266 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
102267 + new_m->vm_mirror = new;
102268 + new->vm_mirror = new_m;
102269 +
102270 + if (new_below)
102271 + new_m->vm_end = addr_m;
102272 + else {
102273 + new_m->vm_start = addr_m;
102274 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
102275 + }
102276 + }
102277 +#endif
102278 +
102279 err = vma_dup_policy(vma, new);
102280 if (err)
102281 goto out_free_vma;
102282 @@ -2445,6 +2850,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
102283 else
102284 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
102285
102286 +#ifdef CONFIG_PAX_SEGMEXEC
102287 + if (!err && vma_m) {
102288 + struct mempolicy *pol = vma_policy(new);
102289 +
102290 + if (anon_vma_clone(new_m, vma_m))
102291 + goto out_free_mpol;
102292 +
102293 + mpol_get(pol);
102294 + set_vma_policy(new_m, pol);
102295 +
102296 + if (new_m->vm_file)
102297 + get_file(new_m->vm_file);
102298 +
102299 + if (new_m->vm_ops && new_m->vm_ops->open)
102300 + new_m->vm_ops->open(new_m);
102301 +
102302 + if (new_below)
102303 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
102304 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
102305 + else
102306 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
102307 +
102308 + if (err) {
102309 + if (new_m->vm_ops && new_m->vm_ops->close)
102310 + new_m->vm_ops->close(new_m);
102311 + if (new_m->vm_file)
102312 + fput(new_m->vm_file);
102313 + mpol_put(pol);
102314 + }
102315 + }
102316 +#endif
102317 +
102318 /* Success. */
102319 if (!err)
102320 return 0;
102321 @@ -2454,10 +2891,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
102322 new->vm_ops->close(new);
102323 if (new->vm_file)
102324 fput(new->vm_file);
102325 - unlink_anon_vmas(new);
102326 out_free_mpol:
102327 mpol_put(vma_policy(new));
102328 out_free_vma:
102329 +
102330 +#ifdef CONFIG_PAX_SEGMEXEC
102331 + if (new_m) {
102332 + unlink_anon_vmas(new_m);
102333 + kmem_cache_free(vm_area_cachep, new_m);
102334 + }
102335 +#endif
102336 +
102337 + unlink_anon_vmas(new);
102338 kmem_cache_free(vm_area_cachep, new);
102339 out_err:
102340 return err;
102341 @@ -2470,6 +2915,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
102342 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
102343 unsigned long addr, int new_below)
102344 {
102345 +
102346 +#ifdef CONFIG_PAX_SEGMEXEC
102347 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
102348 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
102349 + if (mm->map_count >= sysctl_max_map_count-1)
102350 + return -ENOMEM;
102351 + } else
102352 +#endif
102353 +
102354 if (mm->map_count >= sysctl_max_map_count)
102355 return -ENOMEM;
102356
102357 @@ -2481,11 +2935,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
102358 * work. This now handles partial unmappings.
102359 * Jeremy Fitzhardinge <jeremy@goop.org>
102360 */
102361 +#ifdef CONFIG_PAX_SEGMEXEC
102362 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
102363 {
102364 + int ret = __do_munmap(mm, start, len);
102365 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
102366 + return ret;
102367 +
102368 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
102369 +}
102370 +
102371 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
102372 +#else
102373 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
102374 +#endif
102375 +{
102376 unsigned long end;
102377 struct vm_area_struct *vma, *prev, *last;
102378
102379 + /*
102380 + * mm->mmap_sem is required to protect against another thread
102381 + * changing the mappings in case we sleep.
102382 + */
102383 + verify_mm_writelocked(mm);
102384 +
102385 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
102386 return -EINVAL;
102387
102388 @@ -2560,6 +3033,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
102389 /* Fix up all other VM information */
102390 remove_vma_list(mm, vma);
102391
102392 + track_exec_limit(mm, start, end, 0UL);
102393 +
102394 return 0;
102395 }
102396
102397 @@ -2568,6 +3043,13 @@ int vm_munmap(unsigned long start, size_t len)
102398 int ret;
102399 struct mm_struct *mm = current->mm;
102400
102401 +
102402 +#ifdef CONFIG_PAX_SEGMEXEC
102403 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
102404 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
102405 + return -EINVAL;
102406 +#endif
102407 +
102408 down_write(&mm->mmap_sem);
102409 ret = do_munmap(mm, start, len);
102410 up_write(&mm->mmap_sem);
102411 @@ -2581,16 +3063,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
102412 return vm_munmap(addr, len);
102413 }
102414
102415 -static inline void verify_mm_writelocked(struct mm_struct *mm)
102416 -{
102417 -#ifdef CONFIG_DEBUG_VM
102418 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
102419 - WARN_ON(1);
102420 - up_read(&mm->mmap_sem);
102421 - }
102422 -#endif
102423 -}
102424 -
102425 /*
102426 * this is really a simplified "do_mmap". it only handles
102427 * anonymous maps. eventually we may be able to do some
102428 @@ -2604,6 +3076,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
102429 struct rb_node ** rb_link, * rb_parent;
102430 pgoff_t pgoff = addr >> PAGE_SHIFT;
102431 int error;
102432 + unsigned long charged;
102433
102434 len = PAGE_ALIGN(len);
102435 if (!len)
102436 @@ -2611,10 +3084,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
102437
102438 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
102439
102440 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
102441 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
102442 + flags &= ~VM_EXEC;
102443 +
102444 +#ifdef CONFIG_PAX_MPROTECT
102445 + if (mm->pax_flags & MF_PAX_MPROTECT)
102446 + flags &= ~VM_MAYEXEC;
102447 +#endif
102448 +
102449 + }
102450 +#endif
102451 +
102452 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
102453 if (error & ~PAGE_MASK)
102454 return error;
102455
102456 + charged = len >> PAGE_SHIFT;
102457 +
102458 error = mlock_future_check(mm, mm->def_flags, len);
102459 if (error)
102460 return error;
102461 @@ -2628,21 +3115,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
102462 /*
102463 * Clear old maps. this also does some error checking for us
102464 */
102465 - munmap_back:
102466 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
102467 if (do_munmap(mm, addr, len))
102468 return -ENOMEM;
102469 - goto munmap_back;
102470 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
102471 }
102472
102473 /* Check against address space limits *after* clearing old maps... */
102474 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
102475 + if (!may_expand_vm(mm, charged))
102476 return -ENOMEM;
102477
102478 if (mm->map_count > sysctl_max_map_count)
102479 return -ENOMEM;
102480
102481 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
102482 + if (security_vm_enough_memory_mm(mm, charged))
102483 return -ENOMEM;
102484
102485 /* Can we just expand an old private anonymous mapping? */
102486 @@ -2656,7 +3142,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
102487 */
102488 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
102489 if (!vma) {
102490 - vm_unacct_memory(len >> PAGE_SHIFT);
102491 + vm_unacct_memory(charged);
102492 return -ENOMEM;
102493 }
102494
102495 @@ -2670,10 +3156,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
102496 vma_link(mm, vma, prev, rb_link, rb_parent);
102497 out:
102498 perf_event_mmap(vma);
102499 - mm->total_vm += len >> PAGE_SHIFT;
102500 + mm->total_vm += charged;
102501 if (flags & VM_LOCKED)
102502 - mm->locked_vm += (len >> PAGE_SHIFT);
102503 + mm->locked_vm += charged;
102504 vma->vm_flags |= VM_SOFTDIRTY;
102505 + track_exec_limit(mm, addr, addr + len, flags);
102506 return addr;
102507 }
102508
102509 @@ -2735,6 +3222,7 @@ void exit_mmap(struct mm_struct *mm)
102510 while (vma) {
102511 if (vma->vm_flags & VM_ACCOUNT)
102512 nr_accounted += vma_pages(vma);
102513 + vma->vm_mirror = NULL;
102514 vma = remove_vma(vma);
102515 }
102516 vm_unacct_memory(nr_accounted);
102517 @@ -2752,6 +3240,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
102518 struct vm_area_struct *prev;
102519 struct rb_node **rb_link, *rb_parent;
102520
102521 +#ifdef CONFIG_PAX_SEGMEXEC
102522 + struct vm_area_struct *vma_m = NULL;
102523 +#endif
102524 +
102525 + if (security_mmap_addr(vma->vm_start))
102526 + return -EPERM;
102527 +
102528 /*
102529 * The vm_pgoff of a purely anonymous vma should be irrelevant
102530 * until its first write fault, when page's anon_vma and index
102531 @@ -2775,7 +3270,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
102532 security_vm_enough_memory_mm(mm, vma_pages(vma)))
102533 return -ENOMEM;
102534
102535 +#ifdef CONFIG_PAX_SEGMEXEC
102536 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
102537 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
102538 + if (!vma_m)
102539 + return -ENOMEM;
102540 + }
102541 +#endif
102542 +
102543 vma_link(mm, vma, prev, rb_link, rb_parent);
102544 +
102545 +#ifdef CONFIG_PAX_SEGMEXEC
102546 + if (vma_m)
102547 + BUG_ON(pax_mirror_vma(vma_m, vma));
102548 +#endif
102549 +
102550 return 0;
102551 }
102552
102553 @@ -2794,6 +3303,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
102554 struct rb_node **rb_link, *rb_parent;
102555 bool faulted_in_anon_vma = true;
102556
102557 + BUG_ON(vma->vm_mirror);
102558 +
102559 /*
102560 * If anonymous vma has not yet been faulted, update new pgoff
102561 * to match new location, to increase its chance of merging.
102562 @@ -2858,6 +3369,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
102563 return NULL;
102564 }
102565
102566 +#ifdef CONFIG_PAX_SEGMEXEC
102567 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
102568 +{
102569 + struct vm_area_struct *prev_m;
102570 + struct rb_node **rb_link_m, *rb_parent_m;
102571 + struct mempolicy *pol_m;
102572 +
102573 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
102574 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
102575 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
102576 + *vma_m = *vma;
102577 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
102578 + if (anon_vma_clone(vma_m, vma))
102579 + return -ENOMEM;
102580 + pol_m = vma_policy(vma_m);
102581 + mpol_get(pol_m);
102582 + set_vma_policy(vma_m, pol_m);
102583 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
102584 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
102585 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
102586 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
102587 + if (vma_m->vm_file)
102588 + get_file(vma_m->vm_file);
102589 + if (vma_m->vm_ops && vma_m->vm_ops->open)
102590 + vma_m->vm_ops->open(vma_m);
102591 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
102592 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
102593 + vma_m->vm_mirror = vma;
102594 + vma->vm_mirror = vma_m;
102595 + return 0;
102596 +}
102597 +#endif
102598 +
102599 /*
102600 * Return true if the calling process may expand its vm space by the passed
102601 * number of pages
102602 @@ -2869,6 +3413,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
102603
102604 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
102605
102606 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
102607 if (cur + npages > lim)
102608 return 0;
102609 return 1;
102610 @@ -2951,6 +3496,22 @@ static struct vm_area_struct *__install_special_mapping(
102611 vma->vm_start = addr;
102612 vma->vm_end = addr + len;
102613
102614 +#ifdef CONFIG_PAX_MPROTECT
102615 + if (mm->pax_flags & MF_PAX_MPROTECT) {
102616 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
102617 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
102618 + return ERR_PTR(-EPERM);
102619 + if (!(vm_flags & VM_EXEC))
102620 + vm_flags &= ~VM_MAYEXEC;
102621 +#else
102622 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
102623 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
102624 +#endif
102625 + else
102626 + vm_flags &= ~VM_MAYWRITE;
102627 + }
102628 +#endif
102629 +
102630 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
102631 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
102632
102633 diff --git a/mm/mprotect.c b/mm/mprotect.c
102634 index c43d557..0b7ccd2 100644
102635 --- a/mm/mprotect.c
102636 +++ b/mm/mprotect.c
102637 @@ -24,10 +24,18 @@
102638 #include <linux/migrate.h>
102639 #include <linux/perf_event.h>
102640 #include <linux/ksm.h>
102641 +#include <linux/sched/sysctl.h>
102642 +
102643 +#ifdef CONFIG_PAX_MPROTECT
102644 +#include <linux/elf.h>
102645 +#include <linux/binfmts.h>
102646 +#endif
102647 +
102648 #include <asm/uaccess.h>
102649 #include <asm/pgtable.h>
102650 #include <asm/cacheflush.h>
102651 #include <asm/tlbflush.h>
102652 +#include <asm/mmu_context.h>
102653
102654 #ifndef pgprot_modify
102655 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
102656 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
102657 return pages;
102658 }
102659
102660 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
102661 +/* called while holding the mmap semaphor for writing except stack expansion */
102662 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
102663 +{
102664 + unsigned long oldlimit, newlimit = 0UL;
102665 +
102666 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
102667 + return;
102668 +
102669 + spin_lock(&mm->page_table_lock);
102670 + oldlimit = mm->context.user_cs_limit;
102671 + if ((prot & VM_EXEC) && oldlimit < end)
102672 + /* USER_CS limit moved up */
102673 + newlimit = end;
102674 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
102675 + /* USER_CS limit moved down */
102676 + newlimit = start;
102677 +
102678 + if (newlimit) {
102679 + mm->context.user_cs_limit = newlimit;
102680 +
102681 +#ifdef CONFIG_SMP
102682 + wmb();
102683 + cpus_clear(mm->context.cpu_user_cs_mask);
102684 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
102685 +#endif
102686 +
102687 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
102688 + }
102689 + spin_unlock(&mm->page_table_lock);
102690 + if (newlimit == end) {
102691 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
102692 +
102693 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
102694 + if (is_vm_hugetlb_page(vma))
102695 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
102696 + else
102697 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
102698 + }
102699 +}
102700 +#endif
102701 +
102702 int
102703 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
102704 unsigned long start, unsigned long end, unsigned long newflags)
102705 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
102706 int error;
102707 int dirty_accountable = 0;
102708
102709 +#ifdef CONFIG_PAX_SEGMEXEC
102710 + struct vm_area_struct *vma_m = NULL;
102711 + unsigned long start_m, end_m;
102712 +
102713 + start_m = start + SEGMEXEC_TASK_SIZE;
102714 + end_m = end + SEGMEXEC_TASK_SIZE;
102715 +#endif
102716 +
102717 if (newflags == oldflags) {
102718 *pprev = vma;
102719 return 0;
102720 }
102721
102722 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
102723 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
102724 +
102725 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
102726 + return -ENOMEM;
102727 +
102728 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
102729 + return -ENOMEM;
102730 + }
102731 +
102732 /*
102733 * If we make a private mapping writable we increase our commit;
102734 * but (without finer accounting) cannot reduce our commit if we
102735 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
102736 }
102737 }
102738
102739 +#ifdef CONFIG_PAX_SEGMEXEC
102740 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
102741 + if (start != vma->vm_start) {
102742 + error = split_vma(mm, vma, start, 1);
102743 + if (error)
102744 + goto fail;
102745 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
102746 + *pprev = (*pprev)->vm_next;
102747 + }
102748 +
102749 + if (end != vma->vm_end) {
102750 + error = split_vma(mm, vma, end, 0);
102751 + if (error)
102752 + goto fail;
102753 + }
102754 +
102755 + if (pax_find_mirror_vma(vma)) {
102756 + error = __do_munmap(mm, start_m, end_m - start_m);
102757 + if (error)
102758 + goto fail;
102759 + } else {
102760 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
102761 + if (!vma_m) {
102762 + error = -ENOMEM;
102763 + goto fail;
102764 + }
102765 + vma->vm_flags = newflags;
102766 + error = pax_mirror_vma(vma_m, vma);
102767 + if (error) {
102768 + vma->vm_flags = oldflags;
102769 + goto fail;
102770 + }
102771 + }
102772 + }
102773 +#endif
102774 +
102775 /*
102776 * First try to merge with previous and/or next vma.
102777 */
102778 @@ -319,9 +423,21 @@ success:
102779 * vm_flags and vm_page_prot are protected by the mmap_sem
102780 * held in write mode.
102781 */
102782 +
102783 +#ifdef CONFIG_PAX_SEGMEXEC
102784 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
102785 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
102786 +#endif
102787 +
102788 vma->vm_flags = newflags;
102789 +
102790 +#ifdef CONFIG_PAX_MPROTECT
102791 + if (mm->binfmt && mm->binfmt->handle_mprotect)
102792 + mm->binfmt->handle_mprotect(vma, newflags);
102793 +#endif
102794 +
102795 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
102796 - vm_get_page_prot(newflags));
102797 + vm_get_page_prot(vma->vm_flags));
102798
102799 if (vma_wants_writenotify(vma)) {
102800 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
102801 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
102802 end = start + len;
102803 if (end <= start)
102804 return -ENOMEM;
102805 +
102806 +#ifdef CONFIG_PAX_SEGMEXEC
102807 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
102808 + if (end > SEGMEXEC_TASK_SIZE)
102809 + return -EINVAL;
102810 + } else
102811 +#endif
102812 +
102813 + if (end > TASK_SIZE)
102814 + return -EINVAL;
102815 +
102816 if (!arch_validate_prot(prot))
102817 return -EINVAL;
102818
102819 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
102820 /*
102821 * Does the application expect PROT_READ to imply PROT_EXEC:
102822 */
102823 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
102824 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
102825 prot |= PROT_EXEC;
102826
102827 vm_flags = calc_vm_prot_bits(prot);
102828 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
102829 if (start > vma->vm_start)
102830 prev = vma;
102831
102832 +#ifdef CONFIG_PAX_MPROTECT
102833 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
102834 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
102835 +#endif
102836 +
102837 for (nstart = start ; ; ) {
102838 unsigned long newflags;
102839
102840 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
102841
102842 /* newflags >> 4 shift VM_MAY% in place of VM_% */
102843 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
102844 + if (prot & (PROT_WRITE | PROT_EXEC))
102845 + gr_log_rwxmprotect(vma);
102846 +
102847 + error = -EACCES;
102848 + goto out;
102849 + }
102850 +
102851 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
102852 error = -EACCES;
102853 goto out;
102854 }
102855 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
102856 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
102857 if (error)
102858 goto out;
102859 +
102860 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
102861 +
102862 nstart = tmp;
102863
102864 if (nstart < prev->vm_end)
102865 diff --git a/mm/mremap.c b/mm/mremap.c
102866 index 05f1180..c3cde48 100644
102867 --- a/mm/mremap.c
102868 +++ b/mm/mremap.c
102869 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
102870 continue;
102871 pte = ptep_get_and_clear(mm, old_addr, old_pte);
102872 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
102873 +
102874 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
102875 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
102876 + pte = pte_exprotect(pte);
102877 +#endif
102878 +
102879 pte = move_soft_dirty_pte(pte);
102880 set_pte_at(mm, new_addr, new_pte, pte);
102881 }
102882 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
102883 if (is_vm_hugetlb_page(vma))
102884 goto Einval;
102885
102886 +#ifdef CONFIG_PAX_SEGMEXEC
102887 + if (pax_find_mirror_vma(vma))
102888 + goto Einval;
102889 +#endif
102890 +
102891 /* We can't remap across vm area boundaries */
102892 if (old_len > vma->vm_end - addr)
102893 goto Efault;
102894 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
102895 unsigned long ret = -EINVAL;
102896 unsigned long charged = 0;
102897 unsigned long map_flags;
102898 + unsigned long pax_task_size = TASK_SIZE;
102899
102900 if (new_addr & ~PAGE_MASK)
102901 goto out;
102902
102903 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
102904 +#ifdef CONFIG_PAX_SEGMEXEC
102905 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
102906 + pax_task_size = SEGMEXEC_TASK_SIZE;
102907 +#endif
102908 +
102909 + pax_task_size -= PAGE_SIZE;
102910 +
102911 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
102912 goto out;
102913
102914 /* Check if the location we're moving into overlaps the
102915 * old location at all, and fail if it does.
102916 */
102917 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
102918 - goto out;
102919 -
102920 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
102921 + if (addr + old_len > new_addr && new_addr + new_len > addr)
102922 goto out;
102923
102924 ret = do_munmap(mm, new_addr, new_len);
102925 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
102926 unsigned long ret = -EINVAL;
102927 unsigned long charged = 0;
102928 bool locked = false;
102929 + unsigned long pax_task_size = TASK_SIZE;
102930
102931 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
102932 return ret;
102933 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
102934 if (!new_len)
102935 return ret;
102936
102937 +#ifdef CONFIG_PAX_SEGMEXEC
102938 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
102939 + pax_task_size = SEGMEXEC_TASK_SIZE;
102940 +#endif
102941 +
102942 + pax_task_size -= PAGE_SIZE;
102943 +
102944 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
102945 + old_len > pax_task_size || addr > pax_task_size-old_len)
102946 + return ret;
102947 +
102948 down_write(&current->mm->mmap_sem);
102949
102950 if (flags & MREMAP_FIXED) {
102951 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
102952 new_addr = addr;
102953 }
102954 ret = addr;
102955 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
102956 goto out;
102957 }
102958 }
102959 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
102960 goto out;
102961 }
102962
102963 + map_flags = vma->vm_flags;
102964 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
102965 + if (!(ret & ~PAGE_MASK)) {
102966 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
102967 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
102968 + }
102969 }
102970 out:
102971 if (ret & ~PAGE_MASK)
102972 diff --git a/mm/nommu.c b/mm/nommu.c
102973 index 4a852f6..4371a6b 100644
102974 --- a/mm/nommu.c
102975 +++ b/mm/nommu.c
102976 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
102977 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
102978 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
102979 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
102980 -int heap_stack_gap = 0;
102981
102982 atomic_long_t mmap_pages_allocated;
102983
102984 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
102985 EXPORT_SYMBOL(find_vma);
102986
102987 /*
102988 - * find a VMA
102989 - * - we don't extend stack VMAs under NOMMU conditions
102990 - */
102991 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
102992 -{
102993 - return find_vma(mm, addr);
102994 -}
102995 -
102996 -/*
102997 * expand a stack to a given address
102998 * - not supported under NOMMU conditions
102999 */
103000 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
103001
103002 /* most fields are the same, copy all, and then fixup */
103003 *new = *vma;
103004 + INIT_LIST_HEAD(&new->anon_vma_chain);
103005 *region = *vma->vm_region;
103006 new->vm_region = region;
103007
103008 @@ -2007,8 +1998,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
103009 }
103010 EXPORT_SYMBOL(generic_file_remap_pages);
103011
103012 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
103013 - unsigned long addr, void *buf, int len, int write)
103014 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
103015 + unsigned long addr, void *buf, size_t len, int write)
103016 {
103017 struct vm_area_struct *vma;
103018
103019 @@ -2049,8 +2040,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
103020 *
103021 * The caller must hold a reference on @mm.
103022 */
103023 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
103024 - void *buf, int len, int write)
103025 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
103026 + void *buf, size_t len, int write)
103027 {
103028 return __access_remote_vm(NULL, mm, addr, buf, len, write);
103029 }
103030 @@ -2059,7 +2050,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
103031 * Access another process' address space.
103032 * - source/target buffer must be kernel space
103033 */
103034 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
103035 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
103036 {
103037 struct mm_struct *mm;
103038
103039 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
103040 index e0c9430..3c6bf79 100644
103041 --- a/mm/page-writeback.c
103042 +++ b/mm/page-writeback.c
103043 @@ -667,7 +667,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
103044 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
103045 * - the bdi dirty thresh drops quickly due to change of JBOD workload
103046 */
103047 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
103048 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
103049 unsigned long thresh,
103050 unsigned long bg_thresh,
103051 unsigned long dirty,
103052 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
103053 index ef44ad7..1056bc7 100644
103054 --- a/mm/page_alloc.c
103055 +++ b/mm/page_alloc.c
103056 @@ -61,6 +61,7 @@
103057 #include <linux/page-debug-flags.h>
103058 #include <linux/hugetlb.h>
103059 #include <linux/sched/rt.h>
103060 +#include <linux/random.h>
103061
103062 #include <asm/sections.h>
103063 #include <asm/tlbflush.h>
103064 @@ -357,7 +358,7 @@ out:
103065 * This usage means that zero-order pages may not be compound.
103066 */
103067
103068 -static void free_compound_page(struct page *page)
103069 +void free_compound_page(struct page *page)
103070 {
103071 __free_pages_ok(page, compound_order(page));
103072 }
103073 @@ -745,6 +746,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
103074 int i;
103075 int bad = 0;
103076
103077 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103078 + unsigned long index = 1UL << order;
103079 +#endif
103080 +
103081 trace_mm_page_free(page, order);
103082 kmemcheck_free_shadow(page, order);
103083
103084 @@ -761,6 +766,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
103085 debug_check_no_obj_freed(page_address(page),
103086 PAGE_SIZE << order);
103087 }
103088 +
103089 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103090 + for (; index; --index)
103091 + sanitize_highpage(page + index - 1);
103092 +#endif
103093 +
103094 arch_free_page(page, order);
103095 kernel_map_pages(page, 1 << order, 0);
103096
103097 @@ -784,6 +795,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
103098 local_irq_restore(flags);
103099 }
103100
103101 +#ifdef CONFIG_PAX_LATENT_ENTROPY
103102 +bool __meminitdata extra_latent_entropy;
103103 +
103104 +static int __init setup_pax_extra_latent_entropy(char *str)
103105 +{
103106 + extra_latent_entropy = true;
103107 + return 0;
103108 +}
103109 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
103110 +
103111 +volatile u64 latent_entropy __latent_entropy;
103112 +EXPORT_SYMBOL(latent_entropy);
103113 +#endif
103114 +
103115 void __init __free_pages_bootmem(struct page *page, unsigned int order)
103116 {
103117 unsigned int nr_pages = 1 << order;
103118 @@ -799,6 +824,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
103119 __ClearPageReserved(p);
103120 set_page_count(p, 0);
103121
103122 +#ifdef CONFIG_PAX_LATENT_ENTROPY
103123 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
103124 + u64 hash = 0;
103125 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
103126 + const u64 *data = lowmem_page_address(page);
103127 +
103128 + for (index = 0; index < end; index++)
103129 + hash ^= hash + data[index];
103130 + latent_entropy ^= hash;
103131 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
103132 + }
103133 +#endif
103134 +
103135 page_zone(page)->managed_pages += nr_pages;
103136 set_page_refcounted(page);
103137 __free_pages(page, order);
103138 @@ -927,8 +965,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
103139 arch_alloc_page(page, order);
103140 kernel_map_pages(page, 1 << order, 1);
103141
103142 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
103143 if (gfp_flags & __GFP_ZERO)
103144 prep_zero_page(page, order, gfp_flags);
103145 +#endif
103146
103147 if (order && (gfp_flags & __GFP_COMP))
103148 prep_compound_page(page, order);
103149 @@ -2427,7 +2467,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
103150 continue;
103151 mod_zone_page_state(zone, NR_ALLOC_BATCH,
103152 high_wmark_pages(zone) - low_wmark_pages(zone) -
103153 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
103154 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
103155 }
103156 }
103157
103158 diff --git a/mm/percpu.c b/mm/percpu.c
103159 index 2ddf9a9..f8fc075 100644
103160 --- a/mm/percpu.c
103161 +++ b/mm/percpu.c
103162 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
103163 static unsigned int pcpu_high_unit_cpu __read_mostly;
103164
103165 /* the address of the first chunk which starts with the kernel static area */
103166 -void *pcpu_base_addr __read_mostly;
103167 +void *pcpu_base_addr __read_only;
103168 EXPORT_SYMBOL_GPL(pcpu_base_addr);
103169
103170 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
103171 diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
103172 index a8b9199..dfb79e0 100644
103173 --- a/mm/pgtable-generic.c
103174 +++ b/mm/pgtable-generic.c
103175 @@ -195,7 +195,7 @@ void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
103176 pmd_t entry = *pmdp;
103177 if (pmd_numa(entry))
103178 entry = pmd_mknonnuma(entry);
103179 - set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(*pmdp));
103180 + set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
103181 flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
103182 }
103183 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
103184 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
103185 index 5077afc..846c9ef 100644
103186 --- a/mm/process_vm_access.c
103187 +++ b/mm/process_vm_access.c
103188 @@ -13,6 +13,7 @@
103189 #include <linux/uio.h>
103190 #include <linux/sched.h>
103191 #include <linux/highmem.h>
103192 +#include <linux/security.h>
103193 #include <linux/ptrace.h>
103194 #include <linux/slab.h>
103195 #include <linux/syscalls.h>
103196 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
103197 ssize_t iov_len;
103198 size_t total_len = iov_iter_count(iter);
103199
103200 + return -ENOSYS; // PaX: until properly audited
103201 +
103202 /*
103203 * Work out how many pages of struct pages we're going to need
103204 * when eventually calling get_user_pages
103205 */
103206 for (i = 0; i < riovcnt; i++) {
103207 iov_len = rvec[i].iov_len;
103208 - if (iov_len > 0) {
103209 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
103210 - + iov_len)
103211 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
103212 - / PAGE_SIZE + 1;
103213 - nr_pages = max(nr_pages, nr_pages_iov);
103214 - }
103215 + if (iov_len <= 0)
103216 + continue;
103217 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
103218 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
103219 + nr_pages = max(nr_pages, nr_pages_iov);
103220 }
103221
103222 if (nr_pages == 0)
103223 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
103224 goto free_proc_pages;
103225 }
103226
103227 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
103228 + rc = -EPERM;
103229 + goto put_task_struct;
103230 + }
103231 +
103232 mm = mm_access(task, PTRACE_MODE_ATTACH);
103233 if (!mm || IS_ERR(mm)) {
103234 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
103235 diff --git a/mm/rmap.c b/mm/rmap.c
103236 index 22a4a76..9551288 100644
103237 --- a/mm/rmap.c
103238 +++ b/mm/rmap.c
103239 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
103240 struct anon_vma *anon_vma = vma->anon_vma;
103241 struct anon_vma_chain *avc;
103242
103243 +#ifdef CONFIG_PAX_SEGMEXEC
103244 + struct anon_vma_chain *avc_m = NULL;
103245 +#endif
103246 +
103247 might_sleep();
103248 if (unlikely(!anon_vma)) {
103249 struct mm_struct *mm = vma->vm_mm;
103250 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
103251 if (!avc)
103252 goto out_enomem;
103253
103254 +#ifdef CONFIG_PAX_SEGMEXEC
103255 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
103256 + if (!avc_m)
103257 + goto out_enomem_free_avc;
103258 +#endif
103259 +
103260 anon_vma = find_mergeable_anon_vma(vma);
103261 allocated = NULL;
103262 if (!anon_vma) {
103263 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
103264 /* page_table_lock to protect against threads */
103265 spin_lock(&mm->page_table_lock);
103266 if (likely(!vma->anon_vma)) {
103267 +
103268 +#ifdef CONFIG_PAX_SEGMEXEC
103269 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
103270 +
103271 + if (vma_m) {
103272 + BUG_ON(vma_m->anon_vma);
103273 + vma_m->anon_vma = anon_vma;
103274 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
103275 + avc_m = NULL;
103276 + }
103277 +#endif
103278 +
103279 vma->anon_vma = anon_vma;
103280 anon_vma_chain_link(vma, avc, anon_vma);
103281 allocated = NULL;
103282 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
103283
103284 if (unlikely(allocated))
103285 put_anon_vma(allocated);
103286 +
103287 +#ifdef CONFIG_PAX_SEGMEXEC
103288 + if (unlikely(avc_m))
103289 + anon_vma_chain_free(avc_m);
103290 +#endif
103291 +
103292 if (unlikely(avc))
103293 anon_vma_chain_free(avc);
103294 }
103295 return 0;
103296
103297 out_enomem_free_avc:
103298 +
103299 +#ifdef CONFIG_PAX_SEGMEXEC
103300 + if (avc_m)
103301 + anon_vma_chain_free(avc_m);
103302 +#endif
103303 +
103304 anon_vma_chain_free(avc);
103305 out_enomem:
103306 return -ENOMEM;
103307 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
103308 * Attach the anon_vmas from src to dst.
103309 * Returns 0 on success, -ENOMEM on failure.
103310 */
103311 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
103312 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
103313 {
103314 struct anon_vma_chain *avc, *pavc;
103315 struct anon_vma *root = NULL;
103316 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
103317 * the corresponding VMA in the parent process is attached to.
103318 * Returns 0 on success, non-zero on failure.
103319 */
103320 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
103321 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
103322 {
103323 struct anon_vma_chain *avc;
103324 struct anon_vma *anon_vma;
103325 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
103326 void __init anon_vma_init(void)
103327 {
103328 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
103329 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
103330 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
103331 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
103332 + anon_vma_ctor);
103333 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
103334 + SLAB_PANIC|SLAB_NO_SANITIZE);
103335 }
103336
103337 /*
103338 diff --git a/mm/shmem.c b/mm/shmem.c
103339 index af68b15..1227320 100644
103340 --- a/mm/shmem.c
103341 +++ b/mm/shmem.c
103342 @@ -33,7 +33,7 @@
103343 #include <linux/swap.h>
103344 #include <linux/aio.h>
103345
103346 -static struct vfsmount *shm_mnt;
103347 +struct vfsmount *shm_mnt;
103348
103349 #ifdef CONFIG_SHMEM
103350 /*
103351 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
103352 #define BOGO_DIRENT_SIZE 20
103353
103354 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
103355 -#define SHORT_SYMLINK_LEN 128
103356 +#define SHORT_SYMLINK_LEN 64
103357
103358 /*
103359 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
103360 @@ -2219,6 +2219,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
103361 static int shmem_xattr_validate(const char *name)
103362 {
103363 struct { const char *prefix; size_t len; } arr[] = {
103364 +
103365 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
103366 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
103367 +#endif
103368 +
103369 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
103370 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
103371 };
103372 @@ -2274,6 +2279,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
103373 if (err)
103374 return err;
103375
103376 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
103377 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
103378 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
103379 + return -EOPNOTSUPP;
103380 + if (size > 8)
103381 + return -EINVAL;
103382 + }
103383 +#endif
103384 +
103385 return simple_xattr_set(&info->xattrs, name, value, size, flags);
103386 }
103387
103388 @@ -2586,8 +2600,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
103389 int err = -ENOMEM;
103390
103391 /* Round up to L1_CACHE_BYTES to resist false sharing */
103392 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
103393 - L1_CACHE_BYTES), GFP_KERNEL);
103394 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
103395 if (!sbinfo)
103396 return -ENOMEM;
103397
103398 diff --git a/mm/slab.c b/mm/slab.c
103399 index 3070b92..bcfff83 100644
103400 --- a/mm/slab.c
103401 +++ b/mm/slab.c
103402 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
103403 if ((x)->max_freeable < i) \
103404 (x)->max_freeable = i; \
103405 } while (0)
103406 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
103407 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
103408 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
103409 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
103410 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
103411 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
103412 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
103413 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
103414 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
103415 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
103416 #else
103417 #define STATS_INC_ACTIVE(x) do { } while (0)
103418 #define STATS_DEC_ACTIVE(x) do { } while (0)
103419 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
103420 #define STATS_INC_ALLOCMISS(x) do { } while (0)
103421 #define STATS_INC_FREEHIT(x) do { } while (0)
103422 #define STATS_INC_FREEMISS(x) do { } while (0)
103423 +#define STATS_INC_SANITIZED(x) do { } while (0)
103424 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
103425 #endif
103426
103427 #if DEBUG
103428 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
103429 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
103430 */
103431 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
103432 - const struct page *page, void *obj)
103433 + const struct page *page, const void *obj)
103434 {
103435 u32 offset = (obj - page->s_mem);
103436 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
103437 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
103438 */
103439
103440 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
103441 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
103442 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
103443
103444 if (INDEX_AC != INDEX_NODE)
103445 kmalloc_caches[INDEX_NODE] =
103446 create_kmalloc_cache("kmalloc-node",
103447 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
103448 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
103449
103450 slab_early_init = 0;
103451
103452 @@ -3512,6 +3516,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
103453 struct array_cache *ac = cpu_cache_get(cachep);
103454
103455 check_irq_off();
103456 +
103457 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103458 + if (pax_sanitize_slab) {
103459 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
103460 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
103461 +
103462 + if (cachep->ctor)
103463 + cachep->ctor(objp);
103464 +
103465 + STATS_INC_SANITIZED(cachep);
103466 + } else
103467 + STATS_INC_NOT_SANITIZED(cachep);
103468 + }
103469 +#endif
103470 +
103471 kmemleak_free_recursive(objp, cachep->flags);
103472 objp = cache_free_debugcheck(cachep, objp, caller);
103473
103474 @@ -3735,6 +3754,7 @@ void kfree(const void *objp)
103475
103476 if (unlikely(ZERO_OR_NULL_PTR(objp)))
103477 return;
103478 + VM_BUG_ON(!virt_addr_valid(objp));
103479 local_irq_save(flags);
103480 kfree_debugcheck(objp);
103481 c = virt_to_cache(objp);
103482 @@ -4176,14 +4196,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
103483 }
103484 /* cpu stats */
103485 {
103486 - unsigned long allochit = atomic_read(&cachep->allochit);
103487 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
103488 - unsigned long freehit = atomic_read(&cachep->freehit);
103489 - unsigned long freemiss = atomic_read(&cachep->freemiss);
103490 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
103491 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
103492 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
103493 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
103494
103495 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
103496 allochit, allocmiss, freehit, freemiss);
103497 }
103498 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103499 + {
103500 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
103501 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
103502 +
103503 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
103504 + }
103505 +#endif
103506 #endif
103507 }
103508
103509 @@ -4404,13 +4432,69 @@ static const struct file_operations proc_slabstats_operations = {
103510 static int __init slab_proc_init(void)
103511 {
103512 #ifdef CONFIG_DEBUG_SLAB_LEAK
103513 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
103514 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
103515 #endif
103516 return 0;
103517 }
103518 module_init(slab_proc_init);
103519 #endif
103520
103521 +bool is_usercopy_object(const void *ptr)
103522 +{
103523 + struct page *page;
103524 + struct kmem_cache *cachep;
103525 +
103526 + if (ZERO_OR_NULL_PTR(ptr))
103527 + return false;
103528 +
103529 + if (!slab_is_available())
103530 + return false;
103531 +
103532 + if (!virt_addr_valid(ptr))
103533 + return false;
103534 +
103535 + page = virt_to_head_page(ptr);
103536 +
103537 + if (!PageSlab(page))
103538 + return false;
103539 +
103540 + cachep = page->slab_cache;
103541 + return cachep->flags & SLAB_USERCOPY;
103542 +}
103543 +
103544 +#ifdef CONFIG_PAX_USERCOPY
103545 +const char *check_heap_object(const void *ptr, unsigned long n)
103546 +{
103547 + struct page *page;
103548 + struct kmem_cache *cachep;
103549 + unsigned int objnr;
103550 + unsigned long offset;
103551 +
103552 + if (ZERO_OR_NULL_PTR(ptr))
103553 + return "<null>";
103554 +
103555 + if (!virt_addr_valid(ptr))
103556 + return NULL;
103557 +
103558 + page = virt_to_head_page(ptr);
103559 +
103560 + if (!PageSlab(page))
103561 + return NULL;
103562 +
103563 + cachep = page->slab_cache;
103564 + if (!(cachep->flags & SLAB_USERCOPY))
103565 + return cachep->name;
103566 +
103567 + objnr = obj_to_index(cachep, page, ptr);
103568 + BUG_ON(objnr >= cachep->num);
103569 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
103570 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
103571 + return NULL;
103572 +
103573 + return cachep->name;
103574 +}
103575 +#endif
103576 +
103577 /**
103578 * ksize - get the actual amount of memory allocated for a given object
103579 * @objp: Pointer to the object
103580 diff --git a/mm/slab.h b/mm/slab.h
103581 index 961a3fb..6b12514 100644
103582 --- a/mm/slab.h
103583 +++ b/mm/slab.h
103584 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
103585 /* The slab cache that manages slab cache information */
103586 extern struct kmem_cache *kmem_cache;
103587
103588 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103589 +#ifdef CONFIG_X86_64
103590 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
103591 +#else
103592 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
103593 +#endif
103594 +extern bool pax_sanitize_slab;
103595 +#endif
103596 +
103597 unsigned long calculate_alignment(unsigned long flags,
103598 unsigned long align, unsigned long size);
103599
103600 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
103601
103602 /* Legal flag mask for kmem_cache_create(), for various configurations */
103603 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
103604 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
103605 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
103606 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
103607
103608 #if defined(CONFIG_DEBUG_SLAB)
103609 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
103610 @@ -251,6 +261,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
103611 return s;
103612
103613 page = virt_to_head_page(x);
103614 +
103615 + BUG_ON(!PageSlab(page));
103616 +
103617 cachep = page->slab_cache;
103618 if (slab_equal_or_root(cachep, s))
103619 return cachep;
103620 diff --git a/mm/slab_common.c b/mm/slab_common.c
103621 index d31c4ba..1121296 100644
103622 --- a/mm/slab_common.c
103623 +++ b/mm/slab_common.c
103624 @@ -23,11 +23,22 @@
103625
103626 #include "slab.h"
103627
103628 -enum slab_state slab_state;
103629 +enum slab_state slab_state __read_only;
103630 LIST_HEAD(slab_caches);
103631 DEFINE_MUTEX(slab_mutex);
103632 struct kmem_cache *kmem_cache;
103633
103634 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103635 +bool pax_sanitize_slab __read_only = true;
103636 +static int __init pax_sanitize_slab_setup(char *str)
103637 +{
103638 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
103639 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
103640 + return 1;
103641 +}
103642 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
103643 +#endif
103644 +
103645 #ifdef CONFIG_DEBUG_VM
103646 static int kmem_cache_sanity_check(const char *name, size_t size)
103647 {
103648 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
103649 if (err)
103650 goto out_free_cache;
103651
103652 - s->refcount = 1;
103653 + atomic_set(&s->refcount, 1);
103654 list_add(&s->list, &slab_caches);
103655 out:
103656 if (err)
103657 @@ -339,8 +350,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
103658
103659 mutex_lock(&slab_mutex);
103660
103661 - s->refcount--;
103662 - if (s->refcount)
103663 + if (!atomic_dec_and_test(&s->refcount))
103664 goto out_unlock;
103665
103666 if (memcg_cleanup_cache_params(s) != 0)
103667 @@ -360,7 +370,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
103668 rcu_barrier();
103669
103670 memcg_free_cache_params(s);
103671 -#ifdef SLAB_SUPPORTS_SYSFS
103672 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
103673 sysfs_slab_remove(s);
103674 #else
103675 slab_kmem_cache_release(s);
103676 @@ -416,7 +426,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
103677 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
103678 name, size, err);
103679
103680 - s->refcount = -1; /* Exempt from merging for now */
103681 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
103682 }
103683
103684 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
103685 @@ -429,7 +439,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
103686
103687 create_boot_cache(s, name, size, flags);
103688 list_add(&s->list, &slab_caches);
103689 - s->refcount = 1;
103690 + atomic_set(&s->refcount, 1);
103691 return s;
103692 }
103693
103694 @@ -441,6 +451,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
103695 EXPORT_SYMBOL(kmalloc_dma_caches);
103696 #endif
103697
103698 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103699 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
103700 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
103701 +#endif
103702 +
103703 /*
103704 * Conversion table for small slabs sizes / 8 to the index in the
103705 * kmalloc array. This is necessary for slabs < 192 since we have non power
103706 @@ -505,6 +520,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
103707 return kmalloc_dma_caches[index];
103708
103709 #endif
103710 +
103711 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103712 + if (unlikely((flags & GFP_USERCOPY)))
103713 + return kmalloc_usercopy_caches[index];
103714 +
103715 +#endif
103716 +
103717 return kmalloc_caches[index];
103718 }
103719
103720 @@ -561,7 +583,7 @@ void __init create_kmalloc_caches(unsigned long flags)
103721 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
103722 if (!kmalloc_caches[i]) {
103723 kmalloc_caches[i] = create_kmalloc_cache(NULL,
103724 - 1 << i, flags);
103725 + 1 << i, SLAB_USERCOPY | flags);
103726 }
103727
103728 /*
103729 @@ -570,10 +592,10 @@ void __init create_kmalloc_caches(unsigned long flags)
103730 * earlier power of two caches
103731 */
103732 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
103733 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
103734 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
103735
103736 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
103737 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
103738 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
103739 }
103740
103741 /* Kmalloc array is now usable */
103742 @@ -606,6 +628,23 @@ void __init create_kmalloc_caches(unsigned long flags)
103743 }
103744 }
103745 #endif
103746 +
103747 +#ifdef CONFIG_PAX_USERCOPY_SLABS
103748 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
103749 + struct kmem_cache *s = kmalloc_caches[i];
103750 +
103751 + if (s) {
103752 + int size = kmalloc_size(i);
103753 + char *n = kasprintf(GFP_NOWAIT,
103754 + "usercopy-kmalloc-%d", size);
103755 +
103756 + BUG_ON(!n);
103757 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
103758 + size, SLAB_USERCOPY | flags);
103759 + }
103760 + }
103761 +#endif
103762 +
103763 }
103764 #endif /* !CONFIG_SLOB */
103765
103766 @@ -664,6 +703,9 @@ void print_slabinfo_header(struct seq_file *m)
103767 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
103768 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
103769 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
103770 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103771 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
103772 +#endif
103773 #endif
103774 seq_putc(m, '\n');
103775 }
103776 diff --git a/mm/slob.c b/mm/slob.c
103777 index 21980e0..ed9a648 100644
103778 --- a/mm/slob.c
103779 +++ b/mm/slob.c
103780 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
103781 /*
103782 * Return the size of a slob block.
103783 */
103784 -static slobidx_t slob_units(slob_t *s)
103785 +static slobidx_t slob_units(const slob_t *s)
103786 {
103787 if (s->units > 0)
103788 return s->units;
103789 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
103790 /*
103791 * Return the next free slob block pointer after this one.
103792 */
103793 -static slob_t *slob_next(slob_t *s)
103794 +static slob_t *slob_next(const slob_t *s)
103795 {
103796 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
103797 slobidx_t next;
103798 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
103799 /*
103800 * Returns true if s is the last free block in its page.
103801 */
103802 -static int slob_last(slob_t *s)
103803 +static int slob_last(const slob_t *s)
103804 {
103805 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
103806 }
103807
103808 -static void *slob_new_pages(gfp_t gfp, int order, int node)
103809 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
103810 {
103811 - void *page;
103812 + struct page *page;
103813
103814 #ifdef CONFIG_NUMA
103815 if (node != NUMA_NO_NODE)
103816 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
103817 if (!page)
103818 return NULL;
103819
103820 - return page_address(page);
103821 + __SetPageSlab(page);
103822 + return page;
103823 }
103824
103825 -static void slob_free_pages(void *b, int order)
103826 +static void slob_free_pages(struct page *sp, int order)
103827 {
103828 if (current->reclaim_state)
103829 current->reclaim_state->reclaimed_slab += 1 << order;
103830 - free_pages((unsigned long)b, order);
103831 + __ClearPageSlab(sp);
103832 + page_mapcount_reset(sp);
103833 + sp->private = 0;
103834 + __free_pages(sp, order);
103835 }
103836
103837 /*
103838 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
103839
103840 /* Not enough space: must allocate a new page */
103841 if (!b) {
103842 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
103843 - if (!b)
103844 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
103845 + if (!sp)
103846 return NULL;
103847 - sp = virt_to_page(b);
103848 - __SetPageSlab(sp);
103849 + b = page_address(sp);
103850
103851 spin_lock_irqsave(&slob_lock, flags);
103852 sp->units = SLOB_UNITS(PAGE_SIZE);
103853 sp->freelist = b;
103854 + sp->private = 0;
103855 INIT_LIST_HEAD(&sp->lru);
103856 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
103857 set_slob_page_free(sp, slob_list);
103858 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
103859 if (slob_page_free(sp))
103860 clear_slob_page_free(sp);
103861 spin_unlock_irqrestore(&slob_lock, flags);
103862 - __ClearPageSlab(sp);
103863 - page_mapcount_reset(sp);
103864 - slob_free_pages(b, 0);
103865 + slob_free_pages(sp, 0);
103866 return;
103867 }
103868
103869 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
103870 + if (pax_sanitize_slab)
103871 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
103872 +#endif
103873 +
103874 if (!slob_page_free(sp)) {
103875 /* This slob page is about to become partially free. Easy! */
103876 sp->units = units;
103877 @@ -424,11 +431,10 @@ out:
103878 */
103879
103880 static __always_inline void *
103881 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
103882 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
103883 {
103884 - unsigned int *m;
103885 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
103886 - void *ret;
103887 + slob_t *m;
103888 + void *ret = NULL;
103889
103890 gfp &= gfp_allowed_mask;
103891
103892 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
103893
103894 if (!m)
103895 return NULL;
103896 - *m = size;
103897 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
103898 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
103899 + m[0].units = size;
103900 + m[1].units = align;
103901 ret = (void *)m + align;
103902
103903 trace_kmalloc_node(caller, ret,
103904 size, size + align, gfp, node);
103905 } else {
103906 unsigned int order = get_order(size);
103907 + struct page *page;
103908
103909 if (likely(order))
103910 gfp |= __GFP_COMP;
103911 - ret = slob_new_pages(gfp, order, node);
103912 + page = slob_new_pages(gfp, order, node);
103913 + if (page) {
103914 + ret = page_address(page);
103915 + page->private = size;
103916 + }
103917
103918 trace_kmalloc_node(caller, ret,
103919 size, PAGE_SIZE << order, gfp, node);
103920 }
103921
103922 - kmemleak_alloc(ret, size, 1, gfp);
103923 + return ret;
103924 +}
103925 +
103926 +static __always_inline void *
103927 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
103928 +{
103929 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
103930 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
103931 +
103932 + if (!ZERO_OR_NULL_PTR(ret))
103933 + kmemleak_alloc(ret, size, 1, gfp);
103934 return ret;
103935 }
103936
103937 @@ -493,34 +517,112 @@ void kfree(const void *block)
103938 return;
103939 kmemleak_free(block);
103940
103941 + VM_BUG_ON(!virt_addr_valid(block));
103942 sp = virt_to_page(block);
103943 - if (PageSlab(sp)) {
103944 + VM_BUG_ON(!PageSlab(sp));
103945 + if (!sp->private) {
103946 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
103947 - unsigned int *m = (unsigned int *)(block - align);
103948 - slob_free(m, *m + align);
103949 - } else
103950 + slob_t *m = (slob_t *)(block - align);
103951 + slob_free(m, m[0].units + align);
103952 + } else {
103953 + __ClearPageSlab(sp);
103954 + page_mapcount_reset(sp);
103955 + sp->private = 0;
103956 __free_pages(sp, compound_order(sp));
103957 + }
103958 }
103959 EXPORT_SYMBOL(kfree);
103960
103961 +bool is_usercopy_object(const void *ptr)
103962 +{
103963 + if (!slab_is_available())
103964 + return false;
103965 +
103966 + // PAX: TODO
103967 +
103968 + return false;
103969 +}
103970 +
103971 +#ifdef CONFIG_PAX_USERCOPY
103972 +const char *check_heap_object(const void *ptr, unsigned long n)
103973 +{
103974 + struct page *page;
103975 + const slob_t *free;
103976 + const void *base;
103977 + unsigned long flags;
103978 +
103979 + if (ZERO_OR_NULL_PTR(ptr))
103980 + return "<null>";
103981 +
103982 + if (!virt_addr_valid(ptr))
103983 + return NULL;
103984 +
103985 + page = virt_to_head_page(ptr);
103986 + if (!PageSlab(page))
103987 + return NULL;
103988 +
103989 + if (page->private) {
103990 + base = page;
103991 + if (base <= ptr && n <= page->private - (ptr - base))
103992 + return NULL;
103993 + return "<slob>";
103994 + }
103995 +
103996 + /* some tricky double walking to find the chunk */
103997 + spin_lock_irqsave(&slob_lock, flags);
103998 + base = (void *)((unsigned long)ptr & PAGE_MASK);
103999 + free = page->freelist;
104000 +
104001 + while (!slob_last(free) && (void *)free <= ptr) {
104002 + base = free + slob_units(free);
104003 + free = slob_next(free);
104004 + }
104005 +
104006 + while (base < (void *)free) {
104007 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
104008 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
104009 + int offset;
104010 +
104011 + if (ptr < base + align)
104012 + break;
104013 +
104014 + offset = ptr - base - align;
104015 + if (offset >= m) {
104016 + base += size;
104017 + continue;
104018 + }
104019 +
104020 + if (n > m - offset)
104021 + break;
104022 +
104023 + spin_unlock_irqrestore(&slob_lock, flags);
104024 + return NULL;
104025 + }
104026 +
104027 + spin_unlock_irqrestore(&slob_lock, flags);
104028 + return "<slob>";
104029 +}
104030 +#endif
104031 +
104032 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
104033 size_t ksize(const void *block)
104034 {
104035 struct page *sp;
104036 int align;
104037 - unsigned int *m;
104038 + slob_t *m;
104039
104040 BUG_ON(!block);
104041 if (unlikely(block == ZERO_SIZE_PTR))
104042 return 0;
104043
104044 sp = virt_to_page(block);
104045 - if (unlikely(!PageSlab(sp)))
104046 - return PAGE_SIZE << compound_order(sp);
104047 + VM_BUG_ON(!PageSlab(sp));
104048 + if (sp->private)
104049 + return sp->private;
104050
104051 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
104052 - m = (unsigned int *)(block - align);
104053 - return SLOB_UNITS(*m) * SLOB_UNIT;
104054 + m = (slob_t *)(block - align);
104055 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
104056 }
104057 EXPORT_SYMBOL(ksize);
104058
104059 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
104060
104061 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
104062 {
104063 - void *b;
104064 + void *b = NULL;
104065
104066 flags &= gfp_allowed_mask;
104067
104068 lockdep_trace_alloc(flags);
104069
104070 +#ifdef CONFIG_PAX_USERCOPY_SLABS
104071 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
104072 +#else
104073 if (c->size < PAGE_SIZE) {
104074 b = slob_alloc(c->size, flags, c->align, node);
104075 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
104076 SLOB_UNITS(c->size) * SLOB_UNIT,
104077 flags, node);
104078 } else {
104079 - b = slob_new_pages(flags, get_order(c->size), node);
104080 + struct page *sp;
104081 +
104082 + sp = slob_new_pages(flags, get_order(c->size), node);
104083 + if (sp) {
104084 + b = page_address(sp);
104085 + sp->private = c->size;
104086 + }
104087 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
104088 PAGE_SIZE << get_order(c->size),
104089 flags, node);
104090 }
104091 +#endif
104092
104093 if (b && c->ctor)
104094 c->ctor(b);
104095 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
104096
104097 static void __kmem_cache_free(void *b, int size)
104098 {
104099 - if (size < PAGE_SIZE)
104100 + struct page *sp;
104101 +
104102 + sp = virt_to_page(b);
104103 + BUG_ON(!PageSlab(sp));
104104 + if (!sp->private)
104105 slob_free(b, size);
104106 else
104107 - slob_free_pages(b, get_order(size));
104108 + slob_free_pages(sp, get_order(size));
104109 }
104110
104111 static void kmem_rcu_free(struct rcu_head *head)
104112 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
104113
104114 void kmem_cache_free(struct kmem_cache *c, void *b)
104115 {
104116 + int size = c->size;
104117 +
104118 +#ifdef CONFIG_PAX_USERCOPY_SLABS
104119 + if (size + c->align < PAGE_SIZE) {
104120 + size += c->align;
104121 + b -= c->align;
104122 + }
104123 +#endif
104124 +
104125 kmemleak_free_recursive(b, c->flags);
104126 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
104127 struct slob_rcu *slob_rcu;
104128 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
104129 - slob_rcu->size = c->size;
104130 + slob_rcu = b + (size - sizeof(struct slob_rcu));
104131 + slob_rcu->size = size;
104132 call_rcu(&slob_rcu->head, kmem_rcu_free);
104133 } else {
104134 - __kmem_cache_free(b, c->size);
104135 + __kmem_cache_free(b, size);
104136 }
104137
104138 +#ifdef CONFIG_PAX_USERCOPY_SLABS
104139 + trace_kfree(_RET_IP_, b);
104140 +#else
104141 trace_kmem_cache_free(_RET_IP_, b);
104142 +#endif
104143 +
104144 }
104145 EXPORT_SYMBOL(kmem_cache_free);
104146
104147 diff --git a/mm/slub.c b/mm/slub.c
104148 index 7300480..cb92846 100644
104149 --- a/mm/slub.c
104150 +++ b/mm/slub.c
104151 @@ -207,7 +207,7 @@ struct track {
104152
104153 enum track_item { TRACK_ALLOC, TRACK_FREE };
104154
104155 -#ifdef CONFIG_SYSFS
104156 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
104157 static int sysfs_slab_add(struct kmem_cache *);
104158 static int sysfs_slab_alias(struct kmem_cache *, const char *);
104159 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
104160 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
104161 if (!t->addr)
104162 return;
104163
104164 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
104165 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
104166 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
104167 #ifdef CONFIG_STACKTRACE
104168 {
104169 @@ -2673,6 +2673,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
104170
104171 slab_free_hook(s, x);
104172
104173 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
104174 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
104175 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
104176 + if (s->ctor)
104177 + s->ctor(x);
104178 + }
104179 +#endif
104180 +
104181 redo:
104182 /*
104183 * Determine the currently cpus per cpu slab.
104184 @@ -2740,7 +2748,7 @@ static int slub_min_objects;
104185 * Merge control. If this is set then no merging of slab caches will occur.
104186 * (Could be removed. This was introduced to pacify the merge skeptics.)
104187 */
104188 -static int slub_nomerge;
104189 +static int slub_nomerge = 1;
104190
104191 /*
104192 * Calculate the order of allocation given an slab object size.
104193 @@ -3019,6 +3027,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
104194 s->inuse = size;
104195
104196 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
104197 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
104198 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
104199 +#endif
104200 s->ctor)) {
104201 /*
104202 * Relocate free pointer after the object if it is not
104203 @@ -3347,6 +3358,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
104204 EXPORT_SYMBOL(__kmalloc_node);
104205 #endif
104206
104207 +bool is_usercopy_object(const void *ptr)
104208 +{
104209 + struct page *page;
104210 + struct kmem_cache *s;
104211 +
104212 + if (ZERO_OR_NULL_PTR(ptr))
104213 + return false;
104214 +
104215 + if (!slab_is_available())
104216 + return false;
104217 +
104218 + if (!virt_addr_valid(ptr))
104219 + return false;
104220 +
104221 + page = virt_to_head_page(ptr);
104222 +
104223 + if (!PageSlab(page))
104224 + return false;
104225 +
104226 + s = page->slab_cache;
104227 + return s->flags & SLAB_USERCOPY;
104228 +}
104229 +
104230 +#ifdef CONFIG_PAX_USERCOPY
104231 +const char *check_heap_object(const void *ptr, unsigned long n)
104232 +{
104233 + struct page *page;
104234 + struct kmem_cache *s;
104235 + unsigned long offset;
104236 +
104237 + if (ZERO_OR_NULL_PTR(ptr))
104238 + return "<null>";
104239 +
104240 + if (!virt_addr_valid(ptr))
104241 + return NULL;
104242 +
104243 + page = virt_to_head_page(ptr);
104244 +
104245 + if (!PageSlab(page))
104246 + return NULL;
104247 +
104248 + s = page->slab_cache;
104249 + if (!(s->flags & SLAB_USERCOPY))
104250 + return s->name;
104251 +
104252 + offset = (ptr - page_address(page)) % s->size;
104253 + if (offset <= s->object_size && n <= s->object_size - offset)
104254 + return NULL;
104255 +
104256 + return s->name;
104257 +}
104258 +#endif
104259 +
104260 size_t ksize(const void *object)
104261 {
104262 struct page *page;
104263 @@ -3375,6 +3439,7 @@ void kfree(const void *x)
104264 if (unlikely(ZERO_OR_NULL_PTR(x)))
104265 return;
104266
104267 + VM_BUG_ON(!virt_addr_valid(x));
104268 page = virt_to_head_page(x);
104269 if (unlikely(!PageSlab(page))) {
104270 BUG_ON(!PageCompound(page));
104271 @@ -3680,7 +3745,7 @@ static int slab_unmergeable(struct kmem_cache *s)
104272 /*
104273 * We may have set a slab to be unmergeable during bootstrap.
104274 */
104275 - if (s->refcount < 0)
104276 + if (atomic_read(&s->refcount) < 0)
104277 return 1;
104278
104279 return 0;
104280 @@ -3737,7 +3802,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
104281 int i;
104282 struct kmem_cache *c;
104283
104284 - s->refcount++;
104285 + atomic_inc(&s->refcount);
104286
104287 /*
104288 * Adjust the object sizes so that we clear
104289 @@ -3756,7 +3821,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
104290 }
104291
104292 if (sysfs_slab_alias(s, name)) {
104293 - s->refcount--;
104294 + atomic_dec(&s->refcount);
104295 s = NULL;
104296 }
104297 }
104298 @@ -3873,7 +3938,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
104299 }
104300 #endif
104301
104302 -#ifdef CONFIG_SYSFS
104303 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
104304 static int count_inuse(struct page *page)
104305 {
104306 return page->inuse;
104307 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
104308 len += sprintf(buf + len, "%7ld ", l->count);
104309
104310 if (l->addr)
104311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104312 + len += sprintf(buf + len, "%pS", NULL);
104313 +#else
104314 len += sprintf(buf + len, "%pS", (void *)l->addr);
104315 +#endif
104316 else
104317 len += sprintf(buf + len, "<not-available>");
104318
104319 @@ -4258,12 +4327,12 @@ static void resiliency_test(void)
104320 validate_slab_cache(kmalloc_caches[9]);
104321 }
104322 #else
104323 -#ifdef CONFIG_SYSFS
104324 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
104325 static void resiliency_test(void) {};
104326 #endif
104327 #endif
104328
104329 -#ifdef CONFIG_SYSFS
104330 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
104331 enum slab_stat_type {
104332 SL_ALL, /* All slabs */
104333 SL_PARTIAL, /* Only partially allocated slabs */
104334 @@ -4503,13 +4572,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
104335 {
104336 if (!s->ctor)
104337 return 0;
104338 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104339 + return sprintf(buf, "%pS\n", NULL);
104340 +#else
104341 return sprintf(buf, "%pS\n", s->ctor);
104342 +#endif
104343 }
104344 SLAB_ATTR_RO(ctor);
104345
104346 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
104347 {
104348 - return sprintf(buf, "%d\n", s->refcount - 1);
104349 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
104350 }
104351 SLAB_ATTR_RO(aliases);
104352
104353 @@ -4597,6 +4670,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
104354 SLAB_ATTR_RO(cache_dma);
104355 #endif
104356
104357 +#ifdef CONFIG_PAX_USERCOPY_SLABS
104358 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
104359 +{
104360 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
104361 +}
104362 +SLAB_ATTR_RO(usercopy);
104363 +#endif
104364 +
104365 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
104366 {
104367 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
104368 @@ -4931,6 +5012,9 @@ static struct attribute *slab_attrs[] = {
104369 #ifdef CONFIG_ZONE_DMA
104370 &cache_dma_attr.attr,
104371 #endif
104372 +#ifdef CONFIG_PAX_USERCOPY_SLABS
104373 + &usercopy_attr.attr,
104374 +#endif
104375 #ifdef CONFIG_NUMA
104376 &remote_node_defrag_ratio_attr.attr,
104377 #endif
104378 @@ -5181,6 +5265,7 @@ static char *create_unique_id(struct kmem_cache *s)
104379 return name;
104380 }
104381
104382 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
104383 static int sysfs_slab_add(struct kmem_cache *s)
104384 {
104385 int err;
104386 @@ -5254,6 +5339,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
104387 kobject_del(&s->kobj);
104388 kobject_put(&s->kobj);
104389 }
104390 +#endif
104391
104392 /*
104393 * Need to buffer aliases during bootup until sysfs becomes
104394 @@ -5267,6 +5353,7 @@ struct saved_alias {
104395
104396 static struct saved_alias *alias_list;
104397
104398 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
104399 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
104400 {
104401 struct saved_alias *al;
104402 @@ -5289,6 +5376,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
104403 alias_list = al;
104404 return 0;
104405 }
104406 +#endif
104407
104408 static int __init slab_sysfs_init(void)
104409 {
104410 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
104411 index 4cba9c2..b4f9fcc 100644
104412 --- a/mm/sparse-vmemmap.c
104413 +++ b/mm/sparse-vmemmap.c
104414 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
104415 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
104416 if (!p)
104417 return NULL;
104418 - pud_populate(&init_mm, pud, p);
104419 + pud_populate_kernel(&init_mm, pud, p);
104420 }
104421 return pud;
104422 }
104423 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
104424 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
104425 if (!p)
104426 return NULL;
104427 - pgd_populate(&init_mm, pgd, p);
104428 + pgd_populate_kernel(&init_mm, pgd, p);
104429 }
104430 return pgd;
104431 }
104432 diff --git a/mm/sparse.c b/mm/sparse.c
104433 index d1b48b6..6e8590e 100644
104434 --- a/mm/sparse.c
104435 +++ b/mm/sparse.c
104436 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
104437
104438 for (i = 0; i < PAGES_PER_SECTION; i++) {
104439 if (PageHWPoison(&memmap[i])) {
104440 - atomic_long_sub(1, &num_poisoned_pages);
104441 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
104442 ClearPageHWPoison(&memmap[i]);
104443 }
104444 }
104445 diff --git a/mm/swap.c b/mm/swap.c
104446 index 9e8e347..3c22e0f 100644
104447 --- a/mm/swap.c
104448 +++ b/mm/swap.c
104449 @@ -31,6 +31,7 @@
104450 #include <linux/memcontrol.h>
104451 #include <linux/gfp.h>
104452 #include <linux/uio.h>
104453 +#include <linux/hugetlb.h>
104454
104455 #include "internal.h"
104456
104457 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
104458
104459 __page_cache_release(page);
104460 dtor = get_compound_page_dtor(page);
104461 + if (!PageHuge(page))
104462 + BUG_ON(dtor != free_compound_page);
104463 (*dtor)(page);
104464 }
104465
104466 diff --git a/mm/swapfile.c b/mm/swapfile.c
104467 index 4c524f7..f7601f17 100644
104468 --- a/mm/swapfile.c
104469 +++ b/mm/swapfile.c
104470 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
104471
104472 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
104473 /* Activity counter to indicate that a swapon or swapoff has occurred */
104474 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
104475 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
104476
104477 static inline unsigned char swap_count(unsigned char ent)
104478 {
104479 @@ -1945,7 +1945,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
104480 spin_unlock(&swap_lock);
104481
104482 err = 0;
104483 - atomic_inc(&proc_poll_event);
104484 + atomic_inc_unchecked(&proc_poll_event);
104485 wake_up_interruptible(&proc_poll_wait);
104486
104487 out_dput:
104488 @@ -1962,8 +1962,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
104489
104490 poll_wait(file, &proc_poll_wait, wait);
104491
104492 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
104493 - seq->poll_event = atomic_read(&proc_poll_event);
104494 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
104495 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
104496 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
104497 }
104498
104499 @@ -2061,7 +2061,7 @@ static int swaps_open(struct inode *inode, struct file *file)
104500 return ret;
104501
104502 seq = file->private_data;
104503 - seq->poll_event = atomic_read(&proc_poll_event);
104504 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
104505 return 0;
104506 }
104507
104508 @@ -2521,7 +2521,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
104509 (frontswap_map) ? "FS" : "");
104510
104511 mutex_unlock(&swapon_mutex);
104512 - atomic_inc(&proc_poll_event);
104513 + atomic_inc_unchecked(&proc_poll_event);
104514 wake_up_interruptible(&proc_poll_wait);
104515
104516 if (S_ISREG(inode->i_mode))
104517 diff --git a/mm/util.c b/mm/util.c
104518 index 33e9f44..be026b2 100644
104519 --- a/mm/util.c
104520 +++ b/mm/util.c
104521 @@ -296,6 +296,12 @@ done:
104522 void arch_pick_mmap_layout(struct mm_struct *mm)
104523 {
104524 mm->mmap_base = TASK_UNMAPPED_BASE;
104525 +
104526 +#ifdef CONFIG_PAX_RANDMMAP
104527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
104528 + mm->mmap_base += mm->delta_mmap;
104529 +#endif
104530 +
104531 mm->get_unmapped_area = arch_get_unmapped_area;
104532 }
104533 #endif
104534 @@ -472,6 +478,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
104535 if (!mm->arg_end)
104536 goto out_mm; /* Shh! No looking before we're done */
104537
104538 + if (gr_acl_handle_procpidmem(task))
104539 + goto out_mm;
104540 +
104541 len = mm->arg_end - mm->arg_start;
104542
104543 if (len > buflen)
104544 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
104545 index f64632b..e8c52e7 100644
104546 --- a/mm/vmalloc.c
104547 +++ b/mm/vmalloc.c
104548 @@ -40,6 +40,21 @@ struct vfree_deferred {
104549 };
104550 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
104551
104552 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
104553 +struct stack_deferred_llist {
104554 + struct llist_head list;
104555 + void *stack;
104556 + void *lowmem_stack;
104557 +};
104558 +
104559 +struct stack_deferred {
104560 + struct stack_deferred_llist list;
104561 + struct work_struct wq;
104562 +};
104563 +
104564 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
104565 +#endif
104566 +
104567 static void __vunmap(const void *, int);
104568
104569 static void free_work(struct work_struct *w)
104570 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
104571 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
104572 struct llist_node *llnode = llist_del_all(&p->list);
104573 while (llnode) {
104574 - void *p = llnode;
104575 + void *x = llnode;
104576 llnode = llist_next(llnode);
104577 - __vunmap(p, 1);
104578 + __vunmap(x, 1);
104579 }
104580 }
104581
104582 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
104583 +static void unmap_work(struct work_struct *w)
104584 +{
104585 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
104586 + struct llist_node *llnode = llist_del_all(&p->list.list);
104587 + while (llnode) {
104588 + struct stack_deferred_llist *x =
104589 + llist_entry((struct llist_head *)llnode,
104590 + struct stack_deferred_llist, list);
104591 + void *stack = ACCESS_ONCE(x->stack);
104592 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
104593 + llnode = llist_next(llnode);
104594 + __vunmap(stack, 0);
104595 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
104596 + }
104597 +}
104598 +#endif
104599 +
104600 /*** Page table manipulation functions ***/
104601
104602 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
104603 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
104604
104605 pte = pte_offset_kernel(pmd, addr);
104606 do {
104607 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
104608 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
104609 +
104610 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
104611 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
104612 + BUG_ON(!pte_exec(*pte));
104613 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
104614 + continue;
104615 + }
104616 +#endif
104617 +
104618 + {
104619 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
104620 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
104621 + }
104622 } while (pte++, addr += PAGE_SIZE, addr != end);
104623 }
104624
104625 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
104626 pte = pte_alloc_kernel(pmd, addr);
104627 if (!pte)
104628 return -ENOMEM;
104629 +
104630 + pax_open_kernel();
104631 do {
104632 struct page *page = pages[*nr];
104633
104634 - if (WARN_ON(!pte_none(*pte)))
104635 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
104636 + if (pgprot_val(prot) & _PAGE_NX)
104637 +#endif
104638 +
104639 + if (!pte_none(*pte)) {
104640 + pax_close_kernel();
104641 + WARN_ON(1);
104642 return -EBUSY;
104643 - if (WARN_ON(!page))
104644 + }
104645 + if (!page) {
104646 + pax_close_kernel();
104647 + WARN_ON(1);
104648 return -ENOMEM;
104649 + }
104650 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
104651 (*nr)++;
104652 } while (pte++, addr += PAGE_SIZE, addr != end);
104653 + pax_close_kernel();
104654 return 0;
104655 }
104656
104657 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
104658 pmd_t *pmd;
104659 unsigned long next;
104660
104661 - pmd = pmd_alloc(&init_mm, pud, addr);
104662 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
104663 if (!pmd)
104664 return -ENOMEM;
104665 do {
104666 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
104667 pud_t *pud;
104668 unsigned long next;
104669
104670 - pud = pud_alloc(&init_mm, pgd, addr);
104671 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
104672 if (!pud)
104673 return -ENOMEM;
104674 do {
104675 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
104676 if (addr >= MODULES_VADDR && addr < MODULES_END)
104677 return 1;
104678 #endif
104679 +
104680 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
104681 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
104682 + return 1;
104683 +#endif
104684 +
104685 return is_vmalloc_addr(x);
104686 }
104687
104688 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
104689
104690 if (!pgd_none(*pgd)) {
104691 pud_t *pud = pud_offset(pgd, addr);
104692 +#ifdef CONFIG_X86
104693 + if (!pud_large(*pud))
104694 +#endif
104695 if (!pud_none(*pud)) {
104696 pmd_t *pmd = pmd_offset(pud, addr);
104697 +#ifdef CONFIG_X86
104698 + if (!pmd_large(*pmd))
104699 +#endif
104700 if (!pmd_none(*pmd)) {
104701 pte_t *ptep, pte;
104702
104703 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
104704 for_each_possible_cpu(i) {
104705 struct vmap_block_queue *vbq;
104706 struct vfree_deferred *p;
104707 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
104708 + struct stack_deferred *p2;
104709 +#endif
104710
104711 vbq = &per_cpu(vmap_block_queue, i);
104712 spin_lock_init(&vbq->lock);
104713 INIT_LIST_HEAD(&vbq->free);
104714 +
104715 p = &per_cpu(vfree_deferred, i);
104716 init_llist_head(&p->list);
104717 INIT_WORK(&p->wq, free_work);
104718 +
104719 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
104720 + p2 = &per_cpu(stack_deferred, i);
104721 + init_llist_head(&p2->list.list);
104722 + INIT_WORK(&p2->wq, unmap_work);
104723 +#endif
104724 }
104725
104726 /* Import existing vmlist entries. */
104727 @@ -1318,6 +1397,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
104728 struct vm_struct *area;
104729
104730 BUG_ON(in_interrupt());
104731 +
104732 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
104733 + if (flags & VM_KERNEXEC) {
104734 + if (start != VMALLOC_START || end != VMALLOC_END)
104735 + return NULL;
104736 + start = (unsigned long)MODULES_EXEC_VADDR;
104737 + end = (unsigned long)MODULES_EXEC_END;
104738 + }
104739 +#endif
104740 +
104741 if (flags & VM_IOREMAP)
104742 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
104743
104744 @@ -1523,6 +1612,23 @@ void vunmap(const void *addr)
104745 }
104746 EXPORT_SYMBOL(vunmap);
104747
104748 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
104749 +void unmap_process_stacks(struct task_struct *task)
104750 +{
104751 + if (unlikely(in_interrupt())) {
104752 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
104753 + struct stack_deferred_llist *list = task->stack;
104754 + list->stack = task->stack;
104755 + list->lowmem_stack = task->lowmem_stack;
104756 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
104757 + schedule_work(&p->wq);
104758 + } else {
104759 + __vunmap(task->stack, 0);
104760 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
104761 + }
104762 +}
104763 +#endif
104764 +
104765 /**
104766 * vmap - map an array of pages into virtually contiguous space
104767 * @pages: array of page pointers
104768 @@ -1543,6 +1649,11 @@ void *vmap(struct page **pages, unsigned int count,
104769 if (count > totalram_pages)
104770 return NULL;
104771
104772 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
104773 + if (!(pgprot_val(prot) & _PAGE_NX))
104774 + flags |= VM_KERNEXEC;
104775 +#endif
104776 +
104777 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
104778 __builtin_return_address(0));
104779 if (!area)
104780 @@ -1643,6 +1754,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
104781 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
104782 goto fail;
104783
104784 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
104785 + if (!(pgprot_val(prot) & _PAGE_NX))
104786 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
104787 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
104788 + else
104789 +#endif
104790 +
104791 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
104792 start, end, node, gfp_mask, caller);
104793 if (!area)
104794 @@ -1819,10 +1937,9 @@ EXPORT_SYMBOL(vzalloc_node);
104795 * For tight control over page level allocator and protection flags
104796 * use __vmalloc() instead.
104797 */
104798 -
104799 void *vmalloc_exec(unsigned long size)
104800 {
104801 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
104802 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
104803 NUMA_NO_NODE, __builtin_return_address(0));
104804 }
104805
104806 @@ -2129,6 +2246,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
104807 {
104808 struct vm_struct *area;
104809
104810 + BUG_ON(vma->vm_mirror);
104811 +
104812 size = PAGE_ALIGN(size);
104813
104814 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
104815 @@ -2611,7 +2730,11 @@ static int s_show(struct seq_file *m, void *p)
104816 v->addr, v->addr + v->size, v->size);
104817
104818 if (v->caller)
104819 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104820 + seq_printf(m, " %pK", v->caller);
104821 +#else
104822 seq_printf(m, " %pS", v->caller);
104823 +#endif
104824
104825 if (v->nr_pages)
104826 seq_printf(m, " pages=%d", v->nr_pages);
104827 diff --git a/mm/vmstat.c b/mm/vmstat.c
104828 index b37bd49..4d7b3da 100644
104829 --- a/mm/vmstat.c
104830 +++ b/mm/vmstat.c
104831 @@ -20,6 +20,7 @@
104832 #include <linux/writeback.h>
104833 #include <linux/compaction.h>
104834 #include <linux/mm_inline.h>
104835 +#include <linux/grsecurity.h>
104836
104837 #include "internal.h"
104838
104839 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
104840 *
104841 * vm_stat contains the global counters
104842 */
104843 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
104844 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
104845 EXPORT_SYMBOL(vm_stat);
104846
104847 #ifdef CONFIG_SMP
104848 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
104849
104850 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
104851 if (diff[i])
104852 - atomic_long_add(diff[i], &vm_stat[i]);
104853 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
104854 }
104855
104856 /*
104857 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
104858 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
104859 if (v) {
104860
104861 - atomic_long_add(v, &zone->vm_stat[i]);
104862 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
104863 global_diff[i] += v;
104864 #ifdef CONFIG_NUMA
104865 /* 3 seconds idle till flush */
104866 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
104867
104868 v = p->vm_stat_diff[i];
104869 p->vm_stat_diff[i] = 0;
104870 - atomic_long_add(v, &zone->vm_stat[i]);
104871 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
104872 global_diff[i] += v;
104873 }
104874 }
104875 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
104876 if (pset->vm_stat_diff[i]) {
104877 int v = pset->vm_stat_diff[i];
104878 pset->vm_stat_diff[i] = 0;
104879 - atomic_long_add(v, &zone->vm_stat[i]);
104880 - atomic_long_add(v, &vm_stat[i]);
104881 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
104882 + atomic_long_add_unchecked(v, &vm_stat[i]);
104883 }
104884 }
104885 #endif
104886 @@ -1162,10 +1163,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
104887 stat_items_size += sizeof(struct vm_event_state);
104888 #endif
104889
104890 - v = kmalloc(stat_items_size, GFP_KERNEL);
104891 + v = kzalloc(stat_items_size, GFP_KERNEL);
104892 m->private = v;
104893 if (!v)
104894 return ERR_PTR(-ENOMEM);
104895 +
104896 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
104897 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
104898 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
104899 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
104900 + && !in_group_p(grsec_proc_gid)
104901 +#endif
104902 + )
104903 + return (unsigned long *)m->private + *pos;
104904 +#endif
104905 +#endif
104906 +
104907 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
104908 v[i] = global_page_state(i);
104909 v += NR_VM_ZONE_STAT_ITEMS;
104910 @@ -1314,10 +1327,16 @@ static int __init setup_vmstat(void)
104911 cpu_notifier_register_done();
104912 #endif
104913 #ifdef CONFIG_PROC_FS
104914 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
104915 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
104916 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
104917 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
104918 + {
104919 + mode_t gr_mode = S_IRUGO;
104920 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
104921 + gr_mode = S_IRUSR;
104922 +#endif
104923 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
104924 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
104925 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
104926 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
104927 + }
104928 #endif
104929 return 0;
104930 }
104931 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
104932 index 44ebd5c..1f732bae 100644
104933 --- a/net/8021q/vlan.c
104934 +++ b/net/8021q/vlan.c
104935 @@ -475,7 +475,7 @@ out:
104936 return NOTIFY_DONE;
104937 }
104938
104939 -static struct notifier_block vlan_notifier_block __read_mostly = {
104940 +static struct notifier_block vlan_notifier_block = {
104941 .notifier_call = vlan_device_event,
104942 };
104943
104944 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
104945 err = -EPERM;
104946 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
104947 break;
104948 - if ((args.u.name_type >= 0) &&
104949 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
104950 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
104951 struct vlan_net *vn;
104952
104953 vn = net_generic(net, vlan_net_id);
104954 diff --git a/net/9p/client.c b/net/9p/client.c
104955 index 0004cba..feba240 100644
104956 --- a/net/9p/client.c
104957 +++ b/net/9p/client.c
104958 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
104959 len - inline_len);
104960 } else {
104961 err = copy_from_user(ename + inline_len,
104962 - uidata, len - inline_len);
104963 + (char __force_user *)uidata, len - inline_len);
104964 if (err) {
104965 err = -EFAULT;
104966 goto out_err;
104967 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
104968 kernel_buf = 1;
104969 indata = data;
104970 } else
104971 - indata = (__force char *)udata;
104972 + indata = (__force_kernel char *)udata;
104973 /*
104974 * response header len is 11
104975 * PDU Header(7) + IO Size (4)
104976 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
104977 kernel_buf = 1;
104978 odata = data;
104979 } else
104980 - odata = (char *)udata;
104981 + odata = (char __force_kernel *)udata;
104982 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
104983 P9_ZC_HDR_SZ, kernel_buf, "dqd",
104984 fid->fid, offset, rsize);
104985 diff --git a/net/9p/mod.c b/net/9p/mod.c
104986 index 6ab36ae..6f1841b 100644
104987 --- a/net/9p/mod.c
104988 +++ b/net/9p/mod.c
104989 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
104990 void v9fs_register_trans(struct p9_trans_module *m)
104991 {
104992 spin_lock(&v9fs_trans_lock);
104993 - list_add_tail(&m->list, &v9fs_trans_list);
104994 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
104995 spin_unlock(&v9fs_trans_lock);
104996 }
104997 EXPORT_SYMBOL(v9fs_register_trans);
104998 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
104999 void v9fs_unregister_trans(struct p9_trans_module *m)
105000 {
105001 spin_lock(&v9fs_trans_lock);
105002 - list_del_init(&m->list);
105003 + pax_list_del_init((struct list_head *)&m->list);
105004 spin_unlock(&v9fs_trans_lock);
105005 }
105006 EXPORT_SYMBOL(v9fs_unregister_trans);
105007 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
105008 index 80d08f6..de63fd1 100644
105009 --- a/net/9p/trans_fd.c
105010 +++ b/net/9p/trans_fd.c
105011 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
105012 oldfs = get_fs();
105013 set_fs(get_ds());
105014 /* The cast to a user pointer is valid due to the set_fs() */
105015 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
105016 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
105017 set_fs(oldfs);
105018
105019 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
105020 diff --git a/net/Kconfig b/net/Kconfig
105021 index d92afe4..ab63892 100644
105022 --- a/net/Kconfig
105023 +++ b/net/Kconfig
105024 @@ -89,12 +89,8 @@ config NETWORK_SECMARK
105025 to nfmark, but designated for security purposes.
105026 If you are unsure how to answer this question, answer N.
105027
105028 -config NET_PTP_CLASSIFY
105029 - def_bool n
105030 -
105031 config NETWORK_PHY_TIMESTAMPING
105032 bool "Timestamping in PHY devices"
105033 - select NET_PTP_CLASSIFY
105034 help
105035 This allows timestamping of network packets by PHYs with
105036 hardware timestamping capabilities. This option adds some
105037 @@ -269,7 +265,7 @@ config BQL
105038 config BPF_JIT
105039 bool "enable BPF Just In Time compiler"
105040 depends on HAVE_BPF_JIT
105041 - depends on MODULES
105042 + depends on MODULES && X86
105043 ---help---
105044 Berkeley Packet Filter filtering capabilities are normally handled
105045 by an interpreter. This option allows kernel to generate a native
105046 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
105047 index af46bc4..f9adfcd 100644
105048 --- a/net/appletalk/atalk_proc.c
105049 +++ b/net/appletalk/atalk_proc.c
105050 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
105051 struct proc_dir_entry *p;
105052 int rc = -ENOMEM;
105053
105054 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
105055 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
105056 if (!atalk_proc_dir)
105057 goto out;
105058
105059 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
105060 index 876fbe8..8bbea9f 100644
105061 --- a/net/atm/atm_misc.c
105062 +++ b/net/atm/atm_misc.c
105063 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
105064 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
105065 return 1;
105066 atm_return(vcc, truesize);
105067 - atomic_inc(&vcc->stats->rx_drop);
105068 + atomic_inc_unchecked(&vcc->stats->rx_drop);
105069 return 0;
105070 }
105071 EXPORT_SYMBOL(atm_charge);
105072 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
105073 }
105074 }
105075 atm_return(vcc, guess);
105076 - atomic_inc(&vcc->stats->rx_drop);
105077 + atomic_inc_unchecked(&vcc->stats->rx_drop);
105078 return NULL;
105079 }
105080 EXPORT_SYMBOL(atm_alloc_charge);
105081 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
105082
105083 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
105084 {
105085 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
105086 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
105087 __SONET_ITEMS
105088 #undef __HANDLE_ITEM
105089 }
105090 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
105091
105092 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
105093 {
105094 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
105095 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
105096 __SONET_ITEMS
105097 #undef __HANDLE_ITEM
105098 }
105099 diff --git a/net/atm/lec.c b/net/atm/lec.c
105100 index 4c5b8ba..95f7005 100644
105101 --- a/net/atm/lec.c
105102 +++ b/net/atm/lec.c
105103 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
105104 }
105105
105106 static struct lane2_ops lane2_ops = {
105107 - lane2_resolve, /* resolve, spec 3.1.3 */
105108 - lane2_associate_req, /* associate_req, spec 3.1.4 */
105109 - NULL /* associate indicator, spec 3.1.5 */
105110 + .resolve = lane2_resolve,
105111 + .associate_req = lane2_associate_req,
105112 + .associate_indicator = NULL
105113 };
105114
105115 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
105116 diff --git a/net/atm/lec.h b/net/atm/lec.h
105117 index 4149db1..f2ab682 100644
105118 --- a/net/atm/lec.h
105119 +++ b/net/atm/lec.h
105120 @@ -48,7 +48,7 @@ struct lane2_ops {
105121 const u8 *tlvs, u32 sizeoftlvs);
105122 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
105123 const u8 *tlvs, u32 sizeoftlvs);
105124 -};
105125 +} __no_const;
105126
105127 /*
105128 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
105129 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
105130 index d1b2d9a..d549f7f 100644
105131 --- a/net/atm/mpoa_caches.c
105132 +++ b/net/atm/mpoa_caches.c
105133 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
105134
105135
105136 static struct in_cache_ops ingress_ops = {
105137 - in_cache_add_entry, /* add_entry */
105138 - in_cache_get, /* get */
105139 - in_cache_get_with_mask, /* get_with_mask */
105140 - in_cache_get_by_vcc, /* get_by_vcc */
105141 - in_cache_put, /* put */
105142 - in_cache_remove_entry, /* remove_entry */
105143 - cache_hit, /* cache_hit */
105144 - clear_count_and_expired, /* clear_count */
105145 - check_resolving_entries, /* check_resolving */
105146 - refresh_entries, /* refresh */
105147 - in_destroy_cache /* destroy_cache */
105148 + .add_entry = in_cache_add_entry,
105149 + .get = in_cache_get,
105150 + .get_with_mask = in_cache_get_with_mask,
105151 + .get_by_vcc = in_cache_get_by_vcc,
105152 + .put = in_cache_put,
105153 + .remove_entry = in_cache_remove_entry,
105154 + .cache_hit = cache_hit,
105155 + .clear_count = clear_count_and_expired,
105156 + .check_resolving = check_resolving_entries,
105157 + .refresh = refresh_entries,
105158 + .destroy_cache = in_destroy_cache
105159 };
105160
105161 static struct eg_cache_ops egress_ops = {
105162 - eg_cache_add_entry, /* add_entry */
105163 - eg_cache_get_by_cache_id, /* get_by_cache_id */
105164 - eg_cache_get_by_tag, /* get_by_tag */
105165 - eg_cache_get_by_vcc, /* get_by_vcc */
105166 - eg_cache_get_by_src_ip, /* get_by_src_ip */
105167 - eg_cache_put, /* put */
105168 - eg_cache_remove_entry, /* remove_entry */
105169 - update_eg_cache_entry, /* update */
105170 - clear_expired, /* clear_expired */
105171 - eg_destroy_cache /* destroy_cache */
105172 + .add_entry = eg_cache_add_entry,
105173 + .get_by_cache_id = eg_cache_get_by_cache_id,
105174 + .get_by_tag = eg_cache_get_by_tag,
105175 + .get_by_vcc = eg_cache_get_by_vcc,
105176 + .get_by_src_ip = eg_cache_get_by_src_ip,
105177 + .put = eg_cache_put,
105178 + .remove_entry = eg_cache_remove_entry,
105179 + .update = update_eg_cache_entry,
105180 + .clear_expired = clear_expired,
105181 + .destroy_cache = eg_destroy_cache
105182 };
105183
105184
105185 diff --git a/net/atm/proc.c b/net/atm/proc.c
105186 index bbb6461..cf04016 100644
105187 --- a/net/atm/proc.c
105188 +++ b/net/atm/proc.c
105189 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
105190 const struct k_atm_aal_stats *stats)
105191 {
105192 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
105193 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
105194 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
105195 - atomic_read(&stats->rx_drop));
105196 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
105197 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
105198 + atomic_read_unchecked(&stats->rx_drop));
105199 }
105200
105201 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
105202 diff --git a/net/atm/resources.c b/net/atm/resources.c
105203 index 0447d5d..3cf4728 100644
105204 --- a/net/atm/resources.c
105205 +++ b/net/atm/resources.c
105206 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
105207 static void copy_aal_stats(struct k_atm_aal_stats *from,
105208 struct atm_aal_stats *to)
105209 {
105210 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
105211 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
105212 __AAL_STAT_ITEMS
105213 #undef __HANDLE_ITEM
105214 }
105215 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
105216 static void subtract_aal_stats(struct k_atm_aal_stats *from,
105217 struct atm_aal_stats *to)
105218 {
105219 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
105220 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
105221 __AAL_STAT_ITEMS
105222 #undef __HANDLE_ITEM
105223 }
105224 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
105225 index 919a5ce..cc6b444 100644
105226 --- a/net/ax25/sysctl_net_ax25.c
105227 +++ b/net/ax25/sysctl_net_ax25.c
105228 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
105229 {
105230 char path[sizeof("net/ax25/") + IFNAMSIZ];
105231 int k;
105232 - struct ctl_table *table;
105233 + ctl_table_no_const *table;
105234
105235 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
105236 if (!table)
105237 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
105238 index f04224c..f326579 100644
105239 --- a/net/batman-adv/bat_iv_ogm.c
105240 +++ b/net/batman-adv/bat_iv_ogm.c
105241 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
105242
105243 /* randomize initial seqno to avoid collision */
105244 get_random_bytes(&random_seqno, sizeof(random_seqno));
105245 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
105246 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
105247
105248 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
105249 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
105250 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
105251 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
105252
105253 /* change sequence number to network order */
105254 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
105255 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
105256 batadv_ogm_packet->seqno = htonl(seqno);
105257 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
105258 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
105259
105260 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
105261
105262 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
105263 return;
105264
105265 /* could be changed by schedule_own_packet() */
105266 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
105267 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
105268
105269 if (ogm_packet->flags & BATADV_DIRECTLINK)
105270 has_directlink_flag = true;
105271 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
105272 index 022d18a..919daff 100644
105273 --- a/net/batman-adv/fragmentation.c
105274 +++ b/net/batman-adv/fragmentation.c
105275 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
105276 frag_header.packet_type = BATADV_UNICAST_FRAG;
105277 frag_header.version = BATADV_COMPAT_VERSION;
105278 frag_header.ttl = BATADV_TTL;
105279 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
105280 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
105281 frag_header.reserved = 0;
105282 frag_header.no = 0;
105283 frag_header.total_size = htons(skb->len);
105284 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
105285 index cbd677f..b783347 100644
105286 --- a/net/batman-adv/soft-interface.c
105287 +++ b/net/batman-adv/soft-interface.c
105288 @@ -296,7 +296,7 @@ send:
105289 primary_if->net_dev->dev_addr);
105290
105291 /* set broadcast sequence number */
105292 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
105293 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
105294 bcast_packet->seqno = htonl(seqno);
105295
105296 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
105297 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
105298 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
105299
105300 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
105301 - atomic_set(&bat_priv->bcast_seqno, 1);
105302 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
105303 atomic_set(&bat_priv->tt.vn, 0);
105304 atomic_set(&bat_priv->tt.local_changes, 0);
105305 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
105306 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
105307
105308 /* randomize initial seqno to avoid collision */
105309 get_random_bytes(&random_seqno, sizeof(random_seqno));
105310 - atomic_set(&bat_priv->frag_seqno, random_seqno);
105311 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
105312
105313 bat_priv->primary_if = NULL;
105314 bat_priv->num_ifaces = 0;
105315 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
105316 index 8854c05..ee5d5497 100644
105317 --- a/net/batman-adv/types.h
105318 +++ b/net/batman-adv/types.h
105319 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
105320 struct batadv_hard_iface_bat_iv {
105321 unsigned char *ogm_buff;
105322 int ogm_buff_len;
105323 - atomic_t ogm_seqno;
105324 + atomic_unchecked_t ogm_seqno;
105325 };
105326
105327 /**
105328 @@ -768,7 +768,7 @@ struct batadv_priv {
105329 atomic_t bonding;
105330 atomic_t fragmentation;
105331 atomic_t packet_size_max;
105332 - atomic_t frag_seqno;
105333 + atomic_unchecked_t frag_seqno;
105334 #ifdef CONFIG_BATMAN_ADV_BLA
105335 atomic_t bridge_loop_avoidance;
105336 #endif
105337 @@ -787,7 +787,7 @@ struct batadv_priv {
105338 #endif
105339 uint32_t isolation_mark;
105340 uint32_t isolation_mark_mask;
105341 - atomic_t bcast_seqno;
105342 + atomic_unchecked_t bcast_seqno;
105343 atomic_t bcast_queue_left;
105344 atomic_t batman_queue_left;
105345 char num_ifaces;
105346 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
105347 index 80d25c1..aa99a98 100644
105348 --- a/net/bluetooth/hci_sock.c
105349 +++ b/net/bluetooth/hci_sock.c
105350 @@ -1044,7 +1044,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
105351 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
105352 }
105353
105354 - len = min_t(unsigned int, len, sizeof(uf));
105355 + len = min((size_t)len, sizeof(uf));
105356 if (copy_from_user(&uf, optval, len)) {
105357 err = -EFAULT;
105358 break;
105359 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
105360 index 323f23c..5e27529 100644
105361 --- a/net/bluetooth/l2cap_core.c
105362 +++ b/net/bluetooth/l2cap_core.c
105363 @@ -3548,8 +3548,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
105364 break;
105365
105366 case L2CAP_CONF_RFC:
105367 - if (olen == sizeof(rfc))
105368 - memcpy(&rfc, (void *)val, olen);
105369 + if (olen != sizeof(rfc))
105370 + break;
105371 +
105372 + memcpy(&rfc, (void *)val, olen);
105373
105374 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
105375 rfc.mode != chan->mode)
105376 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
105377 index e137869..33f3ebd 100644
105378 --- a/net/bluetooth/l2cap_sock.c
105379 +++ b/net/bluetooth/l2cap_sock.c
105380 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
105381 struct sock *sk = sock->sk;
105382 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
105383 struct l2cap_options opts;
105384 - int len, err = 0;
105385 + int err = 0;
105386 + size_t len = optlen;
105387 u32 opt;
105388
105389 BT_DBG("sk %p", sk);
105390 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
105391 opts.max_tx = chan->max_tx;
105392 opts.txwin_size = chan->tx_win;
105393
105394 - len = min_t(unsigned int, sizeof(opts), optlen);
105395 + len = min(sizeof(opts), len);
105396 if (copy_from_user((char *) &opts, optval, len)) {
105397 err = -EFAULT;
105398 break;
105399 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
105400 struct bt_security sec;
105401 struct bt_power pwr;
105402 struct l2cap_conn *conn;
105403 - int len, err = 0;
105404 + int err = 0;
105405 + size_t len = optlen;
105406 u32 opt;
105407
105408 BT_DBG("sk %p", sk);
105409 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
105410
105411 sec.level = BT_SECURITY_LOW;
105412
105413 - len = min_t(unsigned int, sizeof(sec), optlen);
105414 + len = min(sizeof(sec), len);
105415 if (copy_from_user((char *) &sec, optval, len)) {
105416 err = -EFAULT;
105417 break;
105418 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
105419
105420 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
105421
105422 - len = min_t(unsigned int, sizeof(pwr), optlen);
105423 + len = min(sizeof(pwr), len);
105424 if (copy_from_user((char *) &pwr, optval, len)) {
105425 err = -EFAULT;
105426 break;
105427 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
105428 index c603a5e..7f08991 100644
105429 --- a/net/bluetooth/rfcomm/sock.c
105430 +++ b/net/bluetooth/rfcomm/sock.c
105431 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
105432 struct sock *sk = sock->sk;
105433 struct bt_security sec;
105434 int err = 0;
105435 - size_t len;
105436 + size_t len = optlen;
105437 u32 opt;
105438
105439 BT_DBG("sk %p", sk);
105440 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
105441
105442 sec.level = BT_SECURITY_LOW;
105443
105444 - len = min_t(unsigned int, sizeof(sec), optlen);
105445 + len = min(sizeof(sec), len);
105446 if (copy_from_user((char *) &sec, optval, len)) {
105447 err = -EFAULT;
105448 break;
105449 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
105450 index 8e385a0..a5bdd8e 100644
105451 --- a/net/bluetooth/rfcomm/tty.c
105452 +++ b/net/bluetooth/rfcomm/tty.c
105453 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
105454 BT_DBG("tty %p id %d", tty, tty->index);
105455
105456 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
105457 - dev->channel, dev->port.count);
105458 + dev->channel, atomic_read(&dev->port.count));
105459
105460 err = tty_port_open(&dev->port, tty, filp);
105461 if (err)
105462 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
105463 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
105464
105465 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
105466 - dev->port.count);
105467 + atomic_read(&dev->port.count));
105468
105469 tty_port_close(&dev->port, tty, filp);
105470 }
105471 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
105472 index 1059ed3..d70846a 100644
105473 --- a/net/bridge/netfilter/ebtables.c
105474 +++ b/net/bridge/netfilter/ebtables.c
105475 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
105476 tmp.valid_hooks = t->table->valid_hooks;
105477 }
105478 mutex_unlock(&ebt_mutex);
105479 - if (copy_to_user(user, &tmp, *len) != 0) {
105480 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
105481 BUGPRINT("c2u Didn't work\n");
105482 ret = -EFAULT;
105483 break;
105484 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
105485 goto out;
105486 tmp.valid_hooks = t->valid_hooks;
105487
105488 - if (copy_to_user(user, &tmp, *len) != 0) {
105489 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
105490 ret = -EFAULT;
105491 break;
105492 }
105493 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
105494 tmp.entries_size = t->table->entries_size;
105495 tmp.valid_hooks = t->table->valid_hooks;
105496
105497 - if (copy_to_user(user, &tmp, *len) != 0) {
105498 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
105499 ret = -EFAULT;
105500 break;
105501 }
105502 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
105503 index 0f45522..dab651f 100644
105504 --- a/net/caif/cfctrl.c
105505 +++ b/net/caif/cfctrl.c
105506 @@ -10,6 +10,7 @@
105507 #include <linux/spinlock.h>
105508 #include <linux/slab.h>
105509 #include <linux/pkt_sched.h>
105510 +#include <linux/sched.h>
105511 #include <net/caif/caif_layer.h>
105512 #include <net/caif/cfpkt.h>
105513 #include <net/caif/cfctrl.h>
105514 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
105515 memset(&dev_info, 0, sizeof(dev_info));
105516 dev_info.id = 0xff;
105517 cfsrvl_init(&this->serv, 0, &dev_info, false);
105518 - atomic_set(&this->req_seq_no, 1);
105519 - atomic_set(&this->rsp_seq_no, 1);
105520 + atomic_set_unchecked(&this->req_seq_no, 1);
105521 + atomic_set_unchecked(&this->rsp_seq_no, 1);
105522 this->serv.layer.receive = cfctrl_recv;
105523 sprintf(this->serv.layer.name, "ctrl");
105524 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
105525 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
105526 struct cfctrl_request_info *req)
105527 {
105528 spin_lock_bh(&ctrl->info_list_lock);
105529 - atomic_inc(&ctrl->req_seq_no);
105530 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
105531 + atomic_inc_unchecked(&ctrl->req_seq_no);
105532 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
105533 list_add_tail(&req->list, &ctrl->list);
105534 spin_unlock_bh(&ctrl->info_list_lock);
105535 }
105536 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
105537 if (p != first)
105538 pr_warn("Requests are not received in order\n");
105539
105540 - atomic_set(&ctrl->rsp_seq_no,
105541 + atomic_set_unchecked(&ctrl->rsp_seq_no,
105542 p->sequence_no);
105543 list_del(&p->list);
105544 goto out;
105545 diff --git a/net/can/af_can.c b/net/can/af_can.c
105546 index ce82337..5d17b4d 100644
105547 --- a/net/can/af_can.c
105548 +++ b/net/can/af_can.c
105549 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
105550 };
105551
105552 /* notifier block for netdevice event */
105553 -static struct notifier_block can_netdev_notifier __read_mostly = {
105554 +static struct notifier_block can_netdev_notifier = {
105555 .notifier_call = can_notifier,
105556 };
105557
105558 diff --git a/net/can/bcm.c b/net/can/bcm.c
105559 index dcb75c0..24b1b43 100644
105560 --- a/net/can/bcm.c
105561 +++ b/net/can/bcm.c
105562 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
105563 }
105564
105565 /* create /proc/net/can-bcm directory */
105566 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
105567 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
105568 return 0;
105569 }
105570
105571 diff --git a/net/can/gw.c b/net/can/gw.c
105572 index 050a211..bb9fe33 100644
105573 --- a/net/can/gw.c
105574 +++ b/net/can/gw.c
105575 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
105576 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
105577
105578 static HLIST_HEAD(cgw_list);
105579 -static struct notifier_block notifier;
105580
105581 static struct kmem_cache *cgw_cache __read_mostly;
105582
105583 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
105584 return err;
105585 }
105586
105587 +static struct notifier_block notifier = {
105588 + .notifier_call = cgw_notifier
105589 +};
105590 +
105591 static __init int cgw_module_init(void)
105592 {
105593 /* sanitize given module parameter */
105594 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
105595 return -ENOMEM;
105596
105597 /* set notifier */
105598 - notifier.notifier_call = cgw_notifier;
105599 register_netdevice_notifier(&notifier);
105600
105601 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
105602 diff --git a/net/can/proc.c b/net/can/proc.c
105603 index 1a19b98..df2b4ec 100644
105604 --- a/net/can/proc.c
105605 +++ b/net/can/proc.c
105606 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
105607 void can_init_proc(void)
105608 {
105609 /* create /proc/net/can directory */
105610 - can_dir = proc_mkdir("can", init_net.proc_net);
105611 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
105612
105613 if (!can_dir) {
105614 printk(KERN_INFO "can: failed to create /proc/net/can . "
105615 diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c
105616 index 96238ba..de6662b 100644
105617 --- a/net/ceph/auth_x.c
105618 +++ b/net/ceph/auth_x.c
105619 @@ -13,8 +13,6 @@
105620 #include "auth_x.h"
105621 #include "auth_x_protocol.h"
105622
105623 -#define TEMP_TICKET_BUF_LEN 256
105624 -
105625 static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed);
105626
105627 static int ceph_x_is_authenticated(struct ceph_auth_client *ac)
105628 @@ -64,7 +62,7 @@ static int ceph_x_encrypt(struct ceph_crypto_key *secret,
105629 }
105630
105631 static int ceph_x_decrypt(struct ceph_crypto_key *secret,
105632 - void **p, void *end, void *obuf, size_t olen)
105633 + void **p, void *end, void **obuf, size_t olen)
105634 {
105635 struct ceph_x_encrypt_header head;
105636 size_t head_len = sizeof(head);
105637 @@ -75,8 +73,14 @@ static int ceph_x_decrypt(struct ceph_crypto_key *secret,
105638 return -EINVAL;
105639
105640 dout("ceph_x_decrypt len %d\n", len);
105641 - ret = ceph_decrypt2(secret, &head, &head_len, obuf, &olen,
105642 - *p, len);
105643 + if (*obuf == NULL) {
105644 + *obuf = kmalloc(len, GFP_NOFS);
105645 + if (!*obuf)
105646 + return -ENOMEM;
105647 + olen = len;
105648 + }
105649 +
105650 + ret = ceph_decrypt2(secret, &head, &head_len, *obuf, &olen, *p, len);
105651 if (ret)
105652 return ret;
105653 if (head.struct_v != 1 || le64_to_cpu(head.magic) != CEPHX_ENC_MAGIC)
105654 @@ -129,145 +133,154 @@ static void remove_ticket_handler(struct ceph_auth_client *ac,
105655 kfree(th);
105656 }
105657
105658 +static int process_one_ticket(struct ceph_auth_client *ac,
105659 + struct ceph_crypto_key *secret,
105660 + void **p, void *end)
105661 +{
105662 + struct ceph_x_info *xi = ac->private;
105663 + int type;
105664 + u8 tkt_struct_v, blob_struct_v;
105665 + struct ceph_x_ticket_handler *th;
105666 + void *dbuf = NULL;
105667 + void *dp, *dend;
105668 + int dlen;
105669 + char is_enc;
105670 + struct timespec validity;
105671 + struct ceph_crypto_key old_key;
105672 + void *ticket_buf = NULL;
105673 + void *tp, *tpend;
105674 + struct ceph_timespec new_validity;
105675 + struct ceph_crypto_key new_session_key;
105676 + struct ceph_buffer *new_ticket_blob;
105677 + unsigned long new_expires, new_renew_after;
105678 + u64 new_secret_id;
105679 + int ret;
105680 +
105681 + ceph_decode_need(p, end, sizeof(u32) + 1, bad);
105682 +
105683 + type = ceph_decode_32(p);
105684 + dout(" ticket type %d %s\n", type, ceph_entity_type_name(type));
105685 +
105686 + tkt_struct_v = ceph_decode_8(p);
105687 + if (tkt_struct_v != 1)
105688 + goto bad;
105689 +
105690 + th = get_ticket_handler(ac, type);
105691 + if (IS_ERR(th)) {
105692 + ret = PTR_ERR(th);
105693 + goto out;
105694 + }
105695 +
105696 + /* blob for me */
105697 + dlen = ceph_x_decrypt(secret, p, end, &dbuf, 0);
105698 + if (dlen <= 0) {
105699 + ret = dlen;
105700 + goto out;
105701 + }
105702 + dout(" decrypted %d bytes\n", dlen);
105703 + dp = dbuf;
105704 + dend = dp + dlen;
105705 +
105706 + tkt_struct_v = ceph_decode_8(&dp);
105707 + if (tkt_struct_v != 1)
105708 + goto bad;
105709 +
105710 + memcpy(&old_key, &th->session_key, sizeof(old_key));
105711 + ret = ceph_crypto_key_decode(&new_session_key, &dp, dend);
105712 + if (ret)
105713 + goto out;
105714 +
105715 + ceph_decode_copy(&dp, &new_validity, sizeof(new_validity));
105716 + ceph_decode_timespec(&validity, &new_validity);
105717 + new_expires = get_seconds() + validity.tv_sec;
105718 + new_renew_after = new_expires - (validity.tv_sec / 4);
105719 + dout(" expires=%lu renew_after=%lu\n", new_expires,
105720 + new_renew_after);
105721 +
105722 + /* ticket blob for service */
105723 + ceph_decode_8_safe(p, end, is_enc, bad);
105724 + if (is_enc) {
105725 + /* encrypted */
105726 + dout(" encrypted ticket\n");
105727 + dlen = ceph_x_decrypt(&old_key, p, end, &ticket_buf, 0);
105728 + if (dlen < 0) {
105729 + ret = dlen;
105730 + goto out;
105731 + }
105732 + tp = ticket_buf;
105733 + dlen = ceph_decode_32(&tp);
105734 + } else {
105735 + /* unencrypted */
105736 + ceph_decode_32_safe(p, end, dlen, bad);
105737 + ticket_buf = kmalloc(dlen, GFP_NOFS);
105738 + if (!ticket_buf) {
105739 + ret = -ENOMEM;
105740 + goto out;
105741 + }
105742 + tp = ticket_buf;
105743 + ceph_decode_need(p, end, dlen, bad);
105744 + ceph_decode_copy(p, ticket_buf, dlen);
105745 + }
105746 + tpend = tp + dlen;
105747 + dout(" ticket blob is %d bytes\n", dlen);
105748 + ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad);
105749 + blob_struct_v = ceph_decode_8(&tp);
105750 + new_secret_id = ceph_decode_64(&tp);
105751 + ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend);
105752 + if (ret)
105753 + goto out;
105754 +
105755 + /* all is well, update our ticket */
105756 + ceph_crypto_key_destroy(&th->session_key);
105757 + if (th->ticket_blob)
105758 + ceph_buffer_put(th->ticket_blob);
105759 + th->session_key = new_session_key;
105760 + th->ticket_blob = new_ticket_blob;
105761 + th->validity = new_validity;
105762 + th->secret_id = new_secret_id;
105763 + th->expires = new_expires;
105764 + th->renew_after = new_renew_after;
105765 + dout(" got ticket service %d (%s) secret_id %lld len %d\n",
105766 + type, ceph_entity_type_name(type), th->secret_id,
105767 + (int)th->ticket_blob->vec.iov_len);
105768 + xi->have_keys |= th->service;
105769 +
105770 +out:
105771 + kfree(ticket_buf);
105772 + kfree(dbuf);
105773 + return ret;
105774 +
105775 +bad:
105776 + ret = -EINVAL;
105777 + goto out;
105778 +}
105779 +
105780 static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
105781 struct ceph_crypto_key *secret,
105782 void *buf, void *end)
105783 {
105784 - struct ceph_x_info *xi = ac->private;
105785 - int num;
105786 void *p = buf;
105787 - int ret;
105788 - char *dbuf;
105789 - char *ticket_buf;
105790 u8 reply_struct_v;
105791 + u32 num;
105792 + int ret;
105793
105794 - dbuf = kmalloc(TEMP_TICKET_BUF_LEN, GFP_NOFS);
105795 - if (!dbuf)
105796 - return -ENOMEM;
105797 -
105798 - ret = -ENOMEM;
105799 - ticket_buf = kmalloc(TEMP_TICKET_BUF_LEN, GFP_NOFS);
105800 - if (!ticket_buf)
105801 - goto out_dbuf;
105802 -
105803 - ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
105804 - reply_struct_v = ceph_decode_8(&p);
105805 + ceph_decode_8_safe(&p, end, reply_struct_v, bad);
105806 if (reply_struct_v != 1)
105807 - goto bad;
105808 - num = ceph_decode_32(&p);
105809 + return -EINVAL;
105810 +
105811 + ceph_decode_32_safe(&p, end, num, bad);
105812 dout("%d tickets\n", num);
105813 +
105814 while (num--) {
105815 - int type;
105816 - u8 tkt_struct_v, blob_struct_v;
105817 - struct ceph_x_ticket_handler *th;
105818 - void *dp, *dend;
105819 - int dlen;
105820 - char is_enc;
105821 - struct timespec validity;
105822 - struct ceph_crypto_key old_key;
105823 - void *tp, *tpend;
105824 - struct ceph_timespec new_validity;
105825 - struct ceph_crypto_key new_session_key;
105826 - struct ceph_buffer *new_ticket_blob;
105827 - unsigned long new_expires, new_renew_after;
105828 - u64 new_secret_id;
105829 -
105830 - ceph_decode_need(&p, end, sizeof(u32) + 1, bad);
105831 -
105832 - type = ceph_decode_32(&p);
105833 - dout(" ticket type %d %s\n", type, ceph_entity_type_name(type));
105834 -
105835 - tkt_struct_v = ceph_decode_8(&p);
105836 - if (tkt_struct_v != 1)
105837 - goto bad;
105838 -
105839 - th = get_ticket_handler(ac, type);
105840 - if (IS_ERR(th)) {
105841 - ret = PTR_ERR(th);
105842 - goto out;
105843 - }
105844 -
105845 - /* blob for me */
105846 - dlen = ceph_x_decrypt(secret, &p, end, dbuf,
105847 - TEMP_TICKET_BUF_LEN);
105848 - if (dlen <= 0) {
105849 - ret = dlen;
105850 - goto out;
105851 - }
105852 - dout(" decrypted %d bytes\n", dlen);
105853 - dend = dbuf + dlen;
105854 - dp = dbuf;
105855 -
105856 - tkt_struct_v = ceph_decode_8(&dp);
105857 - if (tkt_struct_v != 1)
105858 - goto bad;
105859 -
105860 - memcpy(&old_key, &th->session_key, sizeof(old_key));
105861 - ret = ceph_crypto_key_decode(&new_session_key, &dp, dend);
105862 + ret = process_one_ticket(ac, secret, &p, end);
105863 if (ret)
105864 - goto out;
105865 -
105866 - ceph_decode_copy(&dp, &new_validity, sizeof(new_validity));
105867 - ceph_decode_timespec(&validity, &new_validity);
105868 - new_expires = get_seconds() + validity.tv_sec;
105869 - new_renew_after = new_expires - (validity.tv_sec / 4);
105870 - dout(" expires=%lu renew_after=%lu\n", new_expires,
105871 - new_renew_after);
105872 -
105873 - /* ticket blob for service */
105874 - ceph_decode_8_safe(&p, end, is_enc, bad);
105875 - tp = ticket_buf;
105876 - if (is_enc) {
105877 - /* encrypted */
105878 - dout(" encrypted ticket\n");
105879 - dlen = ceph_x_decrypt(&old_key, &p, end, ticket_buf,
105880 - TEMP_TICKET_BUF_LEN);
105881 - if (dlen < 0) {
105882 - ret = dlen;
105883 - goto out;
105884 - }
105885 - dlen = ceph_decode_32(&tp);
105886 - } else {
105887 - /* unencrypted */
105888 - ceph_decode_32_safe(&p, end, dlen, bad);
105889 - ceph_decode_need(&p, end, dlen, bad);
105890 - ceph_decode_copy(&p, ticket_buf, dlen);
105891 - }
105892 - tpend = tp + dlen;
105893 - dout(" ticket blob is %d bytes\n", dlen);
105894 - ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad);
105895 - blob_struct_v = ceph_decode_8(&tp);
105896 - new_secret_id = ceph_decode_64(&tp);
105897 - ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend);
105898 - if (ret)
105899 - goto out;
105900 -
105901 - /* all is well, update our ticket */
105902 - ceph_crypto_key_destroy(&th->session_key);
105903 - if (th->ticket_blob)
105904 - ceph_buffer_put(th->ticket_blob);
105905 - th->session_key = new_session_key;
105906 - th->ticket_blob = new_ticket_blob;
105907 - th->validity = new_validity;
105908 - th->secret_id = new_secret_id;
105909 - th->expires = new_expires;
105910 - th->renew_after = new_renew_after;
105911 - dout(" got ticket service %d (%s) secret_id %lld len %d\n",
105912 - type, ceph_entity_type_name(type), th->secret_id,
105913 - (int)th->ticket_blob->vec.iov_len);
105914 - xi->have_keys |= th->service;
105915 + return ret;
105916 }
105917
105918 - ret = 0;
105919 -out:
105920 - kfree(ticket_buf);
105921 -out_dbuf:
105922 - kfree(dbuf);
105923 - return ret;
105924 + return 0;
105925
105926 bad:
105927 - ret = -EINVAL;
105928 - goto out;
105929 + return -EINVAL;
105930 }
105931
105932 static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
105933 @@ -583,13 +596,14 @@ static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
105934 struct ceph_x_ticket_handler *th;
105935 int ret = 0;
105936 struct ceph_x_authorize_reply reply;
105937 + void *preply = &reply;
105938 void *p = au->reply_buf;
105939 void *end = p + sizeof(au->reply_buf);
105940
105941 th = get_ticket_handler(ac, au->service);
105942 if (IS_ERR(th))
105943 return PTR_ERR(th);
105944 - ret = ceph_x_decrypt(&th->session_key, &p, end, &reply, sizeof(reply));
105945 + ret = ceph_x_decrypt(&th->session_key, &p, end, &preply, sizeof(reply));
105946 if (ret < 0)
105947 return ret;
105948 if (ret != sizeof(reply))
105949 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
105950 index 1948d59..9e854d5 100644
105951 --- a/net/ceph/messenger.c
105952 +++ b/net/ceph/messenger.c
105953 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
105954 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
105955
105956 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
105957 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
105958 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
105959
105960 static struct page *zero_page; /* used in certain error cases */
105961
105962 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
105963 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
105964 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
105965
105966 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
105967 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
105968 s = addr_str[i];
105969
105970 switch (ss->ss_family) {
105971 diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
105972 index 067d3af..61fcfc3 100644
105973 --- a/net/ceph/mon_client.c
105974 +++ b/net/ceph/mon_client.c
105975 @@ -1181,7 +1181,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
105976 if (!m) {
105977 pr_info("alloc_msg unknown type %d\n", type);
105978 *skip = 1;
105979 + } else if (front_len > m->front_alloc_len) {
105980 + pr_warning("mon_alloc_msg front %d > prealloc %d (%u#%llu)\n",
105981 + front_len, m->front_alloc_len,
105982 + (unsigned int)con->peer_name.type,
105983 + le64_to_cpu(con->peer_name.num));
105984 + ceph_msg_put(m);
105985 + m = ceph_msg_new(type, front_len, GFP_NOFS, false);
105986 }
105987 +
105988 return m;
105989 }
105990
105991 diff --git a/net/compat.c b/net/compat.c
105992 index bc8aeef..f9c070c 100644
105993 --- a/net/compat.c
105994 +++ b/net/compat.c
105995 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
105996 return -EFAULT;
105997 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
105998 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
105999 - kmsg->msg_name = compat_ptr(tmp1);
106000 - kmsg->msg_iov = compat_ptr(tmp2);
106001 - kmsg->msg_control = compat_ptr(tmp3);
106002 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
106003 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
106004 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
106005 return 0;
106006 }
106007
106008 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
106009
106010 if (kern_msg->msg_name && kern_msg->msg_namelen) {
106011 if (mode == VERIFY_READ) {
106012 - int err = move_addr_to_kernel(kern_msg->msg_name,
106013 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
106014 kern_msg->msg_namelen,
106015 kern_address);
106016 if (err < 0)
106017 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
106018 }
106019
106020 tot_len = iov_from_user_compat_to_kern(kern_iov,
106021 - (struct compat_iovec __user *)kern_msg->msg_iov,
106022 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
106023 kern_msg->msg_iovlen);
106024 if (tot_len >= 0)
106025 kern_msg->msg_iov = kern_iov;
106026 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
106027
106028 #define CMSG_COMPAT_FIRSTHDR(msg) \
106029 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
106030 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
106031 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
106032 (struct compat_cmsghdr __user *)NULL)
106033
106034 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
106035 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
106036 (ucmlen) <= (unsigned long) \
106037 ((mhdr)->msg_controllen - \
106038 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
106039 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
106040
106041 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
106042 struct compat_cmsghdr __user *cmsg, int cmsg_len)
106043 {
106044 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
106045 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
106046 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
106047 msg->msg_controllen)
106048 return NULL;
106049 return (struct compat_cmsghdr __user *)ptr;
106050 @@ -223,7 +223,7 @@ Efault:
106051
106052 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
106053 {
106054 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
106055 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
106056 struct compat_cmsghdr cmhdr;
106057 struct compat_timeval ctv;
106058 struct compat_timespec cts[3];
106059 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
106060
106061 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
106062 {
106063 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
106064 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
106065 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
106066 int fdnum = scm->fp->count;
106067 struct file **fp = scm->fp->fp;
106068 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
106069 return -EFAULT;
106070 old_fs = get_fs();
106071 set_fs(KERNEL_DS);
106072 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
106073 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
106074 set_fs(old_fs);
106075
106076 return err;
106077 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
106078 len = sizeof(ktime);
106079 old_fs = get_fs();
106080 set_fs(KERNEL_DS);
106081 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
106082 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
106083 set_fs(old_fs);
106084
106085 if (!err) {
106086 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
106087 case MCAST_JOIN_GROUP:
106088 case MCAST_LEAVE_GROUP:
106089 {
106090 - struct compat_group_req __user *gr32 = (void *)optval;
106091 + struct compat_group_req __user *gr32 = (void __user *)optval;
106092 struct group_req __user *kgr =
106093 compat_alloc_user_space(sizeof(struct group_req));
106094 u32 interface;
106095 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
106096 case MCAST_BLOCK_SOURCE:
106097 case MCAST_UNBLOCK_SOURCE:
106098 {
106099 - struct compat_group_source_req __user *gsr32 = (void *)optval;
106100 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
106101 struct group_source_req __user *kgsr = compat_alloc_user_space(
106102 sizeof(struct group_source_req));
106103 u32 interface;
106104 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
106105 }
106106 case MCAST_MSFILTER:
106107 {
106108 - struct compat_group_filter __user *gf32 = (void *)optval;
106109 + struct compat_group_filter __user *gf32 = (void __user *)optval;
106110 struct group_filter __user *kgf;
106111 u32 interface, fmode, numsrc;
106112
106113 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
106114 char __user *optval, int __user *optlen,
106115 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
106116 {
106117 - struct compat_group_filter __user *gf32 = (void *)optval;
106118 + struct compat_group_filter __user *gf32 = (void __user *)optval;
106119 struct group_filter __user *kgf;
106120 int __user *koptlen;
106121 u32 interface, fmode, numsrc;
106122 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
106123
106124 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
106125 return -EINVAL;
106126 - if (copy_from_user(a, args, nas[call]))
106127 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
106128 return -EFAULT;
106129 a0 = a[0];
106130 a1 = a[1];
106131 diff --git a/net/core/Makefile b/net/core/Makefile
106132 index 71093d9..a8a035b 100644
106133 --- a/net/core/Makefile
106134 +++ b/net/core/Makefile
106135 @@ -21,6 +21,5 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o
106136 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
106137 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
106138 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
106139 -obj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o
106140 obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
106141 obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
106142 diff --git a/net/core/datagram.c b/net/core/datagram.c
106143 index 488dd1a..7179f0f 100644
106144 --- a/net/core/datagram.c
106145 +++ b/net/core/datagram.c
106146 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
106147 }
106148
106149 kfree_skb(skb);
106150 - atomic_inc(&sk->sk_drops);
106151 + atomic_inc_unchecked(&sk->sk_drops);
106152 sk_mem_reclaim_partial(sk);
106153
106154 return err;
106155 diff --git a/net/core/dev.c b/net/core/dev.c
106156 index 367a586..ef2fe17 100644
106157 --- a/net/core/dev.c
106158 +++ b/net/core/dev.c
106159 @@ -1672,14 +1672,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
106160 {
106161 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
106162 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
106163 - atomic_long_inc(&dev->rx_dropped);
106164 + atomic_long_inc_unchecked(&dev->rx_dropped);
106165 kfree_skb(skb);
106166 return NET_RX_DROP;
106167 }
106168 }
106169
106170 if (unlikely(!is_skb_forwardable(dev, skb))) {
106171 - atomic_long_inc(&dev->rx_dropped);
106172 + atomic_long_inc_unchecked(&dev->rx_dropped);
106173 kfree_skb(skb);
106174 return NET_RX_DROP;
106175 }
106176 @@ -2476,7 +2476,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
106177
106178 struct dev_gso_cb {
106179 void (*destructor)(struct sk_buff *skb);
106180 -};
106181 +} __no_const;
106182
106183 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
106184
106185 @@ -2932,7 +2932,7 @@ recursion_alert:
106186 rc = -ENETDOWN;
106187 rcu_read_unlock_bh();
106188
106189 - atomic_long_inc(&dev->tx_dropped);
106190 + atomic_long_inc_unchecked(&dev->tx_dropped);
106191 kfree_skb(skb);
106192 return rc;
106193 out:
106194 @@ -3276,7 +3276,7 @@ enqueue:
106195
106196 local_irq_restore(flags);
106197
106198 - atomic_long_inc(&skb->dev->rx_dropped);
106199 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
106200 kfree_skb(skb);
106201 return NET_RX_DROP;
106202 }
106203 @@ -3353,7 +3353,7 @@ int netif_rx_ni(struct sk_buff *skb)
106204 }
106205 EXPORT_SYMBOL(netif_rx_ni);
106206
106207 -static void net_tx_action(struct softirq_action *h)
106208 +static __latent_entropy void net_tx_action(void)
106209 {
106210 struct softnet_data *sd = &__get_cpu_var(softnet_data);
106211
106212 @@ -3686,7 +3686,7 @@ ncls:
106213 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
106214 } else {
106215 drop:
106216 - atomic_long_inc(&skb->dev->rx_dropped);
106217 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
106218 kfree_skb(skb);
106219 /* Jamal, now you will not able to escape explaining
106220 * me how you were going to use this. :-)
106221 @@ -4406,7 +4406,7 @@ void netif_napi_del(struct napi_struct *napi)
106222 }
106223 EXPORT_SYMBOL(netif_napi_del);
106224
106225 -static void net_rx_action(struct softirq_action *h)
106226 +static __latent_entropy void net_rx_action(void)
106227 {
106228 struct softnet_data *sd = &__get_cpu_var(softnet_data);
106229 unsigned long time_limit = jiffies + 2;
106230 @@ -6403,8 +6403,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
106231 } else {
106232 netdev_stats_to_stats64(storage, &dev->stats);
106233 }
106234 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
106235 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
106236 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
106237 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
106238 return storage;
106239 }
106240 EXPORT_SYMBOL(dev_get_stats);
106241 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
106242 index cf999e0..c59a975 100644
106243 --- a/net/core/dev_ioctl.c
106244 +++ b/net/core/dev_ioctl.c
106245 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
106246 if (no_module && capable(CAP_NET_ADMIN))
106247 no_module = request_module("netdev-%s", name);
106248 if (no_module && capable(CAP_SYS_MODULE)) {
106249 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
106250 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
106251 +#else
106252 if (!request_module("%s", name))
106253 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
106254 name);
106255 +#endif
106256 }
106257 }
106258 EXPORT_SYMBOL(dev_load);
106259 diff --git a/net/core/filter.c b/net/core/filter.c
106260 index 1dbf646..0f95703 100644
106261 --- a/net/core/filter.c
106262 +++ b/net/core/filter.c
106263 @@ -1,16 +1,11 @@
106264 /*
106265 * Linux Socket Filter - Kernel level socket filtering
106266 *
106267 - * Based on the design of the Berkeley Packet Filter. The new
106268 - * internal format has been designed by PLUMgrid:
106269 + * Author:
106270 + * Jay Schulist <jschlst@samba.org>
106271 *
106272 - * Copyright (c) 2011 - 2014 PLUMgrid, http://plumgrid.com
106273 - *
106274 - * Authors:
106275 - *
106276 - * Jay Schulist <jschlst@samba.org>
106277 - * Alexei Starovoitov <ast@plumgrid.com>
106278 - * Daniel Borkmann <dborkman@redhat.com>
106279 + * Based on the design of:
106280 + * - The Berkeley Packet Filter
106281 *
106282 * This program is free software; you can redistribute it and/or
106283 * modify it under the terms of the GNU General Public License
106284 @@ -45,27 +40,6 @@
106285 #include <linux/seccomp.h>
106286 #include <linux/if_vlan.h>
106287
106288 -/* Registers */
106289 -#define BPF_R0 regs[BPF_REG_0]
106290 -#define BPF_R1 regs[BPF_REG_1]
106291 -#define BPF_R2 regs[BPF_REG_2]
106292 -#define BPF_R3 regs[BPF_REG_3]
106293 -#define BPF_R4 regs[BPF_REG_4]
106294 -#define BPF_R5 regs[BPF_REG_5]
106295 -#define BPF_R6 regs[BPF_REG_6]
106296 -#define BPF_R7 regs[BPF_REG_7]
106297 -#define BPF_R8 regs[BPF_REG_8]
106298 -#define BPF_R9 regs[BPF_REG_9]
106299 -#define BPF_R10 regs[BPF_REG_10]
106300 -
106301 -/* Named registers */
106302 -#define DST regs[insn->dst_reg]
106303 -#define SRC regs[insn->src_reg]
106304 -#define FP regs[BPF_REG_FP]
106305 -#define ARG1 regs[BPF_REG_ARG1]
106306 -#define CTX regs[BPF_REG_CTX]
106307 -#define IMM insn->imm
106308 -
106309 /* No hurry in this branch
106310 *
106311 * Exported for the bpf jit load helper.
106312 @@ -78,9 +52,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
106313 ptr = skb_network_header(skb) + k - SKF_NET_OFF;
106314 else if (k >= SKF_LL_OFF)
106315 ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
106316 +
106317 if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
106318 return ptr;
106319 -
106320 return NULL;
106321 }
106322
106323 @@ -89,7 +63,6 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
106324 {
106325 if (k >= 0)
106326 return skb_header_pointer(skb, k, size, buffer);
106327 -
106328 return bpf_internal_load_pointer_neg_helper(skb, k, size);
106329 }
106330
106331 @@ -135,960 +108,309 @@ int sk_filter(struct sock *sk, struct sk_buff *skb)
106332 }
106333 EXPORT_SYMBOL(sk_filter);
106334
106335 -/* Base function for offset calculation. Needs to go into .text section,
106336 - * therefore keeping it non-static as well; will also be used by JITs
106337 - * anyway later on, so do not let the compiler omit it.
106338 - */
106339 -noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
106340 -{
106341 - return 0;
106342 -}
106343 -
106344 /**
106345 - * __sk_run_filter - run a filter on a given context
106346 - * @ctx: buffer to run the filter on
106347 - * @insn: filter to apply
106348 + * sk_run_filter - run a filter on a socket
106349 + * @skb: buffer to run the filter on
106350 + * @fentry: filter to apply
106351 *
106352 - * Decode and apply filter instructions to the skb->data. Return length to
106353 - * keep, 0 for none. @ctx is the data we are operating on, @insn is the
106354 - * array of filter instructions.
106355 + * Decode and apply filter instructions to the skb->data.
106356 + * Return length to keep, 0 for none. @skb is the data we are
106357 + * filtering, @filter is the array of filter instructions.
106358 + * Because all jumps are guaranteed to be before last instruction,
106359 + * and last instruction guaranteed to be a RET, we dont need to check
106360 + * flen. (We used to pass to this function the length of filter)
106361 */
106362 -static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn)
106363 +unsigned int sk_run_filter(const struct sk_buff *skb,
106364 + const struct sock_filter *fentry)
106365 {
106366 - u64 stack[MAX_BPF_STACK / sizeof(u64)];
106367 - u64 regs[MAX_BPF_REG], tmp;
106368 - static const void *jumptable[256] = {
106369 - [0 ... 255] = &&default_label,
106370 - /* Now overwrite non-defaults ... */
106371 - /* 32 bit ALU operations */
106372 - [BPF_ALU | BPF_ADD | BPF_X] = &&ALU_ADD_X,
106373 - [BPF_ALU | BPF_ADD | BPF_K] = &&ALU_ADD_K,
106374 - [BPF_ALU | BPF_SUB | BPF_X] = &&ALU_SUB_X,
106375 - [BPF_ALU | BPF_SUB | BPF_K] = &&ALU_SUB_K,
106376 - [BPF_ALU | BPF_AND | BPF_X] = &&ALU_AND_X,
106377 - [BPF_ALU | BPF_AND | BPF_K] = &&ALU_AND_K,
106378 - [BPF_ALU | BPF_OR | BPF_X] = &&ALU_OR_X,
106379 - [BPF_ALU | BPF_OR | BPF_K] = &&ALU_OR_K,
106380 - [BPF_ALU | BPF_LSH | BPF_X] = &&ALU_LSH_X,
106381 - [BPF_ALU | BPF_LSH | BPF_K] = &&ALU_LSH_K,
106382 - [BPF_ALU | BPF_RSH | BPF_X] = &&ALU_RSH_X,
106383 - [BPF_ALU | BPF_RSH | BPF_K] = &&ALU_RSH_K,
106384 - [BPF_ALU | BPF_XOR | BPF_X] = &&ALU_XOR_X,
106385 - [BPF_ALU | BPF_XOR | BPF_K] = &&ALU_XOR_K,
106386 - [BPF_ALU | BPF_MUL | BPF_X] = &&ALU_MUL_X,
106387 - [BPF_ALU | BPF_MUL | BPF_K] = &&ALU_MUL_K,
106388 - [BPF_ALU | BPF_MOV | BPF_X] = &&ALU_MOV_X,
106389 - [BPF_ALU | BPF_MOV | BPF_K] = &&ALU_MOV_K,
106390 - [BPF_ALU | BPF_DIV | BPF_X] = &&ALU_DIV_X,
106391 - [BPF_ALU | BPF_DIV | BPF_K] = &&ALU_DIV_K,
106392 - [BPF_ALU | BPF_MOD | BPF_X] = &&ALU_MOD_X,
106393 - [BPF_ALU | BPF_MOD | BPF_K] = &&ALU_MOD_K,
106394 - [BPF_ALU | BPF_NEG] = &&ALU_NEG,
106395 - [BPF_ALU | BPF_END | BPF_TO_BE] = &&ALU_END_TO_BE,
106396 - [BPF_ALU | BPF_END | BPF_TO_LE] = &&ALU_END_TO_LE,
106397 - /* 64 bit ALU operations */
106398 - [BPF_ALU64 | BPF_ADD | BPF_X] = &&ALU64_ADD_X,
106399 - [BPF_ALU64 | BPF_ADD | BPF_K] = &&ALU64_ADD_K,
106400 - [BPF_ALU64 | BPF_SUB | BPF_X] = &&ALU64_SUB_X,
106401 - [BPF_ALU64 | BPF_SUB | BPF_K] = &&ALU64_SUB_K,
106402 - [BPF_ALU64 | BPF_AND | BPF_X] = &&ALU64_AND_X,
106403 - [BPF_ALU64 | BPF_AND | BPF_K] = &&ALU64_AND_K,
106404 - [BPF_ALU64 | BPF_OR | BPF_X] = &&ALU64_OR_X,
106405 - [BPF_ALU64 | BPF_OR | BPF_K] = &&ALU64_OR_K,
106406 - [BPF_ALU64 | BPF_LSH | BPF_X] = &&ALU64_LSH_X,
106407 - [BPF_ALU64 | BPF_LSH | BPF_K] = &&ALU64_LSH_K,
106408 - [BPF_ALU64 | BPF_RSH | BPF_X] = &&ALU64_RSH_X,
106409 - [BPF_ALU64 | BPF_RSH | BPF_K] = &&ALU64_RSH_K,
106410 - [BPF_ALU64 | BPF_XOR | BPF_X] = &&ALU64_XOR_X,
106411 - [BPF_ALU64 | BPF_XOR | BPF_K] = &&ALU64_XOR_K,
106412 - [BPF_ALU64 | BPF_MUL | BPF_X] = &&ALU64_MUL_X,
106413 - [BPF_ALU64 | BPF_MUL | BPF_K] = &&ALU64_MUL_K,
106414 - [BPF_ALU64 | BPF_MOV | BPF_X] = &&ALU64_MOV_X,
106415 - [BPF_ALU64 | BPF_MOV | BPF_K] = &&ALU64_MOV_K,
106416 - [BPF_ALU64 | BPF_ARSH | BPF_X] = &&ALU64_ARSH_X,
106417 - [BPF_ALU64 | BPF_ARSH | BPF_K] = &&ALU64_ARSH_K,
106418 - [BPF_ALU64 | BPF_DIV | BPF_X] = &&ALU64_DIV_X,
106419 - [BPF_ALU64 | BPF_DIV | BPF_K] = &&ALU64_DIV_K,
106420 - [BPF_ALU64 | BPF_MOD | BPF_X] = &&ALU64_MOD_X,
106421 - [BPF_ALU64 | BPF_MOD | BPF_K] = &&ALU64_MOD_K,
106422 - [BPF_ALU64 | BPF_NEG] = &&ALU64_NEG,
106423 - /* Call instruction */
106424 - [BPF_JMP | BPF_CALL] = &&JMP_CALL,
106425 - /* Jumps */
106426 - [BPF_JMP | BPF_JA] = &&JMP_JA,
106427 - [BPF_JMP | BPF_JEQ | BPF_X] = &&JMP_JEQ_X,
106428 - [BPF_JMP | BPF_JEQ | BPF_K] = &&JMP_JEQ_K,
106429 - [BPF_JMP | BPF_JNE | BPF_X] = &&JMP_JNE_X,
106430 - [BPF_JMP | BPF_JNE | BPF_K] = &&JMP_JNE_K,
106431 - [BPF_JMP | BPF_JGT | BPF_X] = &&JMP_JGT_X,
106432 - [BPF_JMP | BPF_JGT | BPF_K] = &&JMP_JGT_K,
106433 - [BPF_JMP | BPF_JGE | BPF_X] = &&JMP_JGE_X,
106434 - [BPF_JMP | BPF_JGE | BPF_K] = &&JMP_JGE_K,
106435 - [BPF_JMP | BPF_JSGT | BPF_X] = &&JMP_JSGT_X,
106436 - [BPF_JMP | BPF_JSGT | BPF_K] = &&JMP_JSGT_K,
106437 - [BPF_JMP | BPF_JSGE | BPF_X] = &&JMP_JSGE_X,
106438 - [BPF_JMP | BPF_JSGE | BPF_K] = &&JMP_JSGE_K,
106439 - [BPF_JMP | BPF_JSET | BPF_X] = &&JMP_JSET_X,
106440 - [BPF_JMP | BPF_JSET | BPF_K] = &&JMP_JSET_K,
106441 - /* Program return */
106442 - [BPF_JMP | BPF_EXIT] = &&JMP_EXIT,
106443 - /* Store instructions */
106444 - [BPF_STX | BPF_MEM | BPF_B] = &&STX_MEM_B,
106445 - [BPF_STX | BPF_MEM | BPF_H] = &&STX_MEM_H,
106446 - [BPF_STX | BPF_MEM | BPF_W] = &&STX_MEM_W,
106447 - [BPF_STX | BPF_MEM | BPF_DW] = &&STX_MEM_DW,
106448 - [BPF_STX | BPF_XADD | BPF_W] = &&STX_XADD_W,
106449 - [BPF_STX | BPF_XADD | BPF_DW] = &&STX_XADD_DW,
106450 - [BPF_ST | BPF_MEM | BPF_B] = &&ST_MEM_B,
106451 - [BPF_ST | BPF_MEM | BPF_H] = &&ST_MEM_H,
106452 - [BPF_ST | BPF_MEM | BPF_W] = &&ST_MEM_W,
106453 - [BPF_ST | BPF_MEM | BPF_DW] = &&ST_MEM_DW,
106454 - /* Load instructions */
106455 - [BPF_LDX | BPF_MEM | BPF_B] = &&LDX_MEM_B,
106456 - [BPF_LDX | BPF_MEM | BPF_H] = &&LDX_MEM_H,
106457 - [BPF_LDX | BPF_MEM | BPF_W] = &&LDX_MEM_W,
106458 - [BPF_LDX | BPF_MEM | BPF_DW] = &&LDX_MEM_DW,
106459 - [BPF_LD | BPF_ABS | BPF_W] = &&LD_ABS_W,
106460 - [BPF_LD | BPF_ABS | BPF_H] = &&LD_ABS_H,
106461 - [BPF_LD | BPF_ABS | BPF_B] = &&LD_ABS_B,
106462 - [BPF_LD | BPF_IND | BPF_W] = &&LD_IND_W,
106463 - [BPF_LD | BPF_IND | BPF_H] = &&LD_IND_H,
106464 - [BPF_LD | BPF_IND | BPF_B] = &&LD_IND_B,
106465 - };
106466 void *ptr;
106467 - int off;
106468 -
106469 -#define CONT ({ insn++; goto select_insn; })
106470 -#define CONT_JMP ({ insn++; goto select_insn; })
106471 -
106472 - FP = (u64) (unsigned long) &stack[ARRAY_SIZE(stack)];
106473 - ARG1 = (u64) (unsigned long) ctx;
106474 -
106475 - /* Registers used in classic BPF programs need to be reset first. */
106476 - regs[BPF_REG_A] = 0;
106477 - regs[BPF_REG_X] = 0;
106478 -
106479 -select_insn:
106480 - goto *jumptable[insn->code];
106481 -
106482 - /* ALU */
106483 -#define ALU(OPCODE, OP) \
106484 - ALU64_##OPCODE##_X: \
106485 - DST = DST OP SRC; \
106486 - CONT; \
106487 - ALU_##OPCODE##_X: \
106488 - DST = (u32) DST OP (u32) SRC; \
106489 - CONT; \
106490 - ALU64_##OPCODE##_K: \
106491 - DST = DST OP IMM; \
106492 - CONT; \
106493 - ALU_##OPCODE##_K: \
106494 - DST = (u32) DST OP (u32) IMM; \
106495 - CONT;
106496 -
106497 - ALU(ADD, +)
106498 - ALU(SUB, -)
106499 - ALU(AND, &)
106500 - ALU(OR, |)
106501 - ALU(LSH, <<)
106502 - ALU(RSH, >>)
106503 - ALU(XOR, ^)
106504 - ALU(MUL, *)
106505 -#undef ALU
106506 - ALU_NEG:
106507 - DST = (u32) -DST;
106508 - CONT;
106509 - ALU64_NEG:
106510 - DST = -DST;
106511 - CONT;
106512 - ALU_MOV_X:
106513 - DST = (u32) SRC;
106514 - CONT;
106515 - ALU_MOV_K:
106516 - DST = (u32) IMM;
106517 - CONT;
106518 - ALU64_MOV_X:
106519 - DST = SRC;
106520 - CONT;
106521 - ALU64_MOV_K:
106522 - DST = IMM;
106523 - CONT;
106524 - ALU64_ARSH_X:
106525 - (*(s64 *) &DST) >>= SRC;
106526 - CONT;
106527 - ALU64_ARSH_K:
106528 - (*(s64 *) &DST) >>= IMM;
106529 - CONT;
106530 - ALU64_MOD_X:
106531 - if (unlikely(SRC == 0))
106532 - return 0;
106533 - tmp = DST;
106534 - DST = do_div(tmp, SRC);
106535 - CONT;
106536 - ALU_MOD_X:
106537 - if (unlikely(SRC == 0))
106538 - return 0;
106539 - tmp = (u32) DST;
106540 - DST = do_div(tmp, (u32) SRC);
106541 - CONT;
106542 - ALU64_MOD_K:
106543 - tmp = DST;
106544 - DST = do_div(tmp, IMM);
106545 - CONT;
106546 - ALU_MOD_K:
106547 - tmp = (u32) DST;
106548 - DST = do_div(tmp, (u32) IMM);
106549 - CONT;
106550 - ALU64_DIV_X:
106551 - if (unlikely(SRC == 0))
106552 - return 0;
106553 - do_div(DST, SRC);
106554 - CONT;
106555 - ALU_DIV_X:
106556 - if (unlikely(SRC == 0))
106557 - return 0;
106558 - tmp = (u32) DST;
106559 - do_div(tmp, (u32) SRC);
106560 - DST = (u32) tmp;
106561 - CONT;
106562 - ALU64_DIV_K:
106563 - do_div(DST, IMM);
106564 - CONT;
106565 - ALU_DIV_K:
106566 - tmp = (u32) DST;
106567 - do_div(tmp, (u32) IMM);
106568 - DST = (u32) tmp;
106569 - CONT;
106570 - ALU_END_TO_BE:
106571 - switch (IMM) {
106572 - case 16:
106573 - DST = (__force u16) cpu_to_be16(DST);
106574 - break;
106575 - case 32:
106576 - DST = (__force u32) cpu_to_be32(DST);
106577 - break;
106578 - case 64:
106579 - DST = (__force u64) cpu_to_be64(DST);
106580 - break;
106581 - }
106582 - CONT;
106583 - ALU_END_TO_LE:
106584 - switch (IMM) {
106585 - case 16:
106586 - DST = (__force u16) cpu_to_le16(DST);
106587 - break;
106588 - case 32:
106589 - DST = (__force u32) cpu_to_le32(DST);
106590 - break;
106591 - case 64:
106592 - DST = (__force u64) cpu_to_le64(DST);
106593 - break;
106594 - }
106595 - CONT;
106596 -
106597 - /* CALL */
106598 - JMP_CALL:
106599 - /* Function call scratches BPF_R1-BPF_R5 registers,
106600 - * preserves BPF_R6-BPF_R9, and stores return value
106601 - * into BPF_R0.
106602 - */
106603 - BPF_R0 = (__bpf_call_base + insn->imm)(BPF_R1, BPF_R2, BPF_R3,
106604 - BPF_R4, BPF_R5);
106605 - CONT;
106606 -
106607 - /* JMP */
106608 - JMP_JA:
106609 - insn += insn->off;
106610 - CONT;
106611 - JMP_JEQ_X:
106612 - if (DST == SRC) {
106613 - insn += insn->off;
106614 - CONT_JMP;
106615 - }
106616 - CONT;
106617 - JMP_JEQ_K:
106618 - if (DST == IMM) {
106619 - insn += insn->off;
106620 - CONT_JMP;
106621 - }
106622 - CONT;
106623 - JMP_JNE_X:
106624 - if (DST != SRC) {
106625 - insn += insn->off;
106626 - CONT_JMP;
106627 - }
106628 - CONT;
106629 - JMP_JNE_K:
106630 - if (DST != IMM) {
106631 - insn += insn->off;
106632 - CONT_JMP;
106633 - }
106634 - CONT;
106635 - JMP_JGT_X:
106636 - if (DST > SRC) {
106637 - insn += insn->off;
106638 - CONT_JMP;
106639 - }
106640 - CONT;
106641 - JMP_JGT_K:
106642 - if (DST > IMM) {
106643 - insn += insn->off;
106644 - CONT_JMP;
106645 - }
106646 - CONT;
106647 - JMP_JGE_X:
106648 - if (DST >= SRC) {
106649 - insn += insn->off;
106650 - CONT_JMP;
106651 - }
106652 - CONT;
106653 - JMP_JGE_K:
106654 - if (DST >= IMM) {
106655 - insn += insn->off;
106656 - CONT_JMP;
106657 - }
106658 - CONT;
106659 - JMP_JSGT_X:
106660 - if (((s64) DST) > ((s64) SRC)) {
106661 - insn += insn->off;
106662 - CONT_JMP;
106663 - }
106664 - CONT;
106665 - JMP_JSGT_K:
106666 - if (((s64) DST) > ((s64) IMM)) {
106667 - insn += insn->off;
106668 - CONT_JMP;
106669 - }
106670 - CONT;
106671 - JMP_JSGE_X:
106672 - if (((s64) DST) >= ((s64) SRC)) {
106673 - insn += insn->off;
106674 - CONT_JMP;
106675 - }
106676 - CONT;
106677 - JMP_JSGE_K:
106678 - if (((s64) DST) >= ((s64) IMM)) {
106679 - insn += insn->off;
106680 - CONT_JMP;
106681 - }
106682 - CONT;
106683 - JMP_JSET_X:
106684 - if (DST & SRC) {
106685 - insn += insn->off;
106686 - CONT_JMP;
106687 - }
106688 - CONT;
106689 - JMP_JSET_K:
106690 - if (DST & IMM) {
106691 - insn += insn->off;
106692 - CONT_JMP;
106693 - }
106694 - CONT;
106695 - JMP_EXIT:
106696 - return BPF_R0;
106697 -
106698 - /* STX and ST and LDX*/
106699 -#define LDST(SIZEOP, SIZE) \
106700 - STX_MEM_##SIZEOP: \
106701 - *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \
106702 - CONT; \
106703 - ST_MEM_##SIZEOP: \
106704 - *(SIZE *)(unsigned long) (DST + insn->off) = IMM; \
106705 - CONT; \
106706 - LDX_MEM_##SIZEOP: \
106707 - DST = *(SIZE *)(unsigned long) (SRC + insn->off); \
106708 - CONT;
106709 -
106710 - LDST(B, u8)
106711 - LDST(H, u16)
106712 - LDST(W, u32)
106713 - LDST(DW, u64)
106714 -#undef LDST
106715 - STX_XADD_W: /* lock xadd *(u32 *)(dst_reg + off16) += src_reg */
106716 - atomic_add((u32) SRC, (atomic_t *)(unsigned long)
106717 - (DST + insn->off));
106718 - CONT;
106719 - STX_XADD_DW: /* lock xadd *(u64 *)(dst_reg + off16) += src_reg */
106720 - atomic64_add((u64) SRC, (atomic64_t *)(unsigned long)
106721 - (DST + insn->off));
106722 - CONT;
106723 - LD_ABS_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + imm32)) */
106724 - off = IMM;
106725 -load_word:
106726 - /* BPF_LD + BPD_ABS and BPF_LD + BPF_IND insns are
106727 - * only appearing in the programs where ctx ==
106728 - * skb. All programs keep 'ctx' in regs[BPF_REG_CTX]
106729 - * == BPF_R6, sk_convert_filter() saves it in BPF_R6,
106730 - * internal BPF verifier will check that BPF_R6 ==
106731 - * ctx.
106732 - *
106733 - * BPF_ABS and BPF_IND are wrappers of function calls,
106734 - * so they scratch BPF_R1-BPF_R5 registers, preserve
106735 - * BPF_R6-BPF_R9, and store return value into BPF_R0.
106736 - *
106737 - * Implicit input:
106738 - * ctx == skb == BPF_R6 == CTX
106739 - *
106740 - * Explicit input:
106741 - * SRC == any register
106742 - * IMM == 32-bit immediate
106743 - *
106744 - * Output:
106745 - * BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
106746 - */
106747 -
106748 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
106749 - if (likely(ptr != NULL)) {
106750 - BPF_R0 = get_unaligned_be32(ptr);
106751 - CONT;
106752 - }
106753 -
106754 - return 0;
106755 - LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
106756 - off = IMM;
106757 -load_half:
106758 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
106759 - if (likely(ptr != NULL)) {
106760 - BPF_R0 = get_unaligned_be16(ptr);
106761 - CONT;
106762 - }
106763 -
106764 - return 0;
106765 - LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
106766 - off = IMM;
106767 -load_byte:
106768 - ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
106769 - if (likely(ptr != NULL)) {
106770 - BPF_R0 = *(u8 *)ptr;
106771 - CONT;
106772 - }
106773 -
106774 - return 0;
106775 - LD_IND_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + src_reg + imm32)) */
106776 - off = IMM + SRC;
106777 - goto load_word;
106778 - LD_IND_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + src_reg + imm32)) */
106779 - off = IMM + SRC;
106780 - goto load_half;
106781 - LD_IND_B: /* BPF_R0 = *(u8 *) (skb->data + src_reg + imm32) */
106782 - off = IMM + SRC;
106783 - goto load_byte;
106784 -
106785 - default_label:
106786 - /* If we ever reach this, we have a bug somewhere. */
106787 - WARN_RATELIMIT(1, "unknown opcode %02x\n", insn->code);
106788 - return 0;
106789 -}
106790 -
106791 -/* Helper to find the offset of pkt_type in sk_buff structure. We want
106792 - * to make sure its still a 3bit field starting at a byte boundary;
106793 - * taken from arch/x86/net/bpf_jit_comp.c.
106794 - */
106795 -#ifdef __BIG_ENDIAN_BITFIELD
106796 -#define PKT_TYPE_MAX (7 << 5)
106797 + u32 A = 0; /* Accumulator */
106798 + u32 X = 0; /* Index Register */
106799 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
106800 + u32 tmp;
106801 + int k;
106802 +
106803 + /*
106804 + * Process array of filter instructions.
106805 + */
106806 + for (;; fentry++) {
106807 +#if defined(CONFIG_X86_32)
106808 +#define K (fentry->k)
106809 #else
106810 -#define PKT_TYPE_MAX 7
106811 + const u32 K = fentry->k;
106812 #endif
106813 -static unsigned int pkt_type_offset(void)
106814 -{
106815 - struct sk_buff skb_probe = { .pkt_type = ~0, };
106816 - u8 *ct = (u8 *) &skb_probe;
106817 - unsigned int off;
106818
106819 - for (off = 0; off < sizeof(struct sk_buff); off++) {
106820 - if (ct[off] == PKT_TYPE_MAX)
106821 - return off;
106822 - }
106823 -
106824 - pr_err_once("Please fix %s, as pkt_type couldn't be found!\n", __func__);
106825 - return -1;
106826 -}
106827 -
106828 -static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
106829 -{
106830 - return __skb_get_poff((struct sk_buff *)(unsigned long) ctx);
106831 -}
106832 -
106833 -static u64 __skb_get_nlattr(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
106834 -{
106835 - struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
106836 - struct nlattr *nla;
106837 -
106838 - if (skb_is_nonlinear(skb))
106839 - return 0;
106840 -
106841 - if (skb->len < sizeof(struct nlattr))
106842 - return 0;
106843 -
106844 - if (a > skb->len - sizeof(struct nlattr))
106845 - return 0;
106846 -
106847 - nla = nla_find((struct nlattr *) &skb->data[a], skb->len - a, x);
106848 - if (nla)
106849 - return (void *) nla - (void *) skb->data;
106850 -
106851 - return 0;
106852 -}
106853 -
106854 -static u64 __skb_get_nlattr_nest(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
106855 -{
106856 - struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
106857 - struct nlattr *nla;
106858 -
106859 - if (skb_is_nonlinear(skb))
106860 - return 0;
106861 -
106862 - if (skb->len < sizeof(struct nlattr))
106863 - return 0;
106864 -
106865 - if (a > skb->len - sizeof(struct nlattr))
106866 - return 0;
106867 -
106868 - nla = (struct nlattr *) &skb->data[a];
106869 - if (nla->nla_len > skb->len - a)
106870 - return 0;
106871 -
106872 - nla = nla_find_nested(nla, x);
106873 - if (nla)
106874 - return (void *) nla - (void *) skb->data;
106875 -
106876 - return 0;
106877 -}
106878 -
106879 -static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
106880 -{
106881 - return raw_smp_processor_id();
106882 -}
106883 -
106884 -/* note that this only generates 32-bit random numbers */
106885 -static u64 __get_random_u32(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
106886 -{
106887 - return prandom_u32();
106888 -}
106889 -
106890 -static bool convert_bpf_extensions(struct sock_filter *fp,
106891 - struct sock_filter_int **insnp)
106892 -{
106893 - struct sock_filter_int *insn = *insnp;
106894 -
106895 - switch (fp->k) {
106896 - case SKF_AD_OFF + SKF_AD_PROTOCOL:
106897 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, protocol) != 2);
106898 -
106899 - /* A = *(u16 *) (CTX + offsetof(protocol)) */
106900 - *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
106901 - offsetof(struct sk_buff, protocol));
106902 - /* A = ntohs(A) [emitting a nop or swap16] */
106903 - *insn = BPF_ENDIAN(BPF_FROM_BE, BPF_REG_A, 16);
106904 - break;
106905 -
106906 - case SKF_AD_OFF + SKF_AD_PKTTYPE:
106907 - *insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
106908 - pkt_type_offset());
106909 - if (insn->off < 0)
106910 - return false;
106911 - insn++;
106912 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX);
106913 -#ifdef __BIG_ENDIAN_BITFIELD
106914 - insn++;
106915 - *insn = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 5);
106916 -#endif
106917 - break;
106918 -
106919 - case SKF_AD_OFF + SKF_AD_IFINDEX:
106920 - case SKF_AD_OFF + SKF_AD_HATYPE:
106921 - BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
106922 - BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
106923 - BUILD_BUG_ON(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)) < 0);
106924 -
106925 - *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)),
106926 - BPF_REG_TMP, BPF_REG_CTX,
106927 - offsetof(struct sk_buff, dev));
106928 - /* if (tmp != 0) goto pc + 1 */
106929 - *insn++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_TMP, 0, 1);
106930 - *insn++ = BPF_EXIT_INSN();
106931 - if (fp->k == SKF_AD_OFF + SKF_AD_IFINDEX)
106932 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_TMP,
106933 - offsetof(struct net_device, ifindex));
106934 - else
106935 - *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_TMP,
106936 - offsetof(struct net_device, type));
106937 - break;
106938 -
106939 - case SKF_AD_OFF + SKF_AD_MARK:
106940 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, mark) != 4);
106941 -
106942 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
106943 - offsetof(struct sk_buff, mark));
106944 - break;
106945 -
106946 - case SKF_AD_OFF + SKF_AD_RXHASH:
106947 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, hash) != 4);
106948 -
106949 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX,
106950 - offsetof(struct sk_buff, hash));
106951 - break;
106952 -
106953 - case SKF_AD_OFF + SKF_AD_QUEUE:
106954 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, queue_mapping) != 2);
106955 -
106956 - *insn = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
106957 - offsetof(struct sk_buff, queue_mapping));
106958 - break;
106959 -
106960 - case SKF_AD_OFF + SKF_AD_VLAN_TAG:
106961 - case SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT:
106962 - BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
106963 - BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
106964 -
106965 - /* A = *(u16 *) (CTX + offsetof(vlan_tci)) */
106966 - *insn++ = BPF_LDX_MEM(BPF_H, BPF_REG_A, BPF_REG_CTX,
106967 - offsetof(struct sk_buff, vlan_tci));
106968 - if (fp->k == SKF_AD_OFF + SKF_AD_VLAN_TAG) {
106969 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A,
106970 - ~VLAN_TAG_PRESENT);
106971 - } else {
106972 - /* A >>= 12 */
106973 - *insn++ = BPF_ALU32_IMM(BPF_RSH, BPF_REG_A, 12);
106974 - /* A &= 1 */
106975 - *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 1);
106976 - }
106977 - break;
106978 -
106979 - case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
106980 - case SKF_AD_OFF + SKF_AD_NLATTR:
106981 - case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
106982 - case SKF_AD_OFF + SKF_AD_CPU:
106983 - case SKF_AD_OFF + SKF_AD_RANDOM:
106984 - /* arg1 = CTX */
106985 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG1, BPF_REG_CTX);
106986 - /* arg2 = A */
106987 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_A);
106988 - /* arg3 = X */
106989 - *insn++ = BPF_MOV64_REG(BPF_REG_ARG3, BPF_REG_X);
106990 - /* Emit call(arg1=CTX, arg2=A, arg3=X) */
106991 - switch (fp->k) {
106992 - case SKF_AD_OFF + SKF_AD_PAY_OFFSET:
106993 - *insn = BPF_EMIT_CALL(__skb_get_pay_offset);
106994 - break;
106995 - case SKF_AD_OFF + SKF_AD_NLATTR:
106996 - *insn = BPF_EMIT_CALL(__skb_get_nlattr);
106997 - break;
106998 - case SKF_AD_OFF + SKF_AD_NLATTR_NEST:
106999 - *insn = BPF_EMIT_CALL(__skb_get_nlattr_nest);
107000 - break;
107001 - case SKF_AD_OFF + SKF_AD_CPU:
107002 - *insn = BPF_EMIT_CALL(__get_raw_cpu_id);
107003 - break;
107004 - case SKF_AD_OFF + SKF_AD_RANDOM:
107005 - *insn = BPF_EMIT_CALL(__get_random_u32);
107006 - break;
107007 - }
107008 - break;
107009 -
107010 - case SKF_AD_OFF + SKF_AD_ALU_XOR_X:
107011 - /* A ^= X */
107012 - *insn = BPF_ALU32_REG(BPF_XOR, BPF_REG_A, BPF_REG_X);
107013 - break;
107014 -
107015 - default:
107016 - /* This is just a dummy call to avoid letting the compiler
107017 - * evict __bpf_call_base() as an optimization. Placed here
107018 - * where no-one bothers.
107019 - */
107020 - BUG_ON(__bpf_call_base(0, 0, 0, 0, 0) != 0);
107021 - return false;
107022 - }
107023 -
107024 - *insnp = insn;
107025 - return true;
107026 -}
107027 -
107028 -/**
107029 - * sk_convert_filter - convert filter program
107030 - * @prog: the user passed filter program
107031 - * @len: the length of the user passed filter program
107032 - * @new_prog: buffer where converted program will be stored
107033 - * @new_len: pointer to store length of converted program
107034 - *
107035 - * Remap 'sock_filter' style BPF instruction set to 'sock_filter_ext' style.
107036 - * Conversion workflow:
107037 - *
107038 - * 1) First pass for calculating the new program length:
107039 - * sk_convert_filter(old_prog, old_len, NULL, &new_len)
107040 - *
107041 - * 2) 2nd pass to remap in two passes: 1st pass finds new
107042 - * jump offsets, 2nd pass remapping:
107043 - * new_prog = kmalloc(sizeof(struct sock_filter_int) * new_len);
107044 - * sk_convert_filter(old_prog, old_len, new_prog, &new_len);
107045 - *
107046 - * User BPF's register A is mapped to our BPF register 6, user BPF
107047 - * register X is mapped to BPF register 7; frame pointer is always
107048 - * register 10; Context 'void *ctx' is stored in register 1, that is,
107049 - * for socket filters: ctx == 'struct sk_buff *', for seccomp:
107050 - * ctx == 'struct seccomp_data *'.
107051 - */
107052 -int sk_convert_filter(struct sock_filter *prog, int len,
107053 - struct sock_filter_int *new_prog, int *new_len)
107054 -{
107055 - int new_flen = 0, pass = 0, target, i;
107056 - struct sock_filter_int *new_insn;
107057 - struct sock_filter *fp;
107058 - int *addrs = NULL;
107059 - u8 bpf_src;
107060 -
107061 - BUILD_BUG_ON(BPF_MEMWORDS * sizeof(u32) > MAX_BPF_STACK);
107062 - BUILD_BUG_ON(BPF_REG_FP + 1 != MAX_BPF_REG);
107063 -
107064 - if (len <= 0 || len > BPF_MAXINSNS)
107065 - return -EINVAL;
107066 -
107067 - if (new_prog) {
107068 - addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
107069 - if (!addrs)
107070 - return -ENOMEM;
107071 - }
107072 -
107073 -do_pass:
107074 - new_insn = new_prog;
107075 - fp = prog;
107076 -
107077 - if (new_insn)
107078 - *new_insn = BPF_MOV64_REG(BPF_REG_CTX, BPF_REG_ARG1);
107079 - new_insn++;
107080 -
107081 - for (i = 0; i < len; fp++, i++) {
107082 - struct sock_filter_int tmp_insns[6] = { };
107083 - struct sock_filter_int *insn = tmp_insns;
107084 -
107085 - if (addrs)
107086 - addrs[i] = new_insn - new_prog;
107087 -
107088 - switch (fp->code) {
107089 - /* All arithmetic insns and skb loads map as-is. */
107090 - case BPF_ALU | BPF_ADD | BPF_X:
107091 - case BPF_ALU | BPF_ADD | BPF_K:
107092 - case BPF_ALU | BPF_SUB | BPF_X:
107093 - case BPF_ALU | BPF_SUB | BPF_K:
107094 - case BPF_ALU | BPF_AND | BPF_X:
107095 - case BPF_ALU | BPF_AND | BPF_K:
107096 - case BPF_ALU | BPF_OR | BPF_X:
107097 - case BPF_ALU | BPF_OR | BPF_K:
107098 - case BPF_ALU | BPF_LSH | BPF_X:
107099 - case BPF_ALU | BPF_LSH | BPF_K:
107100 - case BPF_ALU | BPF_RSH | BPF_X:
107101 - case BPF_ALU | BPF_RSH | BPF_K:
107102 - case BPF_ALU | BPF_XOR | BPF_X:
107103 - case BPF_ALU | BPF_XOR | BPF_K:
107104 - case BPF_ALU | BPF_MUL | BPF_X:
107105 - case BPF_ALU | BPF_MUL | BPF_K:
107106 - case BPF_ALU | BPF_DIV | BPF_X:
107107 - case BPF_ALU | BPF_DIV | BPF_K:
107108 - case BPF_ALU | BPF_MOD | BPF_X:
107109 - case BPF_ALU | BPF_MOD | BPF_K:
107110 - case BPF_ALU | BPF_NEG:
107111 - case BPF_LD | BPF_ABS | BPF_W:
107112 - case BPF_LD | BPF_ABS | BPF_H:
107113 - case BPF_LD | BPF_ABS | BPF_B:
107114 - case BPF_LD | BPF_IND | BPF_W:
107115 - case BPF_LD | BPF_IND | BPF_H:
107116 - case BPF_LD | BPF_IND | BPF_B:
107117 - /* Check for overloaded BPF extension and
107118 - * directly convert it if found, otherwise
107119 - * just move on with mapping.
107120 - */
107121 - if (BPF_CLASS(fp->code) == BPF_LD &&
107122 - BPF_MODE(fp->code) == BPF_ABS &&
107123 - convert_bpf_extensions(fp, &insn))
107124 - break;
107125 -
107126 - *insn = BPF_RAW_INSN(fp->code, BPF_REG_A, BPF_REG_X, 0, fp->k);
107127 - break;
107128 -
107129 - /* Jump transformation cannot use BPF block macros
107130 - * everywhere as offset calculation and target updates
107131 - * require a bit more work than the rest, i.e. jump
107132 - * opcodes map as-is, but offsets need adjustment.
107133 - */
107134 -
107135 -#define BPF_EMIT_JMP \
107136 - do { \
107137 - if (target >= len || target < 0) \
107138 - goto err; \
107139 - insn->off = addrs ? addrs[target] - addrs[i] - 1 : 0; \
107140 - /* Adjust pc relative offset for 2nd or 3rd insn. */ \
107141 - insn->off -= insn - tmp_insns; \
107142 - } while (0)
107143 -
107144 - case BPF_JMP | BPF_JA:
107145 - target = i + fp->k + 1;
107146 - insn->code = fp->code;
107147 - BPF_EMIT_JMP;
107148 - break;
107149 -
107150 - case BPF_JMP | BPF_JEQ | BPF_K:
107151 - case BPF_JMP | BPF_JEQ | BPF_X:
107152 - case BPF_JMP | BPF_JSET | BPF_K:
107153 - case BPF_JMP | BPF_JSET | BPF_X:
107154 - case BPF_JMP | BPF_JGT | BPF_K:
107155 - case BPF_JMP | BPF_JGT | BPF_X:
107156 - case BPF_JMP | BPF_JGE | BPF_K:
107157 - case BPF_JMP | BPF_JGE | BPF_X:
107158 - if (BPF_SRC(fp->code) == BPF_K && (int) fp->k < 0) {
107159 - /* BPF immediates are signed, zero extend
107160 - * immediate into tmp register and use it
107161 - * in compare insn.
107162 - */
107163 - *insn++ = BPF_MOV32_IMM(BPF_REG_TMP, fp->k);
107164 -
107165 - insn->dst_reg = BPF_REG_A;
107166 - insn->src_reg = BPF_REG_TMP;
107167 - bpf_src = BPF_X;
107168 - } else {
107169 - insn->dst_reg = BPF_REG_A;
107170 - insn->src_reg = BPF_REG_X;
107171 - insn->imm = fp->k;
107172 - bpf_src = BPF_SRC(fp->code);
107173 + switch (fentry->code) {
107174 + case BPF_S_ALU_ADD_X:
107175 + A += X;
107176 + continue;
107177 + case BPF_S_ALU_ADD_K:
107178 + A += K;
107179 + continue;
107180 + case BPF_S_ALU_SUB_X:
107181 + A -= X;
107182 + continue;
107183 + case BPF_S_ALU_SUB_K:
107184 + A -= K;
107185 + continue;
107186 + case BPF_S_ALU_MUL_X:
107187 + A *= X;
107188 + continue;
107189 + case BPF_S_ALU_MUL_K:
107190 + A *= K;
107191 + continue;
107192 + case BPF_S_ALU_DIV_X:
107193 + if (X == 0)
107194 + return 0;
107195 + A /= X;
107196 + continue;
107197 + case BPF_S_ALU_DIV_K:
107198 + A /= K;
107199 + continue;
107200 + case BPF_S_ALU_MOD_X:
107201 + if (X == 0)
107202 + return 0;
107203 + A %= X;
107204 + continue;
107205 + case BPF_S_ALU_MOD_K:
107206 + A %= K;
107207 + continue;
107208 + case BPF_S_ALU_AND_X:
107209 + A &= X;
107210 + continue;
107211 + case BPF_S_ALU_AND_K:
107212 + A &= K;
107213 + continue;
107214 + case BPF_S_ALU_OR_X:
107215 + A |= X;
107216 + continue;
107217 + case BPF_S_ALU_OR_K:
107218 + A |= K;
107219 + continue;
107220 + case BPF_S_ANC_ALU_XOR_X:
107221 + case BPF_S_ALU_XOR_X:
107222 + A ^= X;
107223 + continue;
107224 + case BPF_S_ALU_XOR_K:
107225 + A ^= K;
107226 + continue;
107227 + case BPF_S_ALU_LSH_X:
107228 + A <<= X;
107229 + continue;
107230 + case BPF_S_ALU_LSH_K:
107231 + A <<= K;
107232 + continue;
107233 + case BPF_S_ALU_RSH_X:
107234 + A >>= X;
107235 + continue;
107236 + case BPF_S_ALU_RSH_K:
107237 + A >>= K;
107238 + continue;
107239 + case BPF_S_ALU_NEG:
107240 + A = -A;
107241 + continue;
107242 + case BPF_S_JMP_JA:
107243 + fentry += K;
107244 + continue;
107245 + case BPF_S_JMP_JGT_K:
107246 + fentry += (A > K) ? fentry->jt : fentry->jf;
107247 + continue;
107248 + case BPF_S_JMP_JGE_K:
107249 + fentry += (A >= K) ? fentry->jt : fentry->jf;
107250 + continue;
107251 + case BPF_S_JMP_JEQ_K:
107252 + fentry += (A == K) ? fentry->jt : fentry->jf;
107253 + continue;
107254 + case BPF_S_JMP_JSET_K:
107255 + fentry += (A & K) ? fentry->jt : fentry->jf;
107256 + continue;
107257 + case BPF_S_JMP_JGT_X:
107258 + fentry += (A > X) ? fentry->jt : fentry->jf;
107259 + continue;
107260 + case BPF_S_JMP_JGE_X:
107261 + fentry += (A >= X) ? fentry->jt : fentry->jf;
107262 + continue;
107263 + case BPF_S_JMP_JEQ_X:
107264 + fentry += (A == X) ? fentry->jt : fentry->jf;
107265 + continue;
107266 + case BPF_S_JMP_JSET_X:
107267 + fentry += (A & X) ? fentry->jt : fentry->jf;
107268 + continue;
107269 + case BPF_S_LD_W_ABS:
107270 + k = K;
107271 +load_w:
107272 + ptr = load_pointer(skb, k, 4, &tmp);
107273 + if (ptr != NULL) {
107274 + A = get_unaligned_be32(ptr);
107275 + continue;
107276 }
107277 -
107278 - /* Common case where 'jump_false' is next insn. */
107279 - if (fp->jf == 0) {
107280 - insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
107281 - target = i + fp->jt + 1;
107282 - BPF_EMIT_JMP;
107283 - break;
107284 + return 0;
107285 + case BPF_S_LD_H_ABS:
107286 + k = K;
107287 +load_h:
107288 + ptr = load_pointer(skb, k, 2, &tmp);
107289 + if (ptr != NULL) {
107290 + A = get_unaligned_be16(ptr);
107291 + continue;
107292 }
107293 -
107294 - /* Convert JEQ into JNE when 'jump_true' is next insn. */
107295 - if (fp->jt == 0 && BPF_OP(fp->code) == BPF_JEQ) {
107296 - insn->code = BPF_JMP | BPF_JNE | bpf_src;
107297 - target = i + fp->jf + 1;
107298 - BPF_EMIT_JMP;
107299 - break;
107300 + return 0;
107301 + case BPF_S_LD_B_ABS:
107302 + k = K;
107303 +load_b:
107304 + ptr = load_pointer(skb, k, 1, &tmp);
107305 + if (ptr != NULL) {
107306 + A = *(u8 *)ptr;
107307 + continue;
107308 }
107309 -
107310 - /* Other jumps are mapped into two insns: Jxx and JA. */
107311 - target = i + fp->jt + 1;
107312 - insn->code = BPF_JMP | BPF_OP(fp->code) | bpf_src;
107313 - BPF_EMIT_JMP;
107314 - insn++;
107315 -
107316 - insn->code = BPF_JMP | BPF_JA;
107317 - target = i + fp->jf + 1;
107318 - BPF_EMIT_JMP;
107319 - break;
107320 -
107321 - /* ldxb 4 * ([14] & 0xf) is remaped into 6 insns. */
107322 - case BPF_LDX | BPF_MSH | BPF_B:
107323 - /* tmp = A */
107324 - *insn++ = BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_A);
107325 - /* A = BPF_R0 = *(u8 *) (skb->data + K) */
107326 - *insn++ = BPF_LD_ABS(BPF_B, fp->k);
107327 - /* A &= 0xf */
107328 - *insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, 0xf);
107329 - /* A <<= 2 */
107330 - *insn++ = BPF_ALU32_IMM(BPF_LSH, BPF_REG_A, 2);
107331 - /* X = A */
107332 - *insn++ = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
107333 - /* A = tmp */
107334 - *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_TMP);
107335 - break;
107336 -
107337 - /* RET_K, RET_A are remaped into 2 insns. */
107338 - case BPF_RET | BPF_A:
107339 - case BPF_RET | BPF_K:
107340 - *insn++ = BPF_MOV32_RAW(BPF_RVAL(fp->code) == BPF_K ?
107341 - BPF_K : BPF_X, BPF_REG_0,
107342 - BPF_REG_A, fp->k);
107343 - *insn = BPF_EXIT_INSN();
107344 - break;
107345 -
107346 - /* Store to stack. */
107347 - case BPF_ST:
107348 - case BPF_STX:
107349 - *insn = BPF_STX_MEM(BPF_W, BPF_REG_FP, BPF_CLASS(fp->code) ==
107350 - BPF_ST ? BPF_REG_A : BPF_REG_X,
107351 - -(BPF_MEMWORDS - fp->k) * 4);
107352 - break;
107353 -
107354 - /* Load from stack. */
107355 - case BPF_LD | BPF_MEM:
107356 - case BPF_LDX | BPF_MEM:
107357 - *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
107358 - BPF_REG_A : BPF_REG_X, BPF_REG_FP,
107359 - -(BPF_MEMWORDS - fp->k) * 4);
107360 - break;
107361 -
107362 - /* A = K or X = K */
107363 - case BPF_LD | BPF_IMM:
107364 - case BPF_LDX | BPF_IMM:
107365 - *insn = BPF_MOV32_IMM(BPF_CLASS(fp->code) == BPF_LD ?
107366 - BPF_REG_A : BPF_REG_X, fp->k);
107367 - break;
107368 -
107369 - /* X = A */
107370 - case BPF_MISC | BPF_TAX:
107371 - *insn = BPF_MOV64_REG(BPF_REG_X, BPF_REG_A);
107372 - break;
107373 -
107374 - /* A = X */
107375 - case BPF_MISC | BPF_TXA:
107376 - *insn = BPF_MOV64_REG(BPF_REG_A, BPF_REG_X);
107377 - break;
107378 -
107379 - /* A = skb->len or X = skb->len */
107380 - case BPF_LD | BPF_W | BPF_LEN:
107381 - case BPF_LDX | BPF_W | BPF_LEN:
107382 - *insn = BPF_LDX_MEM(BPF_W, BPF_CLASS(fp->code) == BPF_LD ?
107383 - BPF_REG_A : BPF_REG_X, BPF_REG_CTX,
107384 - offsetof(struct sk_buff, len));
107385 - break;
107386 -
107387 - /* Access seccomp_data fields. */
107388 - case BPF_LDX | BPF_ABS | BPF_W:
107389 - /* A = *(u32 *) (ctx + K) */
107390 - *insn = BPF_LDX_MEM(BPF_W, BPF_REG_A, BPF_REG_CTX, fp->k);
107391 - break;
107392 -
107393 - /* Unkown instruction. */
107394 + return 0;
107395 + case BPF_S_LD_W_LEN:
107396 + A = skb->len;
107397 + continue;
107398 + case BPF_S_LDX_W_LEN:
107399 + X = skb->len;
107400 + continue;
107401 + case BPF_S_LD_W_IND:
107402 + k = X + K;
107403 + goto load_w;
107404 + case BPF_S_LD_H_IND:
107405 + k = X + K;
107406 + goto load_h;
107407 + case BPF_S_LD_B_IND:
107408 + k = X + K;
107409 + goto load_b;
107410 + case BPF_S_LDX_B_MSH:
107411 + ptr = load_pointer(skb, K, 1, &tmp);
107412 + if (ptr != NULL) {
107413 + X = (*(u8 *)ptr & 0xf) << 2;
107414 + continue;
107415 + }
107416 + return 0;
107417 + case BPF_S_LD_IMM:
107418 + A = K;
107419 + continue;
107420 + case BPF_S_LDX_IMM:
107421 + X = K;
107422 + continue;
107423 + case BPF_S_LD_MEM:
107424 + A = mem[K&15];
107425 + continue;
107426 + case BPF_S_LDX_MEM:
107427 + X = mem[K&15];
107428 + continue;
107429 + case BPF_S_MISC_TAX:
107430 + X = A;
107431 + continue;
107432 + case BPF_S_MISC_TXA:
107433 + A = X;
107434 + continue;
107435 + case BPF_S_RET_K:
107436 + return K;
107437 + case BPF_S_RET_A:
107438 + return A;
107439 + case BPF_S_ST:
107440 + mem[K&15] = A;
107441 + continue;
107442 + case BPF_S_STX:
107443 + mem[K&15] = X;
107444 + continue;
107445 + case BPF_S_ANC_PROTOCOL:
107446 + A = ntohs(skb->protocol);
107447 + continue;
107448 + case BPF_S_ANC_PKTTYPE:
107449 + A = skb->pkt_type;
107450 + continue;
107451 + case BPF_S_ANC_IFINDEX:
107452 + if (!skb->dev)
107453 + return 0;
107454 + A = skb->dev->ifindex;
107455 + continue;
107456 + case BPF_S_ANC_MARK:
107457 + A = skb->mark;
107458 + continue;
107459 + case BPF_S_ANC_QUEUE:
107460 + A = skb->queue_mapping;
107461 + continue;
107462 + case BPF_S_ANC_HATYPE:
107463 + if (!skb->dev)
107464 + return 0;
107465 + A = skb->dev->type;
107466 + continue;
107467 + case BPF_S_ANC_RXHASH:
107468 + A = skb->hash;
107469 + continue;
107470 + case BPF_S_ANC_CPU:
107471 + A = raw_smp_processor_id();
107472 + continue;
107473 + case BPF_S_ANC_VLAN_TAG:
107474 + A = vlan_tx_tag_get(skb);
107475 + continue;
107476 + case BPF_S_ANC_VLAN_TAG_PRESENT:
107477 + A = !!vlan_tx_tag_present(skb);
107478 + continue;
107479 + case BPF_S_ANC_PAY_OFFSET:
107480 + A = __skb_get_poff(skb);
107481 + continue;
107482 + case BPF_S_ANC_NLATTR: {
107483 + struct nlattr *nla;
107484 +
107485 + if (skb_is_nonlinear(skb))
107486 + return 0;
107487 + if (skb->len < sizeof(struct nlattr))
107488 + return 0;
107489 + if (A > skb->len - sizeof(struct nlattr))
107490 + return 0;
107491 +
107492 + nla = nla_find((struct nlattr *)&skb->data[A],
107493 + skb->len - A, X);
107494 + if (nla)
107495 + A = (void *)nla - (void *)skb->data;
107496 + else
107497 + A = 0;
107498 + continue;
107499 + }
107500 + case BPF_S_ANC_NLATTR_NEST: {
107501 + struct nlattr *nla;
107502 +
107503 + if (skb_is_nonlinear(skb))
107504 + return 0;
107505 + if (skb->len < sizeof(struct nlattr))
107506 + return 0;
107507 + if (A > skb->len - sizeof(struct nlattr))
107508 + return 0;
107509 +
107510 + nla = (struct nlattr *)&skb->data[A];
107511 + if (nla->nla_len > skb->len - A)
107512 + return 0;
107513 +
107514 + nla = nla_find_nested(nla, X);
107515 + if (nla)
107516 + A = (void *)nla - (void *)skb->data;
107517 + else
107518 + A = 0;
107519 + continue;
107520 + }
107521 +#ifdef CONFIG_SECCOMP_FILTER
107522 + case BPF_S_ANC_SECCOMP_LD_W:
107523 + A = seccomp_bpf_load(fentry->k);
107524 + continue;
107525 +#endif
107526 default:
107527 - goto err;
107528 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
107529 + fentry->code, fentry->jt,
107530 + fentry->jf, fentry->k);
107531 + BUG();
107532 + return 0;
107533 }
107534 -
107535 - insn++;
107536 - if (new_prog)
107537 - memcpy(new_insn, tmp_insns,
107538 - sizeof(*insn) * (insn - tmp_insns));
107539 - new_insn += insn - tmp_insns;
107540 - }
107541 -
107542 - if (!new_prog) {
107543 - /* Only calculating new length. */
107544 - *new_len = new_insn - new_prog;
107545 - return 0;
107546 - }
107547 -
107548 - pass++;
107549 - if (new_flen != new_insn - new_prog) {
107550 - new_flen = new_insn - new_prog;
107551 - if (pass > 2)
107552 - goto err;
107553 - goto do_pass;
107554 }
107555
107556 - kfree(addrs);
107557 - BUG_ON(*new_len != new_flen);
107558 return 0;
107559 -err:
107560 - kfree(addrs);
107561 - return -EINVAL;
107562 }
107563 +EXPORT_SYMBOL(sk_run_filter);
107564
107565 -/* Security:
107566 - *
107567 +/*
107568 + * Security :
107569 * A BPF program is able to use 16 cells of memory to store intermediate
107570 - * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter()).
107571 - *
107572 + * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter())
107573 * As we dont want to clear mem[] array for each packet going through
107574 * sk_run_filter(), we check that filter loaded by user never try to read
107575 * a cell if not previously written, and we check all branches to be sure
107576 @@ -1096,46 +418,44 @@ err:
107577 */
107578 static int check_load_and_stores(struct sock_filter *filter, int flen)
107579 {
107580 - u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
107581 + u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
107582 int pc, ret = 0;
107583
107584 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
107585 -
107586 - masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
107587 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
107588 + masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
107589 if (!masks)
107590 return -ENOMEM;
107591 -
107592 memset(masks, 0xff, flen * sizeof(*masks));
107593
107594 for (pc = 0; pc < flen; pc++) {
107595 memvalid &= masks[pc];
107596
107597 switch (filter[pc].code) {
107598 - case BPF_ST:
107599 - case BPF_STX:
107600 + case BPF_S_ST:
107601 + case BPF_S_STX:
107602 memvalid |= (1 << filter[pc].k);
107603 break;
107604 - case BPF_LD | BPF_MEM:
107605 - case BPF_LDX | BPF_MEM:
107606 + case BPF_S_LD_MEM:
107607 + case BPF_S_LDX_MEM:
107608 if (!(memvalid & (1 << filter[pc].k))) {
107609 ret = -EINVAL;
107610 goto error;
107611 }
107612 break;
107613 - case BPF_JMP | BPF_JA:
107614 - /* A jump must set masks on target */
107615 + case BPF_S_JMP_JA:
107616 + /* a jump must set masks on target */
107617 masks[pc + 1 + filter[pc].k] &= memvalid;
107618 memvalid = ~0;
107619 break;
107620 - case BPF_JMP | BPF_JEQ | BPF_K:
107621 - case BPF_JMP | BPF_JEQ | BPF_X:
107622 - case BPF_JMP | BPF_JGE | BPF_K:
107623 - case BPF_JMP | BPF_JGE | BPF_X:
107624 - case BPF_JMP | BPF_JGT | BPF_K:
107625 - case BPF_JMP | BPF_JGT | BPF_X:
107626 - case BPF_JMP | BPF_JSET | BPF_K:
107627 - case BPF_JMP | BPF_JSET | BPF_X:
107628 - /* A jump must set masks on targets */
107629 + case BPF_S_JMP_JEQ_K:
107630 + case BPF_S_JMP_JEQ_X:
107631 + case BPF_S_JMP_JGE_K:
107632 + case BPF_S_JMP_JGE_X:
107633 + case BPF_S_JMP_JGT_K:
107634 + case BPF_S_JMP_JGT_X:
107635 + case BPF_S_JMP_JSET_X:
107636 + case BPF_S_JMP_JSET_K:
107637 + /* a jump must set masks on targets */
107638 masks[pc + 1 + filter[pc].jt] &= memvalid;
107639 masks[pc + 1 + filter[pc].jf] &= memvalid;
107640 memvalid = ~0;
107641 @@ -1147,72 +467,6 @@ error:
107642 return ret;
107643 }
107644
107645 -static bool chk_code_allowed(u16 code_to_probe)
107646 -{
107647 - static const bool codes[] = {
107648 - /* 32 bit ALU operations */
107649 - [BPF_ALU | BPF_ADD | BPF_K] = true,
107650 - [BPF_ALU | BPF_ADD | BPF_X] = true,
107651 - [BPF_ALU | BPF_SUB | BPF_K] = true,
107652 - [BPF_ALU | BPF_SUB | BPF_X] = true,
107653 - [BPF_ALU | BPF_MUL | BPF_K] = true,
107654 - [BPF_ALU | BPF_MUL | BPF_X] = true,
107655 - [BPF_ALU | BPF_DIV | BPF_K] = true,
107656 - [BPF_ALU | BPF_DIV | BPF_X] = true,
107657 - [BPF_ALU | BPF_MOD | BPF_K] = true,
107658 - [BPF_ALU | BPF_MOD | BPF_X] = true,
107659 - [BPF_ALU | BPF_AND | BPF_K] = true,
107660 - [BPF_ALU | BPF_AND | BPF_X] = true,
107661 - [BPF_ALU | BPF_OR | BPF_K] = true,
107662 - [BPF_ALU | BPF_OR | BPF_X] = true,
107663 - [BPF_ALU | BPF_XOR | BPF_K] = true,
107664 - [BPF_ALU | BPF_XOR | BPF_X] = true,
107665 - [BPF_ALU | BPF_LSH | BPF_K] = true,
107666 - [BPF_ALU | BPF_LSH | BPF_X] = true,
107667 - [BPF_ALU | BPF_RSH | BPF_K] = true,
107668 - [BPF_ALU | BPF_RSH | BPF_X] = true,
107669 - [BPF_ALU | BPF_NEG] = true,
107670 - /* Load instructions */
107671 - [BPF_LD | BPF_W | BPF_ABS] = true,
107672 - [BPF_LD | BPF_H | BPF_ABS] = true,
107673 - [BPF_LD | BPF_B | BPF_ABS] = true,
107674 - [BPF_LD | BPF_W | BPF_LEN] = true,
107675 - [BPF_LD | BPF_W | BPF_IND] = true,
107676 - [BPF_LD | BPF_H | BPF_IND] = true,
107677 - [BPF_LD | BPF_B | BPF_IND] = true,
107678 - [BPF_LD | BPF_IMM] = true,
107679 - [BPF_LD | BPF_MEM] = true,
107680 - [BPF_LDX | BPF_W | BPF_LEN] = true,
107681 - [BPF_LDX | BPF_B | BPF_MSH] = true,
107682 - [BPF_LDX | BPF_IMM] = true,
107683 - [BPF_LDX | BPF_MEM] = true,
107684 - /* Store instructions */
107685 - [BPF_ST] = true,
107686 - [BPF_STX] = true,
107687 - /* Misc instructions */
107688 - [BPF_MISC | BPF_TAX] = true,
107689 - [BPF_MISC | BPF_TXA] = true,
107690 - /* Return instructions */
107691 - [BPF_RET | BPF_K] = true,
107692 - [BPF_RET | BPF_A] = true,
107693 - /* Jump instructions */
107694 - [BPF_JMP | BPF_JA] = true,
107695 - [BPF_JMP | BPF_JEQ | BPF_K] = true,
107696 - [BPF_JMP | BPF_JEQ | BPF_X] = true,
107697 - [BPF_JMP | BPF_JGE | BPF_K] = true,
107698 - [BPF_JMP | BPF_JGE | BPF_X] = true,
107699 - [BPF_JMP | BPF_JGT | BPF_K] = true,
107700 - [BPF_JMP | BPF_JGT | BPF_X] = true,
107701 - [BPF_JMP | BPF_JSET | BPF_K] = true,
107702 - [BPF_JMP | BPF_JSET | BPF_X] = true,
107703 - };
107704 -
107705 - if (code_to_probe >= ARRAY_SIZE(codes))
107706 - return false;
107707 -
107708 - return codes[code_to_probe];
107709 -}
107710 -
107711 /**
107712 * sk_chk_filter - verify socket filter code
107713 * @filter: filter to verify
107714 @@ -1229,303 +483,187 @@ static bool chk_code_allowed(u16 code_to_probe)
107715 */
107716 int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
107717 {
107718 - bool anc_found;
107719 + /*
107720 + * Valid instructions are initialized to non-0.
107721 + * Invalid instructions are initialized to 0.
107722 + */
107723 + static const u8 codes[] = {
107724 + [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K,
107725 + [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X,
107726 + [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K,
107727 + [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X,
107728 + [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K,
107729 + [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X,
107730 + [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X,
107731 + [BPF_ALU|BPF_MOD|BPF_K] = BPF_S_ALU_MOD_K,
107732 + [BPF_ALU|BPF_MOD|BPF_X] = BPF_S_ALU_MOD_X,
107733 + [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K,
107734 + [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
107735 + [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
107736 + [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
107737 + [BPF_ALU|BPF_XOR|BPF_K] = BPF_S_ALU_XOR_K,
107738 + [BPF_ALU|BPF_XOR|BPF_X] = BPF_S_ALU_XOR_X,
107739 + [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
107740 + [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
107741 + [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
107742 + [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X,
107743 + [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG,
107744 + [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS,
107745 + [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS,
107746 + [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS,
107747 + [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN,
107748 + [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND,
107749 + [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND,
107750 + [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND,
107751 + [BPF_LD|BPF_IMM] = BPF_S_LD_IMM,
107752 + [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN,
107753 + [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH,
107754 + [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM,
107755 + [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX,
107756 + [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA,
107757 + [BPF_RET|BPF_K] = BPF_S_RET_K,
107758 + [BPF_RET|BPF_A] = BPF_S_RET_A,
107759 + [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K,
107760 + [BPF_LD|BPF_MEM] = BPF_S_LD_MEM,
107761 + [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM,
107762 + [BPF_ST] = BPF_S_ST,
107763 + [BPF_STX] = BPF_S_STX,
107764 + [BPF_JMP|BPF_JA] = BPF_S_JMP_JA,
107765 + [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K,
107766 + [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X,
107767 + [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K,
107768 + [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X,
107769 + [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K,
107770 + [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X,
107771 + [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K,
107772 + [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X,
107773 + };
107774 int pc;
107775 + bool anc_found;
107776
107777 if (flen == 0 || flen > BPF_MAXINSNS)
107778 return -EINVAL;
107779
107780 - /* Check the filter code now */
107781 + /* check the filter code now */
107782 for (pc = 0; pc < flen; pc++) {
107783 struct sock_filter *ftest = &filter[pc];
107784 + u16 code = ftest->code;
107785
107786 - /* May we actually operate on this code? */
107787 - if (!chk_code_allowed(ftest->code))
107788 + if (code >= ARRAY_SIZE(codes))
107789 + return -EINVAL;
107790 + code = codes[code];
107791 + if (!code)
107792 return -EINVAL;
107793 -
107794 /* Some instructions need special checks */
107795 - switch (ftest->code) {
107796 - case BPF_ALU | BPF_DIV | BPF_K:
107797 - case BPF_ALU | BPF_MOD | BPF_K:
107798 - /* Check for division by zero */
107799 + switch (code) {
107800 + case BPF_S_ALU_DIV_K:
107801 + case BPF_S_ALU_MOD_K:
107802 + /* check for division by zero */
107803 if (ftest->k == 0)
107804 return -EINVAL;
107805 break;
107806 - case BPF_LD | BPF_MEM:
107807 - case BPF_LDX | BPF_MEM:
107808 - case BPF_ST:
107809 - case BPF_STX:
107810 - /* Check for invalid memory addresses */
107811 + case BPF_S_LD_MEM:
107812 + case BPF_S_LDX_MEM:
107813 + case BPF_S_ST:
107814 + case BPF_S_STX:
107815 + /* check for invalid memory addresses */
107816 if (ftest->k >= BPF_MEMWORDS)
107817 return -EINVAL;
107818 break;
107819 - case BPF_JMP | BPF_JA:
107820 - /* Note, the large ftest->k might cause loops.
107821 + case BPF_S_JMP_JA:
107822 + /*
107823 + * Note, the large ftest->k might cause loops.
107824 * Compare this with conditional jumps below,
107825 * where offsets are limited. --ANK (981016)
107826 */
107827 - if (ftest->k >= (unsigned int)(flen - pc - 1))
107828 + if (ftest->k >= (unsigned int)(flen-pc-1))
107829 return -EINVAL;
107830 break;
107831 - case BPF_JMP | BPF_JEQ | BPF_K:
107832 - case BPF_JMP | BPF_JEQ | BPF_X:
107833 - case BPF_JMP | BPF_JGE | BPF_K:
107834 - case BPF_JMP | BPF_JGE | BPF_X:
107835 - case BPF_JMP | BPF_JGT | BPF_K:
107836 - case BPF_JMP | BPF_JGT | BPF_X:
107837 - case BPF_JMP | BPF_JSET | BPF_K:
107838 - case BPF_JMP | BPF_JSET | BPF_X:
107839 - /* Both conditionals must be safe */
107840 + case BPF_S_JMP_JEQ_K:
107841 + case BPF_S_JMP_JEQ_X:
107842 + case BPF_S_JMP_JGE_K:
107843 + case BPF_S_JMP_JGE_X:
107844 + case BPF_S_JMP_JGT_K:
107845 + case BPF_S_JMP_JGT_X:
107846 + case BPF_S_JMP_JSET_X:
107847 + case BPF_S_JMP_JSET_K:
107848 + /* for conditionals both must be safe */
107849 if (pc + ftest->jt + 1 >= flen ||
107850 pc + ftest->jf + 1 >= flen)
107851 return -EINVAL;
107852 break;
107853 - case BPF_LD | BPF_W | BPF_ABS:
107854 - case BPF_LD | BPF_H | BPF_ABS:
107855 - case BPF_LD | BPF_B | BPF_ABS:
107856 + case BPF_S_LD_W_ABS:
107857 + case BPF_S_LD_H_ABS:
107858 + case BPF_S_LD_B_ABS:
107859 anc_found = false;
107860 - if (bpf_anc_helper(ftest) & BPF_ANC)
107861 - anc_found = true;
107862 - /* Ancillary operation unknown or unsupported */
107863 +#define ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
107864 + code = BPF_S_ANC_##CODE; \
107865 + anc_found = true; \
107866 + break
107867 + switch (ftest->k) {
107868 + ANCILLARY(PROTOCOL);
107869 + ANCILLARY(PKTTYPE);
107870 + ANCILLARY(IFINDEX);
107871 + ANCILLARY(NLATTR);
107872 + ANCILLARY(NLATTR_NEST);
107873 + ANCILLARY(MARK);
107874 + ANCILLARY(QUEUE);
107875 + ANCILLARY(HATYPE);
107876 + ANCILLARY(RXHASH);
107877 + ANCILLARY(CPU);
107878 + ANCILLARY(ALU_XOR_X);
107879 + ANCILLARY(VLAN_TAG);
107880 + ANCILLARY(VLAN_TAG_PRESENT);
107881 + ANCILLARY(PAY_OFFSET);
107882 + }
107883 +
107884 + /* ancillary operation unknown or unsupported */
107885 if (anc_found == false && ftest->k >= SKF_AD_OFF)
107886 return -EINVAL;
107887 }
107888 + ftest->code = code;
107889 }
107890
107891 - /* Last instruction must be a RET code */
107892 + /* last instruction must be a RET code */
107893 switch (filter[flen - 1].code) {
107894 - case BPF_RET | BPF_K:
107895 - case BPF_RET | BPF_A:
107896 + case BPF_S_RET_K:
107897 + case BPF_S_RET_A:
107898 return check_load_and_stores(filter, flen);
107899 }
107900 -
107901 return -EINVAL;
107902 }
107903 EXPORT_SYMBOL(sk_chk_filter);
107904
107905 -static int sk_store_orig_filter(struct sk_filter *fp,
107906 - const struct sock_fprog *fprog)
107907 -{
107908 - unsigned int fsize = sk_filter_proglen(fprog);
107909 - struct sock_fprog_kern *fkprog;
107910 -
107911 - fp->orig_prog = kmalloc(sizeof(*fkprog), GFP_KERNEL);
107912 - if (!fp->orig_prog)
107913 - return -ENOMEM;
107914 -
107915 - fkprog = fp->orig_prog;
107916 - fkprog->len = fprog->len;
107917 - fkprog->filter = kmemdup(fp->insns, fsize, GFP_KERNEL);
107918 - if (!fkprog->filter) {
107919 - kfree(fp->orig_prog);
107920 - return -ENOMEM;
107921 - }
107922 -
107923 - return 0;
107924 -}
107925 -
107926 -static void sk_release_orig_filter(struct sk_filter *fp)
107927 -{
107928 - struct sock_fprog_kern *fprog = fp->orig_prog;
107929 -
107930 - if (fprog) {
107931 - kfree(fprog->filter);
107932 - kfree(fprog);
107933 - }
107934 -}
107935 -
107936 /**
107937 * sk_filter_release_rcu - Release a socket filter by rcu_head
107938 * @rcu: rcu_head that contains the sk_filter to free
107939 */
107940 -static void sk_filter_release_rcu(struct rcu_head *rcu)
107941 +void sk_filter_release_rcu(struct rcu_head *rcu)
107942 {
107943 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
107944
107945 - sk_release_orig_filter(fp);
107946 - sk_filter_free(fp);
107947 -}
107948 -
107949 -/**
107950 - * sk_filter_release - release a socket filter
107951 - * @fp: filter to remove
107952 - *
107953 - * Remove a filter from a socket and release its resources.
107954 - */
107955 -static void sk_filter_release(struct sk_filter *fp)
107956 -{
107957 - if (atomic_dec_and_test(&fp->refcnt))
107958 - call_rcu(&fp->rcu, sk_filter_release_rcu);
107959 -}
107960 -
107961 -void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
107962 -{
107963 - atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
107964 - sk_filter_release(fp);
107965 -}
107966 -
107967 -void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
107968 -{
107969 - atomic_inc(&fp->refcnt);
107970 - atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
107971 -}
107972 -
107973 -static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp,
107974 - struct sock *sk,
107975 - unsigned int len)
107976 -{
107977 - struct sk_filter *fp_new;
107978 -
107979 - if (sk == NULL)
107980 - return krealloc(fp, len, GFP_KERNEL);
107981 -
107982 - fp_new = sock_kmalloc(sk, len, GFP_KERNEL);
107983 - if (fp_new) {
107984 - *fp_new = *fp;
107985 - /* As we're keeping orig_prog in fp_new along,
107986 - * we need to make sure we're not evicting it
107987 - * from the old fp.
107988 - */
107989 - fp->orig_prog = NULL;
107990 - sk_filter_uncharge(sk, fp);
107991 - }
107992 -
107993 - return fp_new;
107994 -}
107995 -
107996 -static struct sk_filter *__sk_migrate_filter(struct sk_filter *fp,
107997 - struct sock *sk)
107998 -{
107999 - struct sock_filter *old_prog;
108000 - struct sk_filter *old_fp;
108001 - int err, new_len, old_len = fp->len;
108002 -
108003 - /* We are free to overwrite insns et al right here as it
108004 - * won't be used at this point in time anymore internally
108005 - * after the migration to the internal BPF instruction
108006 - * representation.
108007 - */
108008 - BUILD_BUG_ON(sizeof(struct sock_filter) !=
108009 - sizeof(struct sock_filter_int));
108010 -
108011 - /* Conversion cannot happen on overlapping memory areas,
108012 - * so we need to keep the user BPF around until the 2nd
108013 - * pass. At this time, the user BPF is stored in fp->insns.
108014 - */
108015 - old_prog = kmemdup(fp->insns, old_len * sizeof(struct sock_filter),
108016 - GFP_KERNEL);
108017 - if (!old_prog) {
108018 - err = -ENOMEM;
108019 - goto out_err;
108020 - }
108021 -
108022 - /* 1st pass: calculate the new program length. */
108023 - err = sk_convert_filter(old_prog, old_len, NULL, &new_len);
108024 - if (err)
108025 - goto out_err_free;
108026 -
108027 - /* Expand fp for appending the new filter representation. */
108028 - old_fp = fp;
108029 - fp = __sk_migrate_realloc(old_fp, sk, sk_filter_size(new_len));
108030 - if (!fp) {
108031 - /* The old_fp is still around in case we couldn't
108032 - * allocate new memory, so uncharge on that one.
108033 - */
108034 - fp = old_fp;
108035 - err = -ENOMEM;
108036 - goto out_err_free;
108037 - }
108038 -
108039 - fp->len = new_len;
108040 -
108041 - /* 2nd pass: remap sock_filter insns into sock_filter_int insns. */
108042 - err = sk_convert_filter(old_prog, old_len, fp->insnsi, &new_len);
108043 - if (err)
108044 - /* 2nd sk_convert_filter() can fail only if it fails
108045 - * to allocate memory, remapping must succeed. Note,
108046 - * that at this time old_fp has already been released
108047 - * by __sk_migrate_realloc().
108048 - */
108049 - goto out_err_free;
108050 -
108051 - sk_filter_select_runtime(fp);
108052 -
108053 - kfree(old_prog);
108054 - return fp;
108055 -
108056 -out_err_free:
108057 - kfree(old_prog);
108058 -out_err:
108059 - /* Rollback filter setup. */
108060 - if (sk != NULL)
108061 - sk_filter_uncharge(sk, fp);
108062 - else
108063 - kfree(fp);
108064 - return ERR_PTR(err);
108065 -}
108066 -
108067 -void __weak bpf_int_jit_compile(struct sk_filter *prog)
108068 -{
108069 -}
108070 -
108071 -/**
108072 - * sk_filter_select_runtime - select execution runtime for BPF program
108073 - * @fp: sk_filter populated with internal BPF program
108074 - *
108075 - * try to JIT internal BPF program, if JIT is not available select interpreter
108076 - * BPF program will be executed via SK_RUN_FILTER() macro
108077 - */
108078 -void sk_filter_select_runtime(struct sk_filter *fp)
108079 -{
108080 - fp->bpf_func = (void *) __sk_run_filter;
108081 -
108082 - /* Probe if internal BPF can be JITed */
108083 - bpf_int_jit_compile(fp);
108084 -}
108085 -EXPORT_SYMBOL_GPL(sk_filter_select_runtime);
108086 -
108087 -/* free internal BPF program */
108088 -void sk_filter_free(struct sk_filter *fp)
108089 -{
108090 bpf_jit_free(fp);
108091 }
108092 -EXPORT_SYMBOL_GPL(sk_filter_free);
108093 +EXPORT_SYMBOL(sk_filter_release_rcu);
108094
108095 -static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
108096 - struct sock *sk)
108097 +static int __sk_prepare_filter(struct sk_filter *fp)
108098 {
108099 int err;
108100
108101 - fp->bpf_func = NULL;
108102 - fp->jited = 0;
108103 + fp->bpf_func = sk_run_filter;
108104
108105 err = sk_chk_filter(fp->insns, fp->len);
108106 - if (err) {
108107 - if (sk != NULL)
108108 - sk_filter_uncharge(sk, fp);
108109 - else
108110 - kfree(fp);
108111 - return ERR_PTR(err);
108112 - }
108113 + if (err)
108114 + return err;
108115
108116 - /* Probe if we can JIT compile the filter and if so, do
108117 - * the compilation of the filter.
108118 - */
108119 bpf_jit_compile(fp);
108120 -
108121 - /* JIT compiler couldn't process this filter, so do the
108122 - * internal BPF translation for the optimized interpreter.
108123 - */
108124 - if (!fp->jited)
108125 - fp = __sk_migrate_filter(fp, sk);
108126 -
108127 - return fp;
108128 + return 0;
108129 }
108130
108131 /**
108132 * sk_unattached_filter_create - create an unattached filter
108133 + * @fprog: the filter program
108134 * @pfp: the unattached filter that is created
108135 - * @fprog: the filter program
108136 *
108137 * Create a filter independent of any socket. We first run some
108138 * sanity checks on it to make sure it does not explode on us later.
108139 @@ -1533,10 +671,11 @@ static struct sk_filter *__sk_prepare_filter(struct sk_filter *fp,
108140 * a negative errno code is returned. On success the return is zero.
108141 */
108142 int sk_unattached_filter_create(struct sk_filter **pfp,
108143 - struct sock_fprog_kern *fprog)
108144 + struct sock_fprog *fprog)
108145 {
108146 - unsigned int fsize = sk_filter_proglen(fprog);
108147 struct sk_filter *fp;
108148 + unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
108149 + int err;
108150
108151 /* Make sure new filter is there and in the right amounts. */
108152 if (fprog->filter == NULL)
108153 @@ -1545,26 +684,20 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
108154 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
108155 if (!fp)
108156 return -ENOMEM;
108157 -
108158 - memcpy(fp->insns, fprog->filter, fsize);
108159 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
108160
108161 atomic_set(&fp->refcnt, 1);
108162 fp->len = fprog->len;
108163 - /* Since unattached filters are not copied back to user
108164 - * space through sk_get_filter(), we do not need to hold
108165 - * a copy here, and can spare us the work.
108166 - */
108167 - fp->orig_prog = NULL;
108168
108169 - /* __sk_prepare_filter() already takes care of uncharging
108170 - * memory in case something goes wrong.
108171 - */
108172 - fp = __sk_prepare_filter(fp, NULL);
108173 - if (IS_ERR(fp))
108174 - return PTR_ERR(fp);
108175 + err = __sk_prepare_filter(fp);
108176 + if (err)
108177 + goto free_mem;
108178
108179 *pfp = fp;
108180 return 0;
108181 +free_mem:
108182 + kfree(fp);
108183 + return err;
108184 }
108185 EXPORT_SYMBOL_GPL(sk_unattached_filter_create);
108186
108187 @@ -1587,7 +720,7 @@ EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);
108188 int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
108189 {
108190 struct sk_filter *fp, *old_fp;
108191 - unsigned int fsize = sk_filter_proglen(fprog);
108192 + unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
108193 unsigned int sk_fsize = sk_filter_size(fprog->len);
108194 int err;
108195
108196 @@ -1601,7 +734,6 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
108197 fp = sock_kmalloc(sk, sk_fsize, GFP_KERNEL);
108198 if (!fp)
108199 return -ENOMEM;
108200 -
108201 if (copy_from_user(fp->insns, fprog->filter, fsize)) {
108202 sock_kfree_s(sk, fp, sk_fsize);
108203 return -EFAULT;
108204 @@ -1610,26 +742,18 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
108205 atomic_set(&fp->refcnt, 1);
108206 fp->len = fprog->len;
108207
108208 - err = sk_store_orig_filter(fp, fprog);
108209 + err = __sk_prepare_filter(fp);
108210 if (err) {
108211 sk_filter_uncharge(sk, fp);
108212 - return -ENOMEM;
108213 + return err;
108214 }
108215
108216 - /* __sk_prepare_filter() already takes care of uncharging
108217 - * memory in case something goes wrong.
108218 - */
108219 - fp = __sk_prepare_filter(fp, sk);
108220 - if (IS_ERR(fp))
108221 - return PTR_ERR(fp);
108222 -
108223 old_fp = rcu_dereference_protected(sk->sk_filter,
108224 sock_owned_by_user(sk));
108225 rcu_assign_pointer(sk->sk_filter, fp);
108226
108227 if (old_fp)
108228 sk_filter_uncharge(sk, old_fp);
108229 -
108230 return 0;
108231 }
108232 EXPORT_SYMBOL_GPL(sk_attach_filter);
108233 @@ -1649,46 +773,116 @@ int sk_detach_filter(struct sock *sk)
108234 sk_filter_uncharge(sk, filter);
108235 ret = 0;
108236 }
108237 -
108238 return ret;
108239 }
108240 EXPORT_SYMBOL_GPL(sk_detach_filter);
108241
108242 -int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf,
108243 - unsigned int len)
108244 +void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
108245 +{
108246 + static const u16 decodes[] = {
108247 + [BPF_S_ALU_ADD_K] = BPF_ALU|BPF_ADD|BPF_K,
108248 + [BPF_S_ALU_ADD_X] = BPF_ALU|BPF_ADD|BPF_X,
108249 + [BPF_S_ALU_SUB_K] = BPF_ALU|BPF_SUB|BPF_K,
108250 + [BPF_S_ALU_SUB_X] = BPF_ALU|BPF_SUB|BPF_X,
108251 + [BPF_S_ALU_MUL_K] = BPF_ALU|BPF_MUL|BPF_K,
108252 + [BPF_S_ALU_MUL_X] = BPF_ALU|BPF_MUL|BPF_X,
108253 + [BPF_S_ALU_DIV_X] = BPF_ALU|BPF_DIV|BPF_X,
108254 + [BPF_S_ALU_MOD_K] = BPF_ALU|BPF_MOD|BPF_K,
108255 + [BPF_S_ALU_MOD_X] = BPF_ALU|BPF_MOD|BPF_X,
108256 + [BPF_S_ALU_AND_K] = BPF_ALU|BPF_AND|BPF_K,
108257 + [BPF_S_ALU_AND_X] = BPF_ALU|BPF_AND|BPF_X,
108258 + [BPF_S_ALU_OR_K] = BPF_ALU|BPF_OR|BPF_K,
108259 + [BPF_S_ALU_OR_X] = BPF_ALU|BPF_OR|BPF_X,
108260 + [BPF_S_ALU_XOR_K] = BPF_ALU|BPF_XOR|BPF_K,
108261 + [BPF_S_ALU_XOR_X] = BPF_ALU|BPF_XOR|BPF_X,
108262 + [BPF_S_ALU_LSH_K] = BPF_ALU|BPF_LSH|BPF_K,
108263 + [BPF_S_ALU_LSH_X] = BPF_ALU|BPF_LSH|BPF_X,
108264 + [BPF_S_ALU_RSH_K] = BPF_ALU|BPF_RSH|BPF_K,
108265 + [BPF_S_ALU_RSH_X] = BPF_ALU|BPF_RSH|BPF_X,
108266 + [BPF_S_ALU_NEG] = BPF_ALU|BPF_NEG,
108267 + [BPF_S_LD_W_ABS] = BPF_LD|BPF_W|BPF_ABS,
108268 + [BPF_S_LD_H_ABS] = BPF_LD|BPF_H|BPF_ABS,
108269 + [BPF_S_LD_B_ABS] = BPF_LD|BPF_B|BPF_ABS,
108270 + [BPF_S_ANC_PROTOCOL] = BPF_LD|BPF_B|BPF_ABS,
108271 + [BPF_S_ANC_PKTTYPE] = BPF_LD|BPF_B|BPF_ABS,
108272 + [BPF_S_ANC_IFINDEX] = BPF_LD|BPF_B|BPF_ABS,
108273 + [BPF_S_ANC_NLATTR] = BPF_LD|BPF_B|BPF_ABS,
108274 + [BPF_S_ANC_NLATTR_NEST] = BPF_LD|BPF_B|BPF_ABS,
108275 + [BPF_S_ANC_MARK] = BPF_LD|BPF_B|BPF_ABS,
108276 + [BPF_S_ANC_QUEUE] = BPF_LD|BPF_B|BPF_ABS,
108277 + [BPF_S_ANC_HATYPE] = BPF_LD|BPF_B|BPF_ABS,
108278 + [BPF_S_ANC_RXHASH] = BPF_LD|BPF_B|BPF_ABS,
108279 + [BPF_S_ANC_CPU] = BPF_LD|BPF_B|BPF_ABS,
108280 + [BPF_S_ANC_ALU_XOR_X] = BPF_LD|BPF_B|BPF_ABS,
108281 + [BPF_S_ANC_SECCOMP_LD_W] = BPF_LD|BPF_B|BPF_ABS,
108282 + [BPF_S_ANC_VLAN_TAG] = BPF_LD|BPF_B|BPF_ABS,
108283 + [BPF_S_ANC_VLAN_TAG_PRESENT] = BPF_LD|BPF_B|BPF_ABS,
108284 + [BPF_S_ANC_PAY_OFFSET] = BPF_LD|BPF_B|BPF_ABS,
108285 + [BPF_S_LD_W_LEN] = BPF_LD|BPF_W|BPF_LEN,
108286 + [BPF_S_LD_W_IND] = BPF_LD|BPF_W|BPF_IND,
108287 + [BPF_S_LD_H_IND] = BPF_LD|BPF_H|BPF_IND,
108288 + [BPF_S_LD_B_IND] = BPF_LD|BPF_B|BPF_IND,
108289 + [BPF_S_LD_IMM] = BPF_LD|BPF_IMM,
108290 + [BPF_S_LDX_W_LEN] = BPF_LDX|BPF_W|BPF_LEN,
108291 + [BPF_S_LDX_B_MSH] = BPF_LDX|BPF_B|BPF_MSH,
108292 + [BPF_S_LDX_IMM] = BPF_LDX|BPF_IMM,
108293 + [BPF_S_MISC_TAX] = BPF_MISC|BPF_TAX,
108294 + [BPF_S_MISC_TXA] = BPF_MISC|BPF_TXA,
108295 + [BPF_S_RET_K] = BPF_RET|BPF_K,
108296 + [BPF_S_RET_A] = BPF_RET|BPF_A,
108297 + [BPF_S_ALU_DIV_K] = BPF_ALU|BPF_DIV|BPF_K,
108298 + [BPF_S_LD_MEM] = BPF_LD|BPF_MEM,
108299 + [BPF_S_LDX_MEM] = BPF_LDX|BPF_MEM,
108300 + [BPF_S_ST] = BPF_ST,
108301 + [BPF_S_STX] = BPF_STX,
108302 + [BPF_S_JMP_JA] = BPF_JMP|BPF_JA,
108303 + [BPF_S_JMP_JEQ_K] = BPF_JMP|BPF_JEQ|BPF_K,
108304 + [BPF_S_JMP_JEQ_X] = BPF_JMP|BPF_JEQ|BPF_X,
108305 + [BPF_S_JMP_JGE_K] = BPF_JMP|BPF_JGE|BPF_K,
108306 + [BPF_S_JMP_JGE_X] = BPF_JMP|BPF_JGE|BPF_X,
108307 + [BPF_S_JMP_JGT_K] = BPF_JMP|BPF_JGT|BPF_K,
108308 + [BPF_S_JMP_JGT_X] = BPF_JMP|BPF_JGT|BPF_X,
108309 + [BPF_S_JMP_JSET_K] = BPF_JMP|BPF_JSET|BPF_K,
108310 + [BPF_S_JMP_JSET_X] = BPF_JMP|BPF_JSET|BPF_X,
108311 + };
108312 + u16 code;
108313 +
108314 + code = filt->code;
108315 +
108316 + to->code = decodes[code];
108317 + to->jt = filt->jt;
108318 + to->jf = filt->jf;
108319 + to->k = filt->k;
108320 +}
108321 +
108322 +int sk_get_filter(struct sock *sk, struct sock_filter __user *ubuf, unsigned int len)
108323 {
108324 - struct sock_fprog_kern *fprog;
108325 struct sk_filter *filter;
108326 - int ret = 0;
108327 + int i, ret;
108328
108329 lock_sock(sk);
108330 filter = rcu_dereference_protected(sk->sk_filter,
108331 - sock_owned_by_user(sk));
108332 + sock_owned_by_user(sk));
108333 + ret = 0;
108334 if (!filter)
108335 goto out;
108336 -
108337 - /* We're copying the filter that has been originally attached,
108338 - * so no conversion/decode needed anymore.
108339 - */
108340 - fprog = filter->orig_prog;
108341 -
108342 - ret = fprog->len;
108343 + ret = filter->len;
108344 if (!len)
108345 - /* User space only enquires number of filter blocks. */
108346 goto out;
108347 -
108348 ret = -EINVAL;
108349 - if (len < fprog->len)
108350 + if (len < filter->len)
108351 goto out;
108352
108353 ret = -EFAULT;
108354 - if (copy_to_user(ubuf, fprog->filter, sk_filter_proglen(fprog)))
108355 - goto out;
108356 + for (i = 0; i < filter->len; i++) {
108357 + struct sock_filter fb;
108358
108359 - /* Instead of bytes, the API requests to return the number
108360 - * of filter blocks.
108361 - */
108362 - ret = fprog->len;
108363 + sk_decode_filter(&filter->insns[i], &fb);
108364 + if (copy_to_user(&ubuf[i], &fb, sizeof(fb)))
108365 + goto out;
108366 + }
108367 +
108368 + ret = filter->len;
108369 out:
108370 release_sock(sk);
108371 return ret;
108372 diff --git a/net/core/flow.c b/net/core/flow.c
108373 index a0348fd..6951c76 100644
108374 --- a/net/core/flow.c
108375 +++ b/net/core/flow.c
108376 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
108377 static int flow_entry_valid(struct flow_cache_entry *fle,
108378 struct netns_xfrm *xfrm)
108379 {
108380 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
108381 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
108382 return 0;
108383 if (fle->object && !fle->object->ops->check(fle->object))
108384 return 0;
108385 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
108386 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
108387 fcp->hash_count++;
108388 }
108389 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
108390 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
108391 flo = fle->object;
108392 if (!flo)
108393 goto ret_object;
108394 @@ -263,7 +263,7 @@ nocache:
108395 }
108396 flo = resolver(net, key, family, dir, flo, ctx);
108397 if (fle) {
108398 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
108399 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
108400 if (!IS_ERR(flo))
108401 fle->object = flo;
108402 else
108403 diff --git a/net/core/iovec.c b/net/core/iovec.c
108404 index e1ec45a..e5c6f16 100644
108405 --- a/net/core/iovec.c
108406 +++ b/net/core/iovec.c
108407 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
108408 if (m->msg_name && m->msg_namelen) {
108409 if (mode == VERIFY_READ) {
108410 void __user *namep;
108411 - namep = (void __user __force *) m->msg_name;
108412 + namep = (void __force_user *) m->msg_name;
108413 err = move_addr_to_kernel(namep, m->msg_namelen,
108414 address);
108415 if (err < 0)
108416 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
108417 }
108418
108419 size = m->msg_iovlen * sizeof(struct iovec);
108420 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
108421 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
108422 return -EFAULT;
108423
108424 m->msg_iov = iov;
108425 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
108426 index ef31fef..8be66d9 100644
108427 --- a/net/core/neighbour.c
108428 +++ b/net/core/neighbour.c
108429 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
108430 void __user *buffer, size_t *lenp, loff_t *ppos)
108431 {
108432 int size, ret;
108433 - struct ctl_table tmp = *ctl;
108434 + ctl_table_no_const tmp = *ctl;
108435
108436 tmp.extra1 = &zero;
108437 tmp.extra2 = &unres_qlen_max;
108438 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
108439 void __user *buffer,
108440 size_t *lenp, loff_t *ppos)
108441 {
108442 - struct ctl_table tmp = *ctl;
108443 + ctl_table_no_const tmp = *ctl;
108444 int ret;
108445
108446 tmp.extra1 = &zero;
108447 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
108448 index 2bf8329..2eb1423 100644
108449 --- a/net/core/net-procfs.c
108450 +++ b/net/core/net-procfs.c
108451 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
108452 struct rtnl_link_stats64 temp;
108453 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
108454
108455 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
108456 + if (gr_proc_is_restricted())
108457 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
108458 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
108459 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
108460 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
108461 + else
108462 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
108463 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
108464 dev->name, stats->rx_bytes, stats->rx_packets,
108465 stats->rx_errors,
108466 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
108467 return 0;
108468 }
108469
108470 -static const struct seq_operations dev_seq_ops = {
108471 +const struct seq_operations dev_seq_ops = {
108472 .start = dev_seq_start,
108473 .next = dev_seq_next,
108474 .stop = dev_seq_stop,
108475 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
108476
108477 static int softnet_seq_open(struct inode *inode, struct file *file)
108478 {
108479 - return seq_open(file, &softnet_seq_ops);
108480 + return seq_open_restrict(file, &softnet_seq_ops);
108481 }
108482
108483 static const struct file_operations softnet_seq_fops = {
108484 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
108485 else
108486 seq_printf(seq, "%04x", ntohs(pt->type));
108487
108488 +#ifdef CONFIG_GRKERNSEC_HIDESYM
108489 + seq_printf(seq, " %-8s %pf\n",
108490 + pt->dev ? pt->dev->name : "", NULL);
108491 +#else
108492 seq_printf(seq, " %-8s %pf\n",
108493 pt->dev ? pt->dev->name : "", pt->func);
108494 +#endif
108495 }
108496
108497 return 0;
108498 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
108499 index 1cac29e..fb482f3 100644
108500 --- a/net/core/net-sysfs.c
108501 +++ b/net/core/net-sysfs.c
108502 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
108503 {
108504 struct net_device *netdev = to_net_dev(dev);
108505 return sprintf(buf, fmt_dec,
108506 - atomic_read(&netdev->carrier_changes));
108507 + atomic_read_unchecked(&netdev->carrier_changes));
108508 }
108509 static DEVICE_ATTR_RO(carrier_changes);
108510
108511 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
108512 index 85b6269..fc77ea0 100644
108513 --- a/net/core/net_namespace.c
108514 +++ b/net/core/net_namespace.c
108515 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
108516 int error;
108517 LIST_HEAD(net_exit_list);
108518
108519 - list_add_tail(&ops->list, list);
108520 + pax_list_add_tail((struct list_head *)&ops->list, list);
108521 if (ops->init || (ops->id && ops->size)) {
108522 for_each_net(net) {
108523 error = ops_init(ops, net);
108524 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
108525
108526 out_undo:
108527 /* If I have an error cleanup all namespaces I initialized */
108528 - list_del(&ops->list);
108529 + pax_list_del((struct list_head *)&ops->list);
108530 ops_exit_list(ops, &net_exit_list);
108531 ops_free_list(ops, &net_exit_list);
108532 return error;
108533 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
108534 struct net *net;
108535 LIST_HEAD(net_exit_list);
108536
108537 - list_del(&ops->list);
108538 + pax_list_del((struct list_head *)&ops->list);
108539 for_each_net(net)
108540 list_add_tail(&net->exit_list, &net_exit_list);
108541 ops_exit_list(ops, &net_exit_list);
108542 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
108543 mutex_lock(&net_mutex);
108544 error = register_pernet_operations(&pernet_list, ops);
108545 if (!error && (first_device == &pernet_list))
108546 - first_device = &ops->list;
108547 + first_device = (struct list_head *)&ops->list;
108548 mutex_unlock(&net_mutex);
108549 return error;
108550 }
108551 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
108552 index e33937f..b2b4981 100644
108553 --- a/net/core/netpoll.c
108554 +++ b/net/core/netpoll.c
108555 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
108556 struct udphdr *udph;
108557 struct iphdr *iph;
108558 struct ethhdr *eth;
108559 - static atomic_t ip_ident;
108560 + static atomic_unchecked_t ip_ident;
108561 struct ipv6hdr *ip6h;
108562
108563 udp_len = len + sizeof(*udph);
108564 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
108565 put_unaligned(0x45, (unsigned char *)iph);
108566 iph->tos = 0;
108567 put_unaligned(htons(ip_len), &(iph->tot_len));
108568 - iph->id = htons(atomic_inc_return(&ip_ident));
108569 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
108570 iph->frag_off = 0;
108571 iph->ttl = 64;
108572 iph->protocol = IPPROTO_UDP;
108573 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
108574 index fc17a9d..d4a3d88 100644
108575 --- a/net/core/pktgen.c
108576 +++ b/net/core/pktgen.c
108577 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
108578 pn->net = net;
108579 INIT_LIST_HEAD(&pn->pktgen_threads);
108580 pn->pktgen_exiting = false;
108581 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
108582 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
108583 if (!pn->proc_dir) {
108584 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
108585 return -ENODEV;
108586 diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
108587 deleted file mode 100644
108588 index d3027a7..0000000
108589 --- a/net/core/ptp_classifier.c
108590 +++ /dev/null
108591 @@ -1,141 +0,0 @@
108592 -/* PTP classifier
108593 - *
108594 - * This program is free software; you can redistribute it and/or
108595 - * modify it under the terms of version 2 of the GNU General Public
108596 - * License as published by the Free Software Foundation.
108597 - *
108598 - * This program is distributed in the hope that it will be useful, but
108599 - * WITHOUT ANY WARRANTY; without even the implied warranty of
108600 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
108601 - * General Public License for more details.
108602 - */
108603 -
108604 -/* The below program is the bpf_asm (tools/net/) representation of
108605 - * the opcode array in the ptp_filter structure.
108606 - *
108607 - * For convenience, this can easily be altered and reviewed with
108608 - * bpf_asm and bpf_dbg, e.g. `./bpf_asm -c prog` where prog is a
108609 - * simple file containing the below program:
108610 - *
108611 - * ldh [12] ; load ethertype
108612 - *
108613 - * ; PTP over UDP over IPv4 over Ethernet
108614 - * test_ipv4:
108615 - * jneq #0x800, test_ipv6 ; ETH_P_IP ?
108616 - * ldb [23] ; load proto
108617 - * jneq #17, drop_ipv4 ; IPPROTO_UDP ?
108618 - * ldh [20] ; load frag offset field
108619 - * jset #0x1fff, drop_ipv4 ; don't allow fragments
108620 - * ldxb 4*([14]&0xf) ; load IP header len
108621 - * ldh [x + 16] ; load UDP dst port
108622 - * jneq #319, drop_ipv4 ; is port PTP_EV_PORT ?
108623 - * ldh [x + 22] ; load payload
108624 - * and #0xf ; mask PTP_CLASS_VMASK
108625 - * or #0x10 ; PTP_CLASS_IPV4
108626 - * ret a ; return PTP class
108627 - * drop_ipv4: ret #0x0 ; PTP_CLASS_NONE
108628 - *
108629 - * ; PTP over UDP over IPv6 over Ethernet
108630 - * test_ipv6:
108631 - * jneq #0x86dd, test_8021q ; ETH_P_IPV6 ?
108632 - * ldb [20] ; load proto
108633 - * jneq #17, drop_ipv6 ; IPPROTO_UDP ?
108634 - * ldh [56] ; load UDP dst port
108635 - * jneq #319, drop_ipv6 ; is port PTP_EV_PORT ?
108636 - * ldh [62] ; load payload
108637 - * and #0xf ; mask PTP_CLASS_VMASK
108638 - * or #0x20 ; PTP_CLASS_IPV6
108639 - * ret a ; return PTP class
108640 - * drop_ipv6: ret #0x0 ; PTP_CLASS_NONE
108641 - *
108642 - * ; PTP over 802.1Q over Ethernet
108643 - * test_8021q:
108644 - * jneq #0x8100, test_ieee1588 ; ETH_P_8021Q ?
108645 - * ldh [16] ; load inner type
108646 - * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
108647 - * ldb [18] ; load payload
108648 - * and #0x8 ; as we don't have ports here, test
108649 - * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
108650 - * ldh [18] ; reload payload
108651 - * and #0xf ; mask PTP_CLASS_VMASK
108652 - * or #0x40 ; PTP_CLASS_V2_VLAN
108653 - * ret a ; return PTP class
108654 - *
108655 - * ; PTP over Ethernet
108656 - * test_ieee1588:
108657 - * jneq #0x88f7, drop_ieee1588 ; ETH_P_1588 ?
108658 - * ldb [14] ; load payload
108659 - * and #0x8 ; as we don't have ports here, test
108660 - * jneq #0x0, drop_ieee1588 ; for PTP_GEN_BIT and drop these
108661 - * ldh [14] ; reload payload
108662 - * and #0xf ; mask PTP_CLASS_VMASK
108663 - * or #0x30 ; PTP_CLASS_L2
108664 - * ret a ; return PTP class
108665 - * drop_ieee1588: ret #0x0 ; PTP_CLASS_NONE
108666 - */
108667 -
108668 -#include <linux/skbuff.h>
108669 -#include <linux/filter.h>
108670 -#include <linux/ptp_classify.h>
108671 -
108672 -static struct sk_filter *ptp_insns __read_mostly;
108673 -
108674 -unsigned int ptp_classify_raw(const struct sk_buff *skb)
108675 -{
108676 - return SK_RUN_FILTER(ptp_insns, skb);
108677 -}
108678 -EXPORT_SYMBOL_GPL(ptp_classify_raw);
108679 -
108680 -void __init ptp_classifier_init(void)
108681 -{
108682 - static struct sock_filter ptp_filter[] __initdata = {
108683 - { 0x28, 0, 0, 0x0000000c },
108684 - { 0x15, 0, 12, 0x00000800 },
108685 - { 0x30, 0, 0, 0x00000017 },
108686 - { 0x15, 0, 9, 0x00000011 },
108687 - { 0x28, 0, 0, 0x00000014 },
108688 - { 0x45, 7, 0, 0x00001fff },
108689 - { 0xb1, 0, 0, 0x0000000e },
108690 - { 0x48, 0, 0, 0x00000010 },
108691 - { 0x15, 0, 4, 0x0000013f },
108692 - { 0x48, 0, 0, 0x00000016 },
108693 - { 0x54, 0, 0, 0x0000000f },
108694 - { 0x44, 0, 0, 0x00000010 },
108695 - { 0x16, 0, 0, 0x00000000 },
108696 - { 0x06, 0, 0, 0x00000000 },
108697 - { 0x15, 0, 9, 0x000086dd },
108698 - { 0x30, 0, 0, 0x00000014 },
108699 - { 0x15, 0, 6, 0x00000011 },
108700 - { 0x28, 0, 0, 0x00000038 },
108701 - { 0x15, 0, 4, 0x0000013f },
108702 - { 0x28, 0, 0, 0x0000003e },
108703 - { 0x54, 0, 0, 0x0000000f },
108704 - { 0x44, 0, 0, 0x00000020 },
108705 - { 0x16, 0, 0, 0x00000000 },
108706 - { 0x06, 0, 0, 0x00000000 },
108707 - { 0x15, 0, 9, 0x00008100 },
108708 - { 0x28, 0, 0, 0x00000010 },
108709 - { 0x15, 0, 15, 0x000088f7 },
108710 - { 0x30, 0, 0, 0x00000012 },
108711 - { 0x54, 0, 0, 0x00000008 },
108712 - { 0x15, 0, 12, 0x00000000 },
108713 - { 0x28, 0, 0, 0x00000012 },
108714 - { 0x54, 0, 0, 0x0000000f },
108715 - { 0x44, 0, 0, 0x00000040 },
108716 - { 0x16, 0, 0, 0x00000000 },
108717 - { 0x15, 0, 7, 0x000088f7 },
108718 - { 0x30, 0, 0, 0x0000000e },
108719 - { 0x54, 0, 0, 0x00000008 },
108720 - { 0x15, 0, 4, 0x00000000 },
108721 - { 0x28, 0, 0, 0x0000000e },
108722 - { 0x54, 0, 0, 0x0000000f },
108723 - { 0x44, 0, 0, 0x00000030 },
108724 - { 0x16, 0, 0, 0x00000000 },
108725 - { 0x06, 0, 0, 0x00000000 },
108726 - };
108727 - struct sock_fprog_kern ptp_prog = {
108728 - .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
108729 - };
108730 -
108731 - BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
108732 -}
108733 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
108734 index 1063996..0729c19 100644
108735 --- a/net/core/rtnetlink.c
108736 +++ b/net/core/rtnetlink.c
108737 @@ -58,7 +58,7 @@ struct rtnl_link {
108738 rtnl_doit_func doit;
108739 rtnl_dumpit_func dumpit;
108740 rtnl_calcit_func calcit;
108741 -};
108742 +} __no_const;
108743
108744 static DEFINE_MUTEX(rtnl_mutex);
108745
108746 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
108747 if (rtnl_link_ops_get(ops->kind))
108748 return -EEXIST;
108749
108750 - if (!ops->dellink)
108751 - ops->dellink = unregister_netdevice_queue;
108752 + if (!ops->dellink) {
108753 + pax_open_kernel();
108754 + *(void **)&ops->dellink = unregister_netdevice_queue;
108755 + pax_close_kernel();
108756 + }
108757
108758 - list_add_tail(&ops->list, &link_ops);
108759 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
108760 return 0;
108761 }
108762 EXPORT_SYMBOL_GPL(__rtnl_link_register);
108763 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
108764 for_each_net(net) {
108765 __rtnl_kill_links(net, ops);
108766 }
108767 - list_del(&ops->list);
108768 + pax_list_del((struct list_head *)&ops->list);
108769 }
108770 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
108771
108772 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
108773 (dev->ifalias &&
108774 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
108775 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
108776 - atomic_read(&dev->carrier_changes)))
108777 + atomic_read_unchecked(&dev->carrier_changes)))
108778 goto nla_put_failure;
108779
108780 if (1) {
108781 diff --git a/net/core/scm.c b/net/core/scm.c
108782 index b442e7e..6f5b5a2 100644
108783 --- a/net/core/scm.c
108784 +++ b/net/core/scm.c
108785 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
108786 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
108787 {
108788 struct cmsghdr __user *cm
108789 - = (__force struct cmsghdr __user *)msg->msg_control;
108790 + = (struct cmsghdr __force_user *)msg->msg_control;
108791 struct cmsghdr cmhdr;
108792 int cmlen = CMSG_LEN(len);
108793 int err;
108794 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
108795 err = -EFAULT;
108796 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
108797 goto out;
108798 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
108799 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
108800 goto out;
108801 cmlen = CMSG_SPACE(len);
108802 if (msg->msg_controllen < cmlen)
108803 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
108804 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
108805 {
108806 struct cmsghdr __user *cm
108807 - = (__force struct cmsghdr __user*)msg->msg_control;
108808 + = (struct cmsghdr __force_user *)msg->msg_control;
108809
108810 int fdmax = 0;
108811 int fdnum = scm->fp->count;
108812 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
108813 if (fdnum < fdmax)
108814 fdmax = fdnum;
108815
108816 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
108817 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
108818 i++, cmfptr++)
108819 {
108820 struct socket *sock;
108821 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
108822 index 58ff88e..af9b458 100644
108823 --- a/net/core/skbuff.c
108824 +++ b/net/core/skbuff.c
108825 @@ -2010,7 +2010,7 @@ EXPORT_SYMBOL(__skb_checksum);
108826 __wsum skb_checksum(const struct sk_buff *skb, int offset,
108827 int len, __wsum csum)
108828 {
108829 - const struct skb_checksum_ops ops = {
108830 + static const struct skb_checksum_ops ops = {
108831 .update = csum_partial_ext,
108832 .combine = csum_block_add_ext,
108833 };
108834 @@ -3233,13 +3233,15 @@ void __init skb_init(void)
108835 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
108836 sizeof(struct sk_buff),
108837 0,
108838 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
108839 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
108840 + SLAB_NO_SANITIZE,
108841 NULL);
108842 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
108843 (2*sizeof(struct sk_buff)) +
108844 sizeof(atomic_t),
108845 0,
108846 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
108847 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
108848 + SLAB_NO_SANITIZE,
108849 NULL);
108850 }
108851
108852 diff --git a/net/core/sock.c b/net/core/sock.c
108853 index 026e01f..f54f908 100644
108854 --- a/net/core/sock.c
108855 +++ b/net/core/sock.c
108856 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
108857 struct sk_buff_head *list = &sk->sk_receive_queue;
108858
108859 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
108860 - atomic_inc(&sk->sk_drops);
108861 + atomic_inc_unchecked(&sk->sk_drops);
108862 trace_sock_rcvqueue_full(sk, skb);
108863 return -ENOMEM;
108864 }
108865 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
108866 return err;
108867
108868 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
108869 - atomic_inc(&sk->sk_drops);
108870 + atomic_inc_unchecked(&sk->sk_drops);
108871 return -ENOBUFS;
108872 }
108873
108874 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
108875 skb_dst_force(skb);
108876
108877 spin_lock_irqsave(&list->lock, flags);
108878 - skb->dropcount = atomic_read(&sk->sk_drops);
108879 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
108880 __skb_queue_tail(list, skb);
108881 spin_unlock_irqrestore(&list->lock, flags);
108882
108883 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
108884 skb->dev = NULL;
108885
108886 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
108887 - atomic_inc(&sk->sk_drops);
108888 + atomic_inc_unchecked(&sk->sk_drops);
108889 goto discard_and_relse;
108890 }
108891 if (nested)
108892 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
108893 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
108894 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
108895 bh_unlock_sock(sk);
108896 - atomic_inc(&sk->sk_drops);
108897 + atomic_inc_unchecked(&sk->sk_drops);
108898 goto discard_and_relse;
108899 }
108900
108901 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
108902 struct timeval tm;
108903 } v;
108904
108905 - int lv = sizeof(int);
108906 - int len;
108907 + unsigned int lv = sizeof(int);
108908 + unsigned int len;
108909
108910 if (get_user(len, optlen))
108911 return -EFAULT;
108912 - if (len < 0)
108913 + if (len > INT_MAX)
108914 return -EINVAL;
108915
108916 memset(&v, 0, sizeof(v));
108917 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
108918
108919 case SO_PEERNAME:
108920 {
108921 - char address[128];
108922 + char address[_K_SS_MAXSIZE];
108923
108924 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
108925 return -ENOTCONN;
108926 - if (lv < len)
108927 + if (lv < len || sizeof address < len)
108928 return -EINVAL;
108929 if (copy_to_user(optval, address, len))
108930 return -EFAULT;
108931 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
108932
108933 if (len > lv)
108934 len = lv;
108935 - if (copy_to_user(optval, &v, len))
108936 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
108937 return -EFAULT;
108938 lenout:
108939 if (put_user(len, optlen))
108940 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
108941 */
108942 smp_wmb();
108943 atomic_set(&sk->sk_refcnt, 1);
108944 - atomic_set(&sk->sk_drops, 0);
108945 + atomic_set_unchecked(&sk->sk_drops, 0);
108946 }
108947 EXPORT_SYMBOL(sock_init_data);
108948
108949 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
108950 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
108951 int level, int type)
108952 {
108953 + struct sock_extended_err ee;
108954 struct sock_exterr_skb *serr;
108955 struct sk_buff *skb, *skb2;
108956 int copied, err;
108957 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
108958 sock_recv_timestamp(msg, sk, skb);
108959
108960 serr = SKB_EXT_ERR(skb);
108961 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
108962 + ee = serr->ee;
108963 + put_cmsg(msg, level, type, sizeof ee, &ee);
108964
108965 msg->msg_flags |= MSG_ERRQUEUE;
108966 err = copied;
108967 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
108968 index a4216a4..773e3d7 100644
108969 --- a/net/core/sock_diag.c
108970 +++ b/net/core/sock_diag.c
108971 @@ -9,26 +9,33 @@
108972 #include <linux/inet_diag.h>
108973 #include <linux/sock_diag.h>
108974
108975 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
108976 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
108977 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
108978 static DEFINE_MUTEX(sock_diag_table_mutex);
108979
108980 int sock_diag_check_cookie(void *sk, __u32 *cookie)
108981 {
108982 +#ifndef CONFIG_GRKERNSEC_HIDESYM
108983 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
108984 cookie[1] != INET_DIAG_NOCOOKIE) &&
108985 ((u32)(unsigned long)sk != cookie[0] ||
108986 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
108987 return -ESTALE;
108988 else
108989 +#endif
108990 return 0;
108991 }
108992 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
108993
108994 void sock_diag_save_cookie(void *sk, __u32 *cookie)
108995 {
108996 +#ifdef CONFIG_GRKERNSEC_HIDESYM
108997 + cookie[0] = 0;
108998 + cookie[1] = 0;
108999 +#else
109000 cookie[0] = (u32)(unsigned long)sk;
109001 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
109002 +#endif
109003 }
109004 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
109005
109006 @@ -52,10 +59,9 @@ EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
109007 int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
109008 struct sk_buff *skb, int attrtype)
109009 {
109010 - struct sock_fprog_kern *fprog;
109011 - struct sk_filter *filter;
109012 struct nlattr *attr;
109013 - unsigned int flen;
109014 + struct sk_filter *filter;
109015 + unsigned int len;
109016 int err = 0;
109017
109018 if (!may_report_filterinfo) {
109019 @@ -64,20 +70,24 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
109020 }
109021
109022 rcu_read_lock();
109023 +
109024 filter = rcu_dereference(sk->sk_filter);
109025 - if (!filter)
109026 - goto out;
109027 + len = filter ? filter->len * sizeof(struct sock_filter) : 0;
109028
109029 - fprog = filter->orig_prog;
109030 - flen = sk_filter_proglen(fprog);
109031 -
109032 - attr = nla_reserve(skb, attrtype, flen);
109033 + attr = nla_reserve(skb, attrtype, len);
109034 if (attr == NULL) {
109035 err = -EMSGSIZE;
109036 goto out;
109037 }
109038
109039 - memcpy(nla_data(attr), fprog->filter, flen);
109040 + if (filter) {
109041 + struct sock_filter *fb = (struct sock_filter *)nla_data(attr);
109042 + int i;
109043 +
109044 + for (i = 0; i < filter->len; i++, fb++)
109045 + sk_decode_filter(&filter->insns[i], fb);
109046 + }
109047 +
109048 out:
109049 rcu_read_unlock();
109050 return err;
109051 @@ -110,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
109052 mutex_lock(&sock_diag_table_mutex);
109053 if (sock_diag_handlers[hndl->family])
109054 err = -EBUSY;
109055 - else
109056 + else {
109057 + pax_open_kernel();
109058 sock_diag_handlers[hndl->family] = hndl;
109059 + pax_close_kernel();
109060 + }
109061 mutex_unlock(&sock_diag_table_mutex);
109062
109063 return err;
109064 @@ -127,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
109065
109066 mutex_lock(&sock_diag_table_mutex);
109067 BUG_ON(sock_diag_handlers[family] != hnld);
109068 + pax_open_kernel();
109069 sock_diag_handlers[family] = NULL;
109070 + pax_close_kernel();
109071 mutex_unlock(&sock_diag_table_mutex);
109072 }
109073 EXPORT_SYMBOL_GPL(sock_diag_unregister);
109074 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
109075 index cf9cd13..8b56af3 100644
109076 --- a/net/core/sysctl_net_core.c
109077 +++ b/net/core/sysctl_net_core.c
109078 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
109079 {
109080 unsigned int orig_size, size;
109081 int ret, i;
109082 - struct ctl_table tmp = {
109083 + ctl_table_no_const tmp = {
109084 .data = &size,
109085 .maxlen = sizeof(size),
109086 .mode = table->mode
109087 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
109088 void __user *buffer, size_t *lenp, loff_t *ppos)
109089 {
109090 char id[IFNAMSIZ];
109091 - struct ctl_table tbl = {
109092 + ctl_table_no_const tbl = {
109093 .data = id,
109094 .maxlen = IFNAMSIZ,
109095 };
109096 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
109097
109098 static __net_init int sysctl_core_net_init(struct net *net)
109099 {
109100 - struct ctl_table *tbl;
109101 + ctl_table_no_const *tbl = NULL;
109102
109103 net->core.sysctl_somaxconn = SOMAXCONN;
109104
109105 - tbl = netns_core_table;
109106 if (!net_eq(net, &init_net)) {
109107 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
109108 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
109109 if (tbl == NULL)
109110 goto err_dup;
109111
109112 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
109113 if (net->user_ns != &init_user_ns) {
109114 tbl[0].procname = NULL;
109115 }
109116 - }
109117 -
109118 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
109119 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
109120 + } else
109121 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
109122 if (net->core.sysctl_hdr == NULL)
109123 goto err_reg;
109124
109125 return 0;
109126
109127 err_reg:
109128 - if (tbl != netns_core_table)
109129 - kfree(tbl);
109130 + kfree(tbl);
109131 err_dup:
109132 return -ENOMEM;
109133 }
109134 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
109135 kfree(tbl);
109136 }
109137
109138 -static __net_initdata struct pernet_operations sysctl_core_ops = {
109139 +static __net_initconst struct pernet_operations sysctl_core_ops = {
109140 .init = sysctl_core_net_init,
109141 .exit = sysctl_core_net_exit,
109142 };
109143 diff --git a/net/core/timestamping.c b/net/core/timestamping.c
109144 index 6521dfd..661b5a4 100644
109145 --- a/net/core/timestamping.c
109146 +++ b/net/core/timestamping.c
109147 @@ -23,11 +23,16 @@
109148 #include <linux/skbuff.h>
109149 #include <linux/export.h>
109150
109151 +static struct sock_filter ptp_filter[] = {
109152 + PTP_FILTER
109153 +};
109154 +
109155 static unsigned int classify(const struct sk_buff *skb)
109156 {
109157 - if (likely(skb->dev && skb->dev->phydev &&
109158 + if (likely(skb->dev &&
109159 + skb->dev->phydev &&
109160 skb->dev->phydev->drv))
109161 - return ptp_classify_raw(skb);
109162 + return sk_run_filter(skb, ptp_filter);
109163 else
109164 return PTP_CLASS_NONE;
109165 }
109166 @@ -55,13 +60,11 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
109167 if (likely(phydev->drv->txtstamp)) {
109168 if (!atomic_inc_not_zero(&sk->sk_refcnt))
109169 return;
109170 -
109171 clone = skb_clone(skb, GFP_ATOMIC);
109172 if (!clone) {
109173 sock_put(sk);
109174 return;
109175 }
109176 -
109177 clone->sk = sk;
109178 phydev->drv->txtstamp(phydev, clone, type);
109179 }
109180 @@ -86,15 +89,12 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
109181 }
109182
109183 *skb_hwtstamps(skb) = *hwtstamps;
109184 -
109185 serr = SKB_EXT_ERR(skb);
109186 memset(serr, 0, sizeof(*serr));
109187 serr->ee.ee_errno = ENOMSG;
109188 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
109189 skb->sk = NULL;
109190 -
109191 err = sock_queue_err_skb(sk, skb);
109192 -
109193 sock_put(sk);
109194 if (err)
109195 kfree_skb(skb);
109196 @@ -132,3 +132,8 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
109197 return false;
109198 }
109199 EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
109200 +
109201 +void __init skb_timestamping_init(void)
109202 +{
109203 + BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter)));
109204 +}
109205 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
109206 index ae011b4..d2d18bf 100644
109207 --- a/net/decnet/af_decnet.c
109208 +++ b/net/decnet/af_decnet.c
109209 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
109210 .sysctl_rmem = sysctl_decnet_rmem,
109211 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
109212 .obj_size = sizeof(struct dn_sock),
109213 + .slab_flags = SLAB_USERCOPY,
109214 };
109215
109216 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
109217 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
109218 index 3b726f3..1af6368 100644
109219 --- a/net/decnet/dn_dev.c
109220 +++ b/net/decnet/dn_dev.c
109221 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
109222 .extra1 = &min_t3,
109223 .extra2 = &max_t3
109224 },
109225 - {0}
109226 + { }
109227 },
109228 };
109229
109230 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
109231 index 5325b54..a0d4d69 100644
109232 --- a/net/decnet/sysctl_net_decnet.c
109233 +++ b/net/decnet/sysctl_net_decnet.c
109234 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
109235
109236 if (len > *lenp) len = *lenp;
109237
109238 - if (copy_to_user(buffer, addr, len))
109239 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
109240 return -EFAULT;
109241
109242 *lenp = len;
109243 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
109244
109245 if (len > *lenp) len = *lenp;
109246
109247 - if (copy_to_user(buffer, devname, len))
109248 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
109249 return -EFAULT;
109250
109251 *lenp = len;
109252 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
109253 index 6f1428c..9586b83 100644
109254 --- a/net/ieee802154/reassembly.c
109255 +++ b/net/ieee802154/reassembly.c
109256 @@ -438,14 +438,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
109257
109258 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
109259 {
109260 - struct ctl_table *table;
109261 + ctl_table_no_const *table = NULL;
109262 struct ctl_table_header *hdr;
109263 struct netns_ieee802154_lowpan *ieee802154_lowpan =
109264 net_ieee802154_lowpan(net);
109265
109266 - table = lowpan_frags_ns_ctl_table;
109267 if (!net_eq(net, &init_net)) {
109268 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
109269 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
109270 GFP_KERNEL);
109271 if (table == NULL)
109272 goto err_alloc;
109273 @@ -458,9 +457,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
109274 /* Don't export sysctls to unprivileged users */
109275 if (net->user_ns != &init_user_ns)
109276 table[0].procname = NULL;
109277 - }
109278 -
109279 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
109280 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
109281 + } else
109282 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
109283 if (hdr == NULL)
109284 goto err_reg;
109285
109286 @@ -468,8 +467,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
109287 return 0;
109288
109289 err_reg:
109290 - if (!net_eq(net, &init_net))
109291 - kfree(table);
109292 + kfree(table);
109293 err_alloc:
109294 return -ENOMEM;
109295 }
109296 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
109297 index e944937..368fe78 100644
109298 --- a/net/ipv4/devinet.c
109299 +++ b/net/ipv4/devinet.c
109300 @@ -1540,7 +1540,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
109301 idx = 0;
109302 head = &net->dev_index_head[h];
109303 rcu_read_lock();
109304 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
109305 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
109306 net->dev_base_seq;
109307 hlist_for_each_entry_rcu(dev, head, index_hlist) {
109308 if (idx < s_idx)
109309 @@ -1858,7 +1858,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
109310 idx = 0;
109311 head = &net->dev_index_head[h];
109312 rcu_read_lock();
109313 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
109314 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
109315 net->dev_base_seq;
109316 hlist_for_each_entry_rcu(dev, head, index_hlist) {
109317 if (idx < s_idx)
109318 @@ -2093,7 +2093,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
109319 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
109320 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
109321
109322 -static struct devinet_sysctl_table {
109323 +static const struct devinet_sysctl_table {
109324 struct ctl_table_header *sysctl_header;
109325 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
109326 } devinet_sysctl = {
109327 @@ -2215,7 +2215,7 @@ static __net_init int devinet_init_net(struct net *net)
109328 int err;
109329 struct ipv4_devconf *all, *dflt;
109330 #ifdef CONFIG_SYSCTL
109331 - struct ctl_table *tbl = ctl_forward_entry;
109332 + ctl_table_no_const *tbl = NULL;
109333 struct ctl_table_header *forw_hdr;
109334 #endif
109335
109336 @@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
109337 goto err_alloc_dflt;
109338
109339 #ifdef CONFIG_SYSCTL
109340 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
109341 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
109342 if (tbl == NULL)
109343 goto err_alloc_ctl;
109344
109345 @@ -2253,7 +2253,10 @@ static __net_init int devinet_init_net(struct net *net)
109346 goto err_reg_dflt;
109347
109348 err = -ENOMEM;
109349 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
109350 + if (!net_eq(net, &init_net))
109351 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
109352 + else
109353 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
109354 if (forw_hdr == NULL)
109355 goto err_reg_ctl;
109356 net->ipv4.forw_hdr = forw_hdr;
109357 @@ -2269,8 +2272,7 @@ err_reg_ctl:
109358 err_reg_dflt:
109359 __devinet_sysctl_unregister(all);
109360 err_reg_all:
109361 - if (tbl != ctl_forward_entry)
109362 - kfree(tbl);
109363 + kfree(tbl);
109364 err_alloc_ctl:
109365 #endif
109366 if (dflt != &ipv4_devconf_dflt)
109367 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
109368 index 255aa99..45c78f8 100644
109369 --- a/net/ipv4/fib_frontend.c
109370 +++ b/net/ipv4/fib_frontend.c
109371 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
109372 #ifdef CONFIG_IP_ROUTE_MULTIPATH
109373 fib_sync_up(dev);
109374 #endif
109375 - atomic_inc(&net->ipv4.dev_addr_genid);
109376 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
109377 rt_cache_flush(dev_net(dev));
109378 break;
109379 case NETDEV_DOWN:
109380 fib_del_ifaddr(ifa, NULL);
109381 - atomic_inc(&net->ipv4.dev_addr_genid);
109382 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
109383 if (ifa->ifa_dev->ifa_list == NULL) {
109384 /* Last address was deleted from this interface.
109385 * Disable IP.
109386 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
109387 #ifdef CONFIG_IP_ROUTE_MULTIPATH
109388 fib_sync_up(dev);
109389 #endif
109390 - atomic_inc(&net->ipv4.dev_addr_genid);
109391 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
109392 rt_cache_flush(net);
109393 break;
109394 case NETDEV_DOWN:
109395 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
109396 index b10cd43a..22327f9 100644
109397 --- a/net/ipv4/fib_semantics.c
109398 +++ b/net/ipv4/fib_semantics.c
109399 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
109400 nh->nh_saddr = inet_select_addr(nh->nh_dev,
109401 nh->nh_gw,
109402 nh->nh_parent->fib_scope);
109403 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
109404 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
109405
109406 return nh->nh_saddr;
109407 }
109408 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
109409 index 43116e8..e3e6159 100644
109410 --- a/net/ipv4/inet_hashtables.c
109411 +++ b/net/ipv4/inet_hashtables.c
109412 @@ -18,6 +18,7 @@
109413 #include <linux/sched.h>
109414 #include <linux/slab.h>
109415 #include <linux/wait.h>
109416 +#include <linux/security.h>
109417
109418 #include <net/inet_connection_sock.h>
109419 #include <net/inet_hashtables.h>
109420 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
109421 return inet_ehashfn(net, laddr, lport, faddr, fport);
109422 }
109423
109424 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
109425 +
109426 /*
109427 * Allocate and initialize a new local port bind bucket.
109428 * The bindhash mutex for snum's hash chain must be held here.
109429 @@ -554,6 +557,8 @@ ok:
109430 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
109431 spin_unlock(&head->lock);
109432
109433 + gr_update_task_in_ip_table(current, inet_sk(sk));
109434 +
109435 if (tw) {
109436 inet_twsk_deschedule(tw, death_row);
109437 while (twrefcnt) {
109438 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
109439 index bd5f592..e80e605 100644
109440 --- a/net/ipv4/inetpeer.c
109441 +++ b/net/ipv4/inetpeer.c
109442 @@ -482,7 +482,7 @@ relookup:
109443 if (p) {
109444 p->daddr = *daddr;
109445 atomic_set(&p->refcnt, 1);
109446 - atomic_set(&p->rid, 0);
109447 + atomic_set_unchecked(&p->rid, 0);
109448 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
109449 p->rate_tokens = 0;
109450 /* 60*HZ is arbitrary, but chosen enough high so that the first
109451 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
109452 index ed32313..3762abe 100644
109453 --- a/net/ipv4/ip_fragment.c
109454 +++ b/net/ipv4/ip_fragment.c
109455 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
109456 return 0;
109457
109458 start = qp->rid;
109459 - end = atomic_inc_return(&peer->rid);
109460 + end = atomic_inc_return_unchecked(&peer->rid);
109461 qp->rid = end;
109462
109463 rc = qp->q.fragments && (end - start) > max;
109464 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
109465
109466 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
109467 {
109468 - struct ctl_table *table;
109469 + ctl_table_no_const *table = NULL;
109470 struct ctl_table_header *hdr;
109471
109472 - table = ip4_frags_ns_ctl_table;
109473 if (!net_eq(net, &init_net)) {
109474 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
109475 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
109476 if (table == NULL)
109477 goto err_alloc;
109478
109479 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
109480 /* Don't export sysctls to unprivileged users */
109481 if (net->user_ns != &init_user_ns)
109482 table[0].procname = NULL;
109483 - }
109484 + hdr = register_net_sysctl(net, "net/ipv4", table);
109485 + } else
109486 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
109487
109488 - hdr = register_net_sysctl(net, "net/ipv4", table);
109489 if (hdr == NULL)
109490 goto err_reg;
109491
109492 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
109493 return 0;
109494
109495 err_reg:
109496 - if (!net_eq(net, &init_net))
109497 - kfree(table);
109498 + kfree(table);
109499 err_alloc:
109500 return -ENOMEM;
109501 }
109502 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
109503 index 9b84254..c776611 100644
109504 --- a/net/ipv4/ip_gre.c
109505 +++ b/net/ipv4/ip_gre.c
109506 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
109507 module_param(log_ecn_error, bool, 0644);
109508 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
109509
109510 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
109511 +static struct rtnl_link_ops ipgre_link_ops;
109512 static int ipgre_tunnel_init(struct net_device *dev);
109513
109514 static int ipgre_net_id __read_mostly;
109515 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
109516 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
109517 };
109518
109519 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
109520 +static struct rtnl_link_ops ipgre_link_ops = {
109521 .kind = "gre",
109522 .maxtype = IFLA_GRE_MAX,
109523 .policy = ipgre_policy,
109524 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
109525 .fill_info = ipgre_fill_info,
109526 };
109527
109528 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
109529 +static struct rtnl_link_ops ipgre_tap_ops = {
109530 .kind = "gretap",
109531 .maxtype = IFLA_GRE_MAX,
109532 .policy = ipgre_policy,
109533 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
109534 index 64741b9..6f334a2 100644
109535 --- a/net/ipv4/ip_sockglue.c
109536 +++ b/net/ipv4/ip_sockglue.c
109537 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
109538 len = min_t(unsigned int, len, opt->optlen);
109539 if (put_user(len, optlen))
109540 return -EFAULT;
109541 - if (copy_to_user(optval, opt->__data, len))
109542 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
109543 + copy_to_user(optval, opt->__data, len))
109544 return -EFAULT;
109545 return 0;
109546 }
109547 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
109548 if (sk->sk_type != SOCK_STREAM)
109549 return -ENOPROTOOPT;
109550
109551 - msg.msg_control = optval;
109552 + msg.msg_control = (void __force_kernel *)optval;
109553 msg.msg_controllen = len;
109554 msg.msg_flags = flags;
109555
109556 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
109557 index b8960f3..0f025db 100644
109558 --- a/net/ipv4/ip_vti.c
109559 +++ b/net/ipv4/ip_vti.c
109560 @@ -45,7 +45,7 @@
109561 #include <net/net_namespace.h>
109562 #include <net/netns/generic.h>
109563
109564 -static struct rtnl_link_ops vti_link_ops __read_mostly;
109565 +static struct rtnl_link_ops vti_link_ops;
109566
109567 static int vti_net_id __read_mostly;
109568 static int vti_tunnel_init(struct net_device *dev);
109569 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
109570 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
109571 };
109572
109573 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
109574 +static struct rtnl_link_ops vti_link_ops = {
109575 .kind = "vti",
109576 .maxtype = IFLA_VTI_MAX,
109577 .policy = vti_policy,
109578 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
109579 index b3e86ea..18ce98c 100644
109580 --- a/net/ipv4/ipconfig.c
109581 +++ b/net/ipv4/ipconfig.c
109582 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
109583
109584 mm_segment_t oldfs = get_fs();
109585 set_fs(get_ds());
109586 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
109587 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
109588 set_fs(oldfs);
109589 return res;
109590 }
109591 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
109592
109593 mm_segment_t oldfs = get_fs();
109594 set_fs(get_ds());
109595 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
109596 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
109597 set_fs(oldfs);
109598 return res;
109599 }
109600 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
109601
109602 mm_segment_t oldfs = get_fs();
109603 set_fs(get_ds());
109604 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
109605 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
109606 set_fs(oldfs);
109607 return res;
109608 }
109609 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
109610 index 62eaa00..29b2dc2 100644
109611 --- a/net/ipv4/ipip.c
109612 +++ b/net/ipv4/ipip.c
109613 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
109614 static int ipip_net_id __read_mostly;
109615
109616 static int ipip_tunnel_init(struct net_device *dev);
109617 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
109618 +static struct rtnl_link_ops ipip_link_ops;
109619
109620 static int ipip_err(struct sk_buff *skb, u32 info)
109621 {
109622 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
109623 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
109624 };
109625
109626 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
109627 +static struct rtnl_link_ops ipip_link_ops = {
109628 .kind = "ipip",
109629 .maxtype = IFLA_IPTUN_MAX,
109630 .policy = ipip_policy,
109631 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
109632 index f95b6f9..2ee2097 100644
109633 --- a/net/ipv4/netfilter/arp_tables.c
109634 +++ b/net/ipv4/netfilter/arp_tables.c
109635 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
109636 #endif
109637
109638 static int get_info(struct net *net, void __user *user,
109639 - const int *len, int compat)
109640 + int len, int compat)
109641 {
109642 char name[XT_TABLE_MAXNAMELEN];
109643 struct xt_table *t;
109644 int ret;
109645
109646 - if (*len != sizeof(struct arpt_getinfo)) {
109647 - duprintf("length %u != %Zu\n", *len,
109648 + if (len != sizeof(struct arpt_getinfo)) {
109649 + duprintf("length %u != %Zu\n", len,
109650 sizeof(struct arpt_getinfo));
109651 return -EINVAL;
109652 }
109653 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
109654 info.size = private->size;
109655 strcpy(info.name, name);
109656
109657 - if (copy_to_user(user, &info, *len) != 0)
109658 + if (copy_to_user(user, &info, len) != 0)
109659 ret = -EFAULT;
109660 else
109661 ret = 0;
109662 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
109663
109664 switch (cmd) {
109665 case ARPT_SO_GET_INFO:
109666 - ret = get_info(sock_net(sk), user, len, 1);
109667 + ret = get_info(sock_net(sk), user, *len, 1);
109668 break;
109669 case ARPT_SO_GET_ENTRIES:
109670 ret = compat_get_entries(sock_net(sk), user, len);
109671 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
109672
109673 switch (cmd) {
109674 case ARPT_SO_GET_INFO:
109675 - ret = get_info(sock_net(sk), user, len, 0);
109676 + ret = get_info(sock_net(sk), user, *len, 0);
109677 break;
109678
109679 case ARPT_SO_GET_ENTRIES:
109680 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
109681 index 99e810f..3711b81 100644
109682 --- a/net/ipv4/netfilter/ip_tables.c
109683 +++ b/net/ipv4/netfilter/ip_tables.c
109684 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
109685 #endif
109686
109687 static int get_info(struct net *net, void __user *user,
109688 - const int *len, int compat)
109689 + int len, int compat)
109690 {
109691 char name[XT_TABLE_MAXNAMELEN];
109692 struct xt_table *t;
109693 int ret;
109694
109695 - if (*len != sizeof(struct ipt_getinfo)) {
109696 - duprintf("length %u != %zu\n", *len,
109697 + if (len != sizeof(struct ipt_getinfo)) {
109698 + duprintf("length %u != %zu\n", len,
109699 sizeof(struct ipt_getinfo));
109700 return -EINVAL;
109701 }
109702 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
109703 info.size = private->size;
109704 strcpy(info.name, name);
109705
109706 - if (copy_to_user(user, &info, *len) != 0)
109707 + if (copy_to_user(user, &info, len) != 0)
109708 ret = -EFAULT;
109709 else
109710 ret = 0;
109711 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109712
109713 switch (cmd) {
109714 case IPT_SO_GET_INFO:
109715 - ret = get_info(sock_net(sk), user, len, 1);
109716 + ret = get_info(sock_net(sk), user, *len, 1);
109717 break;
109718 case IPT_SO_GET_ENTRIES:
109719 ret = compat_get_entries(sock_net(sk), user, len);
109720 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
109721
109722 switch (cmd) {
109723 case IPT_SO_GET_INFO:
109724 - ret = get_info(sock_net(sk), user, len, 0);
109725 + ret = get_info(sock_net(sk), user, *len, 0);
109726 break;
109727
109728 case IPT_SO_GET_ENTRIES:
109729 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
109730 index 2510c02..cfb34fa 100644
109731 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
109732 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
109733 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
109734 spin_lock_init(&cn->lock);
109735
109736 #ifdef CONFIG_PROC_FS
109737 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
109738 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
109739 if (!cn->procdir) {
109740 pr_err("Unable to proc dir entry\n");
109741 return -ENOMEM;
109742 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
109743 index 044a0dd..3399751 100644
109744 --- a/net/ipv4/ping.c
109745 +++ b/net/ipv4/ping.c
109746 @@ -59,7 +59,7 @@ struct ping_table {
109747 };
109748
109749 static struct ping_table ping_table;
109750 -struct pingv6_ops pingv6_ops;
109751 +struct pingv6_ops *pingv6_ops;
109752 EXPORT_SYMBOL_GPL(pingv6_ops);
109753
109754 static u16 ping_port_rover;
109755 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
109756 return -ENODEV;
109757 }
109758 }
109759 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
109760 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
109761 scoped);
109762 rcu_read_unlock();
109763
109764 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
109765 }
109766 #if IS_ENABLED(CONFIG_IPV6)
109767 } else if (skb->protocol == htons(ETH_P_IPV6)) {
109768 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
109769 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
109770 #endif
109771 }
109772
109773 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
109774 info, (u8 *)icmph);
109775 #if IS_ENABLED(CONFIG_IPV6)
109776 } else if (family == AF_INET6) {
109777 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
109778 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
109779 info, (u8 *)icmph);
109780 #endif
109781 }
109782 @@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
109783 return ip_recv_error(sk, msg, len, addr_len);
109784 #if IS_ENABLED(CONFIG_IPV6)
109785 } else if (family == AF_INET6) {
109786 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
109787 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
109788 addr_len);
109789 #endif
109790 }
109791 @@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
109792 }
109793
109794 if (inet6_sk(sk)->rxopt.all)
109795 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
109796 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
109797 if (skb->protocol == htons(ETH_P_IPV6) &&
109798 inet6_sk(sk)->rxopt.all)
109799 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
109800 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
109801 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
109802 ip_cmsg_recv(msg, skb);
109803 #endif
109804 @@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
109805 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
109806 0, sock_i_ino(sp),
109807 atomic_read(&sp->sk_refcnt), sp,
109808 - atomic_read(&sp->sk_drops));
109809 + atomic_read_unchecked(&sp->sk_drops));
109810 }
109811
109812 static int ping_v4_seq_show(struct seq_file *seq, void *v)
109813 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
109814 index 2c65160..213ecdf 100644
109815 --- a/net/ipv4/raw.c
109816 +++ b/net/ipv4/raw.c
109817 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
109818 int raw_rcv(struct sock *sk, struct sk_buff *skb)
109819 {
109820 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
109821 - atomic_inc(&sk->sk_drops);
109822 + atomic_inc_unchecked(&sk->sk_drops);
109823 kfree_skb(skb);
109824 return NET_RX_DROP;
109825 }
109826 @@ -748,16 +748,20 @@ static int raw_init(struct sock *sk)
109827
109828 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
109829 {
109830 + struct icmp_filter filter;
109831 +
109832 if (optlen > sizeof(struct icmp_filter))
109833 optlen = sizeof(struct icmp_filter);
109834 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
109835 + if (copy_from_user(&filter, optval, optlen))
109836 return -EFAULT;
109837 + raw_sk(sk)->filter = filter;
109838 return 0;
109839 }
109840
109841 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
109842 {
109843 int len, ret = -EFAULT;
109844 + struct icmp_filter filter;
109845
109846 if (get_user(len, optlen))
109847 goto out;
109848 @@ -767,8 +771,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
109849 if (len > sizeof(struct icmp_filter))
109850 len = sizeof(struct icmp_filter);
109851 ret = -EFAULT;
109852 - if (put_user(len, optlen) ||
109853 - copy_to_user(optval, &raw_sk(sk)->filter, len))
109854 + filter = raw_sk(sk)->filter;
109855 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
109856 goto out;
109857 ret = 0;
109858 out: return ret;
109859 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
109860 0, 0L, 0,
109861 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
109862 0, sock_i_ino(sp),
109863 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
109864 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
109865 }
109866
109867 static int raw_seq_show(struct seq_file *seq, void *v)
109868 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
109869 index 1901998..a9a850a 100644
109870 --- a/net/ipv4/route.c
109871 +++ b/net/ipv4/route.c
109872 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
109873
109874 static int rt_cache_seq_open(struct inode *inode, struct file *file)
109875 {
109876 - return seq_open(file, &rt_cache_seq_ops);
109877 + return seq_open_restrict(file, &rt_cache_seq_ops);
109878 }
109879
109880 static const struct file_operations rt_cache_seq_fops = {
109881 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
109882
109883 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
109884 {
109885 - return seq_open(file, &rt_cpu_seq_ops);
109886 + return seq_open_restrict(file, &rt_cpu_seq_ops);
109887 }
109888
109889 static const struct file_operations rt_cpu_seq_fops = {
109890 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
109891
109892 static int rt_acct_proc_open(struct inode *inode, struct file *file)
109893 {
109894 - return single_open(file, rt_acct_proc_show, NULL);
109895 + return single_open_restrict(file, rt_acct_proc_show, NULL);
109896 }
109897
109898 static const struct file_operations rt_acct_proc_fops = {
109899 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
109900
109901 #define IP_IDENTS_SZ 2048u
109902 struct ip_ident_bucket {
109903 - atomic_t id;
109904 + atomic_unchecked_t id;
109905 u32 stamp32;
109906 };
109907
109908 -static struct ip_ident_bucket *ip_idents __read_mostly;
109909 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
109910
109911 /* In order to protect privacy, we add a perturbation to identifiers
109912 * if one generator is seldom used. This makes hard for an attacker
109913 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
109914 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
109915 delta = prandom_u32_max(now - old);
109916
109917 - return atomic_add_return(segs + delta, &bucket->id) - segs;
109918 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
109919 }
109920 EXPORT_SYMBOL(ip_idents_reserve);
109921
109922 @@ -2625,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
109923 .maxlen = sizeof(int),
109924 .mode = 0200,
109925 .proc_handler = ipv4_sysctl_rtcache_flush,
109926 + .extra1 = &init_net,
109927 },
109928 { },
109929 };
109930
109931 static __net_init int sysctl_route_net_init(struct net *net)
109932 {
109933 - struct ctl_table *tbl;
109934 + ctl_table_no_const *tbl = NULL;
109935
109936 - tbl = ipv4_route_flush_table;
109937 if (!net_eq(net, &init_net)) {
109938 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
109939 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
109940 if (tbl == NULL)
109941 goto err_dup;
109942
109943 /* Don't export sysctls to unprivileged users */
109944 if (net->user_ns != &init_user_ns)
109945 tbl[0].procname = NULL;
109946 - }
109947 - tbl[0].extra1 = net;
109948 + tbl[0].extra1 = net;
109949 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
109950 + } else
109951 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
109952
109953 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
109954 if (net->ipv4.route_hdr == NULL)
109955 goto err_reg;
109956 return 0;
109957
109958 err_reg:
109959 - if (tbl != ipv4_route_flush_table)
109960 - kfree(tbl);
109961 + kfree(tbl);
109962 err_dup:
109963 return -ENOMEM;
109964 }
109965 @@ -2675,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
109966
109967 static __net_init int rt_genid_init(struct net *net)
109968 {
109969 - atomic_set(&net->ipv4.rt_genid, 0);
109970 - atomic_set(&net->fnhe_genid, 0);
109971 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
109972 + atomic_set_unchecked(&net->fnhe_genid, 0);
109973 get_random_bytes(&net->ipv4.dev_addr_genid,
109974 sizeof(net->ipv4.dev_addr_genid));
109975 return 0;
109976 @@ -2719,11 +2719,7 @@ int __init ip_rt_init(void)
109977 {
109978 int rc = 0;
109979
109980 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
109981 - if (!ip_idents)
109982 - panic("IP: failed to allocate ip_idents\n");
109983 -
109984 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
109985 + prandom_bytes(ip_idents, sizeof(ip_idents));
109986
109987 #ifdef CONFIG_IP_ROUTE_CLASSID
109988 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
109989 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
109990 index 79a007c..5023029 100644
109991 --- a/net/ipv4/sysctl_net_ipv4.c
109992 +++ b/net/ipv4/sysctl_net_ipv4.c
109993 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
109994 container_of(table->data, struct net, ipv4.ip_local_ports.range);
109995 int ret;
109996 int range[2];
109997 - struct ctl_table tmp = {
109998 + ctl_table_no_const tmp = {
109999 .data = &range,
110000 .maxlen = sizeof(range),
110001 .mode = table->mode,
110002 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
110003 int ret;
110004 gid_t urange[2];
110005 kgid_t low, high;
110006 - struct ctl_table tmp = {
110007 + ctl_table_no_const tmp = {
110008 .data = &urange,
110009 .maxlen = sizeof(urange),
110010 .mode = table->mode,
110011 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
110012 void __user *buffer, size_t *lenp, loff_t *ppos)
110013 {
110014 char val[TCP_CA_NAME_MAX];
110015 - struct ctl_table tbl = {
110016 + ctl_table_no_const tbl = {
110017 .data = val,
110018 .maxlen = TCP_CA_NAME_MAX,
110019 };
110020 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
110021 void __user *buffer, size_t *lenp,
110022 loff_t *ppos)
110023 {
110024 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
110025 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
110026 int ret;
110027
110028 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
110029 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
110030 void __user *buffer, size_t *lenp,
110031 loff_t *ppos)
110032 {
110033 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
110034 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
110035 int ret;
110036
110037 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
110038 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
110039 void __user *buffer, size_t *lenp,
110040 loff_t *ppos)
110041 {
110042 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
110043 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
110044 struct tcp_fastopen_context *ctxt;
110045 int ret;
110046 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
110047 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
110048
110049 static __net_init int ipv4_sysctl_init_net(struct net *net)
110050 {
110051 - struct ctl_table *table;
110052 + ctl_table_no_const *table = NULL;
110053
110054 - table = ipv4_net_table;
110055 if (!net_eq(net, &init_net)) {
110056 int i;
110057
110058 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
110059 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
110060 if (table == NULL)
110061 goto err_alloc;
110062
110063 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
110064 table[i].data += (void *)net - (void *)&init_net;
110065 }
110066
110067 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
110068 + if (!net_eq(net, &init_net))
110069 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
110070 + else
110071 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
110072 if (net->ipv4.ipv4_hdr == NULL)
110073 goto err_reg;
110074
110075 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
110076 index 40639c2..dfc86b2 100644
110077 --- a/net/ipv4/tcp_input.c
110078 +++ b/net/ipv4/tcp_input.c
110079 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
110080 * without any lock. We want to make sure compiler wont store
110081 * intermediate values in this location.
110082 */
110083 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
110084 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
110085 sk->sk_max_pacing_rate);
110086 }
110087
110088 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
110089 * simplifies code)
110090 */
110091 static void
110092 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
110093 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
110094 struct sk_buff *head, struct sk_buff *tail,
110095 u32 start, u32 end)
110096 {
110097 @@ -5536,6 +5536,7 @@ discard:
110098 tcp_paws_reject(&tp->rx_opt, 0))
110099 goto discard_and_undo;
110100
110101 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
110102 if (th->syn) {
110103 /* We see SYN without ACK. It is attempt of
110104 * simultaneous connect with crossed SYNs.
110105 @@ -5586,6 +5587,7 @@ discard:
110106 goto discard;
110107 #endif
110108 }
110109 +#endif
110110 /* "fifth, if neither of the SYN or RST bits is set then
110111 * drop the segment and return."
110112 */
110113 @@ -5632,7 +5634,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
110114 goto discard;
110115
110116 if (th->syn) {
110117 - if (th->fin)
110118 + if (th->fin || th->urg || th->psh)
110119 goto discard;
110120 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
110121 return 1;
110122 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
110123 index 77cccda..10122c4 100644
110124 --- a/net/ipv4/tcp_ipv4.c
110125 +++ b/net/ipv4/tcp_ipv4.c
110126 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
110127 EXPORT_SYMBOL(sysctl_tcp_low_latency);
110128
110129
110130 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110131 +extern int grsec_enable_blackhole;
110132 +#endif
110133 +
110134 #ifdef CONFIG_TCP_MD5SIG
110135 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
110136 __be32 daddr, __be32 saddr, const struct tcphdr *th);
110137 @@ -1591,6 +1595,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
110138 return 0;
110139
110140 reset:
110141 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110142 + if (!grsec_enable_blackhole)
110143 +#endif
110144 tcp_v4_send_reset(rsk, skb);
110145 discard:
110146 kfree_skb(skb);
110147 @@ -1737,12 +1744,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
110148 TCP_SKB_CB(skb)->sacked = 0;
110149
110150 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
110151 - if (!sk)
110152 + if (!sk) {
110153 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110154 + ret = 1;
110155 +#endif
110156 goto no_tcp_socket;
110157 -
110158 + }
110159 process:
110160 - if (sk->sk_state == TCP_TIME_WAIT)
110161 + if (sk->sk_state == TCP_TIME_WAIT) {
110162 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110163 + ret = 2;
110164 +#endif
110165 goto do_time_wait;
110166 + }
110167
110168 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
110169 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
110170 @@ -1796,6 +1810,10 @@ csum_error:
110171 bad_packet:
110172 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
110173 } else {
110174 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110175 + if (!grsec_enable_blackhole || (ret == 1 &&
110176 + (skb->dev->flags & IFF_LOOPBACK)))
110177 +#endif
110178 tcp_v4_send_reset(NULL, skb);
110179 }
110180
110181 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
110182 index e68e0d4..0334263 100644
110183 --- a/net/ipv4/tcp_minisocks.c
110184 +++ b/net/ipv4/tcp_minisocks.c
110185 @@ -27,6 +27,10 @@
110186 #include <net/inet_common.h>
110187 #include <net/xfrm.h>
110188
110189 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110190 +extern int grsec_enable_blackhole;
110191 +#endif
110192 +
110193 int sysctl_tcp_syncookies __read_mostly = 1;
110194 EXPORT_SYMBOL(sysctl_tcp_syncookies);
110195
110196 @@ -740,7 +744,10 @@ embryonic_reset:
110197 * avoid becoming vulnerable to outside attack aiming at
110198 * resetting legit local connections.
110199 */
110200 - req->rsk_ops->send_reset(sk, skb);
110201 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110202 + if (!grsec_enable_blackhole)
110203 +#endif
110204 + req->rsk_ops->send_reset(sk, skb);
110205 } else if (fastopen) { /* received a valid RST pkt */
110206 reqsk_fastopen_remove(sk, req, true);
110207 tcp_reset(sk);
110208 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
110209 index 3b66610..bfbe23a 100644
110210 --- a/net/ipv4/tcp_probe.c
110211 +++ b/net/ipv4/tcp_probe.c
110212 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
110213 if (cnt + width >= len)
110214 break;
110215
110216 - if (copy_to_user(buf + cnt, tbuf, width))
110217 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
110218 return -EFAULT;
110219 cnt += width;
110220 }
110221 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
110222 index 286227a..c495a76 100644
110223 --- a/net/ipv4/tcp_timer.c
110224 +++ b/net/ipv4/tcp_timer.c
110225 @@ -22,6 +22,10 @@
110226 #include <linux/gfp.h>
110227 #include <net/tcp.h>
110228
110229 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110230 +extern int grsec_lastack_retries;
110231 +#endif
110232 +
110233 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
110234 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
110235 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
110236 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
110237 }
110238 }
110239
110240 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110241 + if ((sk->sk_state == TCP_LAST_ACK) &&
110242 + (grsec_lastack_retries > 0) &&
110243 + (grsec_lastack_retries < retry_until))
110244 + retry_until = grsec_lastack_retries;
110245 +#endif
110246 +
110247 if (retransmits_timed_out(sk, retry_until,
110248 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
110249 /* Has it gone just too far? */
110250 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
110251 index 7d5a866..4874211 100644
110252 --- a/net/ipv4/udp.c
110253 +++ b/net/ipv4/udp.c
110254 @@ -87,6 +87,7 @@
110255 #include <linux/types.h>
110256 #include <linux/fcntl.h>
110257 #include <linux/module.h>
110258 +#include <linux/security.h>
110259 #include <linux/socket.h>
110260 #include <linux/sockios.h>
110261 #include <linux/igmp.h>
110262 @@ -113,6 +114,10 @@
110263 #include <net/busy_poll.h>
110264 #include "udp_impl.h"
110265
110266 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110267 +extern int grsec_enable_blackhole;
110268 +#endif
110269 +
110270 struct udp_table udp_table __read_mostly;
110271 EXPORT_SYMBOL(udp_table);
110272
110273 @@ -615,6 +620,9 @@ found:
110274 return s;
110275 }
110276
110277 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
110278 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
110279 +
110280 /*
110281 * This routine is called by the ICMP module when it gets some
110282 * sort of error condition. If err < 0 then the socket should
110283 @@ -952,9 +960,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
110284 dport = usin->sin_port;
110285 if (dport == 0)
110286 return -EINVAL;
110287 +
110288 + err = gr_search_udp_sendmsg(sk, usin);
110289 + if (err)
110290 + return err;
110291 } else {
110292 if (sk->sk_state != TCP_ESTABLISHED)
110293 return -EDESTADDRREQ;
110294 +
110295 + err = gr_search_udp_sendmsg(sk, NULL);
110296 + if (err)
110297 + return err;
110298 +
110299 daddr = inet->inet_daddr;
110300 dport = inet->inet_dport;
110301 /* Open fast path for connected socket.
110302 @@ -1202,7 +1219,7 @@ static unsigned int first_packet_length(struct sock *sk)
110303 IS_UDPLITE(sk));
110304 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
110305 IS_UDPLITE(sk));
110306 - atomic_inc(&sk->sk_drops);
110307 + atomic_inc_unchecked(&sk->sk_drops);
110308 __skb_unlink(skb, rcvq);
110309 __skb_queue_tail(&list_kill, skb);
110310 }
110311 @@ -1282,6 +1299,10 @@ try_again:
110312 if (!skb)
110313 goto out;
110314
110315 + err = gr_search_udp_recvmsg(sk, skb);
110316 + if (err)
110317 + goto out_free;
110318 +
110319 ulen = skb->len - sizeof(struct udphdr);
110320 copied = len;
110321 if (copied > ulen)
110322 @@ -1315,7 +1336,7 @@ try_again:
110323 if (unlikely(err)) {
110324 trace_kfree_skb(skb, udp_recvmsg);
110325 if (!peeked) {
110326 - atomic_inc(&sk->sk_drops);
110327 + atomic_inc_unchecked(&sk->sk_drops);
110328 UDP_INC_STATS_USER(sock_net(sk),
110329 UDP_MIB_INERRORS, is_udplite);
110330 }
110331 @@ -1612,7 +1633,7 @@ csum_error:
110332 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
110333 drop:
110334 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
110335 - atomic_inc(&sk->sk_drops);
110336 + atomic_inc_unchecked(&sk->sk_drops);
110337 kfree_skb(skb);
110338 return -1;
110339 }
110340 @@ -1631,7 +1652,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
110341 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
110342
110343 if (!skb1) {
110344 - atomic_inc(&sk->sk_drops);
110345 + atomic_inc_unchecked(&sk->sk_drops);
110346 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
110347 IS_UDPLITE(sk));
110348 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
110349 @@ -1817,6 +1838,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
110350 goto csum_error;
110351
110352 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
110353 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110354 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
110355 +#endif
110356 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
110357
110358 /*
110359 @@ -2403,7 +2427,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
110360 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
110361 0, sock_i_ino(sp),
110362 atomic_read(&sp->sk_refcnt), sp,
110363 - atomic_read(&sp->sk_drops));
110364 + atomic_read_unchecked(&sp->sk_drops));
110365 }
110366
110367 int udp4_seq_show(struct seq_file *seq, void *v)
110368 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
110369 index 6156f68..d6ab46d 100644
110370 --- a/net/ipv4/xfrm4_policy.c
110371 +++ b/net/ipv4/xfrm4_policy.c
110372 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
110373 fl4->flowi4_tos = iph->tos;
110374 }
110375
110376 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
110377 +static int xfrm4_garbage_collect(struct dst_ops *ops)
110378 {
110379 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
110380
110381 - xfrm4_policy_afinfo.garbage_collect(net);
110382 + xfrm_garbage_collect_deferred(net);
110383 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
110384 }
110385
110386 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
110387
110388 static int __net_init xfrm4_net_init(struct net *net)
110389 {
110390 - struct ctl_table *table;
110391 + ctl_table_no_const *table = NULL;
110392 struct ctl_table_header *hdr;
110393
110394 - table = xfrm4_policy_table;
110395 if (!net_eq(net, &init_net)) {
110396 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
110397 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
110398 if (!table)
110399 goto err_alloc;
110400
110401 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
110402 - }
110403 -
110404 - hdr = register_net_sysctl(net, "net/ipv4", table);
110405 + hdr = register_net_sysctl(net, "net/ipv4", table);
110406 + } else
110407 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
110408 if (!hdr)
110409 goto err_reg;
110410
110411 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
110412 return 0;
110413
110414 err_reg:
110415 - if (!net_eq(net, &init_net))
110416 - kfree(table);
110417 + kfree(table);
110418 err_alloc:
110419 return -ENOMEM;
110420 }
110421 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
110422 index 5667b30..2044f61 100644
110423 --- a/net/ipv6/addrconf.c
110424 +++ b/net/ipv6/addrconf.c
110425 @@ -593,7 +593,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
110426 idx = 0;
110427 head = &net->dev_index_head[h];
110428 rcu_read_lock();
110429 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
110430 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
110431 net->dev_base_seq;
110432 hlist_for_each_entry_rcu(dev, head, index_hlist) {
110433 if (idx < s_idx)
110434 @@ -2390,7 +2390,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
110435 p.iph.ihl = 5;
110436 p.iph.protocol = IPPROTO_IPV6;
110437 p.iph.ttl = 64;
110438 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
110439 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
110440
110441 if (ops->ndo_do_ioctl) {
110442 mm_segment_t oldfs = get_fs();
110443 @@ -3516,16 +3516,23 @@ static const struct file_operations if6_fops = {
110444 .release = seq_release_net,
110445 };
110446
110447 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
110448 +extern void unregister_ipv6_seq_ops_addr(void);
110449 +
110450 static int __net_init if6_proc_net_init(struct net *net)
110451 {
110452 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
110453 + register_ipv6_seq_ops_addr(&if6_seq_ops);
110454 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
110455 + unregister_ipv6_seq_ops_addr();
110456 return -ENOMEM;
110457 + }
110458 return 0;
110459 }
110460
110461 static void __net_exit if6_proc_net_exit(struct net *net)
110462 {
110463 remove_proc_entry("if_inet6", net->proc_net);
110464 + unregister_ipv6_seq_ops_addr();
110465 }
110466
110467 static struct pernet_operations if6_proc_net_ops = {
110468 @@ -4141,7 +4148,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
110469 s_ip_idx = ip_idx = cb->args[2];
110470
110471 rcu_read_lock();
110472 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
110473 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
110474 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
110475 idx = 0;
110476 head = &net->dev_index_head[h];
110477 @@ -4741,11 +4748,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
110478
110479 rt = rt6_lookup(dev_net(dev), &ifp->peer_addr, NULL,
110480 dev->ifindex, 1);
110481 - if (rt) {
110482 - dst_hold(&rt->dst);
110483 - if (ip6_del_rt(rt))
110484 - dst_free(&rt->dst);
110485 - }
110486 + if (rt && ip6_del_rt(rt))
110487 + dst_free(&rt->dst);
110488 }
110489 dst_hold(&ifp->rt->dst);
110490
110491 @@ -4753,7 +4757,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
110492 dst_free(&ifp->rt->dst);
110493 break;
110494 }
110495 - atomic_inc(&net->ipv6.dev_addr_genid);
110496 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
110497 rt_genid_bump_ipv6(net);
110498 }
110499
110500 @@ -4774,7 +4778,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
110501 int *valp = ctl->data;
110502 int val = *valp;
110503 loff_t pos = *ppos;
110504 - struct ctl_table lctl;
110505 + ctl_table_no_const lctl;
110506 int ret;
110507
110508 /*
110509 @@ -4859,7 +4863,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
110510 int *valp = ctl->data;
110511 int val = *valp;
110512 loff_t pos = *ppos;
110513 - struct ctl_table lctl;
110514 + ctl_table_no_const lctl;
110515 int ret;
110516
110517 /*
110518 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
110519 index 7cb4392..dc96d28 100644
110520 --- a/net/ipv6/af_inet6.c
110521 +++ b/net/ipv6/af_inet6.c
110522 @@ -765,7 +765,7 @@ static int __net_init inet6_net_init(struct net *net)
110523 net->ipv6.sysctl.bindv6only = 0;
110524 net->ipv6.sysctl.icmpv6_time = 1*HZ;
110525 net->ipv6.sysctl.flowlabel_consistency = 1;
110526 - atomic_set(&net->ipv6.rt_genid, 0);
110527 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
110528
110529 err = ipv6_init_mibs(net);
110530 if (err)
110531 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
110532 index c3bf2d2..1f00573 100644
110533 --- a/net/ipv6/datagram.c
110534 +++ b/net/ipv6/datagram.c
110535 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
110536 0,
110537 sock_i_ino(sp),
110538 atomic_read(&sp->sk_refcnt), sp,
110539 - atomic_read(&sp->sk_drops));
110540 + atomic_read_unchecked(&sp->sk_drops));
110541 }
110542 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
110543 index f6c84a6..9f2084e 100644
110544 --- a/net/ipv6/icmp.c
110545 +++ b/net/ipv6/icmp.c
110546 @@ -990,7 +990,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
110547
110548 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
110549 {
110550 - struct ctl_table *table;
110551 + ctl_table_no_const *table;
110552
110553 table = kmemdup(ipv6_icmp_table_template,
110554 sizeof(ipv6_icmp_table_template),
110555 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
110556 index 3873181..220ad3f 100644
110557 --- a/net/ipv6/ip6_gre.c
110558 +++ b/net/ipv6/ip6_gre.c
110559 @@ -71,8 +71,8 @@ struct ip6gre_net {
110560 struct net_device *fb_tunnel_dev;
110561 };
110562
110563 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
110564 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
110565 +static struct rtnl_link_ops ip6gre_link_ops;
110566 +static struct rtnl_link_ops ip6gre_tap_ops;
110567 static int ip6gre_tunnel_init(struct net_device *dev);
110568 static void ip6gre_tunnel_setup(struct net_device *dev);
110569 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
110570 @@ -1280,7 +1280,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
110571 }
110572
110573
110574 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
110575 +static struct inet6_protocol ip6gre_protocol = {
110576 .handler = ip6gre_rcv,
110577 .err_handler = ip6gre_err,
110578 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
110579 @@ -1638,7 +1638,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
110580 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
110581 };
110582
110583 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
110584 +static struct rtnl_link_ops ip6gre_link_ops = {
110585 .kind = "ip6gre",
110586 .maxtype = IFLA_GRE_MAX,
110587 .policy = ip6gre_policy,
110588 @@ -1652,7 +1652,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
110589 .fill_info = ip6gre_fill_info,
110590 };
110591
110592 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
110593 +static struct rtnl_link_ops ip6gre_tap_ops = {
110594 .kind = "ip6gretap",
110595 .maxtype = IFLA_GRE_MAX,
110596 .policy = ip6gre_policy,
110597 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
110598 index afa0824..04ba530 100644
110599 --- a/net/ipv6/ip6_tunnel.c
110600 +++ b/net/ipv6/ip6_tunnel.c
110601 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
110602
110603 static int ip6_tnl_dev_init(struct net_device *dev);
110604 static void ip6_tnl_dev_setup(struct net_device *dev);
110605 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
110606 +static struct rtnl_link_ops ip6_link_ops;
110607
110608 static int ip6_tnl_net_id __read_mostly;
110609 struct ip6_tnl_net {
110610 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
110611 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
110612 };
110613
110614 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
110615 +static struct rtnl_link_ops ip6_link_ops = {
110616 .kind = "ip6tnl",
110617 .maxtype = IFLA_IPTUN_MAX,
110618 .policy = ip6_tnl_policy,
110619 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
110620 index 9aaa6bb..5c13e57 100644
110621 --- a/net/ipv6/ip6_vti.c
110622 +++ b/net/ipv6/ip6_vti.c
110623 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
110624
110625 static int vti6_dev_init(struct net_device *dev);
110626 static void vti6_dev_setup(struct net_device *dev);
110627 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
110628 +static struct rtnl_link_ops vti6_link_ops;
110629
110630 static int vti6_net_id __read_mostly;
110631 struct vti6_net {
110632 @@ -977,7 +977,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
110633 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
110634 };
110635
110636 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
110637 +static struct rtnl_link_ops vti6_link_ops = {
110638 .kind = "vti6",
110639 .maxtype = IFLA_VTI_MAX,
110640 .policy = vti6_policy,
110641 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
110642 index edb58af..78de133 100644
110643 --- a/net/ipv6/ipv6_sockglue.c
110644 +++ b/net/ipv6/ipv6_sockglue.c
110645 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
110646 if (sk->sk_type != SOCK_STREAM)
110647 return -ENOPROTOOPT;
110648
110649 - msg.msg_control = optval;
110650 + msg.msg_control = (void __force_kernel *)optval;
110651 msg.msg_controllen = len;
110652 msg.msg_flags = flags;
110653
110654 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
110655 index e080fbb..412b3cf 100644
110656 --- a/net/ipv6/netfilter/ip6_tables.c
110657 +++ b/net/ipv6/netfilter/ip6_tables.c
110658 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
110659 #endif
110660
110661 static int get_info(struct net *net, void __user *user,
110662 - const int *len, int compat)
110663 + int len, int compat)
110664 {
110665 char name[XT_TABLE_MAXNAMELEN];
110666 struct xt_table *t;
110667 int ret;
110668
110669 - if (*len != sizeof(struct ip6t_getinfo)) {
110670 - duprintf("length %u != %zu\n", *len,
110671 + if (len != sizeof(struct ip6t_getinfo)) {
110672 + duprintf("length %u != %zu\n", len,
110673 sizeof(struct ip6t_getinfo));
110674 return -EINVAL;
110675 }
110676 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
110677 info.size = private->size;
110678 strcpy(info.name, name);
110679
110680 - if (copy_to_user(user, &info, *len) != 0)
110681 + if (copy_to_user(user, &info, len) != 0)
110682 ret = -EFAULT;
110683 else
110684 ret = 0;
110685 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
110686
110687 switch (cmd) {
110688 case IP6T_SO_GET_INFO:
110689 - ret = get_info(sock_net(sk), user, len, 1);
110690 + ret = get_info(sock_net(sk), user, *len, 1);
110691 break;
110692 case IP6T_SO_GET_ENTRIES:
110693 ret = compat_get_entries(sock_net(sk), user, len);
110694 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
110695
110696 switch (cmd) {
110697 case IP6T_SO_GET_INFO:
110698 - ret = get_info(sock_net(sk), user, len, 0);
110699 + ret = get_info(sock_net(sk), user, *len, 0);
110700 break;
110701
110702 case IP6T_SO_GET_ENTRIES:
110703 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
110704 index 0d5279f..89d9f6f 100644
110705 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
110706 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
110707 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
110708
110709 static int nf_ct_frag6_sysctl_register(struct net *net)
110710 {
110711 - struct ctl_table *table;
110712 + ctl_table_no_const *table = NULL;
110713 struct ctl_table_header *hdr;
110714
110715 - table = nf_ct_frag6_sysctl_table;
110716 if (!net_eq(net, &init_net)) {
110717 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
110718 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
110719 GFP_KERNEL);
110720 if (table == NULL)
110721 goto err_alloc;
110722 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
110723 table[0].data = &net->nf_frag.frags.timeout;
110724 table[1].data = &net->nf_frag.frags.low_thresh;
110725 table[2].data = &net->nf_frag.frags.high_thresh;
110726 - }
110727 -
110728 - hdr = register_net_sysctl(net, "net/netfilter", table);
110729 + hdr = register_net_sysctl(net, "net/netfilter", table);
110730 + } else
110731 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
110732 if (hdr == NULL)
110733 goto err_reg;
110734
110735 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
110736 return 0;
110737
110738 err_reg:
110739 - if (!net_eq(net, &init_net))
110740 - kfree(table);
110741 + kfree(table);
110742 err_alloc:
110743 return -ENOMEM;
110744 }
110745 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
110746 index 5b7a1ed..d9da205 100644
110747 --- a/net/ipv6/ping.c
110748 +++ b/net/ipv6/ping.c
110749 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
110750 };
110751 #endif
110752
110753 +static struct pingv6_ops real_pingv6_ops = {
110754 + .ipv6_recv_error = ipv6_recv_error,
110755 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
110756 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
110757 + .icmpv6_err_convert = icmpv6_err_convert,
110758 + .ipv6_icmp_error = ipv6_icmp_error,
110759 + .ipv6_chk_addr = ipv6_chk_addr,
110760 +};
110761 +
110762 +static struct pingv6_ops dummy_pingv6_ops = {
110763 + .ipv6_recv_error = dummy_ipv6_recv_error,
110764 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
110765 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
110766 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
110767 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
110768 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
110769 +};
110770 +
110771 int __init pingv6_init(void)
110772 {
110773 #ifdef CONFIG_PROC_FS
110774 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
110775 if (ret)
110776 return ret;
110777 #endif
110778 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
110779 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
110780 - pingv6_ops.ip6_datagram_recv_specific_ctl =
110781 - ip6_datagram_recv_specific_ctl;
110782 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
110783 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
110784 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
110785 + pingv6_ops = &real_pingv6_ops;
110786 return inet6_register_protosw(&pingv6_protosw);
110787 }
110788
110789 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
110790 */
110791 void pingv6_exit(void)
110792 {
110793 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
110794 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
110795 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
110796 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
110797 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
110798 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
110799 #ifdef CONFIG_PROC_FS
110800 unregister_pernet_subsys(&ping_v6_net_ops);
110801 #endif
110802 + pingv6_ops = &dummy_pingv6_ops;
110803 inet6_unregister_protosw(&pingv6_protosw);
110804 }
110805 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
110806 index 3317440..201764e 100644
110807 --- a/net/ipv6/proc.c
110808 +++ b/net/ipv6/proc.c
110809 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
110810 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
110811 goto proc_snmp6_fail;
110812
110813 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
110814 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
110815 if (!net->mib.proc_net_devsnmp6)
110816 goto proc_dev_snmp6_fail;
110817 return 0;
110818 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
110819 index b2dc60b..a6b6c10 100644
110820 --- a/net/ipv6/raw.c
110821 +++ b/net/ipv6/raw.c
110822 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
110823 {
110824 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
110825 skb_checksum_complete(skb)) {
110826 - atomic_inc(&sk->sk_drops);
110827 + atomic_inc_unchecked(&sk->sk_drops);
110828 kfree_skb(skb);
110829 return NET_RX_DROP;
110830 }
110831 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
110832 struct raw6_sock *rp = raw6_sk(sk);
110833
110834 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
110835 - atomic_inc(&sk->sk_drops);
110836 + atomic_inc_unchecked(&sk->sk_drops);
110837 kfree_skb(skb);
110838 return NET_RX_DROP;
110839 }
110840 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
110841
110842 if (inet->hdrincl) {
110843 if (skb_checksum_complete(skb)) {
110844 - atomic_inc(&sk->sk_drops);
110845 + atomic_inc_unchecked(&sk->sk_drops);
110846 kfree_skb(skb);
110847 return NET_RX_DROP;
110848 }
110849 @@ -610,7 +610,7 @@ out:
110850 return err;
110851 }
110852
110853 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
110854 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
110855 struct flowi6 *fl6, struct dst_entry **dstp,
110856 unsigned int flags)
110857 {
110858 @@ -916,12 +916,15 @@ do_confirm:
110859 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
110860 char __user *optval, int optlen)
110861 {
110862 + struct icmp6_filter filter;
110863 +
110864 switch (optname) {
110865 case ICMPV6_FILTER:
110866 if (optlen > sizeof(struct icmp6_filter))
110867 optlen = sizeof(struct icmp6_filter);
110868 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
110869 + if (copy_from_user(&filter, optval, optlen))
110870 return -EFAULT;
110871 + raw6_sk(sk)->filter = filter;
110872 return 0;
110873 default:
110874 return -ENOPROTOOPT;
110875 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
110876 char __user *optval, int __user *optlen)
110877 {
110878 int len;
110879 + struct icmp6_filter filter;
110880
110881 switch (optname) {
110882 case ICMPV6_FILTER:
110883 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
110884 len = sizeof(struct icmp6_filter);
110885 if (put_user(len, optlen))
110886 return -EFAULT;
110887 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
110888 + filter = raw6_sk(sk)->filter;
110889 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
110890 return -EFAULT;
110891 return 0;
110892 default:
110893 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
110894 index cc85a9b..526a133 100644
110895 --- a/net/ipv6/reassembly.c
110896 +++ b/net/ipv6/reassembly.c
110897 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
110898
110899 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
110900 {
110901 - struct ctl_table *table;
110902 + ctl_table_no_const *table = NULL;
110903 struct ctl_table_header *hdr;
110904
110905 - table = ip6_frags_ns_ctl_table;
110906 if (!net_eq(net, &init_net)) {
110907 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
110908 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
110909 if (table == NULL)
110910 goto err_alloc;
110911
110912 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
110913 /* Don't export sysctls to unprivileged users */
110914 if (net->user_ns != &init_user_ns)
110915 table[0].procname = NULL;
110916 - }
110917 + hdr = register_net_sysctl(net, "net/ipv6", table);
110918 + } else
110919 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
110920
110921 - hdr = register_net_sysctl(net, "net/ipv6", table);
110922 if (hdr == NULL)
110923 goto err_reg;
110924
110925 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
110926 return 0;
110927
110928 err_reg:
110929 - if (!net_eq(net, &init_net))
110930 - kfree(table);
110931 + kfree(table);
110932 err_alloc:
110933 return -ENOMEM;
110934 }
110935 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
110936 index f23fbd2..7868241 100644
110937 --- a/net/ipv6/route.c
110938 +++ b/net/ipv6/route.c
110939 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
110940
110941 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
110942 {
110943 - struct ctl_table *table;
110944 + ctl_table_no_const *table;
110945
110946 table = kmemdup(ipv6_route_table_template,
110947 sizeof(ipv6_route_table_template),
110948 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
110949 index 4f40817..54dcbef 100644
110950 --- a/net/ipv6/sit.c
110951 +++ b/net/ipv6/sit.c
110952 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
110953 static void ipip6_dev_free(struct net_device *dev);
110954 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
110955 __be32 *v4dst);
110956 -static struct rtnl_link_ops sit_link_ops __read_mostly;
110957 +static struct rtnl_link_ops sit_link_ops;
110958
110959 static int sit_net_id __read_mostly;
110960 struct sit_net {
110961 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
110962 unregister_netdevice_queue(dev, head);
110963 }
110964
110965 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
110966 +static struct rtnl_link_ops sit_link_ops = {
110967 .kind = "sit",
110968 .maxtype = IFLA_IPTUN_MAX,
110969 .policy = ipip6_policy,
110970 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
110971 index 058f3ec..dec973d 100644
110972 --- a/net/ipv6/sysctl_net_ipv6.c
110973 +++ b/net/ipv6/sysctl_net_ipv6.c
110974 @@ -61,7 +61,7 @@ static struct ctl_table ipv6_rotable[] = {
110975
110976 static int __net_init ipv6_sysctl_net_init(struct net *net)
110977 {
110978 - struct ctl_table *ipv6_table;
110979 + ctl_table_no_const *ipv6_table;
110980 struct ctl_table *ipv6_route_table;
110981 struct ctl_table *ipv6_icmp_table;
110982 int err;
110983 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
110984 index 229239ad..ee2802f 100644
110985 --- a/net/ipv6/tcp_ipv6.c
110986 +++ b/net/ipv6/tcp_ipv6.c
110987 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
110988 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
110989 }
110990
110991 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
110992 +extern int grsec_enable_blackhole;
110993 +#endif
110994 +
110995 static void tcp_v6_hash(struct sock *sk)
110996 {
110997 if (sk->sk_state != TCP_CLOSE) {
110998 @@ -1424,6 +1428,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
110999 return 0;
111000
111001 reset:
111002 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
111003 + if (!grsec_enable_blackhole)
111004 +#endif
111005 tcp_v6_send_reset(sk, skb);
111006 discard:
111007 if (opt_skb)
111008 @@ -1508,12 +1515,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
111009 TCP_SKB_CB(skb)->sacked = 0;
111010
111011 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
111012 - if (!sk)
111013 + if (!sk) {
111014 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
111015 + ret = 1;
111016 +#endif
111017 goto no_tcp_socket;
111018 + }
111019
111020 process:
111021 - if (sk->sk_state == TCP_TIME_WAIT)
111022 + if (sk->sk_state == TCP_TIME_WAIT) {
111023 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
111024 + ret = 2;
111025 +#endif
111026 goto do_time_wait;
111027 + }
111028
111029 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
111030 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
111031 @@ -1565,6 +1580,10 @@ csum_error:
111032 bad_packet:
111033 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
111034 } else {
111035 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
111036 + if (!grsec_enable_blackhole || (ret == 1 &&
111037 + (skb->dev->flags & IFF_LOOPBACK)))
111038 +#endif
111039 tcp_v6_send_reset(NULL, skb);
111040 }
111041
111042 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
111043 index 7092ff7..3fd0eb4 100644
111044 --- a/net/ipv6/udp.c
111045 +++ b/net/ipv6/udp.c
111046 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
111047 udp_ipv6_hash_secret + net_hash_mix(net));
111048 }
111049
111050 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
111051 +extern int grsec_enable_blackhole;
111052 +#endif
111053 +
111054 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
111055 {
111056 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
111057 @@ -435,7 +439,7 @@ try_again:
111058 if (unlikely(err)) {
111059 trace_kfree_skb(skb, udpv6_recvmsg);
111060 if (!peeked) {
111061 - atomic_inc(&sk->sk_drops);
111062 + atomic_inc_unchecked(&sk->sk_drops);
111063 if (is_udp4)
111064 UDP_INC_STATS_USER(sock_net(sk),
111065 UDP_MIB_INERRORS,
111066 @@ -698,7 +702,7 @@ csum_error:
111067 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
111068 drop:
111069 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
111070 - atomic_inc(&sk->sk_drops);
111071 + atomic_inc_unchecked(&sk->sk_drops);
111072 kfree_skb(skb);
111073 return -1;
111074 }
111075 @@ -754,7 +758,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
111076 if (likely(skb1 == NULL))
111077 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
111078 if (!skb1) {
111079 - atomic_inc(&sk->sk_drops);
111080 + atomic_inc_unchecked(&sk->sk_drops);
111081 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
111082 IS_UDPLITE(sk));
111083 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
111084 @@ -920,6 +924,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
111085 goto csum_error;
111086
111087 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
111088 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
111089 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
111090 +#endif
111091 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
111092
111093 kfree_skb(skb);
111094 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
111095 index 2a0bbda..d75ca57 100644
111096 --- a/net/ipv6/xfrm6_policy.c
111097 +++ b/net/ipv6/xfrm6_policy.c
111098 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
111099 }
111100 }
111101
111102 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
111103 +static int xfrm6_garbage_collect(struct dst_ops *ops)
111104 {
111105 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
111106
111107 - xfrm6_policy_afinfo.garbage_collect(net);
111108 + xfrm_garbage_collect_deferred(net);
111109 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
111110 }
111111
111112 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
111113
111114 static int __net_init xfrm6_net_init(struct net *net)
111115 {
111116 - struct ctl_table *table;
111117 + ctl_table_no_const *table = NULL;
111118 struct ctl_table_header *hdr;
111119
111120 - table = xfrm6_policy_table;
111121 if (!net_eq(net, &init_net)) {
111122 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
111123 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
111124 if (!table)
111125 goto err_alloc;
111126
111127 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
111128 - }
111129 + hdr = register_net_sysctl(net, "net/ipv6", table);
111130 + } else
111131 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
111132
111133 - hdr = register_net_sysctl(net, "net/ipv6", table);
111134 if (!hdr)
111135 goto err_reg;
111136
111137 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
111138 return 0;
111139
111140 err_reg:
111141 - if (!net_eq(net, &init_net))
111142 - kfree(table);
111143 + kfree(table);
111144 err_alloc:
111145 return -ENOMEM;
111146 }
111147 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
111148 index e15c16a..7cf07aa 100644
111149 --- a/net/ipx/ipx_proc.c
111150 +++ b/net/ipx/ipx_proc.c
111151 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
111152 struct proc_dir_entry *p;
111153 int rc = -ENOMEM;
111154
111155 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
111156 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
111157
111158 if (!ipx_proc_dir)
111159 goto out;
111160 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
111161 index 2ba8b97..6d33010 100644
111162 --- a/net/irda/ircomm/ircomm_tty.c
111163 +++ b/net/irda/ircomm/ircomm_tty.c
111164 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
111165 add_wait_queue(&port->open_wait, &wait);
111166
111167 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
111168 - __FILE__, __LINE__, tty->driver->name, port->count);
111169 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
111170
111171 spin_lock_irqsave(&port->lock, flags);
111172 if (!tty_hung_up_p(filp))
111173 - port->count--;
111174 + atomic_dec(&port->count);
111175 port->blocked_open++;
111176 spin_unlock_irqrestore(&port->lock, flags);
111177
111178 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
111179 }
111180
111181 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
111182 - __FILE__, __LINE__, tty->driver->name, port->count);
111183 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
111184
111185 schedule();
111186 }
111187 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
111188
111189 spin_lock_irqsave(&port->lock, flags);
111190 if (!tty_hung_up_p(filp))
111191 - port->count++;
111192 + atomic_inc(&port->count);
111193 port->blocked_open--;
111194 spin_unlock_irqrestore(&port->lock, flags);
111195
111196 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
111197 - __FILE__, __LINE__, tty->driver->name, port->count);
111198 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
111199
111200 if (!retval)
111201 port->flags |= ASYNC_NORMAL_ACTIVE;
111202 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
111203
111204 /* ++ is not atomic, so this should be protected - Jean II */
111205 spin_lock_irqsave(&self->port.lock, flags);
111206 - self->port.count++;
111207 + atomic_inc(&self->port.count);
111208 spin_unlock_irqrestore(&self->port.lock, flags);
111209 tty_port_tty_set(&self->port, tty);
111210
111211 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
111212 - self->line, self->port.count);
111213 + self->line, atomic_read(&self->port.count));
111214
111215 /* Not really used by us, but lets do it anyway */
111216 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
111217 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
111218 tty_kref_put(port->tty);
111219 }
111220 port->tty = NULL;
111221 - port->count = 0;
111222 + atomic_set(&port->count, 0);
111223 spin_unlock_irqrestore(&port->lock, flags);
111224
111225 wake_up_interruptible(&port->open_wait);
111226 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
111227 seq_putc(m, '\n');
111228
111229 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
111230 - seq_printf(m, "Open count: %d\n", self->port.count);
111231 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
111232 seq_printf(m, "Max data size: %d\n", self->max_data_size);
111233 seq_printf(m, "Max header size: %d\n", self->max_header_size);
111234
111235 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
111236 index b9ac598..f88cc56 100644
111237 --- a/net/irda/irproc.c
111238 +++ b/net/irda/irproc.c
111239 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
111240 {
111241 int i;
111242
111243 - proc_irda = proc_mkdir("irda", init_net.proc_net);
111244 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
111245 if (proc_irda == NULL)
111246 return;
111247
111248 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
111249 index 7a95fa4..57be196 100644
111250 --- a/net/iucv/af_iucv.c
111251 +++ b/net/iucv/af_iucv.c
111252 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
111253 {
111254 char name[12];
111255
111256 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
111257 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
111258 while (__iucv_get_sock_by_name(name)) {
111259 sprintf(name, "%08x",
111260 - atomic_inc_return(&iucv_sk_list.autobind_name));
111261 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
111262 }
111263 memcpy(iucv->src_name, name, 8);
111264 }
111265 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
111266 index da78793..bdd78cf 100644
111267 --- a/net/iucv/iucv.c
111268 +++ b/net/iucv/iucv.c
111269 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
111270 return NOTIFY_OK;
111271 }
111272
111273 -static struct notifier_block __refdata iucv_cpu_notifier = {
111274 +static struct notifier_block iucv_cpu_notifier = {
111275 .notifier_call = iucv_cpu_notify,
111276 };
111277
111278 diff --git a/net/key/af_key.c b/net/key/af_key.c
111279 index ba2a2f9..b658bc3 100644
111280 --- a/net/key/af_key.c
111281 +++ b/net/key/af_key.c
111282 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
111283 static u32 get_acqseq(void)
111284 {
111285 u32 res;
111286 - static atomic_t acqseq;
111287 + static atomic_unchecked_t acqseq;
111288
111289 do {
111290 - res = atomic_inc_return(&acqseq);
111291 + res = atomic_inc_return_unchecked(&acqseq);
111292 } while (!res);
111293 return res;
111294 }
111295 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
111296 index 76125c5..e474828 100644
111297 --- a/net/l2tp/l2tp_eth.c
111298 +++ b/net/l2tp/l2tp_eth.c
111299 @@ -42,12 +42,12 @@ struct l2tp_eth {
111300 struct sock *tunnel_sock;
111301 struct l2tp_session *session;
111302 struct list_head list;
111303 - atomic_long_t tx_bytes;
111304 - atomic_long_t tx_packets;
111305 - atomic_long_t tx_dropped;
111306 - atomic_long_t rx_bytes;
111307 - atomic_long_t rx_packets;
111308 - atomic_long_t rx_errors;
111309 + atomic_long_unchecked_t tx_bytes;
111310 + atomic_long_unchecked_t tx_packets;
111311 + atomic_long_unchecked_t tx_dropped;
111312 + atomic_long_unchecked_t rx_bytes;
111313 + atomic_long_unchecked_t rx_packets;
111314 + atomic_long_unchecked_t rx_errors;
111315 };
111316
111317 /* via l2tp_session_priv() */
111318 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
111319 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
111320
111321 if (likely(ret == NET_XMIT_SUCCESS)) {
111322 - atomic_long_add(len, &priv->tx_bytes);
111323 - atomic_long_inc(&priv->tx_packets);
111324 + atomic_long_add_unchecked(len, &priv->tx_bytes);
111325 + atomic_long_inc_unchecked(&priv->tx_packets);
111326 } else {
111327 - atomic_long_inc(&priv->tx_dropped);
111328 + atomic_long_inc_unchecked(&priv->tx_dropped);
111329 }
111330 return NETDEV_TX_OK;
111331 }
111332 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
111333 {
111334 struct l2tp_eth *priv = netdev_priv(dev);
111335
111336 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
111337 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
111338 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
111339 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
111340 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
111341 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
111342 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
111343 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
111344 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
111345 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
111346 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
111347 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
111348 return stats;
111349 }
111350
111351 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
111352 nf_reset(skb);
111353
111354 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
111355 - atomic_long_inc(&priv->rx_packets);
111356 - atomic_long_add(data_len, &priv->rx_bytes);
111357 + atomic_long_inc_unchecked(&priv->rx_packets);
111358 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
111359 } else {
111360 - atomic_long_inc(&priv->rx_errors);
111361 + atomic_long_inc_unchecked(&priv->rx_errors);
111362 }
111363 return;
111364
111365 error:
111366 - atomic_long_inc(&priv->rx_errors);
111367 + atomic_long_inc_unchecked(&priv->rx_errors);
111368 kfree_skb(skb);
111369 }
111370
111371 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
111372 index 13752d9..b704a93 100644
111373 --- a/net/l2tp/l2tp_ppp.c
111374 +++ b/net/l2tp/l2tp_ppp.c
111375 @@ -755,7 +755,8 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
111376 /* If PMTU discovery was enabled, use the MTU that was discovered */
111377 dst = sk_dst_get(tunnel->sock);
111378 if (dst != NULL) {
111379 - u32 pmtu = dst_mtu(__sk_dst_get(tunnel->sock));
111380 + u32 pmtu = dst_mtu(dst);
111381 +
111382 if (pmtu != 0)
111383 session->mtu = session->mru = pmtu -
111384 PPPOL2TP_HEADER_OVERHEAD;
111385 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
111386 index 1a3c7e0..80f8b0c 100644
111387 --- a/net/llc/llc_proc.c
111388 +++ b/net/llc/llc_proc.c
111389 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
111390 int rc = -ENOMEM;
111391 struct proc_dir_entry *p;
111392
111393 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
111394 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
111395 if (!llc_proc_dir)
111396 goto out;
111397
111398 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
111399 index 592f4b1..efa7aa9 100644
111400 --- a/net/mac80211/cfg.c
111401 +++ b/net/mac80211/cfg.c
111402 @@ -864,7 +864,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
111403 ret = ieee80211_vif_use_channel(sdata, chandef,
111404 IEEE80211_CHANCTX_EXCLUSIVE);
111405 }
111406 - } else if (local->open_count == local->monitors) {
111407 + } else if (local_read(&local->open_count) == local->monitors) {
111408 local->_oper_chandef = *chandef;
111409 ieee80211_hw_config(local, 0);
111410 }
111411 @@ -3574,7 +3574,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
111412 else
111413 local->probe_req_reg--;
111414
111415 - if (!local->open_count)
111416 + if (!local_read(&local->open_count))
111417 break;
111418
111419 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
111420 @@ -3723,8 +3723,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
111421 if (chanctx_conf) {
111422 *chandef = chanctx_conf->def;
111423 ret = 0;
111424 - } else if (local->open_count > 0 &&
111425 - local->open_count == local->monitors &&
111426 + } else if (local_read(&local->open_count) > 0 &&
111427 + local_read(&local->open_count) == local->monitors &&
111428 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
111429 if (local->use_chanctx)
111430 *chandef = local->monitor_chandef;
111431 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
111432 index ac9836e..32613c1 100644
111433 --- a/net/mac80211/ieee80211_i.h
111434 +++ b/net/mac80211/ieee80211_i.h
111435 @@ -28,6 +28,7 @@
111436 #include <net/ieee80211_radiotap.h>
111437 #include <net/cfg80211.h>
111438 #include <net/mac80211.h>
111439 +#include <asm/local.h>
111440 #include "key.h"
111441 #include "sta_info.h"
111442 #include "debug.h"
111443 @@ -1011,7 +1012,7 @@ struct ieee80211_local {
111444 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
111445 spinlock_t queue_stop_reason_lock;
111446
111447 - int open_count;
111448 + local_t open_count;
111449 int monitors, cooked_mntrs;
111450 /* number of interfaces with corresponding FIF_ flags */
111451 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
111452 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
111453 index 388b863..6575b55 100644
111454 --- a/net/mac80211/iface.c
111455 +++ b/net/mac80211/iface.c
111456 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
111457 break;
111458 }
111459
111460 - if (local->open_count == 0) {
111461 + if (local_read(&local->open_count) == 0) {
111462 res = drv_start(local);
111463 if (res)
111464 goto err_del_bss;
111465 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
111466 res = drv_add_interface(local, sdata);
111467 if (res)
111468 goto err_stop;
111469 - } else if (local->monitors == 0 && local->open_count == 0) {
111470 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
111471 res = ieee80211_add_virtual_monitor(local);
111472 if (res)
111473 goto err_stop;
111474 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
111475 atomic_inc(&local->iff_promiscs);
111476
111477 if (coming_up)
111478 - local->open_count++;
111479 + local_inc(&local->open_count);
111480
111481 if (hw_reconf_flags)
111482 ieee80211_hw_config(local, hw_reconf_flags);
111483 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
111484 err_del_interface:
111485 drv_remove_interface(local, sdata);
111486 err_stop:
111487 - if (!local->open_count)
111488 + if (!local_read(&local->open_count))
111489 drv_stop(local);
111490 err_del_bss:
111491 sdata->bss = NULL;
111492 @@ -888,7 +888,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
111493 }
111494
111495 if (going_down)
111496 - local->open_count--;
111497 + local_dec(&local->open_count);
111498
111499 switch (sdata->vif.type) {
111500 case NL80211_IFTYPE_AP_VLAN:
111501 @@ -949,7 +949,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
111502 }
111503 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
111504
111505 - if (local->open_count == 0)
111506 + if (local_read(&local->open_count) == 0)
111507 ieee80211_clear_tx_pending(local);
111508
111509 /*
111510 @@ -989,7 +989,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
111511
111512 ieee80211_recalc_ps(local, -1);
111513
111514 - if (local->open_count == 0) {
111515 + if (local_read(&local->open_count) == 0) {
111516 ieee80211_stop_device(local);
111517
111518 /* no reconfiguring after stop! */
111519 @@ -1000,7 +1000,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
111520 ieee80211_configure_filter(local);
111521 ieee80211_hw_config(local, hw_reconf_flags);
111522
111523 - if (local->monitors == local->open_count)
111524 + if (local->monitors == local_read(&local->open_count))
111525 ieee80211_add_virtual_monitor(local);
111526 }
111527
111528 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
111529 index d17c26d..43d6bfb 100644
111530 --- a/net/mac80211/main.c
111531 +++ b/net/mac80211/main.c
111532 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
111533 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
111534 IEEE80211_CONF_CHANGE_POWER);
111535
111536 - if (changed && local->open_count) {
111537 + if (changed && local_read(&local->open_count)) {
111538 ret = drv_config(local, changed);
111539 /*
111540 * Goal:
111541 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
111542 index d478b88..8c8d157 100644
111543 --- a/net/mac80211/pm.c
111544 +++ b/net/mac80211/pm.c
111545 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
111546 struct ieee80211_sub_if_data *sdata;
111547 struct sta_info *sta;
111548
111549 - if (!local->open_count)
111550 + if (!local_read(&local->open_count))
111551 goto suspend;
111552
111553 ieee80211_scan_cancel(local);
111554 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
111555 cancel_work_sync(&local->dynamic_ps_enable_work);
111556 del_timer_sync(&local->dynamic_ps_timer);
111557
111558 - local->wowlan = wowlan && local->open_count;
111559 + local->wowlan = wowlan && local_read(&local->open_count);
111560 if (local->wowlan) {
111561 int err = drv_suspend(local, wowlan);
111562 if (err < 0) {
111563 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
111564 WARN_ON(!list_empty(&local->chanctx_list));
111565
111566 /* stop hardware - this must stop RX */
111567 - if (local->open_count)
111568 + if (local_read(&local->open_count))
111569 ieee80211_stop_device(local);
111570
111571 suspend:
111572 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
111573 index 8fdadfd..a4f72b8 100644
111574 --- a/net/mac80211/rate.c
111575 +++ b/net/mac80211/rate.c
111576 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
111577
111578 ASSERT_RTNL();
111579
111580 - if (local->open_count)
111581 + if (local_read(&local->open_count))
111582 return -EBUSY;
111583
111584 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
111585 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
111586 index 6ff1346..936ca9a 100644
111587 --- a/net/mac80211/rc80211_pid_debugfs.c
111588 +++ b/net/mac80211/rc80211_pid_debugfs.c
111589 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
111590
111591 spin_unlock_irqrestore(&events->lock, status);
111592
111593 - if (copy_to_user(buf, pb, p))
111594 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
111595 return -EFAULT;
111596
111597 return p;
111598 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
111599 index a6cda52..f3b6776 100644
111600 --- a/net/mac80211/util.c
111601 +++ b/net/mac80211/util.c
111602 @@ -1548,7 +1548,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
111603 }
111604 #endif
111605 /* everything else happens only if HW was up & running */
111606 - if (!local->open_count)
111607 + if (!local_read(&local->open_count))
111608 goto wake_up;
111609
111610 /*
111611 @@ -1772,7 +1772,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
111612 local->in_reconfig = false;
111613 barrier();
111614
111615 - if (local->monitors == local->open_count && local->monitors > 0)
111616 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
111617 ieee80211_add_virtual_monitor(local);
111618
111619 /*
111620 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
111621 index e9410d1..77b6378 100644
111622 --- a/net/netfilter/Kconfig
111623 +++ b/net/netfilter/Kconfig
111624 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
111625
111626 To compile it as a module, choose M here. If unsure, say N.
111627
111628 +config NETFILTER_XT_MATCH_GRADM
111629 + tristate '"gradm" match support'
111630 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
111631 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
111632 + ---help---
111633 + The gradm match allows to match on grsecurity RBAC being enabled.
111634 + It is useful when iptables rules are applied early on bootup to
111635 + prevent connections to the machine (except from a trusted host)
111636 + while the RBAC system is disabled.
111637 +
111638 config NETFILTER_XT_MATCH_HASHLIMIT
111639 tristate '"hashlimit" match support'
111640 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
111641 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
111642 index bffdad7..f9317d1 100644
111643 --- a/net/netfilter/Makefile
111644 +++ b/net/netfilter/Makefile
111645 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
111646 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
111647 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
111648 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
111649 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
111650 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
111651 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
111652 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
111653 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
111654 index ec8114f..6b2bfba 100644
111655 --- a/net/netfilter/ipset/ip_set_core.c
111656 +++ b/net/netfilter/ipset/ip_set_core.c
111657 @@ -1921,7 +1921,7 @@ done:
111658 return ret;
111659 }
111660
111661 -static struct nf_sockopt_ops so_set __read_mostly = {
111662 +static struct nf_sockopt_ops so_set = {
111663 .pf = PF_INET,
111664 .get_optmin = SO_IP_SET,
111665 .get_optmax = SO_IP_SET + 1,
111666 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
111667 index 610e19c..08d0c3f 100644
111668 --- a/net/netfilter/ipvs/ip_vs_conn.c
111669 +++ b/net/netfilter/ipvs/ip_vs_conn.c
111670 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
111671 /* Increase the refcnt counter of the dest */
111672 ip_vs_dest_hold(dest);
111673
111674 - conn_flags = atomic_read(&dest->conn_flags);
111675 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
111676 if (cp->protocol != IPPROTO_UDP)
111677 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
111678 flags = cp->flags;
111679 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
111680
111681 cp->control = NULL;
111682 atomic_set(&cp->n_control, 0);
111683 - atomic_set(&cp->in_pkts, 0);
111684 + atomic_set_unchecked(&cp->in_pkts, 0);
111685
111686 cp->packet_xmit = NULL;
111687 cp->app = NULL;
111688 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
111689
111690 /* Don't drop the entry if its number of incoming packets is not
111691 located in [0, 8] */
111692 - i = atomic_read(&cp->in_pkts);
111693 + i = atomic_read_unchecked(&cp->in_pkts);
111694 if (i > 8 || i < 0) return 0;
111695
111696 if (!todrop_rate[i]) return 0;
111697 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
111698 index e683675..67cb16b 100644
111699 --- a/net/netfilter/ipvs/ip_vs_core.c
111700 +++ b/net/netfilter/ipvs/ip_vs_core.c
111701 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
111702 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
111703 /* do not touch skb anymore */
111704
111705 - atomic_inc(&cp->in_pkts);
111706 + atomic_inc_unchecked(&cp->in_pkts);
111707 ip_vs_conn_put(cp);
111708 return ret;
111709 }
111710 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
111711 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
111712 pkts = sysctl_sync_threshold(ipvs);
111713 else
111714 - pkts = atomic_add_return(1, &cp->in_pkts);
111715 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
111716
111717 if (ipvs->sync_state & IP_VS_STATE_MASTER)
111718 ip_vs_sync_conn(net, cp, pkts);
111719 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
111720 index 581a658..910e112 100644
111721 --- a/net/netfilter/ipvs/ip_vs_ctl.c
111722 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
111723 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
111724 */
111725 ip_vs_rs_hash(ipvs, dest);
111726 }
111727 - atomic_set(&dest->conn_flags, conn_flags);
111728 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
111729
111730 /* bind the service */
111731 old_svc = rcu_dereference_protected(dest->svc, 1);
111732 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
111733 * align with netns init in ip_vs_control_net_init()
111734 */
111735
111736 -static struct ctl_table vs_vars[] = {
111737 +static ctl_table_no_const vs_vars[] __read_only = {
111738 {
111739 .procname = "amemthresh",
111740 .maxlen = sizeof(int),
111741 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
111742 " %-7s %-6d %-10d %-10d\n",
111743 &dest->addr.in6,
111744 ntohs(dest->port),
111745 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
111746 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
111747 atomic_read(&dest->weight),
111748 atomic_read(&dest->activeconns),
111749 atomic_read(&dest->inactconns));
111750 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
111751 "%-7s %-6d %-10d %-10d\n",
111752 ntohl(dest->addr.ip),
111753 ntohs(dest->port),
111754 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
111755 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
111756 atomic_read(&dest->weight),
111757 atomic_read(&dest->activeconns),
111758 atomic_read(&dest->inactconns));
111759 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
111760
111761 entry.addr = dest->addr.ip;
111762 entry.port = dest->port;
111763 - entry.conn_flags = atomic_read(&dest->conn_flags);
111764 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
111765 entry.weight = atomic_read(&dest->weight);
111766 entry.u_threshold = dest->u_threshold;
111767 entry.l_threshold = dest->l_threshold;
111768 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
111769 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
111770 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
111771 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
111772 - (atomic_read(&dest->conn_flags) &
111773 + (atomic_read_unchecked(&dest->conn_flags) &
111774 IP_VS_CONN_F_FWD_MASK)) ||
111775 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
111776 atomic_read(&dest->weight)) ||
111777 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
111778 {
111779 int idx;
111780 struct netns_ipvs *ipvs = net_ipvs(net);
111781 - struct ctl_table *tbl;
111782 + ctl_table_no_const *tbl;
111783
111784 atomic_set(&ipvs->dropentry, 0);
111785 spin_lock_init(&ipvs->dropentry_lock);
111786 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
111787 index 547ff33..c8c8117 100644
111788 --- a/net/netfilter/ipvs/ip_vs_lblc.c
111789 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
111790 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
111791 * IPVS LBLC sysctl table
111792 */
111793 #ifdef CONFIG_SYSCTL
111794 -static struct ctl_table vs_vars_table[] = {
111795 +static ctl_table_no_const vs_vars_table[] __read_only = {
111796 {
111797 .procname = "lblc_expiration",
111798 .data = NULL,
111799 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
111800 index 3f21a2f..a112e85 100644
111801 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
111802 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
111803 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
111804 * IPVS LBLCR sysctl table
111805 */
111806
111807 -static struct ctl_table vs_vars_table[] = {
111808 +static ctl_table_no_const vs_vars_table[] __read_only = {
111809 {
111810 .procname = "lblcr_expiration",
111811 .data = NULL,
111812 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
111813 index db80126..ef7110e 100644
111814 --- a/net/netfilter/ipvs/ip_vs_sync.c
111815 +++ b/net/netfilter/ipvs/ip_vs_sync.c
111816 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
111817 cp = cp->control;
111818 if (cp) {
111819 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
111820 - pkts = atomic_add_return(1, &cp->in_pkts);
111821 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
111822 else
111823 pkts = sysctl_sync_threshold(ipvs);
111824 ip_vs_sync_conn(net, cp->control, pkts);
111825 @@ -771,7 +771,7 @@ control:
111826 if (!cp)
111827 return;
111828 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
111829 - pkts = atomic_add_return(1, &cp->in_pkts);
111830 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
111831 else
111832 pkts = sysctl_sync_threshold(ipvs);
111833 goto sloop;
111834 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
111835
111836 if (opt)
111837 memcpy(&cp->in_seq, opt, sizeof(*opt));
111838 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
111839 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
111840 cp->state = state;
111841 cp->old_state = cp->state;
111842 /*
111843 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
111844 index 73ba1cc..1adfc7a 100644
111845 --- a/net/netfilter/ipvs/ip_vs_xmit.c
111846 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
111847 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
111848 else
111849 rc = NF_ACCEPT;
111850 /* do not touch skb anymore */
111851 - atomic_inc(&cp->in_pkts);
111852 + atomic_inc_unchecked(&cp->in_pkts);
111853 goto out;
111854 }
111855
111856 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
111857 else
111858 rc = NF_ACCEPT;
111859 /* do not touch skb anymore */
111860 - atomic_inc(&cp->in_pkts);
111861 + atomic_inc_unchecked(&cp->in_pkts);
111862 goto out;
111863 }
111864
111865 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
111866 index a4b5e2a..13b1de3 100644
111867 --- a/net/netfilter/nf_conntrack_acct.c
111868 +++ b/net/netfilter/nf_conntrack_acct.c
111869 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
111870 #ifdef CONFIG_SYSCTL
111871 static int nf_conntrack_acct_init_sysctl(struct net *net)
111872 {
111873 - struct ctl_table *table;
111874 + ctl_table_no_const *table;
111875
111876 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
111877 GFP_KERNEL);
111878 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
111879 index 1f4f954..e364ad7 100644
111880 --- a/net/netfilter/nf_conntrack_core.c
111881 +++ b/net/netfilter/nf_conntrack_core.c
111882 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
111883 #define DYING_NULLS_VAL ((1<<30)+1)
111884 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
111885
111886 +#ifdef CONFIG_GRKERNSEC_HIDESYM
111887 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
111888 +#endif
111889 +
111890 int nf_conntrack_init_net(struct net *net)
111891 {
111892 int ret = -ENOMEM;
111893 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
111894 if (!net->ct.stat)
111895 goto err_pcpu_lists;
111896
111897 +#ifdef CONFIG_GRKERNSEC_HIDESYM
111898 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
111899 +#else
111900 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
111901 +#endif
111902 if (!net->ct.slabname)
111903 goto err_slabname;
111904
111905 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
111906 index 1df1761..ce8b88a 100644
111907 --- a/net/netfilter/nf_conntrack_ecache.c
111908 +++ b/net/netfilter/nf_conntrack_ecache.c
111909 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
111910 #ifdef CONFIG_SYSCTL
111911 static int nf_conntrack_event_init_sysctl(struct net *net)
111912 {
111913 - struct ctl_table *table;
111914 + ctl_table_no_const *table;
111915
111916 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
111917 GFP_KERNEL);
111918 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
111919 index 5b3eae7..dd4b8fe 100644
111920 --- a/net/netfilter/nf_conntrack_helper.c
111921 +++ b/net/netfilter/nf_conntrack_helper.c
111922 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
111923
111924 static int nf_conntrack_helper_init_sysctl(struct net *net)
111925 {
111926 - struct ctl_table *table;
111927 + ctl_table_no_const *table;
111928
111929 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
111930 GFP_KERNEL);
111931 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
111932 index b65d586..beec902 100644
111933 --- a/net/netfilter/nf_conntrack_proto.c
111934 +++ b/net/netfilter/nf_conntrack_proto.c
111935 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
111936
111937 static void
111938 nf_ct_unregister_sysctl(struct ctl_table_header **header,
111939 - struct ctl_table **table,
111940 + ctl_table_no_const **table,
111941 unsigned int users)
111942 {
111943 if (users > 0)
111944 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
111945 index f641751..d3c5b51 100644
111946 --- a/net/netfilter/nf_conntrack_standalone.c
111947 +++ b/net/netfilter/nf_conntrack_standalone.c
111948 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
111949
111950 static int nf_conntrack_standalone_init_sysctl(struct net *net)
111951 {
111952 - struct ctl_table *table;
111953 + ctl_table_no_const *table;
111954
111955 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
111956 GFP_KERNEL);
111957 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
111958 index 7a394df..bd91a8a 100644
111959 --- a/net/netfilter/nf_conntrack_timestamp.c
111960 +++ b/net/netfilter/nf_conntrack_timestamp.c
111961 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
111962 #ifdef CONFIG_SYSCTL
111963 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
111964 {
111965 - struct ctl_table *table;
111966 + ctl_table_no_const *table;
111967
111968 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
111969 GFP_KERNEL);
111970 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
111971 index 85296d4..8becdec 100644
111972 --- a/net/netfilter/nf_log.c
111973 +++ b/net/netfilter/nf_log.c
111974 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
111975
111976 #ifdef CONFIG_SYSCTL
111977 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
111978 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
111979 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
111980
111981 static int nf_log_proc_dostring(struct ctl_table *table, int write,
111982 void __user *buffer, size_t *lenp, loff_t *ppos)
111983 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
111984 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
111985 mutex_unlock(&nf_log_mutex);
111986 } else {
111987 + ctl_table_no_const nf_log_table = *table;
111988 +
111989 mutex_lock(&nf_log_mutex);
111990 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
111991 lockdep_is_held(&nf_log_mutex));
111992 if (!logger)
111993 - table->data = "NONE";
111994 + nf_log_table.data = "NONE";
111995 else
111996 - table->data = logger->name;
111997 - r = proc_dostring(table, write, buffer, lenp, ppos);
111998 + nf_log_table.data = logger->name;
111999 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
112000 mutex_unlock(&nf_log_mutex);
112001 }
112002
112003 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
112004 index f042ae5..30ea486 100644
112005 --- a/net/netfilter/nf_sockopt.c
112006 +++ b/net/netfilter/nf_sockopt.c
112007 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
112008 }
112009 }
112010
112011 - list_add(&reg->list, &nf_sockopts);
112012 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
112013 out:
112014 mutex_unlock(&nf_sockopt_mutex);
112015 return ret;
112016 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
112017 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
112018 {
112019 mutex_lock(&nf_sockopt_mutex);
112020 - list_del(&reg->list);
112021 + pax_list_del((struct list_head *)&reg->list);
112022 mutex_unlock(&nf_sockopt_mutex);
112023 }
112024 EXPORT_SYMBOL(nf_unregister_sockopt);
112025 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
112026 index d292c8d..9f1e166 100644
112027 --- a/net/netfilter/nfnetlink_log.c
112028 +++ b/net/netfilter/nfnetlink_log.c
112029 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
112030 struct nfnl_log_net {
112031 spinlock_t instances_lock;
112032 struct hlist_head instance_table[INSTANCE_BUCKETS];
112033 - atomic_t global_seq;
112034 + atomic_unchecked_t global_seq;
112035 };
112036
112037 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
112038 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
112039 /* global sequence number */
112040 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
112041 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
112042 - htonl(atomic_inc_return(&log->global_seq))))
112043 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
112044 goto nla_put_failure;
112045
112046 if (data_len) {
112047 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
112048 index 1840989..6895744 100644
112049 --- a/net/netfilter/nft_compat.c
112050 +++ b/net/netfilter/nft_compat.c
112051 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
112052 /* We want to reuse existing compat_to_user */
112053 old_fs = get_fs();
112054 set_fs(KERNEL_DS);
112055 - t->compat_to_user(out, in);
112056 + t->compat_to_user((void __force_user *)out, in);
112057 set_fs(old_fs);
112058 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
112059 kfree(out);
112060 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
112061 /* We want to reuse existing compat_to_user */
112062 old_fs = get_fs();
112063 set_fs(KERNEL_DS);
112064 - m->compat_to_user(out, in);
112065 + m->compat_to_user((void __force_user *)out, in);
112066 set_fs(old_fs);
112067 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
112068 kfree(out);
112069 diff --git a/net/netfilter/xt_bpf.c b/net/netfilter/xt_bpf.c
112070 index bbffdbda..12d4da8 100644
112071 --- a/net/netfilter/xt_bpf.c
112072 +++ b/net/netfilter/xt_bpf.c
112073 @@ -23,11 +23,10 @@ MODULE_ALIAS("ip6t_bpf");
112074 static int bpf_mt_check(const struct xt_mtchk_param *par)
112075 {
112076 struct xt_bpf_info *info = par->matchinfo;
112077 - struct sock_fprog_kern program;
112078 + struct sock_fprog program;
112079
112080 program.len = info->bpf_program_num_elem;
112081 - program.filter = info->bpf_program;
112082 -
112083 + program.filter = (struct sock_filter __user *) info->bpf_program;
112084 if (sk_unattached_filter_create(&info->filter, &program)) {
112085 pr_info("bpf: check failed: parse error\n");
112086 return -EINVAL;
112087 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
112088 new file mode 100644
112089 index 0000000..c566332
112090 --- /dev/null
112091 +++ b/net/netfilter/xt_gradm.c
112092 @@ -0,0 +1,51 @@
112093 +/*
112094 + * gradm match for netfilter
112095 + * Copyright © Zbigniew Krzystolik, 2010
112096 + *
112097 + * This program is free software; you can redistribute it and/or modify
112098 + * it under the terms of the GNU General Public License; either version
112099 + * 2 or 3 as published by the Free Software Foundation.
112100 + */
112101 +#include <linux/module.h>
112102 +#include <linux/moduleparam.h>
112103 +#include <linux/skbuff.h>
112104 +#include <linux/netfilter/x_tables.h>
112105 +#include <linux/grsecurity.h>
112106 +#include <linux/netfilter/xt_gradm.h>
112107 +
112108 +static bool
112109 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
112110 +{
112111 + const struct xt_gradm_mtinfo *info = par->matchinfo;
112112 + bool retval = false;
112113 + if (gr_acl_is_enabled())
112114 + retval = true;
112115 + return retval ^ info->invflags;
112116 +}
112117 +
112118 +static struct xt_match gradm_mt_reg __read_mostly = {
112119 + .name = "gradm",
112120 + .revision = 0,
112121 + .family = NFPROTO_UNSPEC,
112122 + .match = gradm_mt,
112123 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
112124 + .me = THIS_MODULE,
112125 +};
112126 +
112127 +static int __init gradm_mt_init(void)
112128 +{
112129 + return xt_register_match(&gradm_mt_reg);
112130 +}
112131 +
112132 +static void __exit gradm_mt_exit(void)
112133 +{
112134 + xt_unregister_match(&gradm_mt_reg);
112135 +}
112136 +
112137 +module_init(gradm_mt_init);
112138 +module_exit(gradm_mt_exit);
112139 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
112140 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
112141 +MODULE_LICENSE("GPL");
112142 +MODULE_ALIAS("ipt_gradm");
112143 +MODULE_ALIAS("ip6t_gradm");
112144 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
112145 index a3910fc..2d2ba14 100644
112146 --- a/net/netfilter/xt_hashlimit.c
112147 +++ b/net/netfilter/xt_hashlimit.c
112148 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
112149 {
112150 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
112151
112152 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
112153 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
112154 if (!hashlimit_net->ipt_hashlimit)
112155 return -ENOMEM;
112156 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
112157 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
112158 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
112159 if (!hashlimit_net->ip6t_hashlimit) {
112160 remove_proc_entry("ipt_hashlimit", net->proc_net);
112161 return -ENOMEM;
112162 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
112163 index a9faae8..1ea30e0 100644
112164 --- a/net/netfilter/xt_recent.c
112165 +++ b/net/netfilter/xt_recent.c
112166 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
112167 {
112168 struct recent_net *recent_net = recent_pernet(net);
112169
112170 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
112171 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
112172 if (!recent_net->xt_recent)
112173 return -ENOMEM;
112174 return 0;
112175 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
112176 index 11de55e..f25e448 100644
112177 --- a/net/netfilter/xt_statistic.c
112178 +++ b/net/netfilter/xt_statistic.c
112179 @@ -19,7 +19,7 @@
112180 #include <linux/module.h>
112181
112182 struct xt_statistic_priv {
112183 - atomic_t count;
112184 + atomic_unchecked_t count;
112185 } ____cacheline_aligned_in_smp;
112186
112187 MODULE_LICENSE("GPL");
112188 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
112189 break;
112190 case XT_STATISTIC_MODE_NTH:
112191 do {
112192 - oval = atomic_read(&info->master->count);
112193 + oval = atomic_read_unchecked(&info->master->count);
112194 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
112195 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
112196 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
112197 if (nval == 0)
112198 ret = !ret;
112199 break;
112200 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
112201 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
112202 if (info->master == NULL)
112203 return -ENOMEM;
112204 - atomic_set(&info->master->count, info->u.nth.count);
112205 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
112206
112207 return 0;
112208 }
112209 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
112210 index e6fac7e..cdcd25e 100644
112211 --- a/net/netlink/af_netlink.c
112212 +++ b/net/netlink/af_netlink.c
112213 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
112214 sk->sk_error_report(sk);
112215 }
112216 }
112217 - atomic_inc(&sk->sk_drops);
112218 + atomic_inc_unchecked(&sk->sk_drops);
112219 }
112220
112221 static void netlink_rcv_wake(struct sock *sk)
112222 @@ -3058,7 +3058,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
112223 sk_wmem_alloc_get(s),
112224 nlk->cb_running,
112225 atomic_read(&s->sk_refcnt),
112226 - atomic_read(&s->sk_drops),
112227 + atomic_read_unchecked(&s->sk_drops),
112228 sock_i_ino(s)
112229 );
112230
112231 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
112232 index b85c67c..09705b7 100644
112233 --- a/net/packet/af_packet.c
112234 +++ b/net/packet/af_packet.c
112235 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
112236
112237 return ret;
112238 drop:
112239 - atomic_long_inc(&dev->tx_dropped);
112240 + atomic_long_inc_unchecked(&dev->tx_dropped);
112241 kfree_skb(skb);
112242 return NET_XMIT_DROP;
112243 }
112244 @@ -636,6 +636,7 @@ static void init_prb_bdqc(struct packet_sock *po,
112245 p1->tov_in_jiffies = msecs_to_jiffies(p1->retire_blk_tov);
112246 p1->blk_sizeof_priv = req_u->req3.tp_sizeof_priv;
112247
112248 + p1->max_frame_len = p1->kblk_size - BLK_PLUS_PRIV(p1->blk_sizeof_priv);
112249 prb_init_ft_ops(p1, req_u);
112250 prb_setup_retire_blk_timer(po, tx_ring);
112251 prb_open_block(p1, pbd);
112252 @@ -1845,7 +1846,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
112253
112254 spin_lock(&sk->sk_receive_queue.lock);
112255 po->stats.stats1.tp_packets++;
112256 - skb->dropcount = atomic_read(&sk->sk_drops);
112257 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
112258 __skb_queue_tail(&sk->sk_receive_queue, skb);
112259 spin_unlock(&sk->sk_receive_queue.lock);
112260 sk->sk_data_ready(sk);
112261 @@ -1854,7 +1855,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
112262 drop_n_acct:
112263 spin_lock(&sk->sk_receive_queue.lock);
112264 po->stats.stats1.tp_drops++;
112265 - atomic_inc(&sk->sk_drops);
112266 + atomic_inc_unchecked(&sk->sk_drops);
112267 spin_unlock(&sk->sk_receive_queue.lock);
112268
112269 drop_n_restore:
112270 @@ -1946,6 +1947,18 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
112271 if ((int)snaplen < 0)
112272 snaplen = 0;
112273 }
112274 + } else if (unlikely(macoff + snaplen >
112275 + GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len)) {
112276 + u32 nval;
112277 +
112278 + nval = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len - macoff;
112279 + pr_err_once("tpacket_rcv: packet too big, clamped from %u to %u. macoff=%u\n",
112280 + snaplen, nval, macoff);
112281 + snaplen = nval;
112282 + if (unlikely((int)snaplen < 0)) {
112283 + snaplen = 0;
112284 + macoff = GET_PBDQC_FROM_RB(&po->rx_ring)->max_frame_len;
112285 + }
112286 }
112287 spin_lock(&sk->sk_receive_queue.lock);
112288 h.raw = packet_current_rx_frame(po, skb,
112289 @@ -3459,7 +3472,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
112290 case PACKET_HDRLEN:
112291 if (len > sizeof(int))
112292 len = sizeof(int);
112293 - if (copy_from_user(&val, optval, len))
112294 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
112295 return -EFAULT;
112296 switch (val) {
112297 case TPACKET_V1:
112298 @@ -3505,7 +3518,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
112299 len = lv;
112300 if (put_user(len, optlen))
112301 return -EFAULT;
112302 - if (copy_to_user(optval, data, len))
112303 + if (len > sizeof(st) || copy_to_user(optval, data, len))
112304 return -EFAULT;
112305 return 0;
112306 }
112307 @@ -3789,6 +3802,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
112308 goto out;
112309 if (unlikely(req->tp_block_size & (PAGE_SIZE - 1)))
112310 goto out;
112311 + if (po->tp_version >= TPACKET_V3 &&
112312 + (int)(req->tp_block_size -
112313 + BLK_PLUS_PRIV(req_u->req3.tp_sizeof_priv)) <= 0)
112314 + goto out;
112315 if (unlikely(req->tp_frame_size < po->tp_hdrlen +
112316 po->tp_reserve))
112317 goto out;
112318 diff --git a/net/packet/internal.h b/net/packet/internal.h
112319 index eb9580a..cdddf6a 100644
112320 --- a/net/packet/internal.h
112321 +++ b/net/packet/internal.h
112322 @@ -29,6 +29,7 @@ struct tpacket_kbdq_core {
112323 char *pkblk_start;
112324 char *pkblk_end;
112325 int kblk_size;
112326 + unsigned int max_frame_len;
112327 unsigned int knum_blocks;
112328 uint64_t knxt_seq_num;
112329 char *prev;
112330 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
112331 index 70a547e..23477fe 100644
112332 --- a/net/phonet/pep.c
112333 +++ b/net/phonet/pep.c
112334 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
112335
112336 case PNS_PEP_CTRL_REQ:
112337 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
112338 - atomic_inc(&sk->sk_drops);
112339 + atomic_inc_unchecked(&sk->sk_drops);
112340 break;
112341 }
112342 __skb_pull(skb, 4);
112343 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
112344 }
112345
112346 if (pn->rx_credits == 0) {
112347 - atomic_inc(&sk->sk_drops);
112348 + atomic_inc_unchecked(&sk->sk_drops);
112349 err = -ENOBUFS;
112350 break;
112351 }
112352 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
112353 }
112354
112355 if (pn->rx_credits == 0) {
112356 - atomic_inc(&sk->sk_drops);
112357 + atomic_inc_unchecked(&sk->sk_drops);
112358 err = NET_RX_DROP;
112359 break;
112360 }
112361 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
112362 index 008214a..bb68240 100644
112363 --- a/net/phonet/socket.c
112364 +++ b/net/phonet/socket.c
112365 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
112366 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
112367 sock_i_ino(sk),
112368 atomic_read(&sk->sk_refcnt), sk,
112369 - atomic_read(&sk->sk_drops));
112370 + atomic_read_unchecked(&sk->sk_drops));
112371 }
112372 seq_pad(seq, '\n');
112373 return 0;
112374 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
112375 index c02a8c4..3c5b600 100644
112376 --- a/net/phonet/sysctl.c
112377 +++ b/net/phonet/sysctl.c
112378 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
112379 {
112380 int ret;
112381 int range[2] = {local_port_range[0], local_port_range[1]};
112382 - struct ctl_table tmp = {
112383 + ctl_table_no_const tmp = {
112384 .data = &range,
112385 .maxlen = sizeof(range),
112386 .mode = table->mode,
112387 diff --git a/net/rds/cong.c b/net/rds/cong.c
112388 index e5b65ac..f3b6fb7 100644
112389 --- a/net/rds/cong.c
112390 +++ b/net/rds/cong.c
112391 @@ -78,7 +78,7 @@
112392 * finds that the saved generation number is smaller than the global generation
112393 * number, it wakes up the process.
112394 */
112395 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
112396 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
112397
112398 /*
112399 * Congestion monitoring
112400 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
112401 rdsdebug("waking map %p for %pI4\n",
112402 map, &map->m_addr);
112403 rds_stats_inc(s_cong_update_received);
112404 - atomic_inc(&rds_cong_generation);
112405 + atomic_inc_unchecked(&rds_cong_generation);
112406 if (waitqueue_active(&map->m_waitq))
112407 wake_up(&map->m_waitq);
112408 if (waitqueue_active(&rds_poll_waitq))
112409 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
112410
112411 int rds_cong_updated_since(unsigned long *recent)
112412 {
112413 - unsigned long gen = atomic_read(&rds_cong_generation);
112414 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
112415
112416 if (likely(*recent == gen))
112417 return 0;
112418 diff --git a/net/rds/ib.h b/net/rds/ib.h
112419 index 7280ab8..e04f4ea 100644
112420 --- a/net/rds/ib.h
112421 +++ b/net/rds/ib.h
112422 @@ -128,7 +128,7 @@ struct rds_ib_connection {
112423 /* sending acks */
112424 unsigned long i_ack_flags;
112425 #ifdef KERNEL_HAS_ATOMIC64
112426 - atomic64_t i_ack_next; /* next ACK to send */
112427 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
112428 #else
112429 spinlock_t i_ack_lock; /* protect i_ack_next */
112430 u64 i_ack_next; /* next ACK to send */
112431 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
112432 index 31b74f5..dc1fbfa 100644
112433 --- a/net/rds/ib_cm.c
112434 +++ b/net/rds/ib_cm.c
112435 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
112436 /* Clear the ACK state */
112437 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
112438 #ifdef KERNEL_HAS_ATOMIC64
112439 - atomic64_set(&ic->i_ack_next, 0);
112440 + atomic64_set_unchecked(&ic->i_ack_next, 0);
112441 #else
112442 ic->i_ack_next = 0;
112443 #endif
112444 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
112445 index d67de45..73dbf51 100644
112446 --- a/net/rds/ib_recv.c
112447 +++ b/net/rds/ib_recv.c
112448 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
112449 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
112450 int ack_required)
112451 {
112452 - atomic64_set(&ic->i_ack_next, seq);
112453 + atomic64_set_unchecked(&ic->i_ack_next, seq);
112454 if (ack_required) {
112455 smp_mb__before_atomic();
112456 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
112457 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
112458 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
112459 smp_mb__after_atomic();
112460
112461 - return atomic64_read(&ic->i_ack_next);
112462 + return atomic64_read_unchecked(&ic->i_ack_next);
112463 }
112464 #endif
112465
112466 diff --git a/net/rds/iw.h b/net/rds/iw.h
112467 index 04ce3b1..48119a6 100644
112468 --- a/net/rds/iw.h
112469 +++ b/net/rds/iw.h
112470 @@ -134,7 +134,7 @@ struct rds_iw_connection {
112471 /* sending acks */
112472 unsigned long i_ack_flags;
112473 #ifdef KERNEL_HAS_ATOMIC64
112474 - atomic64_t i_ack_next; /* next ACK to send */
112475 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
112476 #else
112477 spinlock_t i_ack_lock; /* protect i_ack_next */
112478 u64 i_ack_next; /* next ACK to send */
112479 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
112480 index a91e1db..cf3053f 100644
112481 --- a/net/rds/iw_cm.c
112482 +++ b/net/rds/iw_cm.c
112483 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
112484 /* Clear the ACK state */
112485 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
112486 #ifdef KERNEL_HAS_ATOMIC64
112487 - atomic64_set(&ic->i_ack_next, 0);
112488 + atomic64_set_unchecked(&ic->i_ack_next, 0);
112489 #else
112490 ic->i_ack_next = 0;
112491 #endif
112492 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
112493 index aa8bf67..b70133c 100644
112494 --- a/net/rds/iw_recv.c
112495 +++ b/net/rds/iw_recv.c
112496 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
112497 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
112498 int ack_required)
112499 {
112500 - atomic64_set(&ic->i_ack_next, seq);
112501 + atomic64_set_unchecked(&ic->i_ack_next, seq);
112502 if (ack_required) {
112503 smp_mb__before_atomic();
112504 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
112505 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
112506 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
112507 smp_mb__after_atomic();
112508
112509 - return atomic64_read(&ic->i_ack_next);
112510 + return atomic64_read_unchecked(&ic->i_ack_next);
112511 }
112512 #endif
112513
112514 diff --git a/net/rds/rds.h b/net/rds/rds.h
112515 index 48f8ffc..0ef3eec 100644
112516 --- a/net/rds/rds.h
112517 +++ b/net/rds/rds.h
112518 @@ -449,7 +449,7 @@ struct rds_transport {
112519 void (*sync_mr)(void *trans_private, int direction);
112520 void (*free_mr)(void *trans_private, int invalidate);
112521 void (*flush_mrs)(void);
112522 -};
112523 +} __do_const;
112524
112525 struct rds_sock {
112526 struct sock rs_sk;
112527 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
112528 index edac9ef..16bcb98 100644
112529 --- a/net/rds/tcp.c
112530 +++ b/net/rds/tcp.c
112531 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
112532 int val = 1;
112533
112534 set_fs(KERNEL_DS);
112535 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
112536 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
112537 sizeof(val));
112538 set_fs(oldfs);
112539 }
112540 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
112541 index 53b17ca..45463e7 100644
112542 --- a/net/rds/tcp_send.c
112543 +++ b/net/rds/tcp_send.c
112544 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
112545
112546 oldfs = get_fs();
112547 set_fs(KERNEL_DS);
112548 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
112549 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
112550 sizeof(val));
112551 set_fs(oldfs);
112552 }
112553 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
112554 index 7b16704..9628ec6 100644
112555 --- a/net/rxrpc/af_rxrpc.c
112556 +++ b/net/rxrpc/af_rxrpc.c
112557 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
112558 __be32 rxrpc_epoch;
112559
112560 /* current debugging ID */
112561 -atomic_t rxrpc_debug_id;
112562 +atomic_unchecked_t rxrpc_debug_id;
112563
112564 /* count of skbs currently in use */
112565 atomic_t rxrpc_n_skbs;
112566 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
112567 index c6be17a..2a6200a 100644
112568 --- a/net/rxrpc/ar-ack.c
112569 +++ b/net/rxrpc/ar-ack.c
112570 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
112571
112572 _enter("{%d,%d,%d,%d},",
112573 call->acks_hard, call->acks_unacked,
112574 - atomic_read(&call->sequence),
112575 + atomic_read_unchecked(&call->sequence),
112576 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
112577
112578 stop = 0;
112579 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
112580
112581 /* each Tx packet has a new serial number */
112582 sp->hdr.serial =
112583 - htonl(atomic_inc_return(&call->conn->serial));
112584 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
112585
112586 hdr = (struct rxrpc_header *) txb->head;
112587 hdr->serial = sp->hdr.serial;
112588 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
112589 */
112590 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
112591 {
112592 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
112593 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
112594 }
112595
112596 /*
112597 @@ -677,7 +677,7 @@ process_further:
112598
112599 latest = ntohl(sp->hdr.serial);
112600 hard = ntohl(ack.firstPacket);
112601 - tx = atomic_read(&call->sequence);
112602 + tx = atomic_read_unchecked(&call->sequence);
112603
112604 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
112605 latest,
112606 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
112607 goto maybe_reschedule;
112608
112609 send_ACK_with_skew:
112610 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
112611 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
112612 ntohl(ack.serial));
112613 send_ACK:
112614 mtu = call->conn->trans->peer->if_mtu;
112615 @@ -1221,7 +1221,7 @@ send_ACK:
112616 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
112617 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
112618
112619 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
112620 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
112621 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
112622 ntohl(hdr.serial),
112623 ntohs(ack.maxSkew),
112624 @@ -1239,7 +1239,7 @@ send_ACK:
112625 send_message:
112626 _debug("send message");
112627
112628 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
112629 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
112630 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
112631 send_message_2:
112632
112633 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
112634 index a9e05db..194e793 100644
112635 --- a/net/rxrpc/ar-call.c
112636 +++ b/net/rxrpc/ar-call.c
112637 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
112638 spin_lock_init(&call->lock);
112639 rwlock_init(&call->state_lock);
112640 atomic_set(&call->usage, 1);
112641 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
112642 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
112643 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
112644
112645 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
112646 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
112647 index 6631f4f..bfdf056 100644
112648 --- a/net/rxrpc/ar-connection.c
112649 +++ b/net/rxrpc/ar-connection.c
112650 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
112651 rwlock_init(&conn->lock);
112652 spin_lock_init(&conn->state_lock);
112653 atomic_set(&conn->usage, 1);
112654 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
112655 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
112656 conn->avail_calls = RXRPC_MAXCALLS;
112657 conn->size_align = 4;
112658 conn->header_size = sizeof(struct rxrpc_header);
112659 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
112660 index e7ed43a..6afa140 100644
112661 --- a/net/rxrpc/ar-connevent.c
112662 +++ b/net/rxrpc/ar-connevent.c
112663 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
112664
112665 len = iov[0].iov_len + iov[1].iov_len;
112666
112667 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
112668 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
112669 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
112670
112671 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
112672 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
112673 index 63b21e5..330232e 100644
112674 --- a/net/rxrpc/ar-input.c
112675 +++ b/net/rxrpc/ar-input.c
112676 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
112677 /* track the latest serial number on this connection for ACK packet
112678 * information */
112679 serial = ntohl(sp->hdr.serial);
112680 - hi_serial = atomic_read(&call->conn->hi_serial);
112681 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
112682 while (serial > hi_serial)
112683 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
112684 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
112685 serial);
112686
112687 /* request ACK generation for any ACK or DATA packet that requests
112688 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
112689 index ba9fd36..9bbfe01 100644
112690 --- a/net/rxrpc/ar-internal.h
112691 +++ b/net/rxrpc/ar-internal.h
112692 @@ -272,8 +272,8 @@ struct rxrpc_connection {
112693 int error; /* error code for local abort */
112694 int debug_id; /* debug ID for printks */
112695 unsigned int call_counter; /* call ID counter */
112696 - atomic_t serial; /* packet serial number counter */
112697 - atomic_t hi_serial; /* highest serial number received */
112698 + atomic_unchecked_t serial; /* packet serial number counter */
112699 + atomic_unchecked_t hi_serial; /* highest serial number received */
112700 u8 avail_calls; /* number of calls available */
112701 u8 size_align; /* data size alignment (for security) */
112702 u8 header_size; /* rxrpc + security header size */
112703 @@ -346,7 +346,7 @@ struct rxrpc_call {
112704 spinlock_t lock;
112705 rwlock_t state_lock; /* lock for state transition */
112706 atomic_t usage;
112707 - atomic_t sequence; /* Tx data packet sequence counter */
112708 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
112709 u32 abort_code; /* local/remote abort code */
112710 enum { /* current state of call */
112711 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
112712 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
112713 */
112714 extern atomic_t rxrpc_n_skbs;
112715 extern __be32 rxrpc_epoch;
112716 -extern atomic_t rxrpc_debug_id;
112717 +extern atomic_unchecked_t rxrpc_debug_id;
112718 extern struct workqueue_struct *rxrpc_workqueue;
112719
112720 /*
112721 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
112722 index 87f7135..74d3703 100644
112723 --- a/net/rxrpc/ar-local.c
112724 +++ b/net/rxrpc/ar-local.c
112725 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
112726 spin_lock_init(&local->lock);
112727 rwlock_init(&local->services_lock);
112728 atomic_set(&local->usage, 1);
112729 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
112730 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
112731 memcpy(&local->srx, srx, sizeof(*srx));
112732 }
112733
112734 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
112735 index 0b4b9a7..966ffbb 100644
112736 --- a/net/rxrpc/ar-output.c
112737 +++ b/net/rxrpc/ar-output.c
112738 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
112739 memset(skb_put(skb, pad), 0, pad);
112740 }
112741
112742 - seq = atomic_inc_return(&call->sequence);
112743 + seq = atomic_inc_return_unchecked(&call->sequence);
112744
112745 sp->hdr.epoch = conn->epoch;
112746 sp->hdr.cid = call->cid;
112747 sp->hdr.callNumber = call->call_id;
112748 sp->hdr.seq = htonl(seq);
112749 sp->hdr.serial =
112750 - htonl(atomic_inc_return(&conn->serial));
112751 + htonl(atomic_inc_return_unchecked(&conn->serial));
112752 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
112753 sp->hdr.userStatus = 0;
112754 sp->hdr.securityIndex = conn->security_ix;
112755 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
112756 index bebaa43..2644591 100644
112757 --- a/net/rxrpc/ar-peer.c
112758 +++ b/net/rxrpc/ar-peer.c
112759 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
112760 INIT_LIST_HEAD(&peer->error_targets);
112761 spin_lock_init(&peer->lock);
112762 atomic_set(&peer->usage, 1);
112763 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
112764 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
112765 memcpy(&peer->srx, srx, sizeof(*srx));
112766
112767 rxrpc_assess_MTU_size(peer);
112768 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
112769 index 38047f7..9f48511 100644
112770 --- a/net/rxrpc/ar-proc.c
112771 +++ b/net/rxrpc/ar-proc.c
112772 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
112773 atomic_read(&conn->usage),
112774 rxrpc_conn_states[conn->state],
112775 key_serial(conn->key),
112776 - atomic_read(&conn->serial),
112777 - atomic_read(&conn->hi_serial));
112778 + atomic_read_unchecked(&conn->serial),
112779 + atomic_read_unchecked(&conn->hi_serial));
112780
112781 return 0;
112782 }
112783 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
112784 index 1976dec..aa70be5 100644
112785 --- a/net/rxrpc/ar-transport.c
112786 +++ b/net/rxrpc/ar-transport.c
112787 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
112788 spin_lock_init(&trans->client_lock);
112789 rwlock_init(&trans->conn_lock);
112790 atomic_set(&trans->usage, 1);
112791 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
112792 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
112793
112794 if (peer->srx.transport.family == AF_INET) {
112795 switch (peer->srx.transport_type) {
112796 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
112797 index f226709..0e735a8 100644
112798 --- a/net/rxrpc/rxkad.c
112799 +++ b/net/rxrpc/rxkad.c
112800 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
112801
112802 len = iov[0].iov_len + iov[1].iov_len;
112803
112804 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
112805 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
112806 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
112807
112808 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
112809 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
112810
112811 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
112812
112813 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
112814 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
112815 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
112816
112817 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
112818 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
112819 index 13f64df..1618696 100644
112820 --- a/net/sched/cls_bpf.c
112821 +++ b/net/sched/cls_bpf.c
112822 @@ -160,7 +160,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
112823 {
112824 struct sock_filter *bpf_ops, *bpf_old;
112825 struct tcf_exts exts;
112826 - struct sock_fprog_kern tmp;
112827 + struct sock_fprog tmp;
112828 struct sk_filter *fp, *fp_old;
112829 u16 bpf_size, bpf_len;
112830 u32 classid;
112831 @@ -191,7 +191,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
112832 memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
112833
112834 tmp.len = bpf_len;
112835 - tmp.filter = bpf_ops;
112836 + tmp.filter = (struct sock_filter __user *) bpf_ops;
112837
112838 ret = sk_unattached_filter_create(&fp, &tmp);
112839 if (ret)
112840 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
112841 index e1543b0..7ce8bd0 100644
112842 --- a/net/sched/sch_generic.c
112843 +++ b/net/sched/sch_generic.c
112844 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
112845 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
112846 if (dev->reg_state == NETREG_UNINITIALIZED)
112847 return;
112848 - atomic_inc(&dev->carrier_changes);
112849 + atomic_inc_unchecked(&dev->carrier_changes);
112850 linkwatch_fire_event(dev);
112851 if (netif_running(dev))
112852 __netdev_watchdog_up(dev);
112853 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
112854 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
112855 if (dev->reg_state == NETREG_UNINITIALIZED)
112856 return;
112857 - atomic_inc(&dev->carrier_changes);
112858 + atomic_inc_unchecked(&dev->carrier_changes);
112859 linkwatch_fire_event(dev);
112860 }
112861 }
112862 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
112863 index 1999592..6684af6 100644
112864 --- a/net/sctp/ipv6.c
112865 +++ b/net/sctp/ipv6.c
112866 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
112867 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
112868 };
112869
112870 -static struct sctp_af sctp_af_inet6 = {
112871 +static struct sctp_af sctp_af_inet6 __read_only = {
112872 .sa_family = AF_INET6,
112873 .sctp_xmit = sctp_v6_xmit,
112874 .setsockopt = ipv6_setsockopt,
112875 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
112876 #endif
112877 };
112878
112879 -static struct sctp_pf sctp_pf_inet6 = {
112880 +static struct sctp_pf sctp_pf_inet6 __read_only = {
112881 .event_msgname = sctp_inet6_event_msgname,
112882 .skb_msgname = sctp_inet6_skb_msgname,
112883 .af_supported = sctp_inet6_af_supported,
112884 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
112885
112886 void sctp_v6_pf_exit(void)
112887 {
112888 - list_del(&sctp_af_inet6.list);
112889 + pax_list_del(&sctp_af_inet6.list);
112890 }
112891
112892 /* Initialize IPv6 support and register with socket layer. */
112893 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
112894 index 6789d785..0798d76 100644
112895 --- a/net/sctp/protocol.c
112896 +++ b/net/sctp/protocol.c
112897 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
112898 return 0;
112899 }
112900
112901 + pax_open_kernel();
112902 INIT_LIST_HEAD(&af->list);
112903 - list_add_tail(&af->list, &sctp_address_families);
112904 + pax_close_kernel();
112905 + pax_list_add_tail(&af->list, &sctp_address_families);
112906 return 1;
112907 }
112908
112909 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
112910
112911 static struct sctp_af sctp_af_inet;
112912
112913 -static struct sctp_pf sctp_pf_inet = {
112914 +static struct sctp_pf sctp_pf_inet __read_only = {
112915 .event_msgname = sctp_inet_event_msgname,
112916 .skb_msgname = sctp_inet_skb_msgname,
112917 .af_supported = sctp_inet_af_supported,
112918 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
112919 };
112920
112921 /* IPv4 address related functions. */
112922 -static struct sctp_af sctp_af_inet = {
112923 +static struct sctp_af sctp_af_inet __read_only = {
112924 .sa_family = AF_INET,
112925 .sctp_xmit = sctp_v4_xmit,
112926 .setsockopt = ip_setsockopt,
112927 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
112928
112929 static void sctp_v4_pf_exit(void)
112930 {
112931 - list_del(&sctp_af_inet.list);
112932 + pax_list_del(&sctp_af_inet.list);
112933 }
112934
112935 static int sctp_v4_protosw_init(void)
112936 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
112937 index fef2acd..c705c4f 100644
112938 --- a/net/sctp/sm_sideeffect.c
112939 +++ b/net/sctp/sm_sideeffect.c
112940 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
112941 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
112942 }
112943
112944 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
112945 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
112946 NULL,
112947 sctp_generate_t1_cookie_event,
112948 sctp_generate_t1_init_event,
112949 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
112950 index 4298996..fa5f636 100644
112951 --- a/net/sctp/socket.c
112952 +++ b/net/sctp/socket.c
112953 @@ -2176,11 +2176,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
112954 {
112955 struct sctp_association *asoc;
112956 struct sctp_ulpevent *event;
112957 + struct sctp_event_subscribe subscribe;
112958
112959 if (optlen > sizeof(struct sctp_event_subscribe))
112960 return -EINVAL;
112961 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
112962 + if (copy_from_user(&subscribe, optval, optlen))
112963 return -EFAULT;
112964 + sctp_sk(sk)->subscribe = subscribe;
112965
112966 /*
112967 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
112968 @@ -4260,13 +4262,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
112969 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
112970 int __user *optlen)
112971 {
112972 + struct sctp_event_subscribe subscribe;
112973 +
112974 if (len <= 0)
112975 return -EINVAL;
112976 if (len > sizeof(struct sctp_event_subscribe))
112977 len = sizeof(struct sctp_event_subscribe);
112978 if (put_user(len, optlen))
112979 return -EFAULT;
112980 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
112981 + subscribe = sctp_sk(sk)->subscribe;
112982 + if (copy_to_user(optval, &subscribe, len))
112983 return -EFAULT;
112984 return 0;
112985 }
112986 @@ -4284,6 +4289,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
112987 */
112988 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
112989 {
112990 + __u32 autoclose;
112991 +
112992 /* Applicable to UDP-style socket only */
112993 if (sctp_style(sk, TCP))
112994 return -EOPNOTSUPP;
112995 @@ -4292,7 +4299,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
112996 len = sizeof(int);
112997 if (put_user(len, optlen))
112998 return -EFAULT;
112999 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
113000 + autoclose = sctp_sk(sk)->autoclose;
113001 + if (copy_to_user(optval, &autoclose, sizeof(int)))
113002 return -EFAULT;
113003 return 0;
113004 }
113005 @@ -4667,12 +4675,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
113006 */
113007 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
113008 {
113009 + struct sctp_initmsg initmsg;
113010 +
113011 if (len < sizeof(struct sctp_initmsg))
113012 return -EINVAL;
113013 len = sizeof(struct sctp_initmsg);
113014 if (put_user(len, optlen))
113015 return -EFAULT;
113016 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
113017 + initmsg = sctp_sk(sk)->initmsg;
113018 + if (copy_to_user(optval, &initmsg, len))
113019 return -EFAULT;
113020 return 0;
113021 }
113022 @@ -4713,6 +4724,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
113023 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
113024 if (space_left < addrlen)
113025 return -ENOMEM;
113026 + if (addrlen > sizeof(temp) || addrlen < 0)
113027 + return -EFAULT;
113028 if (copy_to_user(to, &temp, addrlen))
113029 return -EFAULT;
113030 to += addrlen;
113031 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
113032 index 12c7e01..a755b3e 100644
113033 --- a/net/sctp/sysctl.c
113034 +++ b/net/sctp/sysctl.c
113035 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
113036 loff_t *ppos)
113037 {
113038 struct net *net = current->nsproxy->net_ns;
113039 - struct ctl_table tbl;
113040 + ctl_table_no_const tbl;
113041 bool changed = false;
113042 char *none = "none";
113043 char tmp[8];
113044 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
113045 struct net *net = current->nsproxy->net_ns;
113046 unsigned int min = *(unsigned int *) ctl->extra1;
113047 unsigned int max = *(unsigned int *) ctl->extra2;
113048 - struct ctl_table tbl;
113049 + ctl_table_no_const tbl;
113050 int ret, new_value;
113051
113052 memset(&tbl, 0, sizeof(struct ctl_table));
113053 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
113054 struct net *net = current->nsproxy->net_ns;
113055 unsigned int min = *(unsigned int *) ctl->extra1;
113056 unsigned int max = *(unsigned int *) ctl->extra2;
113057 - struct ctl_table tbl;
113058 + ctl_table_no_const tbl;
113059 int ret, new_value;
113060
113061 memset(&tbl, 0, sizeof(struct ctl_table));
113062 @@ -435,7 +435,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
113063 loff_t *ppos)
113064 {
113065 struct net *net = current->nsproxy->net_ns;
113066 - struct ctl_table tbl;
113067 + ctl_table_no_const tbl;
113068 int new_value, ret;
113069
113070 memset(&tbl, 0, sizeof(struct ctl_table));
113071 @@ -462,7 +462,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
113072
113073 int sctp_sysctl_net_register(struct net *net)
113074 {
113075 - struct ctl_table *table;
113076 + ctl_table_no_const *table;
113077 int i;
113078
113079 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
113080 diff --git a/net/socket.c b/net/socket.c
113081 index abf56b2..768e89d 100644
113082 --- a/net/socket.c
113083 +++ b/net/socket.c
113084 @@ -72,7 +72,6 @@
113085 #include <linux/if_bridge.h>
113086 #include <linux/if_frad.h>
113087 #include <linux/if_vlan.h>
113088 -#include <linux/ptp_classify.h>
113089 #include <linux/init.h>
113090 #include <linux/poll.h>
113091 #include <linux/cache.h>
113092 @@ -89,6 +88,7 @@
113093 #include <linux/magic.h>
113094 #include <linux/slab.h>
113095 #include <linux/xattr.h>
113096 +#include <linux/in.h>
113097
113098 #include <asm/uaccess.h>
113099 #include <asm/unistd.h>
113100 @@ -112,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
113101 unsigned int sysctl_net_busy_poll __read_mostly;
113102 #endif
113103
113104 +#include <linux/grsock.h>
113105 +
113106 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
113107 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
113108 unsigned long nr_segs, loff_t pos);
113109 @@ -163,7 +165,7 @@ static const struct file_operations socket_file_ops = {
113110 */
113111
113112 static DEFINE_SPINLOCK(net_family_lock);
113113 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
113114 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
113115
113116 /*
113117 * Statistics counters of the socket lists
113118 @@ -329,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
113119 &sockfs_dentry_operations, SOCKFS_MAGIC);
113120 }
113121
113122 -static struct vfsmount *sock_mnt __read_mostly;
113123 +struct vfsmount *sock_mnt __read_mostly;
113124
113125 static struct file_system_type sock_fs_type = {
113126 .name = "sockfs",
113127 @@ -1257,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
113128 return -EAFNOSUPPORT;
113129 if (type < 0 || type >= SOCK_MAX)
113130 return -EINVAL;
113131 + if (protocol < 0)
113132 + return -EINVAL;
113133
113134 /* Compatibility.
113135
113136 @@ -1277,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
113137 if (err)
113138 return err;
113139
113140 + if(!kern && !gr_search_socket(family, type, protocol)) {
113141 + if (rcu_access_pointer(net_families[family]) == NULL)
113142 + return -EAFNOSUPPORT;
113143 + else
113144 + return -EACCES;
113145 + }
113146 +
113147 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
113148 + if (rcu_access_pointer(net_families[family]) == NULL)
113149 + return -EAFNOSUPPORT;
113150 + else
113151 + return -EACCES;
113152 + }
113153 +
113154 /*
113155 * Allocate the socket and allow the family to set things up. if
113156 * the protocol is 0, the family is instructed to select an appropriate
113157 @@ -1528,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
113158 if (sock) {
113159 err = move_addr_to_kernel(umyaddr, addrlen, &address);
113160 if (err >= 0) {
113161 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
113162 + err = -EACCES;
113163 + goto error;
113164 + }
113165 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
113166 + if (err)
113167 + goto error;
113168 +
113169 err = security_socket_bind(sock,
113170 (struct sockaddr *)&address,
113171 addrlen);
113172 @@ -1536,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
113173 (struct sockaddr *)
113174 &address, addrlen);
113175 }
113176 +error:
113177 fput_light(sock->file, fput_needed);
113178 }
113179 return err;
113180 @@ -1559,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
113181 if ((unsigned int)backlog > somaxconn)
113182 backlog = somaxconn;
113183
113184 + if (gr_handle_sock_server_other(sock->sk)) {
113185 + err = -EPERM;
113186 + goto error;
113187 + }
113188 +
113189 + err = gr_search_listen(sock);
113190 + if (err)
113191 + goto error;
113192 +
113193 err = security_socket_listen(sock, backlog);
113194 if (!err)
113195 err = sock->ops->listen(sock, backlog);
113196
113197 +error:
113198 fput_light(sock->file, fput_needed);
113199 }
113200 return err;
113201 @@ -1606,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
113202 newsock->type = sock->type;
113203 newsock->ops = sock->ops;
113204
113205 + if (gr_handle_sock_server_other(sock->sk)) {
113206 + err = -EPERM;
113207 + sock_release(newsock);
113208 + goto out_put;
113209 + }
113210 +
113211 + err = gr_search_accept(sock);
113212 + if (err) {
113213 + sock_release(newsock);
113214 + goto out_put;
113215 + }
113216 +
113217 /*
113218 * We don't need try_module_get here, as the listening socket (sock)
113219 * has the protocol module (sock->ops->owner) held.
113220 @@ -1651,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
113221 fd_install(newfd, newfile);
113222 err = newfd;
113223
113224 + gr_attach_curr_ip(newsock->sk);
113225 +
113226 out_put:
113227 fput_light(sock->file, fput_needed);
113228 out:
113229 @@ -1683,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
113230 int, addrlen)
113231 {
113232 struct socket *sock;
113233 + struct sockaddr *sck;
113234 struct sockaddr_storage address;
113235 int err, fput_needed;
113236
113237 @@ -1693,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
113238 if (err < 0)
113239 goto out_put;
113240
113241 + sck = (struct sockaddr *)&address;
113242 +
113243 + if (gr_handle_sock_client(sck)) {
113244 + err = -EACCES;
113245 + goto out_put;
113246 + }
113247 +
113248 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
113249 + if (err)
113250 + goto out_put;
113251 +
113252 err =
113253 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
113254 if (err)
113255 @@ -1774,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
113256 * the protocol.
113257 */
113258
113259 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
113260 +
113261 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
113262 unsigned int, flags, struct sockaddr __user *, addr,
113263 int, addr_len)
113264 @@ -1840,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
113265 struct socket *sock;
113266 struct iovec iov;
113267 struct msghdr msg;
113268 - struct sockaddr_storage address;
113269 + struct sockaddr_storage address = { };
113270 int err, err2;
113271 int fput_needed;
113272
113273 @@ -1988,6 +2053,9 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
113274 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
113275 return -EFAULT;
113276
113277 + if (kmsg->msg_name == NULL)
113278 + kmsg->msg_namelen = 0;
113279 +
113280 if (kmsg->msg_namelen < 0)
113281 return -EINVAL;
113282
113283 @@ -2066,7 +2134,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
113284 * checking falls down on this.
113285 */
113286 if (copy_from_user(ctl_buf,
113287 - (void __user __force *)msg_sys->msg_control,
113288 + (void __force_user *)msg_sys->msg_control,
113289 ctl_len))
113290 goto out_freectl;
113291 msg_sys->msg_control = ctl_buf;
113292 @@ -2217,7 +2285,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
113293 int err, total_len, len;
113294
113295 /* kernel mode address */
113296 - struct sockaddr_storage addr;
113297 + struct sockaddr_storage addr = { };
113298
113299 /* user mode address pointers */
113300 struct sockaddr __user *uaddr;
113301 @@ -2246,7 +2314,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
113302 /* Save the user-mode address (verify_iovec will change the
113303 * kernel msghdr to use the kernel address space)
113304 */
113305 - uaddr = (__force void __user *)msg_sys->msg_name;
113306 + uaddr = (void __force_user *)msg_sys->msg_name;
113307 uaddr_len = COMPAT_NAMELEN(msg);
113308 if (MSG_CMSG_COMPAT & flags)
113309 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
113310 @@ -2686,7 +2754,9 @@ static int __init sock_init(void)
113311 goto out;
113312 #endif
113313
113314 - ptp_classifier_init();
113315 +#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
113316 + skb_timestamping_init();
113317 +#endif
113318
113319 out:
113320 return err;
113321 @@ -2887,7 +2957,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
113322 ifr = compat_alloc_user_space(buf_size);
113323 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
113324
113325 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
113326 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
113327 return -EFAULT;
113328
113329 if (put_user(convert_in ? rxnfc : compat_ptr(data),
113330 @@ -2998,7 +3068,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
113331 old_fs = get_fs();
113332 set_fs(KERNEL_DS);
113333 err = dev_ioctl(net, cmd,
113334 - (struct ifreq __user __force *) &kifr);
113335 + (struct ifreq __force_user *) &kifr);
113336 set_fs(old_fs);
113337
113338 return err;
113339 @@ -3091,7 +3161,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
113340
113341 old_fs = get_fs();
113342 set_fs(KERNEL_DS);
113343 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
113344 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
113345 set_fs(old_fs);
113346
113347 if (cmd == SIOCGIFMAP && !err) {
113348 @@ -3175,7 +3245,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
113349 ret |= get_user(rtdev, &(ur4->rt_dev));
113350 if (rtdev) {
113351 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
113352 - r4.rt_dev = (char __user __force *)devname;
113353 + r4.rt_dev = (char __force_user *)devname;
113354 devname[15] = 0;
113355 } else
113356 r4.rt_dev = NULL;
113357 @@ -3402,8 +3472,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
113358 int __user *uoptlen;
113359 int err;
113360
113361 - uoptval = (char __user __force *) optval;
113362 - uoptlen = (int __user __force *) optlen;
113363 + uoptval = (char __force_user *) optval;
113364 + uoptlen = (int __force_user *) optlen;
113365
113366 set_fs(KERNEL_DS);
113367 if (level == SOL_SOCKET)
113368 @@ -3423,7 +3493,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
113369 char __user *uoptval;
113370 int err;
113371
113372 - uoptval = (char __user __force *) optval;
113373 + uoptval = (char __force_user *) optval;
113374
113375 set_fs(KERNEL_DS);
113376 if (level == SOL_SOCKET)
113377 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
113378 index 4ce5ecce..7bef300 100644
113379 --- a/net/sunrpc/auth_gss/svcauth_gss.c
113380 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
113381 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
113382 uint64_t *handle)
113383 {
113384 struct rsc rsci, *rscp = NULL;
113385 - static atomic64_t ctxhctr;
113386 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
113387 long long ctxh;
113388 struct gss_api_mech *gm = NULL;
113389 time_t expiry;
113390 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
113391 status = -ENOMEM;
113392 /* the handle needs to be just a unique id,
113393 * use a static counter */
113394 - ctxh = atomic64_inc_return(&ctxhctr);
113395 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
113396
113397 /* make a copy for the caller */
113398 *handle = ctxh;
113399 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
113400 index 0663621..c4928d4 100644
113401 --- a/net/sunrpc/cache.c
113402 +++ b/net/sunrpc/cache.c
113403 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
113404 struct sunrpc_net *sn;
113405
113406 sn = net_generic(net, sunrpc_net_id);
113407 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
113408 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
113409 if (cd->u.procfs.proc_ent == NULL)
113410 goto out_nomem;
113411 cd->u.procfs.channel_ent = NULL;
113412 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
113413 index 2e6ab10..3170800 100644
113414 --- a/net/sunrpc/clnt.c
113415 +++ b/net/sunrpc/clnt.c
113416 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
113417 (RPC_IS_ASYNC(task) ? "async" : "sync"));
113418
113419 /* Increment call count */
113420 - task->tk_msg.rpc_proc->p_count++;
113421 + pax_open_kernel();
113422 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
113423 + pax_close_kernel();
113424 clnt->cl_stats->rpccnt++;
113425 task->tk_action = call_reserve;
113426 }
113427 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
113428 index c0365c1..b7f02b3 100644
113429 --- a/net/sunrpc/sched.c
113430 +++ b/net/sunrpc/sched.c
113431 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
113432 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
113433 static void rpc_task_set_debuginfo(struct rpc_task *task)
113434 {
113435 - static atomic_t rpc_pid;
113436 + static atomic_unchecked_t rpc_pid;
113437
113438 - task->tk_pid = atomic_inc_return(&rpc_pid);
113439 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
113440 }
113441 #else
113442 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
113443 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
113444 index 5453049..465669a 100644
113445 --- a/net/sunrpc/stats.c
113446 +++ b/net/sunrpc/stats.c
113447 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
113448
113449 dprintk("RPC: registering /proc/net/rpc\n");
113450 sn = net_generic(net, sunrpc_net_id);
113451 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
113452 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
113453 if (sn->proc_net_rpc == NULL)
113454 return -ENOMEM;
113455
113456 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
113457 index 5de6801..b4e330d 100644
113458 --- a/net/sunrpc/svc.c
113459 +++ b/net/sunrpc/svc.c
113460 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
113461 svc_putnl(resv, RPC_SUCCESS);
113462
113463 /* Bump per-procedure stats counter */
113464 - procp->pc_count++;
113465 + pax_open_kernel();
113466 + (*(unsigned int *)&procp->pc_count)++;
113467 + pax_close_kernel();
113468
113469 /* Initialize storage for argp and resp */
113470 memset(rqstp->rq_argp, 0, procp->pc_argsize);
113471 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
113472 index 621ca7b..59421dd 100644
113473 --- a/net/sunrpc/svcauth_unix.c
113474 +++ b/net/sunrpc/svcauth_unix.c
113475 @@ -414,7 +414,7 @@ struct unix_gid {
113476 struct group_info *gi;
113477 };
113478
113479 -static int unix_gid_hash(kuid_t uid)
113480 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
113481 {
113482 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
113483 }
113484 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
113485 (*bpp)[-1] = '\n';
113486 }
113487
113488 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
113489 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
113490
113491 static int unix_gid_parse(struct cache_detail *cd,
113492 char *mesg, int mlen)
113493 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
113494 index c1b6270..05089c1 100644
113495 --- a/net/sunrpc/xprtrdma/svc_rdma.c
113496 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
113497 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
113498 static unsigned int min_max_inline = 4096;
113499 static unsigned int max_max_inline = 65536;
113500
113501 -atomic_t rdma_stat_recv;
113502 -atomic_t rdma_stat_read;
113503 -atomic_t rdma_stat_write;
113504 -atomic_t rdma_stat_sq_starve;
113505 -atomic_t rdma_stat_rq_starve;
113506 -atomic_t rdma_stat_rq_poll;
113507 -atomic_t rdma_stat_rq_prod;
113508 -atomic_t rdma_stat_sq_poll;
113509 -atomic_t rdma_stat_sq_prod;
113510 +atomic_unchecked_t rdma_stat_recv;
113511 +atomic_unchecked_t rdma_stat_read;
113512 +atomic_unchecked_t rdma_stat_write;
113513 +atomic_unchecked_t rdma_stat_sq_starve;
113514 +atomic_unchecked_t rdma_stat_rq_starve;
113515 +atomic_unchecked_t rdma_stat_rq_poll;
113516 +atomic_unchecked_t rdma_stat_rq_prod;
113517 +atomic_unchecked_t rdma_stat_sq_poll;
113518 +atomic_unchecked_t rdma_stat_sq_prod;
113519
113520 /* Temporary NFS request map and context caches */
113521 struct kmem_cache *svc_rdma_map_cachep;
113522 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
113523 len -= *ppos;
113524 if (len > *lenp)
113525 len = *lenp;
113526 - if (len && copy_to_user(buffer, str_buf, len))
113527 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
113528 return -EFAULT;
113529 *lenp = len;
113530 *ppos += len;
113531 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
113532 {
113533 .procname = "rdma_stat_read",
113534 .data = &rdma_stat_read,
113535 - .maxlen = sizeof(atomic_t),
113536 + .maxlen = sizeof(atomic_unchecked_t),
113537 .mode = 0644,
113538 .proc_handler = read_reset_stat,
113539 },
113540 {
113541 .procname = "rdma_stat_recv",
113542 .data = &rdma_stat_recv,
113543 - .maxlen = sizeof(atomic_t),
113544 + .maxlen = sizeof(atomic_unchecked_t),
113545 .mode = 0644,
113546 .proc_handler = read_reset_stat,
113547 },
113548 {
113549 .procname = "rdma_stat_write",
113550 .data = &rdma_stat_write,
113551 - .maxlen = sizeof(atomic_t),
113552 + .maxlen = sizeof(atomic_unchecked_t),
113553 .mode = 0644,
113554 .proc_handler = read_reset_stat,
113555 },
113556 {
113557 .procname = "rdma_stat_sq_starve",
113558 .data = &rdma_stat_sq_starve,
113559 - .maxlen = sizeof(atomic_t),
113560 + .maxlen = sizeof(atomic_unchecked_t),
113561 .mode = 0644,
113562 .proc_handler = read_reset_stat,
113563 },
113564 {
113565 .procname = "rdma_stat_rq_starve",
113566 .data = &rdma_stat_rq_starve,
113567 - .maxlen = sizeof(atomic_t),
113568 + .maxlen = sizeof(atomic_unchecked_t),
113569 .mode = 0644,
113570 .proc_handler = read_reset_stat,
113571 },
113572 {
113573 .procname = "rdma_stat_rq_poll",
113574 .data = &rdma_stat_rq_poll,
113575 - .maxlen = sizeof(atomic_t),
113576 + .maxlen = sizeof(atomic_unchecked_t),
113577 .mode = 0644,
113578 .proc_handler = read_reset_stat,
113579 },
113580 {
113581 .procname = "rdma_stat_rq_prod",
113582 .data = &rdma_stat_rq_prod,
113583 - .maxlen = sizeof(atomic_t),
113584 + .maxlen = sizeof(atomic_unchecked_t),
113585 .mode = 0644,
113586 .proc_handler = read_reset_stat,
113587 },
113588 {
113589 .procname = "rdma_stat_sq_poll",
113590 .data = &rdma_stat_sq_poll,
113591 - .maxlen = sizeof(atomic_t),
113592 + .maxlen = sizeof(atomic_unchecked_t),
113593 .mode = 0644,
113594 .proc_handler = read_reset_stat,
113595 },
113596 {
113597 .procname = "rdma_stat_sq_prod",
113598 .data = &rdma_stat_sq_prod,
113599 - .maxlen = sizeof(atomic_t),
113600 + .maxlen = sizeof(atomic_unchecked_t),
113601 .mode = 0644,
113602 .proc_handler = read_reset_stat,
113603 },
113604 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
113605 index 8f92a61..eb13b74 100644
113606 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
113607 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
113608 @@ -219,7 +219,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
113609 *page_no = pg_no;
113610 *page_offset = pg_off;
113611 ret = read;
113612 - atomic_inc(&rdma_stat_read);
113613 + atomic_inc_unchecked(&rdma_stat_read);
113614 return ret;
113615 err:
113616 svc_rdma_unmap_dma(ctxt);
113617 @@ -355,7 +355,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
113618 *page_no = pg_no;
113619 *page_offset = pg_off;
113620 ret = read;
113621 - atomic_inc(&rdma_stat_read);
113622 + atomic_inc_unchecked(&rdma_stat_read);
113623 return ret;
113624 err:
113625 svc_rdma_unmap_dma(ctxt);
113626 @@ -512,7 +512,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
113627 dto_q);
113628 list_del_init(&ctxt->dto_q);
113629 } else {
113630 - atomic_inc(&rdma_stat_rq_starve);
113631 + atomic_inc_unchecked(&rdma_stat_rq_starve);
113632 clear_bit(XPT_DATA, &xprt->xpt_flags);
113633 ctxt = NULL;
113634 }
113635 @@ -531,7 +531,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
113636 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
113637 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
113638 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
113639 - atomic_inc(&rdma_stat_recv);
113640 + atomic_inc_unchecked(&rdma_stat_recv);
113641
113642 /* Build up the XDR from the receive buffers. */
113643 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
113644 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
113645 index 49fd21a..4bc455b 100644
113646 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
113647 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
113648 @@ -206,7 +206,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
113649 write_wr.wr.rdma.remote_addr = to;
113650
113651 /* Post It */
113652 - atomic_inc(&rdma_stat_write);
113653 + atomic_inc_unchecked(&rdma_stat_write);
113654 if (svc_rdma_send(xprt, &write_wr))
113655 goto err;
113656 return 0;
113657 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
113658 index 06a5d92..c2fa21a 100644
113659 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
113660 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
113661 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
113662 return;
113663
113664 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
113665 - atomic_inc(&rdma_stat_rq_poll);
113666 + atomic_inc_unchecked(&rdma_stat_rq_poll);
113667
113668 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
113669 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
113670 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
113671 }
113672
113673 if (ctxt)
113674 - atomic_inc(&rdma_stat_rq_prod);
113675 + atomic_inc_unchecked(&rdma_stat_rq_prod);
113676
113677 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
113678 /*
113679 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
113680 return;
113681
113682 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
113683 - atomic_inc(&rdma_stat_sq_poll);
113684 + atomic_inc_unchecked(&rdma_stat_sq_poll);
113685 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
113686 int i;
113687
113688 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
113689 }
113690
113691 if (ctxt)
113692 - atomic_inc(&rdma_stat_sq_prod);
113693 + atomic_inc_unchecked(&rdma_stat_sq_prod);
113694 }
113695
113696 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
113697 @@ -1279,7 +1279,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
113698 spin_lock_bh(&xprt->sc_lock);
113699 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
113700 spin_unlock_bh(&xprt->sc_lock);
113701 - atomic_inc(&rdma_stat_sq_starve);
113702 + atomic_inc_unchecked(&rdma_stat_sq_starve);
113703
113704 /* See if we can opportunistically reap SQ WR to make room */
113705 sq_cq_reap(xprt);
113706 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
113707 index e7000be..e3b0ba7 100644
113708 --- a/net/sysctl_net.c
113709 +++ b/net/sysctl_net.c
113710 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
113711 kgid_t root_gid = make_kgid(net->user_ns, 0);
113712
113713 /* Allow network administrator to have same access as root. */
113714 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
113715 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
113716 uid_eq(root_uid, current_euid())) {
113717 int mode = (table->mode >> 6) & 7;
113718 return (mode << 6) | (mode << 3) | mode;
113719 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
113720 index 6424372..afd36e9 100644
113721 --- a/net/tipc/subscr.c
113722 +++ b/net/tipc/subscr.c
113723 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
113724 struct tipc_subscriber *subscriber = sub->subscriber;
113725 struct kvec msg_sect;
113726
113727 - msg_sect.iov_base = (void *)&sub->evt;
113728 + msg_sect.iov_base = &sub->evt;
113729 msg_sect.iov_len = sizeof(struct tipc_event);
113730 sub->evt.event = htohl(event, sub->swap);
113731 sub->evt.found_lower = htohl(found_lower, sub->swap);
113732 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
113733 index e968843..bc95776 100644
113734 --- a/net/unix/af_unix.c
113735 +++ b/net/unix/af_unix.c
113736 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
113737 err = -ECONNREFUSED;
113738 if (!S_ISSOCK(inode->i_mode))
113739 goto put_fail;
113740 +
113741 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
113742 + err = -EACCES;
113743 + goto put_fail;
113744 + }
113745 +
113746 u = unix_find_socket_byinode(inode);
113747 if (!u)
113748 goto put_fail;
113749 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
113750 if (u) {
113751 struct dentry *dentry;
113752 dentry = unix_sk(u)->path.dentry;
113753 +
113754 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
113755 + err = -EPERM;
113756 + sock_put(u);
113757 + goto fail;
113758 + }
113759 +
113760 if (dentry)
113761 touch_atime(&unix_sk(u)->path);
113762 } else
113763 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
113764 */
113765 err = security_path_mknod(&path, dentry, mode, 0);
113766 if (!err) {
113767 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
113768 + err = -EACCES;
113769 + goto out;
113770 + }
113771 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
113772 if (!err) {
113773 res->mnt = mntget(path.mnt);
113774 res->dentry = dget(dentry);
113775 + gr_handle_create(dentry, path.mnt);
113776 }
113777 }
113778 +out:
113779 done_path_create(&path, dentry);
113780 return err;
113781 }
113782 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
113783 seq_puts(seq, "Num RefCount Protocol Flags Type St "
113784 "Inode Path\n");
113785 else {
113786 - struct sock *s = v;
113787 + struct sock *s = v, *peer;
113788 struct unix_sock *u = unix_sk(s);
113789 unix_state_lock(s);
113790 + peer = unix_peer(s);
113791 + unix_state_unlock(s);
113792 +
113793 + unix_state_double_lock(s, peer);
113794
113795 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
113796 s,
113797 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
113798 }
113799 for ( ; i < len; i++)
113800 seq_putc(seq, u->addr->name->sun_path[i]);
113801 - }
113802 - unix_state_unlock(s);
113803 + } else if (peer)
113804 + seq_printf(seq, " P%lu", sock_i_ino(peer));
113805 +
113806 + unix_state_double_unlock(s, peer);
113807 seq_putc(seq, '\n');
113808 }
113809
113810 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
113811 index b3d5150..ff3a837 100644
113812 --- a/net/unix/sysctl_net_unix.c
113813 +++ b/net/unix/sysctl_net_unix.c
113814 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
113815
113816 int __net_init unix_sysctl_register(struct net *net)
113817 {
113818 - struct ctl_table *table;
113819 + ctl_table_no_const *table;
113820
113821 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
113822 if (table == NULL)
113823 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
113824 index 9b7f207..2596621 100644
113825 --- a/net/vmw_vsock/vmci_transport_notify.c
113826 +++ b/net/vmw_vsock/vmci_transport_notify.c
113827 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
113828
113829 /* Socket control packet based operations. */
113830 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
113831 - vmci_transport_notify_pkt_socket_init,
113832 - vmci_transport_notify_pkt_socket_destruct,
113833 - vmci_transport_notify_pkt_poll_in,
113834 - vmci_transport_notify_pkt_poll_out,
113835 - vmci_transport_notify_pkt_handle_pkt,
113836 - vmci_transport_notify_pkt_recv_init,
113837 - vmci_transport_notify_pkt_recv_pre_block,
113838 - vmci_transport_notify_pkt_recv_pre_dequeue,
113839 - vmci_transport_notify_pkt_recv_post_dequeue,
113840 - vmci_transport_notify_pkt_send_init,
113841 - vmci_transport_notify_pkt_send_pre_block,
113842 - vmci_transport_notify_pkt_send_pre_enqueue,
113843 - vmci_transport_notify_pkt_send_post_enqueue,
113844 - vmci_transport_notify_pkt_process_request,
113845 - vmci_transport_notify_pkt_process_negotiate,
113846 + .socket_init = vmci_transport_notify_pkt_socket_init,
113847 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
113848 + .poll_in = vmci_transport_notify_pkt_poll_in,
113849 + .poll_out = vmci_transport_notify_pkt_poll_out,
113850 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
113851 + .recv_init = vmci_transport_notify_pkt_recv_init,
113852 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
113853 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
113854 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
113855 + .send_init = vmci_transport_notify_pkt_send_init,
113856 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
113857 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
113858 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
113859 + .process_request = vmci_transport_notify_pkt_process_request,
113860 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
113861 };
113862 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
113863 index dc9c792..3089de0 100644
113864 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
113865 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
113866 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
113867
113868 /* Socket always on control packet based operations. */
113869 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
113870 - vmci_transport_notify_pkt_socket_init,
113871 - vmci_transport_notify_pkt_socket_destruct,
113872 - vmci_transport_notify_pkt_poll_in,
113873 - vmci_transport_notify_pkt_poll_out,
113874 - vmci_transport_notify_pkt_handle_pkt,
113875 - vmci_transport_notify_pkt_recv_init,
113876 - vmci_transport_notify_pkt_recv_pre_block,
113877 - vmci_transport_notify_pkt_recv_pre_dequeue,
113878 - vmci_transport_notify_pkt_recv_post_dequeue,
113879 - vmci_transport_notify_pkt_send_init,
113880 - vmci_transport_notify_pkt_send_pre_block,
113881 - vmci_transport_notify_pkt_send_pre_enqueue,
113882 - vmci_transport_notify_pkt_send_post_enqueue,
113883 - vmci_transport_notify_pkt_process_request,
113884 - vmci_transport_notify_pkt_process_negotiate,
113885 + .socket_init = vmci_transport_notify_pkt_socket_init,
113886 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
113887 + .poll_in = vmci_transport_notify_pkt_poll_in,
113888 + .poll_out = vmci_transport_notify_pkt_poll_out,
113889 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
113890 + .recv_init = vmci_transport_notify_pkt_recv_init,
113891 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
113892 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
113893 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
113894 + .send_init = vmci_transport_notify_pkt_send_init,
113895 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
113896 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
113897 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
113898 + .process_request = vmci_transport_notify_pkt_process_request,
113899 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
113900 };
113901 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
113902 index c8717c1..08539f5 100644
113903 --- a/net/wireless/wext-core.c
113904 +++ b/net/wireless/wext-core.c
113905 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
113906 */
113907
113908 /* Support for very large requests */
113909 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
113910 - (user_length > descr->max_tokens)) {
113911 + if (user_length > descr->max_tokens) {
113912 /* Allow userspace to GET more than max so
113913 * we can support any size GET requests.
113914 * There is still a limit : -ENOMEM.
113915 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
113916 }
113917 }
113918
113919 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
113920 - /*
113921 - * If this is a GET, but not NOMAX, it means that the extra
113922 - * data is not bounded by userspace, but by max_tokens. Thus
113923 - * set the length to max_tokens. This matches the extra data
113924 - * allocation.
113925 - * The driver should fill it with the number of tokens it
113926 - * provided, and it may check iwp->length rather than having
113927 - * knowledge of max_tokens. If the driver doesn't change the
113928 - * iwp->length, this ioctl just copies back max_token tokens
113929 - * filled with zeroes. Hopefully the driver isn't claiming
113930 - * them to be valid data.
113931 - */
113932 - iwp->length = descr->max_tokens;
113933 - }
113934 -
113935 err = handler(dev, info, (union iwreq_data *) iwp, extra);
113936
113937 iwp->length += essid_compat;
113938 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
113939 index 4323952..a06dfe1 100644
113940 --- a/net/x25/sysctl_net_x25.c
113941 +++ b/net/x25/sysctl_net_x25.c
113942 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
113943 .mode = 0644,
113944 .proc_handler = proc_dointvec,
113945 },
113946 - { 0, },
113947 + { },
113948 };
113949
113950 void __init x25_register_sysctl(void)
113951 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
113952 index 0917f04..f4e3d8c 100644
113953 --- a/net/x25/x25_proc.c
113954 +++ b/net/x25/x25_proc.c
113955 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
113956
113957 int __init x25_proc_init(void)
113958 {
113959 - if (!proc_mkdir("x25", init_net.proc_net))
113960 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
113961 return -ENOMEM;
113962
113963 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
113964 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
113965 index 0525d78..cccf7fd 100644
113966 --- a/net/xfrm/xfrm_policy.c
113967 +++ b/net/xfrm/xfrm_policy.c
113968 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
113969 {
113970 policy->walk.dead = 1;
113971
113972 - atomic_inc(&policy->genid);
113973 + atomic_inc_unchecked(&policy->genid);
113974
113975 if (del_timer(&policy->polq.hold_timer))
113976 xfrm_pol_put(policy);
113977 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
113978 hlist_add_head(&policy->bydst, chain);
113979 xfrm_pol_hold(policy);
113980 net->xfrm.policy_count[dir]++;
113981 - atomic_inc(&net->xfrm.flow_cache_genid);
113982 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
113983
113984 /* After previous checking, family can either be AF_INET or AF_INET6 */
113985 if (policy->family == AF_INET)
113986 @@ -1749,7 +1749,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
113987
113988 xdst->num_pols = num_pols;
113989 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
113990 - xdst->policy_genid = atomic_read(&pols[0]->genid);
113991 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
113992
113993 return xdst;
113994 }
113995 @@ -2538,10 +2538,11 @@ void xfrm_garbage_collect(struct net *net)
113996 }
113997 EXPORT_SYMBOL(xfrm_garbage_collect);
113998
113999 -static void xfrm_garbage_collect_deferred(struct net *net)
114000 +void xfrm_garbage_collect_deferred(struct net *net)
114001 {
114002 flow_cache_flush_deferred(net);
114003 }
114004 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
114005
114006 static void xfrm_init_pmtu(struct dst_entry *dst)
114007 {
114008 @@ -2591,7 +2592,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
114009 if (xdst->xfrm_genid != dst->xfrm->genid)
114010 return 0;
114011 if (xdst->num_pols > 0 &&
114012 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
114013 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
114014 return 0;
114015
114016 mtu = dst_mtu(dst->child);
114017 @@ -2679,8 +2680,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
114018 dst_ops->link_failure = xfrm_link_failure;
114019 if (likely(dst_ops->neigh_lookup == NULL))
114020 dst_ops->neigh_lookup = xfrm_neigh_lookup;
114021 - if (likely(afinfo->garbage_collect == NULL))
114022 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
114023 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
114024 }
114025 spin_unlock(&xfrm_policy_afinfo_lock);
114026 @@ -2734,7 +2733,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
114027 dst_ops->check = NULL;
114028 dst_ops->negative_advice = NULL;
114029 dst_ops->link_failure = NULL;
114030 - afinfo->garbage_collect = NULL;
114031 }
114032 return err;
114033 }
114034 @@ -3119,7 +3117,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
114035 sizeof(pol->xfrm_vec[i].saddr));
114036 pol->xfrm_vec[i].encap_family = mp->new_family;
114037 /* flush bundles */
114038 - atomic_inc(&pol->genid);
114039 + atomic_inc_unchecked(&pol->genid);
114040 }
114041 }
114042
114043 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
114044 index 0ab5413..73dd2cf 100644
114045 --- a/net/xfrm/xfrm_state.c
114046 +++ b/net/xfrm/xfrm_state.c
114047 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
114048
114049 if (unlikely(afinfo == NULL))
114050 return -EAFNOSUPPORT;
114051 - typemap = afinfo->type_map;
114052 + typemap = (const struct xfrm_type **)afinfo->type_map;
114053 spin_lock_bh(&xfrm_type_lock);
114054
114055 - if (likely(typemap[type->proto] == NULL))
114056 + if (likely(typemap[type->proto] == NULL)) {
114057 + pax_open_kernel();
114058 typemap[type->proto] = type;
114059 - else
114060 + pax_close_kernel();
114061 + } else
114062 err = -EEXIST;
114063 spin_unlock_bh(&xfrm_type_lock);
114064 xfrm_state_put_afinfo(afinfo);
114065 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
114066
114067 if (unlikely(afinfo == NULL))
114068 return -EAFNOSUPPORT;
114069 - typemap = afinfo->type_map;
114070 + typemap = (const struct xfrm_type **)afinfo->type_map;
114071 spin_lock_bh(&xfrm_type_lock);
114072
114073 if (unlikely(typemap[type->proto] != type))
114074 err = -ENOENT;
114075 - else
114076 + else {
114077 + pax_open_kernel();
114078 typemap[type->proto] = NULL;
114079 + pax_close_kernel();
114080 + }
114081 spin_unlock_bh(&xfrm_type_lock);
114082 xfrm_state_put_afinfo(afinfo);
114083 return err;
114084 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
114085 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
114086 {
114087 struct xfrm_state_afinfo *afinfo;
114088 - const struct xfrm_type **typemap;
114089 const struct xfrm_type *type;
114090 int modload_attempted = 0;
114091
114092 @@ -218,9 +222,8 @@ retry:
114093 afinfo = xfrm_state_get_afinfo(family);
114094 if (unlikely(afinfo == NULL))
114095 return NULL;
114096 - typemap = afinfo->type_map;
114097
114098 - type = typemap[proto];
114099 + type = afinfo->type_map[proto];
114100 if (unlikely(type && !try_module_get(type->owner)))
114101 type = NULL;
114102 if (!type && !modload_attempted) {
114103 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
114104 return -EAFNOSUPPORT;
114105
114106 err = -EEXIST;
114107 - modemap = afinfo->mode_map;
114108 + modemap = (struct xfrm_mode **)afinfo->mode_map;
114109 spin_lock_bh(&xfrm_mode_lock);
114110 if (modemap[mode->encap])
114111 goto out;
114112 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
114113 if (!try_module_get(afinfo->owner))
114114 goto out;
114115
114116 - mode->afinfo = afinfo;
114117 + pax_open_kernel();
114118 + *(const void **)&mode->afinfo = afinfo;
114119 modemap[mode->encap] = mode;
114120 + pax_close_kernel();
114121 err = 0;
114122
114123 out:
114124 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
114125 return -EAFNOSUPPORT;
114126
114127 err = -ENOENT;
114128 - modemap = afinfo->mode_map;
114129 + modemap = (struct xfrm_mode **)afinfo->mode_map;
114130 spin_lock_bh(&xfrm_mode_lock);
114131 if (likely(modemap[mode->encap] == mode)) {
114132 + pax_open_kernel();
114133 modemap[mode->encap] = NULL;
114134 + pax_close_kernel();
114135 module_put(mode->afinfo->owner);
114136 err = 0;
114137 }
114138 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
114139 u32 xfrm_get_acqseq(void)
114140 {
114141 u32 res;
114142 - static atomic_t acqseq;
114143 + static atomic_unchecked_t acqseq;
114144
114145 do {
114146 - res = atomic_inc_return(&acqseq);
114147 + res = atomic_inc_return_unchecked(&acqseq);
114148 } while (!res);
114149
114150 return res;
114151 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
114152 index 05a6e3d..6716ec9 100644
114153 --- a/net/xfrm/xfrm_sysctl.c
114154 +++ b/net/xfrm/xfrm_sysctl.c
114155 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
114156
114157 int __net_init xfrm_sysctl_init(struct net *net)
114158 {
114159 - struct ctl_table *table;
114160 + ctl_table_no_const *table;
114161
114162 __xfrm_sysctl_init(net);
114163
114164 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
114165 index bf3e677..c7d426e 100644
114166 --- a/scripts/Makefile.build
114167 +++ b/scripts/Makefile.build
114168 @@ -60,7 +60,7 @@ endif
114169 endif
114170
114171 # Do not include host rules unless needed
114172 -ifneq ($(hostprogs-y)$(hostprogs-m),)
114173 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
114174 include scripts/Makefile.host
114175 endif
114176
114177 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
114178 index 686cb0d..9d653bf 100644
114179 --- a/scripts/Makefile.clean
114180 +++ b/scripts/Makefile.clean
114181 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
114182 __clean-files := $(extra-y) $(always) \
114183 $(targets) $(clean-files) \
114184 $(host-progs) \
114185 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
114186 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
114187 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
114188
114189 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
114190
114191 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
114192 index 6689364..e56dc6a 100644
114193 --- a/scripts/Makefile.host
114194 +++ b/scripts/Makefile.host
114195 @@ -31,6 +31,8 @@
114196 # Note: Shared libraries consisting of C++ files are not supported
114197
114198 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
114199 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
114200 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
114201
114202 # C code
114203 # Executables compiled from a single .c file
114204 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
114205 # Shared libaries (only .c supported)
114206 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
114207 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
114208 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
114209 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
114210 # Remove .so files from "xxx-objs"
114211 host-cobjs := $(filter-out %.so,$(host-cobjs))
114212 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
114213
114214 -#Object (.o) files used by the shared libaries
114215 +# Object (.o) files used by the shared libaries
114216 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
114217 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
114218
114219 # output directory for programs/.o files
114220 # hostprogs-y := tools/build may have been specified. Retrieve directory
114221 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
114222 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
114223 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
114224 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
114225 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
114226 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
114227 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
114228 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
114229
114230 obj-dirs += $(host-objdirs)
114231 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
114232 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
114233 $(call if_changed_dep,host-cshobjs)
114234
114235 +# Compile .c file, create position independent .o file
114236 +# host-cxxshobjs -> .o
114237 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
114238 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
114239 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
114240 + $(call if_changed_dep,host-cxxshobjs)
114241 +
114242 # Link a shared library, based on position independent .o files
114243 # *.o -> .so shared library (host-cshlib)
114244 quiet_cmd_host-cshlib = HOSTLLD -shared $@
114245 @@ -165,5 +180,14 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
114246 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
114247 $(call if_changed,host-cshlib)
114248
114249 +# Link a shared library, based on position independent .o files
114250 +# *.o -> .so shared library (host-cxxshlib)
114251 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
114252 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
114253 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
114254 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
114255 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
114256 + $(call if_changed,host-cxxshlib)
114257 +
114258 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
114259 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
114260 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
114261 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
114262 index b304068..462d24e 100644
114263 --- a/scripts/basic/fixdep.c
114264 +++ b/scripts/basic/fixdep.c
114265 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
114266 /*
114267 * Lookup a value in the configuration string.
114268 */
114269 -static int is_defined_config(const char *name, int len, unsigned int hash)
114270 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
114271 {
114272 struct item *aux;
114273
114274 @@ -211,10 +211,10 @@ static void clear_config(void)
114275 /*
114276 * Record the use of a CONFIG_* word.
114277 */
114278 -static void use_config(const char *m, int slen)
114279 +static void use_config(const char *m, unsigned int slen)
114280 {
114281 unsigned int hash = strhash(m, slen);
114282 - int c, i;
114283 + unsigned int c, i;
114284
114285 if (is_defined_config(m, slen, hash))
114286 return;
114287 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
114288
114289 static void parse_config_file(const char *map, size_t len)
114290 {
114291 - const int *end = (const int *) (map + len);
114292 + const unsigned int *end = (const unsigned int *) (map + len);
114293 /* start at +1, so that p can never be < map */
114294 - const int *m = (const int *) map + 1;
114295 + const unsigned int *m = (const unsigned int *) map + 1;
114296 const char *p, *q;
114297
114298 for (; m < end; m++) {
114299 @@ -435,7 +435,7 @@ static void print_deps(void)
114300 static void traps(void)
114301 {
114302 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
114303 - int *p = (int *)test;
114304 + unsigned int *p = (unsigned int *)test;
114305
114306 if (*p != INT_CONF) {
114307 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
114308 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
114309 new file mode 100644
114310 index 0000000..3fd3699
114311 --- /dev/null
114312 +++ b/scripts/gcc-plugin.sh
114313 @@ -0,0 +1,43 @@
114314 +#!/bin/bash
114315 +srctree=$(dirname "$0")
114316 +gccplugins_dir=$($3 -print-file-name=plugin)
114317 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
114318 +#include "gcc-common.h"
114319 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
114320 +#warning $2 CXX
114321 +#else
114322 +#warning $1 CC
114323 +#endif
114324 +EOF
114325 +)
114326 +
114327 +if [ $? -ne 0 ]
114328 +then
114329 + exit 1
114330 +fi
114331 +
114332 +if [[ "$plugincc" =~ "$1 CC" ]]
114333 +then
114334 + echo "$1"
114335 + exit 0
114336 +fi
114337 +
114338 +if [[ "$plugincc" =~ "$2 CXX" ]]
114339 +then
114340 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
114341 +#include "gcc-common.h"
114342 +class test {
114343 +public:
114344 + int test;
114345 +} test = {
114346 + .test = 1
114347 +};
114348 +EOF
114349 +)
114350 +if [ $? -eq 0 ]
114351 +then
114352 + echo "$2"
114353 + exit 0
114354 +fi
114355 +fi
114356 +exit 1
114357 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
114358 index 5de5660..d3deb89 100644
114359 --- a/scripts/headers_install.sh
114360 +++ b/scripts/headers_install.sh
114361 @@ -32,6 +32,7 @@ do
114362 FILE="$(basename "$i")"
114363 sed -r \
114364 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
114365 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
114366 -e 's/__attribute_const__([ \t]|$)/\1/g' \
114367 -e 's@^#include <linux/compiler.h>@@' \
114368 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
114369 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
114370 index 86a4fe7..99e91f9 100644
114371 --- a/scripts/link-vmlinux.sh
114372 +++ b/scripts/link-vmlinux.sh
114373 @@ -166,7 +166,7 @@ else
114374 fi;
114375
114376 # final build of init/
114377 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
114378 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
114379
114380 kallsymso=""
114381 kallsyms_vmlinux=""
114382 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
114383 index e614ef6..d9d2b01 100644
114384 --- a/scripts/mod/file2alias.c
114385 +++ b/scripts/mod/file2alias.c
114386 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
114387 unsigned long size, unsigned long id_size,
114388 void *symval)
114389 {
114390 - int i;
114391 + unsigned int i;
114392
114393 if (size % id_size || size < id_size) {
114394 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
114395 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
114396 /* USB is special because the bcdDevice can be matched against a numeric range */
114397 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
114398 static void do_usb_entry(void *symval,
114399 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
114400 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
114401 unsigned char range_lo, unsigned char range_hi,
114402 unsigned char max, struct module *mod)
114403 {
114404 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
114405 {
114406 unsigned int devlo, devhi;
114407 unsigned char chi, clo, max;
114408 - int ndigits;
114409 + unsigned int ndigits;
114410
114411 DEF_FIELD(symval, usb_device_id, match_flags);
114412 DEF_FIELD(symval, usb_device_id, idVendor);
114413 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
114414 for (i = 0; i < count; i++) {
114415 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
114416 char acpi_id[sizeof(*id)];
114417 - int j;
114418 + unsigned int j;
114419
114420 buf_printf(&mod->dev_table_buf,
114421 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
114422 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
114423
114424 for (j = 0; j < PNP_MAX_DEVICES; j++) {
114425 const char *id = (char *)(*devs)[j].id;
114426 - int i2, j2;
114427 + unsigned int i2, j2;
114428 int dup = 0;
114429
114430 if (!id[0])
114431 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
114432 /* add an individual alias for every device entry */
114433 if (!dup) {
114434 char acpi_id[PNP_ID_LEN];
114435 - int k;
114436 + unsigned int k;
114437
114438 buf_printf(&mod->dev_table_buf,
114439 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
114440 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
114441 static int do_dmi_entry(const char *filename, void *symval,
114442 char *alias)
114443 {
114444 - int i, j;
114445 + unsigned int i, j;
114446 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
114447 sprintf(alias, "dmi*");
114448
114449 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
114450 index 9d9c5b9..a3af177 100644
114451 --- a/scripts/mod/modpost.c
114452 +++ b/scripts/mod/modpost.c
114453 @@ -949,6 +949,7 @@ enum mismatch {
114454 ANY_INIT_TO_ANY_EXIT,
114455 ANY_EXIT_TO_ANY_INIT,
114456 EXPORT_TO_INIT_EXIT,
114457 + DATA_TO_TEXT
114458 };
114459
114460 struct sectioncheck {
114461 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
114462 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
114463 .mismatch = EXPORT_TO_INIT_EXIT,
114464 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
114465 +},
114466 +/* Do not reference code from writable data */
114467 +{
114468 + .fromsec = { DATA_SECTIONS, NULL },
114469 + .tosec = { TEXT_SECTIONS, NULL },
114470 + .mismatch = DATA_TO_TEXT
114471 }
114472 };
114473
114474 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
114475 continue;
114476 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
114477 continue;
114478 - if (sym->st_value == addr)
114479 - return sym;
114480 /* Find a symbol nearby - addr are maybe negative */
114481 d = sym->st_value - addr;
114482 + if (d == 0)
114483 + return sym;
114484 if (d < 0)
114485 d = addr - sym->st_value;
114486 if (d < distance) {
114487 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
114488 tosym, prl_to, prl_to, tosym);
114489 free(prl_to);
114490 break;
114491 + case DATA_TO_TEXT:
114492 +#if 0
114493 + fprintf(stderr,
114494 + "The %s %s:%s references\n"
114495 + "the %s %s:%s%s\n",
114496 + from, fromsec, fromsym, to, tosec, tosym, to_p);
114497 +#endif
114498 + break;
114499 }
114500 fprintf(stderr, "\n");
114501 }
114502 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
114503 static void check_sec_ref(struct module *mod, const char *modname,
114504 struct elf_info *elf)
114505 {
114506 - int i;
114507 + unsigned int i;
114508 Elf_Shdr *sechdrs = elf->sechdrs;
114509
114510 /* Walk through all sections */
114511 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
114512 va_end(ap);
114513 }
114514
114515 -void buf_write(struct buffer *buf, const char *s, int len)
114516 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
114517 {
114518 if (buf->size - buf->pos < len) {
114519 buf->size += len + SZ;
114520 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
114521 if (fstat(fileno(file), &st) < 0)
114522 goto close_write;
114523
114524 - if (st.st_size != b->pos)
114525 + if (st.st_size != (off_t)b->pos)
114526 goto close_write;
114527
114528 tmp = NOFAIL(malloc(b->pos));
114529 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
114530 index 168b43d..77914bf 100644
114531 --- a/scripts/mod/modpost.h
114532 +++ b/scripts/mod/modpost.h
114533 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
114534
114535 struct buffer {
114536 char *p;
114537 - int pos;
114538 - int size;
114539 + unsigned int pos;
114540 + unsigned int size;
114541 };
114542
114543 void __attribute__((format(printf, 2, 3)))
114544 buf_printf(struct buffer *buf, const char *fmt, ...);
114545
114546 void
114547 -buf_write(struct buffer *buf, const char *s, int len);
114548 +buf_write(struct buffer *buf, const char *s, unsigned int len);
114549
114550 struct module {
114551 struct module *next;
114552 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
114553 index 944418d..15291e4 100644
114554 --- a/scripts/mod/sumversion.c
114555 +++ b/scripts/mod/sumversion.c
114556 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
114557 goto out;
114558 }
114559
114560 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
114561 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
114562 warn("writing sum in %s failed: %s\n",
114563 filename, strerror(errno));
114564 goto out;
114565 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
114566 index 0865b3e..7235dd4 100644
114567 --- a/scripts/module-common.lds
114568 +++ b/scripts/module-common.lds
114569 @@ -6,6 +6,10 @@
114570 SECTIONS {
114571 /DISCARD/ : { *(.discard) }
114572
114573 + .rodata : {
114574 + *(.rodata) *(.rodata.*)
114575 + *(.data..read_only)
114576 + }
114577 __ksymtab : { *(SORT(___ksymtab+*)) }
114578 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
114579 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
114580 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
114581 index 35d5a58..9e04789 100644
114582 --- a/scripts/package/builddeb
114583 +++ b/scripts/package/builddeb
114584 @@ -295,6 +295,7 @@ fi
114585 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
114586 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
114587 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
114588 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
114589 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
114590 mkdir -p "$destdir"
114591 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
114592 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
114593 index 4718d78..9220d58 100644
114594 --- a/scripts/pnmtologo.c
114595 +++ b/scripts/pnmtologo.c
114596 @@ -244,14 +244,14 @@ static void write_header(void)
114597 fprintf(out, " * Linux logo %s\n", logoname);
114598 fputs(" */\n\n", out);
114599 fputs("#include <linux/linux_logo.h>\n\n", out);
114600 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
114601 + fprintf(out, "static unsigned char %s_data[] = {\n",
114602 logoname);
114603 }
114604
114605 static void write_footer(void)
114606 {
114607 fputs("\n};\n\n", out);
114608 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
114609 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
114610 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
114611 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
114612 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
114613 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
114614 fputs("\n};\n\n", out);
114615
114616 /* write logo clut */
114617 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
114618 + fprintf(out, "static unsigned char %s_clut[] = {\n",
114619 logoname);
114620 write_hex_cnt = 0;
114621 for (i = 0; i < logo_clutsize; i++) {
114622 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
114623 index 8fac3fd..32ff38d 100644
114624 --- a/scripts/sortextable.h
114625 +++ b/scripts/sortextable.h
114626 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
114627 const char *secstrtab;
114628 const char *strtab;
114629 char *extab_image;
114630 - int extab_index = 0;
114631 - int i;
114632 - int idx;
114633 + unsigned int extab_index = 0;
114634 + unsigned int i;
114635 + unsigned int idx;
114636 unsigned int num_sections;
114637 unsigned int secindex_strings;
114638
114639 diff --git a/security/Kconfig b/security/Kconfig
114640 index beb86b5..40b1edb 100644
114641 --- a/security/Kconfig
114642 +++ b/security/Kconfig
114643 @@ -4,6 +4,957 @@
114644
114645 menu "Security options"
114646
114647 +menu "Grsecurity"
114648 +
114649 + config ARCH_TRACK_EXEC_LIMIT
114650 + bool
114651 +
114652 + config PAX_KERNEXEC_PLUGIN
114653 + bool
114654 +
114655 + config PAX_PER_CPU_PGD
114656 + bool
114657 +
114658 + config TASK_SIZE_MAX_SHIFT
114659 + int
114660 + depends on X86_64
114661 + default 47 if !PAX_PER_CPU_PGD
114662 + default 42 if PAX_PER_CPU_PGD
114663 +
114664 + config PAX_ENABLE_PAE
114665 + bool
114666 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
114667 +
114668 + config PAX_USERCOPY_SLABS
114669 + bool
114670 +
114671 +config GRKERNSEC
114672 + bool "Grsecurity"
114673 + select CRYPTO
114674 + select CRYPTO_SHA256
114675 + select PROC_FS
114676 + select STOP_MACHINE
114677 + select TTY
114678 + select DEBUG_KERNEL
114679 + select DEBUG_LIST
114680 + help
114681 + If you say Y here, you will be able to configure many features
114682 + that will enhance the security of your system. It is highly
114683 + recommended that you say Y here and read through the help
114684 + for each option so that you fully understand the features and
114685 + can evaluate their usefulness for your machine.
114686 +
114687 +choice
114688 + prompt "Configuration Method"
114689 + depends on GRKERNSEC
114690 + default GRKERNSEC_CONFIG_CUSTOM
114691 + help
114692 +
114693 +config GRKERNSEC_CONFIG_AUTO
114694 + bool "Automatic"
114695 + help
114696 + If you choose this configuration method, you'll be able to answer a small
114697 + number of simple questions about how you plan to use this kernel.
114698 + The settings of grsecurity and PaX will be automatically configured for
114699 + the highest commonly-used settings within the provided constraints.
114700 +
114701 + If you require additional configuration, custom changes can still be made
114702 + from the "custom configuration" menu.
114703 +
114704 +config GRKERNSEC_CONFIG_CUSTOM
114705 + bool "Custom"
114706 + help
114707 + If you choose this configuration method, you'll be able to configure all
114708 + grsecurity and PaX settings manually. Via this method, no options are
114709 + automatically enabled.
114710 +
114711 +endchoice
114712 +
114713 +choice
114714 + prompt "Usage Type"
114715 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
114716 + default GRKERNSEC_CONFIG_SERVER
114717 + help
114718 +
114719 +config GRKERNSEC_CONFIG_SERVER
114720 + bool "Server"
114721 + help
114722 + Choose this option if you plan to use this kernel on a server.
114723 +
114724 +config GRKERNSEC_CONFIG_DESKTOP
114725 + bool "Desktop"
114726 + help
114727 + Choose this option if you plan to use this kernel on a desktop.
114728 +
114729 +endchoice
114730 +
114731 +choice
114732 + prompt "Virtualization Type"
114733 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
114734 + default GRKERNSEC_CONFIG_VIRT_NONE
114735 + help
114736 +
114737 +config GRKERNSEC_CONFIG_VIRT_NONE
114738 + bool "None"
114739 + help
114740 + Choose this option if this kernel will be run on bare metal.
114741 +
114742 +config GRKERNSEC_CONFIG_VIRT_GUEST
114743 + bool "Guest"
114744 + help
114745 + Choose this option if this kernel will be run as a VM guest.
114746 +
114747 +config GRKERNSEC_CONFIG_VIRT_HOST
114748 + bool "Host"
114749 + help
114750 + Choose this option if this kernel will be run as a VM host.
114751 +
114752 +endchoice
114753 +
114754 +choice
114755 + prompt "Virtualization Hardware"
114756 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
114757 + help
114758 +
114759 +config GRKERNSEC_CONFIG_VIRT_EPT
114760 + bool "EPT/RVI Processor Support"
114761 + depends on X86
114762 + help
114763 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
114764 + hardware virtualization. This allows for additional kernel hardening protections
114765 + to operate without additional performance impact.
114766 +
114767 + To see if your Intel processor supports EPT, see:
114768 + http://ark.intel.com/Products/VirtualizationTechnology
114769 + (Most Core i3/5/7 support EPT)
114770 +
114771 + To see if your AMD processor supports RVI, see:
114772 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
114773 +
114774 +config GRKERNSEC_CONFIG_VIRT_SOFT
114775 + bool "First-gen/No Hardware Virtualization"
114776 + help
114777 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
114778 + support hardware virtualization or doesn't support the EPT/RVI extensions.
114779 +
114780 +endchoice
114781 +
114782 +choice
114783 + prompt "Virtualization Software"
114784 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
114785 + help
114786 +
114787 +config GRKERNSEC_CONFIG_VIRT_XEN
114788 + bool "Xen"
114789 + help
114790 + Choose this option if this kernel is running as a Xen guest or host.
114791 +
114792 +config GRKERNSEC_CONFIG_VIRT_VMWARE
114793 + bool "VMWare"
114794 + help
114795 + Choose this option if this kernel is running as a VMWare guest or host.
114796 +
114797 +config GRKERNSEC_CONFIG_VIRT_KVM
114798 + bool "KVM"
114799 + help
114800 + Choose this option if this kernel is running as a KVM guest or host.
114801 +
114802 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
114803 + bool "VirtualBox"
114804 + help
114805 + Choose this option if this kernel is running as a VirtualBox guest or host.
114806 +
114807 +endchoice
114808 +
114809 +choice
114810 + prompt "Required Priorities"
114811 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
114812 + default GRKERNSEC_CONFIG_PRIORITY_PERF
114813 + help
114814 +
114815 +config GRKERNSEC_CONFIG_PRIORITY_PERF
114816 + bool "Performance"
114817 + help
114818 + Choose this option if performance is of highest priority for this deployment
114819 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
114820 + clearing of structures intended for userland, and freed memory sanitizing will
114821 + be disabled.
114822 +
114823 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
114824 + bool "Security"
114825 + help
114826 + Choose this option if security is of highest priority for this deployment of
114827 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
114828 + for userland, and freed memory sanitizing will be enabled for this kernel.
114829 + In a worst-case scenario, these features can introduce a 20% performance hit
114830 + (UDEREF on x64 contributing half of this hit).
114831 +
114832 +endchoice
114833 +
114834 +menu "Default Special Groups"
114835 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
114836 +
114837 +config GRKERNSEC_PROC_GID
114838 + int "GID exempted from /proc restrictions"
114839 + default 1001
114840 + help
114841 + Setting this GID determines which group will be exempted from
114842 + grsecurity's /proc restrictions, allowing users of the specified
114843 + group to view network statistics and the existence of other users'
114844 + processes on the system. This GID may also be chosen at boot time
114845 + via "grsec_proc_gid=" on the kernel commandline.
114846 +
114847 +config GRKERNSEC_TPE_UNTRUSTED_GID
114848 + int "GID for TPE-untrusted users"
114849 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
114850 + default 1005
114851 + help
114852 + Setting this GID determines which group untrusted users should
114853 + be added to. These users will be placed under grsecurity's Trusted Path
114854 + Execution mechanism, preventing them from executing their own binaries.
114855 + The users will only be able to execute binaries in directories owned and
114856 + writable only by the root user. If the sysctl option is enabled, a sysctl
114857 + option with name "tpe_gid" is created.
114858 +
114859 +config GRKERNSEC_TPE_TRUSTED_GID
114860 + int "GID for TPE-trusted users"
114861 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
114862 + default 1005
114863 + help
114864 + Setting this GID determines what group TPE restrictions will be
114865 + *disabled* for. If the sysctl option is enabled, a sysctl option
114866 + with name "tpe_gid" is created.
114867 +
114868 +config GRKERNSEC_SYMLINKOWN_GID
114869 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
114870 + depends on GRKERNSEC_CONFIG_SERVER
114871 + default 1006
114872 + help
114873 + Setting this GID determines what group kernel-enforced
114874 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
114875 + is enabled, a sysctl option with name "symlinkown_gid" is created.
114876 +
114877 +
114878 +endmenu
114879 +
114880 +menu "Customize Configuration"
114881 +depends on GRKERNSEC
114882 +
114883 +menu "PaX"
114884 +
114885 +config PAX
114886 + bool "Enable various PaX features"
114887 + default y if GRKERNSEC_CONFIG_AUTO
114888 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
114889 + help
114890 + This allows you to enable various PaX features. PaX adds
114891 + intrusion prevention mechanisms to the kernel that reduce
114892 + the risks posed by exploitable memory corruption bugs.
114893 +
114894 +menu "PaX Control"
114895 + depends on PAX
114896 +
114897 +config PAX_SOFTMODE
114898 + bool 'Support soft mode'
114899 + help
114900 + Enabling this option will allow you to run PaX in soft mode, that
114901 + is, PaX features will not be enforced by default, only on executables
114902 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
114903 + support as they are the only way to mark executables for soft mode use.
114904 +
114905 + Soft mode can be activated by using the "pax_softmode=1" kernel command
114906 + line option on boot. Furthermore you can control various PaX features
114907 + at runtime via the entries in /proc/sys/kernel/pax.
114908 +
114909 +config PAX_EI_PAX
114910 + bool 'Use legacy ELF header marking'
114911 + default y if GRKERNSEC_CONFIG_AUTO
114912 + help
114913 + Enabling this option will allow you to control PaX features on
114914 + a per executable basis via the 'chpax' utility available at
114915 + http://pax.grsecurity.net/. The control flags will be read from
114916 + an otherwise reserved part of the ELF header. This marking has
114917 + numerous drawbacks (no support for soft-mode, toolchain does not
114918 + know about the non-standard use of the ELF header) therefore it
114919 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
114920 + support.
114921 +
114922 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
114923 + support as well, they will override the legacy EI_PAX marks.
114924 +
114925 + If you enable none of the marking options then all applications
114926 + will run with PaX enabled on them by default.
114927 +
114928 +config PAX_PT_PAX_FLAGS
114929 + bool 'Use ELF program header marking'
114930 + default y if GRKERNSEC_CONFIG_AUTO
114931 + help
114932 + Enabling this option will allow you to control PaX features on
114933 + a per executable basis via the 'paxctl' utility available at
114934 + http://pax.grsecurity.net/. The control flags will be read from
114935 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
114936 + has the benefits of supporting both soft mode and being fully
114937 + integrated into the toolchain (the binutils patch is available
114938 + from http://pax.grsecurity.net).
114939 +
114940 + Note that if you enable the legacy EI_PAX marking support as well,
114941 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
114942 +
114943 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
114944 + must make sure that the marks are the same if a binary has both marks.
114945 +
114946 + If you enable none of the marking options then all applications
114947 + will run with PaX enabled on them by default.
114948 +
114949 +config PAX_XATTR_PAX_FLAGS
114950 + bool 'Use filesystem extended attributes marking'
114951 + default y if GRKERNSEC_CONFIG_AUTO
114952 + select CIFS_XATTR if CIFS
114953 + select F2FS_FS_XATTR if F2FS_FS
114954 + select EXT2_FS_XATTR if EXT2_FS
114955 + select EXT3_FS_XATTR if EXT3_FS
114956 + select JFFS2_FS_XATTR if JFFS2_FS
114957 + select REISERFS_FS_XATTR if REISERFS_FS
114958 + select SQUASHFS_XATTR if SQUASHFS
114959 + select TMPFS_XATTR if TMPFS
114960 + help
114961 + Enabling this option will allow you to control PaX features on
114962 + a per executable basis via the 'setfattr' utility. The control
114963 + flags will be read from the user.pax.flags extended attribute of
114964 + the file. This marking has the benefit of supporting binary-only
114965 + applications that self-check themselves (e.g., skype) and would
114966 + not tolerate chpax/paxctl changes. The main drawback is that
114967 + extended attributes are not supported by some filesystems (e.g.,
114968 + isofs, udf, vfat) so copying files through such filesystems will
114969 + lose the extended attributes and these PaX markings.
114970 +
114971 + Note that if you enable the legacy EI_PAX marking support as well,
114972 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
114973 +
114974 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
114975 + must make sure that the marks are the same if a binary has both marks.
114976 +
114977 + If you enable none of the marking options then all applications
114978 + will run with PaX enabled on them by default.
114979 +
114980 +choice
114981 + prompt 'MAC system integration'
114982 + default PAX_HAVE_ACL_FLAGS
114983 + help
114984 + Mandatory Access Control systems have the option of controlling
114985 + PaX flags on a per executable basis, choose the method supported
114986 + by your particular system.
114987 +
114988 + - "none": if your MAC system does not interact with PaX,
114989 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
114990 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
114991 +
114992 + NOTE: this option is for developers/integrators only.
114993 +
114994 + config PAX_NO_ACL_FLAGS
114995 + bool 'none'
114996 +
114997 + config PAX_HAVE_ACL_FLAGS
114998 + bool 'direct'
114999 +
115000 + config PAX_HOOK_ACL_FLAGS
115001 + bool 'hook'
115002 +endchoice
115003 +
115004 +endmenu
115005 +
115006 +menu "Non-executable pages"
115007 + depends on PAX
115008 +
115009 +config PAX_NOEXEC
115010 + bool "Enforce non-executable pages"
115011 + default y if GRKERNSEC_CONFIG_AUTO
115012 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
115013 + help
115014 + By design some architectures do not allow for protecting memory
115015 + pages against execution or even if they do, Linux does not make
115016 + use of this feature. In practice this means that if a page is
115017 + readable (such as the stack or heap) it is also executable.
115018 +
115019 + There is a well known exploit technique that makes use of this
115020 + fact and a common programming mistake where an attacker can
115021 + introduce code of his choice somewhere in the attacked program's
115022 + memory (typically the stack or the heap) and then execute it.
115023 +
115024 + If the attacked program was running with different (typically
115025 + higher) privileges than that of the attacker, then he can elevate
115026 + his own privilege level (e.g. get a root shell, write to files for
115027 + which he does not have write access to, etc).
115028 +
115029 + Enabling this option will let you choose from various features
115030 + that prevent the injection and execution of 'foreign' code in
115031 + a program.
115032 +
115033 + This will also break programs that rely on the old behaviour and
115034 + expect that dynamically allocated memory via the malloc() family
115035 + of functions is executable (which it is not). Notable examples
115036 + are the XFree86 4.x server, the java runtime and wine.
115037 +
115038 +config PAX_PAGEEXEC
115039 + bool "Paging based non-executable pages"
115040 + default y if GRKERNSEC_CONFIG_AUTO
115041 + 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)
115042 + select ARCH_TRACK_EXEC_LIMIT if X86_32
115043 + help
115044 + This implementation is based on the paging feature of the CPU.
115045 + On i386 without hardware non-executable bit support there is a
115046 + variable but usually low performance impact, however on Intel's
115047 + P4 core based CPUs it is very high so you should not enable this
115048 + for kernels meant to be used on such CPUs.
115049 +
115050 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
115051 + with hardware non-executable bit support there is no performance
115052 + impact, on ppc the impact is negligible.
115053 +
115054 + Note that several architectures require various emulations due to
115055 + badly designed userland ABIs, this will cause a performance impact
115056 + but will disappear as soon as userland is fixed. For example, ppc
115057 + userland MUST have been built with secure-plt by a recent toolchain.
115058 +
115059 +config PAX_SEGMEXEC
115060 + bool "Segmentation based non-executable pages"
115061 + default y if GRKERNSEC_CONFIG_AUTO
115062 + depends on PAX_NOEXEC && X86_32
115063 + help
115064 + This implementation is based on the segmentation feature of the
115065 + CPU and has a very small performance impact, however applications
115066 + will be limited to a 1.5 GB address space instead of the normal
115067 + 3 GB.
115068 +
115069 +config PAX_EMUTRAMP
115070 + bool "Emulate trampolines"
115071 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
115072 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
115073 + help
115074 + There are some programs and libraries that for one reason or
115075 + another attempt to execute special small code snippets from
115076 + non-executable memory pages. Most notable examples are the
115077 + signal handler return code generated by the kernel itself and
115078 + the GCC trampolines.
115079 +
115080 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
115081 + such programs will no longer work under your kernel.
115082 +
115083 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
115084 + utilities to enable trampoline emulation for the affected programs
115085 + yet still have the protection provided by the non-executable pages.
115086 +
115087 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
115088 + your system will not even boot.
115089 +
115090 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
115091 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
115092 + for the affected files.
115093 +
115094 + NOTE: enabling this feature *may* open up a loophole in the
115095 + protection provided by non-executable pages that an attacker
115096 + could abuse. Therefore the best solution is to not have any
115097 + files on your system that would require this option. This can
115098 + be achieved by not using libc5 (which relies on the kernel
115099 + signal handler return code) and not using or rewriting programs
115100 + that make use of the nested function implementation of GCC.
115101 + Skilled users can just fix GCC itself so that it implements
115102 + nested function calls in a way that does not interfere with PaX.
115103 +
115104 +config PAX_EMUSIGRT
115105 + bool "Automatically emulate sigreturn trampolines"
115106 + depends on PAX_EMUTRAMP && PARISC
115107 + default y
115108 + help
115109 + Enabling this option will have the kernel automatically detect
115110 + and emulate signal return trampolines executing on the stack
115111 + that would otherwise lead to task termination.
115112 +
115113 + This solution is intended as a temporary one for users with
115114 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
115115 + Modula-3 runtime, etc) or executables linked to such, basically
115116 + everything that does not specify its own SA_RESTORER function in
115117 + normal executable memory like glibc 2.1+ does.
115118 +
115119 + On parisc you MUST enable this option, otherwise your system will
115120 + not even boot.
115121 +
115122 + NOTE: this feature cannot be disabled on a per executable basis
115123 + and since it *does* open up a loophole in the protection provided
115124 + by non-executable pages, the best solution is to not have any
115125 + files on your system that would require this option.
115126 +
115127 +config PAX_MPROTECT
115128 + bool "Restrict mprotect()"
115129 + default y if GRKERNSEC_CONFIG_AUTO
115130 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
115131 + help
115132 + Enabling this option will prevent programs from
115133 + - changing the executable status of memory pages that were
115134 + not originally created as executable,
115135 + - making read-only executable pages writable again,
115136 + - creating executable pages from anonymous memory,
115137 + - making read-only-after-relocations (RELRO) data pages writable again.
115138 +
115139 + You should say Y here to complete the protection provided by
115140 + the enforcement of non-executable pages.
115141 +
115142 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
115143 + this feature on a per file basis.
115144 +
115145 +config PAX_MPROTECT_COMPAT
115146 + bool "Use legacy/compat protection demoting (read help)"
115147 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
115148 + depends on PAX_MPROTECT
115149 + help
115150 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
115151 + by sending the proper error code to the application. For some broken
115152 + userland, this can cause problems with Python or other applications. The
115153 + current implementation however allows for applications like clamav to
115154 + detect if JIT compilation/execution is allowed and to fall back gracefully
115155 + to an interpreter-based mode if it does not. While we encourage everyone
115156 + to use the current implementation as-is and push upstream to fix broken
115157 + userland (note that the RWX logging option can assist with this), in some
115158 + environments this may not be possible. Having to disable MPROTECT
115159 + completely on certain binaries reduces the security benefit of PaX,
115160 + so this option is provided for those environments to revert to the old
115161 + behavior.
115162 +
115163 +config PAX_ELFRELOCS
115164 + bool "Allow ELF text relocations (read help)"
115165 + depends on PAX_MPROTECT
115166 + default n
115167 + help
115168 + Non-executable pages and mprotect() restrictions are effective
115169 + in preventing the introduction of new executable code into an
115170 + attacked task's address space. There remain only two venues
115171 + for this kind of attack: if the attacker can execute already
115172 + existing code in the attacked task then he can either have it
115173 + create and mmap() a file containing his code or have it mmap()
115174 + an already existing ELF library that does not have position
115175 + independent code in it and use mprotect() on it to make it
115176 + writable and copy his code there. While protecting against
115177 + the former approach is beyond PaX, the latter can be prevented
115178 + by having only PIC ELF libraries on one's system (which do not
115179 + need to relocate their code). If you are sure this is your case,
115180 + as is the case with all modern Linux distributions, then leave
115181 + this option disabled. You should say 'n' here.
115182 +
115183 +config PAX_ETEXECRELOCS
115184 + bool "Allow ELF ET_EXEC text relocations"
115185 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
115186 + select PAX_ELFRELOCS
115187 + default y
115188 + help
115189 + On some architectures there are incorrectly created applications
115190 + that require text relocations and would not work without enabling
115191 + this option. If you are an alpha, ia64 or parisc user, you should
115192 + enable this option and disable it once you have made sure that
115193 + none of your applications need it.
115194 +
115195 +config PAX_EMUPLT
115196 + bool "Automatically emulate ELF PLT"
115197 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
115198 + default y
115199 + help
115200 + Enabling this option will have the kernel automatically detect
115201 + and emulate the Procedure Linkage Table entries in ELF files.
115202 + On some architectures such entries are in writable memory, and
115203 + become non-executable leading to task termination. Therefore
115204 + it is mandatory that you enable this option on alpha, parisc,
115205 + sparc and sparc64, otherwise your system would not even boot.
115206 +
115207 + NOTE: this feature *does* open up a loophole in the protection
115208 + provided by the non-executable pages, therefore the proper
115209 + solution is to modify the toolchain to produce a PLT that does
115210 + not need to be writable.
115211 +
115212 +config PAX_DLRESOLVE
115213 + bool 'Emulate old glibc resolver stub'
115214 + depends on PAX_EMUPLT && SPARC
115215 + default n
115216 + help
115217 + This option is needed if userland has an old glibc (before 2.4)
115218 + that puts a 'save' instruction into the runtime generated resolver
115219 + stub that needs special emulation.
115220 +
115221 +config PAX_KERNEXEC
115222 + bool "Enforce non-executable kernel pages"
115223 + 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))
115224 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
115225 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
115226 + select PAX_KERNEXEC_PLUGIN if X86_64
115227 + help
115228 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
115229 + that is, enabling this option will make it harder to inject
115230 + and execute 'foreign' code in kernel memory itself.
115231 +
115232 +choice
115233 + prompt "Return Address Instrumentation Method"
115234 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
115235 + depends on PAX_KERNEXEC_PLUGIN
115236 + help
115237 + Select the method used to instrument function pointer dereferences.
115238 + Note that binary modules cannot be instrumented by this approach.
115239 +
115240 + Note that the implementation requires a gcc with plugin support,
115241 + i.e., gcc 4.5 or newer. You may need to install the supporting
115242 + headers explicitly in addition to the normal gcc package.
115243 +
115244 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
115245 + bool "bts"
115246 + help
115247 + This method is compatible with binary only modules but has
115248 + a higher runtime overhead.
115249 +
115250 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
115251 + bool "or"
115252 + depends on !PARAVIRT
115253 + help
115254 + This method is incompatible with binary only modules but has
115255 + a lower runtime overhead.
115256 +endchoice
115257 +
115258 +config PAX_KERNEXEC_PLUGIN_METHOD
115259 + string
115260 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
115261 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
115262 + default ""
115263 +
115264 +config PAX_KERNEXEC_MODULE_TEXT
115265 + int "Minimum amount of memory reserved for module code"
115266 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
115267 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
115268 + depends on PAX_KERNEXEC && X86_32
115269 + help
115270 + Due to implementation details the kernel must reserve a fixed
115271 + amount of memory for runtime allocated code (such as modules)
115272 + at compile time that cannot be changed at runtime. Here you
115273 + can specify the minimum amount in MB that will be reserved.
115274 + Due to the same implementation details this size will always
115275 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
115276 + the actually available memory for runtime allocated code will
115277 + usually be more than this minimum.
115278 +
115279 + The default 4 MB should be enough for most users but if you have
115280 + an excessive number of modules (e.g., most distribution configs
115281 + compile many drivers as modules) or use huge modules such as
115282 + nvidia's kernel driver, you will need to adjust this amount.
115283 + A good rule of thumb is to look at your currently loaded kernel
115284 + modules and add up their sizes.
115285 +
115286 +endmenu
115287 +
115288 +menu "Address Space Layout Randomization"
115289 + depends on PAX
115290 +
115291 +config PAX_ASLR
115292 + bool "Address Space Layout Randomization"
115293 + default y if GRKERNSEC_CONFIG_AUTO
115294 + help
115295 + Many if not most exploit techniques rely on the knowledge of
115296 + certain addresses in the attacked program. The following options
115297 + will allow the kernel to apply a certain amount of randomization
115298 + to specific parts of the program thereby forcing an attacker to
115299 + guess them in most cases. Any failed guess will most likely crash
115300 + the attacked program which allows the kernel to detect such attempts
115301 + and react on them. PaX itself provides no reaction mechanisms,
115302 + instead it is strongly encouraged that you make use of grsecurity's
115303 + (http://www.grsecurity.net/) built-in crash detection features or
115304 + develop one yourself.
115305 +
115306 + By saying Y here you can choose to randomize the following areas:
115307 + - top of the task's kernel stack
115308 + - top of the task's userland stack
115309 + - base address for mmap() requests that do not specify one
115310 + (this includes all libraries)
115311 + - base address of the main executable
115312 +
115313 + It is strongly recommended to say Y here as address space layout
115314 + randomization has negligible impact on performance yet it provides
115315 + a very effective protection.
115316 +
115317 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
115318 + this feature on a per file basis.
115319 +
115320 +config PAX_RANDKSTACK
115321 + bool "Randomize kernel stack base"
115322 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
115323 + depends on X86_TSC && X86
115324 + help
115325 + By saying Y here the kernel will randomize every task's kernel
115326 + stack on every system call. This will not only force an attacker
115327 + to guess it but also prevent him from making use of possible
115328 + leaked information about it.
115329 +
115330 + Since the kernel stack is a rather scarce resource, randomization
115331 + may cause unexpected stack overflows, therefore you should very
115332 + carefully test your system. Note that once enabled in the kernel
115333 + configuration, this feature cannot be disabled on a per file basis.
115334 +
115335 +config PAX_RANDUSTACK
115336 + bool
115337 +
115338 +config PAX_RANDMMAP
115339 + bool "Randomize user stack and mmap() bases"
115340 + default y if GRKERNSEC_CONFIG_AUTO
115341 + depends on PAX_ASLR
115342 + select PAX_RANDUSTACK
115343 + help
115344 + By saying Y here the kernel will randomize every task's userland
115345 + stack and use a randomized base address for mmap() requests that
115346 + do not specify one themselves.
115347 +
115348 + The stack randomization is done in two steps where the second
115349 + one may apply a big amount of shift to the top of the stack and
115350 + cause problems for programs that want to use lots of memory (more
115351 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
115352 +
115353 + As a result of mmap randomization all dynamically loaded libraries
115354 + will appear at random addresses and therefore be harder to exploit
115355 + by a technique where an attacker attempts to execute library code
115356 + for his purposes (e.g. spawn a shell from an exploited program that
115357 + is running at an elevated privilege level).
115358 +
115359 + Furthermore, if a program is relinked as a dynamic ELF file, its
115360 + base address will be randomized as well, completing the full
115361 + randomization of the address space layout. Attacking such programs
115362 + becomes a guess game. You can find an example of doing this at
115363 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
115364 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
115365 +
115366 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
115367 + feature on a per file basis.
115368 +
115369 +endmenu
115370 +
115371 +menu "Miscellaneous hardening features"
115372 +
115373 +config PAX_MEMORY_SANITIZE
115374 + bool "Sanitize all freed memory"
115375 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
115376 + help
115377 + By saying Y here the kernel will erase memory pages and slab objects
115378 + as soon as they are freed. This in turn reduces the lifetime of data
115379 + stored in them, making it less likely that sensitive information such
115380 + as passwords, cryptographic secrets, etc stay in memory for too long.
115381 +
115382 + This is especially useful for programs whose runtime is short, long
115383 + lived processes and the kernel itself benefit from this as long as
115384 + they ensure timely freeing of memory that may hold sensitive
115385 + information.
115386 +
115387 + A nice side effect of the sanitization of slab objects is the
115388 + reduction of possible info leaks caused by padding bytes within the
115389 + leaky structures. Use-after-free bugs for structures containing
115390 + pointers can also be detected as dereferencing the sanitized pointer
115391 + will generate an access violation.
115392 +
115393 + The tradeoff is performance impact, on a single CPU system kernel
115394 + compilation sees a 3% slowdown, other systems and workloads may vary
115395 + and you are advised to test this feature on your expected workload
115396 + before deploying it.
115397 +
115398 + To reduce the performance penalty by sanitizing pages only, albeit
115399 + limiting the effectiveness of this feature at the same time, slab
115400 + sanitization can be disabled with the kernel commandline parameter
115401 + "pax_sanitize_slab=0".
115402 +
115403 + Note that this feature does not protect data stored in live pages,
115404 + e.g., process memory swapped to disk may stay there for a long time.
115405 +
115406 +config PAX_MEMORY_STACKLEAK
115407 + bool "Sanitize kernel stack"
115408 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
115409 + depends on X86
115410 + help
115411 + By saying Y here the kernel will erase the kernel stack before it
115412 + returns from a system call. This in turn reduces the information
115413 + that a kernel stack leak bug can reveal.
115414 +
115415 + Note that such a bug can still leak information that was put on
115416 + the stack by the current system call (the one eventually triggering
115417 + the bug) but traces of earlier system calls on the kernel stack
115418 + cannot leak anymore.
115419 +
115420 + The tradeoff is performance impact: on a single CPU system kernel
115421 + compilation sees a 1% slowdown, other systems and workloads may vary
115422 + and you are advised to test this feature on your expected workload
115423 + before deploying it.
115424 +
115425 + Note that the full feature requires a gcc with plugin support,
115426 + i.e., gcc 4.5 or newer. You may need to install the supporting
115427 + headers explicitly in addition to the normal gcc package. Using
115428 + older gcc versions means that functions with large enough stack
115429 + frames may leave uninitialized memory behind that may be exposed
115430 + to a later syscall leaking the stack.
115431 +
115432 +config PAX_MEMORY_STRUCTLEAK
115433 + bool "Forcibly initialize local variables copied to userland"
115434 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
115435 + help
115436 + By saying Y here the kernel will zero initialize some local
115437 + variables that are going to be copied to userland. This in
115438 + turn prevents unintended information leakage from the kernel
115439 + stack should later code forget to explicitly set all parts of
115440 + the copied variable.
115441 +
115442 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
115443 + at a much smaller coverage.
115444 +
115445 + Note that the implementation requires a gcc with plugin support,
115446 + i.e., gcc 4.5 or newer. You may need to install the supporting
115447 + headers explicitly in addition to the normal gcc package.
115448 +
115449 +config PAX_MEMORY_UDEREF
115450 + bool "Prevent invalid userland pointer dereference"
115451 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
115452 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
115453 + select PAX_PER_CPU_PGD if X86_64
115454 + help
115455 + By saying Y here the kernel will be prevented from dereferencing
115456 + userland pointers in contexts where the kernel expects only kernel
115457 + pointers. This is both a useful runtime debugging feature and a
115458 + security measure that prevents exploiting a class of kernel bugs.
115459 +
115460 + The tradeoff is that some virtualization solutions may experience
115461 + a huge slowdown and therefore you should not enable this feature
115462 + for kernels meant to run in such environments. Whether a given VM
115463 + solution is affected or not is best determined by simply trying it
115464 + out, the performance impact will be obvious right on boot as this
115465 + mechanism engages from very early on. A good rule of thumb is that
115466 + VMs running on CPUs without hardware virtualization support (i.e.,
115467 + the majority of IA-32 CPUs) will likely experience the slowdown.
115468 +
115469 + On X86_64 the kernel will make use of PCID support when available
115470 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
115471 + or performance impact. Pass pax_weakuderef on the kernel command
115472 + line to choose the latter.
115473 +
115474 +config PAX_REFCOUNT
115475 + bool "Prevent various kernel object reference counter overflows"
115476 + default y if GRKERNSEC_CONFIG_AUTO
115477 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
115478 + help
115479 + By saying Y here the kernel will detect and prevent overflowing
115480 + various (but not all) kinds of object reference counters. Such
115481 + overflows can normally occur due to bugs only and are often, if
115482 + not always, exploitable.
115483 +
115484 + The tradeoff is that data structures protected by an overflowed
115485 + refcount will never be freed and therefore will leak memory. Note
115486 + that this leak also happens even without this protection but in
115487 + that case the overflow can eventually trigger the freeing of the
115488 + data structure while it is still being used elsewhere, resulting
115489 + in the exploitable situation that this feature prevents.
115490 +
115491 + Since this has a negligible performance impact, you should enable
115492 + this feature.
115493 +
115494 +config PAX_CONSTIFY_PLUGIN
115495 + bool "Automatically constify eligible structures"
115496 + default y
115497 + depends on !UML && PAX_KERNEXEC
115498 + help
115499 + By saying Y here the compiler will automatically constify a class
115500 + of types that contain only function pointers. This reduces the
115501 + kernel's attack surface and also produces a better memory layout.
115502 +
115503 + Note that the implementation requires a gcc with plugin support,
115504 + i.e., gcc 4.5 or newer. You may need to install the supporting
115505 + headers explicitly in addition to the normal gcc package.
115506 +
115507 + Note that if some code really has to modify constified variables
115508 + then the source code will have to be patched to allow it. Examples
115509 + can be found in PaX itself (the no_const attribute) and for some
115510 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
115511 +
115512 +config PAX_USERCOPY
115513 + bool "Harden heap object copies between kernel and userland"
115514 + default y if GRKERNSEC_CONFIG_AUTO
115515 + depends on ARM || IA64 || PPC || SPARC || X86
115516 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
115517 + select PAX_USERCOPY_SLABS
115518 + help
115519 + By saying Y here the kernel will enforce the size of heap objects
115520 + when they are copied in either direction between the kernel and
115521 + userland, even if only a part of the heap object is copied.
115522 +
115523 + Specifically, this checking prevents information leaking from the
115524 + kernel heap during kernel to userland copies (if the kernel heap
115525 + object is otherwise fully initialized) and prevents kernel heap
115526 + overflows during userland to kernel copies.
115527 +
115528 + Note that the current implementation provides the strictest bounds
115529 + checks for the SLUB allocator.
115530 +
115531 + Enabling this option also enables per-slab cache protection against
115532 + data in a given cache being copied into/out of via userland
115533 + accessors. Though the whitelist of regions will be reduced over
115534 + time, it notably protects important data structures like task structs.
115535 +
115536 + If frame pointers are enabled on x86, this option will also restrict
115537 + copies into and out of the kernel stack to local variables within a
115538 + single frame.
115539 +
115540 + Since this has a negligible performance impact, you should enable
115541 + this feature.
115542 +
115543 +config PAX_USERCOPY_DEBUG
115544 + bool
115545 + depends on X86 && PAX_USERCOPY
115546 + default n
115547 +
115548 +config PAX_SIZE_OVERFLOW
115549 + bool "Prevent various integer overflows in function size parameters"
115550 + default y if GRKERNSEC_CONFIG_AUTO
115551 + depends on X86
115552 + help
115553 + By saying Y here the kernel recomputes expressions of function
115554 + arguments marked by a size_overflow attribute with double integer
115555 + precision (DImode/TImode for 32/64 bit integer types).
115556 +
115557 + The recomputed argument is checked against TYPE_MAX and an event
115558 + is logged on overflow and the triggering process is killed.
115559 +
115560 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
115561 +
115562 + Note that the implementation requires a gcc with plugin support,
115563 + i.e., gcc 4.5 or newer. You may need to install the supporting
115564 + headers explicitly in addition to the normal gcc package.
115565 +
115566 +config PAX_LATENT_ENTROPY
115567 + bool "Generate some entropy during boot and runtime"
115568 + default y if GRKERNSEC_CONFIG_AUTO
115569 + help
115570 + By saying Y here the kernel will instrument some kernel code to
115571 + extract some entropy from both original and artificially created
115572 + program state. This will help especially embedded systems where
115573 + there is little 'natural' source of entropy normally. The cost
115574 + is some slowdown of the boot process and fork and irq processing.
115575 +
115576 + When pax_extra_latent_entropy is passed on the kernel command line,
115577 + entropy will be extracted from up to the first 4GB of RAM while the
115578 + runtime memory allocator is being initialized. This costs even more
115579 + slowdown of the boot process.
115580 +
115581 + Note that the implementation requires a gcc with plugin support,
115582 + i.e., gcc 4.5 or newer. You may need to install the supporting
115583 + headers explicitly in addition to the normal gcc package.
115584 +
115585 + Note that entropy extracted this way is not cryptographically
115586 + secure!
115587 +
115588 +endmenu
115589 +
115590 +endmenu
115591 +
115592 +source grsecurity/Kconfig
115593 +
115594 +endmenu
115595 +
115596 +endmenu
115597 +
115598 source security/keys/Kconfig
115599
115600 config SECURITY_DMESG_RESTRICT
115601 @@ -103,7 +1054,7 @@ config INTEL_TXT
115602 config LSM_MMAP_MIN_ADDR
115603 int "Low address space for LSM to protect from user allocation"
115604 depends on SECURITY && SECURITY_SELINUX
115605 - default 32768 if ARM || (ARM64 && COMPAT)
115606 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
115607 default 65536
115608 help
115609 This is the portion of low virtual memory which should be protected
115610 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
115611 index fdaa50c..2761dcb 100644
115612 --- a/security/apparmor/file.c
115613 +++ b/security/apparmor/file.c
115614 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
115615 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
115616 struct path *new_dir, struct dentry *new_dentry)
115617 {
115618 - struct path link = { new_dir->mnt, new_dentry };
115619 - struct path target = { new_dir->mnt, old_dentry };
115620 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
115621 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
115622 struct path_cond cond = {
115623 old_dentry->d_inode->i_uid,
115624 old_dentry->d_inode->i_mode
115625 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
115626 index 9981000..eb21356 100644
115627 --- a/security/apparmor/lsm.c
115628 +++ b/security/apparmor/lsm.c
115629 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
115630 struct dentry *dentry, u32 mask,
115631 struct path_cond *cond)
115632 {
115633 - struct path path = { dir->mnt, dentry };
115634 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
115635
115636 return common_perm(op, &path, mask, cond);
115637 }
115638 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
115639 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
115640 struct dentry *dentry, u32 mask)
115641 {
115642 - struct path path = { mnt, dentry };
115643 + struct path path = { .mnt = mnt, .dentry = dentry };
115644 struct path_cond cond = { dentry->d_inode->i_uid,
115645 dentry->d_inode->i_mode
115646 };
115647 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
115648
115649 profile = aa_current_profile();
115650 if (!unconfined(profile)) {
115651 - struct path old_path = { old_dir->mnt, old_dentry };
115652 - struct path new_path = { new_dir->mnt, new_dentry };
115653 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
115654 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
115655 struct path_cond cond = { old_dentry->d_inode->i_uid,
115656 old_dentry->d_inode->i_mode
115657 };
115658 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
115659 return error;
115660 }
115661
115662 -static struct security_operations apparmor_ops = {
115663 +static struct security_operations apparmor_ops __read_only = {
115664 .name = "apparmor",
115665
115666 .ptrace_access_check = apparmor_ptrace_access_check,
115667 diff --git a/security/commoncap.c b/security/commoncap.c
115668 index b9d613e..f68305c 100644
115669 --- a/security/commoncap.c
115670 +++ b/security/commoncap.c
115671 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
115672 return 0;
115673 }
115674
115675 +/* returns:
115676 + 1 for suid privilege
115677 + 2 for sgid privilege
115678 + 3 for fscap privilege
115679 +*/
115680 +int is_privileged_binary(const struct dentry *dentry)
115681 +{
115682 + struct cpu_vfs_cap_data capdata;
115683 + struct inode *inode = dentry->d_inode;
115684 +
115685 + if (!inode || S_ISDIR(inode->i_mode))
115686 + return 0;
115687 +
115688 + if (inode->i_mode & S_ISUID)
115689 + return 1;
115690 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
115691 + return 2;
115692 +
115693 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
115694 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
115695 + return 3;
115696 + }
115697 +
115698 + return 0;
115699 +}
115700 +
115701 /*
115702 * Attempt to get the on-exec apply capability sets for an executable file from
115703 * its xattrs and, if present, apply them to the proposed credentials being
115704 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
115705 const struct cred *cred = current_cred();
115706 kuid_t root_uid = make_kuid(cred->user_ns, 0);
115707
115708 + if (gr_acl_enable_at_secure())
115709 + return 1;
115710 +
115711 if (!uid_eq(cred->uid, root_uid)) {
115712 if (bprm->cap_effective)
115713 return 1;
115714 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
115715 index f79fa8b..6161868 100644
115716 --- a/security/integrity/ima/ima.h
115717 +++ b/security/integrity/ima/ima.h
115718 @@ -118,8 +118,8 @@ int ima_init_template(void);
115719 extern spinlock_t ima_queue_lock;
115720
115721 struct ima_h_table {
115722 - atomic_long_t len; /* number of stored measurements in the list */
115723 - atomic_long_t violations;
115724 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
115725 + atomic_long_unchecked_t violations;
115726 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
115727 };
115728 extern struct ima_h_table ima_htable;
115729 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
115730 index d9cd5ce..c5c29ac 100644
115731 --- a/security/integrity/ima/ima_api.c
115732 +++ b/security/integrity/ima/ima_api.c
115733 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
115734 int result;
115735
115736 /* can overflow, only indicator */
115737 - atomic_long_inc(&ima_htable.violations);
115738 + atomic_long_inc_unchecked(&ima_htable.violations);
115739
115740 result = ima_alloc_init_template(NULL, file, filename,
115741 NULL, 0, &entry);
115742 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
115743 index da92fcc..8a5d390 100644
115744 --- a/security/integrity/ima/ima_fs.c
115745 +++ b/security/integrity/ima/ima_fs.c
115746 @@ -28,12 +28,12 @@
115747 static int valid_policy = 1;
115748 #define TMPBUFLEN 12
115749 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
115750 - loff_t *ppos, atomic_long_t *val)
115751 + loff_t *ppos, atomic_long_unchecked_t *val)
115752 {
115753 char tmpbuf[TMPBUFLEN];
115754 ssize_t len;
115755
115756 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
115757 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
115758 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
115759 }
115760
115761 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
115762 index 552705d..9920f4fb 100644
115763 --- a/security/integrity/ima/ima_queue.c
115764 +++ b/security/integrity/ima/ima_queue.c
115765 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
115766 INIT_LIST_HEAD(&qe->later);
115767 list_add_tail_rcu(&qe->later, &ima_measurements);
115768
115769 - atomic_long_inc(&ima_htable.len);
115770 + atomic_long_inc_unchecked(&ima_htable.len);
115771 key = ima_hash_key(entry->digest);
115772 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
115773 return 0;
115774 diff --git a/security/keys/compat.c b/security/keys/compat.c
115775 index 3478965..ec7bb9e 100644
115776 --- a/security/keys/compat.c
115777 +++ b/security/keys/compat.c
115778 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
115779 if (ret == 0)
115780 goto no_payload_free;
115781
115782 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
115783 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
115784 err:
115785 if (iov != iovstack)
115786 kfree(iov);
115787 diff --git a/security/keys/internal.h b/security/keys/internal.h
115788 index 5f20da0..444ccf1 100644
115789 --- a/security/keys/internal.h
115790 +++ b/security/keys/internal.h
115791 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
115792 extern long keyctl_invalidate_key(key_serial_t);
115793
115794 extern long keyctl_instantiate_key_common(key_serial_t,
115795 - const struct iovec *,
115796 + const struct iovec __user *,
115797 unsigned, size_t, key_serial_t);
115798 #ifdef CONFIG_PERSISTENT_KEYRINGS
115799 extern long keyctl_get_persistent(uid_t, key_serial_t);
115800 diff --git a/security/keys/key.c b/security/keys/key.c
115801 index 2048a11..101df4c 100644
115802 --- a/security/keys/key.c
115803 +++ b/security/keys/key.c
115804 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
115805
115806 atomic_set(&key->usage, 1);
115807 init_rwsem(&key->sem);
115808 - lockdep_set_class(&key->sem, &type->lock_class);
115809 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
115810 key->index_key.type = type;
115811 key->user = user;
115812 key->quotalen = quotalen;
115813 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
115814 struct key_type *p;
115815 int ret;
115816
115817 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
115818 + pax_open_kernel();
115819 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
115820 + pax_close_kernel();
115821
115822 ret = -EEXIST;
115823 down_write(&key_types_sem);
115824 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
115825 }
115826
115827 /* store the type */
115828 - list_add(&ktype->link, &key_types_list);
115829 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
115830
115831 pr_notice("Key type %s registered\n", ktype->name);
115832 ret = 0;
115833 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
115834 void unregister_key_type(struct key_type *ktype)
115835 {
115836 down_write(&key_types_sem);
115837 - list_del_init(&ktype->link);
115838 + pax_list_del_init((struct list_head *)&ktype->link);
115839 downgrade_write(&key_types_sem);
115840 key_gc_keytype(ktype);
115841 pr_notice("Key type %s unregistered\n", ktype->name);
115842 @@ -1088,10 +1090,10 @@ void __init key_init(void)
115843 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
115844
115845 /* add the special key types */
115846 - list_add_tail(&key_type_keyring.link, &key_types_list);
115847 - list_add_tail(&key_type_dead.link, &key_types_list);
115848 - list_add_tail(&key_type_user.link, &key_types_list);
115849 - list_add_tail(&key_type_logon.link, &key_types_list);
115850 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
115851 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
115852 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
115853 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
115854
115855 /* record the root user tracking */
115856 rb_link_node(&root_key_user.node,
115857 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
115858 index cd5bd0c..acd0d5c 100644
115859 --- a/security/keys/keyctl.c
115860 +++ b/security/keys/keyctl.c
115861 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
115862 /*
115863 * Copy the iovec data from userspace
115864 */
115865 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
115866 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
115867 unsigned ioc)
115868 {
115869 for (; ioc > 0; ioc--) {
115870 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
115871 * If successful, 0 will be returned.
115872 */
115873 long keyctl_instantiate_key_common(key_serial_t id,
115874 - const struct iovec *payload_iov,
115875 + const struct iovec __user *payload_iov,
115876 unsigned ioc,
115877 size_t plen,
115878 key_serial_t ringid)
115879 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
115880 [0].iov_len = plen
115881 };
115882
115883 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
115884 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
115885 }
115886
115887 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
115888 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
115889 if (ret == 0)
115890 goto no_payload_free;
115891
115892 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
115893 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
115894 err:
115895 if (iov != iovstack)
115896 kfree(iov);
115897 diff --git a/security/min_addr.c b/security/min_addr.c
115898 index f728728..6457a0c 100644
115899 --- a/security/min_addr.c
115900 +++ b/security/min_addr.c
115901 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
115902 */
115903 static void update_mmap_min_addr(void)
115904 {
115905 +#ifndef SPARC
115906 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
115907 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
115908 mmap_min_addr = dac_mmap_min_addr;
115909 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
115910 #else
115911 mmap_min_addr = dac_mmap_min_addr;
115912 #endif
115913 +#endif
115914 }
115915
115916 /*
115917 diff --git a/security/security.c b/security/security.c
115918 index 31614e9..8b86b12 100644
115919 --- a/security/security.c
115920 +++ b/security/security.c
115921 @@ -33,8 +33,8 @@
115922 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
115923 CONFIG_DEFAULT_SECURITY;
115924
115925 -static struct security_operations *security_ops;
115926 -static struct security_operations default_security_ops = {
115927 +struct security_operations *security_ops __read_only;
115928 +struct security_operations default_security_ops __read_only = {
115929 .name = "default",
115930 };
115931
115932 @@ -73,11 +73,6 @@ int __init security_init(void)
115933 return 0;
115934 }
115935
115936 -void reset_security_ops(void)
115937 -{
115938 - security_ops = &default_security_ops;
115939 -}
115940 -
115941 /* Save user chosen LSM */
115942 static int __init choose_lsm(char *str)
115943 {
115944 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
115945 index a18f1fa..c9b9fc4 100644
115946 --- a/security/selinux/avc.c
115947 +++ b/security/selinux/avc.c
115948 @@ -59,7 +59,7 @@ struct avc_node {
115949 struct avc_cache {
115950 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
115951 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
115952 - atomic_t lru_hint; /* LRU hint for reclaim scan */
115953 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
115954 atomic_t active_nodes;
115955 u32 latest_notif; /* latest revocation notification */
115956 };
115957 @@ -167,7 +167,7 @@ void __init avc_init(void)
115958 spin_lock_init(&avc_cache.slots_lock[i]);
115959 }
115960 atomic_set(&avc_cache.active_nodes, 0);
115961 - atomic_set(&avc_cache.lru_hint, 0);
115962 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
115963
115964 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
115965 0, SLAB_PANIC, NULL);
115966 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
115967 spinlock_t *lock;
115968
115969 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
115970 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
115971 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
115972 head = &avc_cache.slots[hvalue];
115973 lock = &avc_cache.slots_lock[hvalue];
115974
115975 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
115976 index 83d06db..d4d6861 100644
115977 --- a/security/selinux/hooks.c
115978 +++ b/security/selinux/hooks.c
115979 @@ -95,8 +95,6 @@
115980 #include "audit.h"
115981 #include "avc_ss.h"
115982
115983 -extern struct security_operations *security_ops;
115984 -
115985 /* SECMARK reference count */
115986 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
115987
115988 @@ -5761,7 +5759,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
115989
115990 #endif
115991
115992 -static struct security_operations selinux_ops = {
115993 +static struct security_operations selinux_ops __read_only = {
115994 .name = "selinux",
115995
115996 .ptrace_access_check = selinux_ptrace_access_check,
115997 @@ -6114,6 +6112,9 @@ static void selinux_nf_ip_exit(void)
115998 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
115999 static int selinux_disabled;
116000
116001 +extern struct security_operations *security_ops;
116002 +extern struct security_operations default_security_ops;
116003 +
116004 int selinux_disable(void)
116005 {
116006 if (ss_initialized) {
116007 @@ -6131,7 +6132,9 @@ int selinux_disable(void)
116008 selinux_disabled = 1;
116009 selinux_enabled = 0;
116010
116011 - reset_security_ops();
116012 + pax_open_kernel();
116013 + security_ops = &default_security_ops;
116014 + pax_close_kernel();
116015
116016 /* Try to destroy the avc node cache */
116017 avc_disable();
116018 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
116019 index 1450f85..a91e0bc 100644
116020 --- a/security/selinux/include/xfrm.h
116021 +++ b/security/selinux/include/xfrm.h
116022 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
116023
116024 rtnl_lock();
116025 for_each_net(net) {
116026 - atomic_inc(&net->xfrm.flow_cache_genid);
116027 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
116028 rt_genid_bump_all(net);
116029 }
116030 rtnl_unlock();
116031 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
116032 index f2c3080..813c85e 100644
116033 --- a/security/smack/smack_lsm.c
116034 +++ b/security/smack/smack_lsm.c
116035 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
116036 return 0;
116037 }
116038
116039 -struct security_operations smack_ops = {
116040 +struct security_operations smack_ops __read_only = {
116041 .name = "smack",
116042
116043 .ptrace_access_check = smack_ptrace_access_check,
116044 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
116045 index 4003907..13a2b55 100644
116046 --- a/security/tomoyo/file.c
116047 +++ b/security/tomoyo/file.c
116048 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
116049 {
116050 struct tomoyo_request_info r;
116051 struct tomoyo_obj_info obj = {
116052 - .path1 = *path,
116053 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
116054 };
116055 int error = -ENOMEM;
116056 struct tomoyo_path_info buf;
116057 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
116058 struct tomoyo_path_info buf;
116059 struct tomoyo_request_info r;
116060 struct tomoyo_obj_info obj = {
116061 - .path1 = *path,
116062 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
116063 };
116064 int idx;
116065
116066 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
116067 {
116068 struct tomoyo_request_info r;
116069 struct tomoyo_obj_info obj = {
116070 - .path1 = *path,
116071 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
116072 };
116073 int error;
116074 struct tomoyo_path_info buf;
116075 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
116076 {
116077 struct tomoyo_request_info r;
116078 struct tomoyo_obj_info obj = {
116079 - .path1 = *path,
116080 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
116081 };
116082 int error = -ENOMEM;
116083 struct tomoyo_path_info buf;
116084 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
116085 struct tomoyo_path_info buf2;
116086 struct tomoyo_request_info r;
116087 struct tomoyo_obj_info obj = {
116088 - .path1 = *path1,
116089 - .path2 = *path2,
116090 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
116091 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
116092 };
116093 int idx;
116094
116095 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
116096 index 390c646..f2f8db3 100644
116097 --- a/security/tomoyo/mount.c
116098 +++ b/security/tomoyo/mount.c
116099 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
116100 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
116101 need_dev = -1; /* dev_name is a directory */
116102 } else {
116103 + if (!capable(CAP_SYS_ADMIN)) {
116104 + error = -EPERM;
116105 + goto out;
116106 + }
116107 fstype = get_fs_type(type);
116108 if (!fstype) {
116109 error = -ENODEV;
116110 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
116111 index f0b756e..8aa497b 100644
116112 --- a/security/tomoyo/tomoyo.c
116113 +++ b/security/tomoyo/tomoyo.c
116114 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
116115 */
116116 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
116117 {
116118 - struct path path = { mnt, dentry };
116119 + struct path path = { .mnt = mnt, .dentry = dentry };
116120 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
116121 }
116122
116123 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
116124 */
116125 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
116126 {
116127 - struct path path = { parent->mnt, dentry };
116128 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
116129 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
116130 }
116131
116132 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
116133 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
116134 umode_t mode)
116135 {
116136 - struct path path = { parent->mnt, dentry };
116137 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
116138 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
116139 mode & S_IALLUGO);
116140 }
116141 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
116142 */
116143 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
116144 {
116145 - struct path path = { parent->mnt, dentry };
116146 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
116147 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
116148 }
116149
116150 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
116151 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
116152 const char *old_name)
116153 {
116154 - struct path path = { parent->mnt, dentry };
116155 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
116156 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
116157 }
116158
116159 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
116160 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
116161 umode_t mode, unsigned int dev)
116162 {
116163 - struct path path = { parent->mnt, dentry };
116164 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
116165 int type = TOMOYO_TYPE_CREATE;
116166 const unsigned int perm = mode & S_IALLUGO;
116167
116168 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
116169 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
116170 struct dentry *new_dentry)
116171 {
116172 - struct path path1 = { new_dir->mnt, old_dentry };
116173 - struct path path2 = { new_dir->mnt, new_dentry };
116174 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
116175 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
116176 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
116177 }
116178
116179 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
116180 struct path *new_parent,
116181 struct dentry *new_dentry)
116182 {
116183 - struct path path1 = { old_parent->mnt, old_dentry };
116184 - struct path path2 = { new_parent->mnt, new_dentry };
116185 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
116186 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
116187 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
116188 }
116189
116190 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
116191 */
116192 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
116193 {
116194 - struct path path = { mnt, mnt->mnt_root };
116195 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
116196 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
116197 }
116198
116199 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
116200 * tomoyo_security_ops is a "struct security_operations" which is used for
116201 * registering TOMOYO.
116202 */
116203 -static struct security_operations tomoyo_security_ops = {
116204 +static struct security_operations tomoyo_security_ops __read_only = {
116205 .name = "tomoyo",
116206 .cred_alloc_blank = tomoyo_cred_alloc_blank,
116207 .cred_prepare = tomoyo_cred_prepare,
116208 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
116209 index 20ef514..4182bed 100644
116210 --- a/security/yama/Kconfig
116211 +++ b/security/yama/Kconfig
116212 @@ -1,6 +1,6 @@
116213 config SECURITY_YAMA
116214 bool "Yama support"
116215 - depends on SECURITY
116216 + depends on SECURITY && !GRKERNSEC
116217 select SECURITYFS
116218 select SECURITY_PATH
116219 default n
116220 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
116221 index 13c88fbc..f8c115e 100644
116222 --- a/security/yama/yama_lsm.c
116223 +++ b/security/yama/yama_lsm.c
116224 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
116225 }
116226
116227 #ifndef CONFIG_SECURITY_YAMA_STACKED
116228 -static struct security_operations yama_ops = {
116229 +static struct security_operations yama_ops __read_only = {
116230 .name = "yama",
116231
116232 .ptrace_access_check = yama_ptrace_access_check,
116233 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
116234 #endif
116235
116236 #ifdef CONFIG_SYSCTL
116237 +static int zero __read_only;
116238 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
116239 +
116240 static int yama_dointvec_minmax(struct ctl_table *table, int write,
116241 void __user *buffer, size_t *lenp, loff_t *ppos)
116242 {
116243 - int rc;
116244 + ctl_table_no_const yama_table;
116245
116246 if (write && !capable(CAP_SYS_PTRACE))
116247 return -EPERM;
116248
116249 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
116250 - if (rc)
116251 - return rc;
116252 -
116253 + yama_table = *table;
116254 /* Lock the max value if it ever gets set. */
116255 - if (write && *(int *)table->data == *(int *)table->extra2)
116256 - table->extra1 = table->extra2;
116257 -
116258 - return rc;
116259 + if (ptrace_scope == max_scope)
116260 + yama_table.extra1 = &max_scope;
116261 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
116262 }
116263
116264 -static int zero;
116265 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
116266 -
116267 struct ctl_path yama_sysctl_path[] = {
116268 { .procname = "kernel", },
116269 { .procname = "yama", },
116270 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
116271 index 401107b..b9c47c6 100644
116272 --- a/sound/aoa/codecs/onyx.c
116273 +++ b/sound/aoa/codecs/onyx.c
116274 @@ -54,7 +54,7 @@ struct onyx {
116275 spdif_locked:1,
116276 analog_locked:1,
116277 original_mute:2;
116278 - int open_count;
116279 + local_t open_count;
116280 struct codec_info *codec_info;
116281
116282 /* mutex serializes concurrent access to the device
116283 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
116284 struct onyx *onyx = cii->codec_data;
116285
116286 mutex_lock(&onyx->mutex);
116287 - onyx->open_count++;
116288 + local_inc(&onyx->open_count);
116289 mutex_unlock(&onyx->mutex);
116290
116291 return 0;
116292 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
116293 struct onyx *onyx = cii->codec_data;
116294
116295 mutex_lock(&onyx->mutex);
116296 - onyx->open_count--;
116297 - if (!onyx->open_count)
116298 + if (local_dec_and_test(&onyx->open_count))
116299 onyx->spdif_locked = onyx->analog_locked = 0;
116300 mutex_unlock(&onyx->mutex);
116301
116302 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
116303 index ffd2025..df062c9 100644
116304 --- a/sound/aoa/codecs/onyx.h
116305 +++ b/sound/aoa/codecs/onyx.h
116306 @@ -11,6 +11,7 @@
116307 #include <linux/i2c.h>
116308 #include <asm/pmac_low_i2c.h>
116309 #include <asm/prom.h>
116310 +#include <asm/local.h>
116311
116312 /* PCM3052 register definitions */
116313
116314 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
116315 index ada69d7..5f65386 100644
116316 --- a/sound/core/oss/pcm_oss.c
116317 +++ b/sound/core/oss/pcm_oss.c
116318 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
116319 if (in_kernel) {
116320 mm_segment_t fs;
116321 fs = snd_enter_user();
116322 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
116323 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
116324 snd_leave_user(fs);
116325 } else {
116326 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
116327 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
116328 }
116329 if (ret != -EPIPE && ret != -ESTRPIPE)
116330 break;
116331 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
116332 if (in_kernel) {
116333 mm_segment_t fs;
116334 fs = snd_enter_user();
116335 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
116336 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
116337 snd_leave_user(fs);
116338 } else {
116339 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
116340 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
116341 }
116342 if (ret == -EPIPE) {
116343 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
116344 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
116345 struct snd_pcm_plugin_channel *channels;
116346 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
116347 if (!in_kernel) {
116348 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
116349 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
116350 return -EFAULT;
116351 buf = runtime->oss.buffer;
116352 }
116353 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
116354 }
116355 } else {
116356 tmp = snd_pcm_oss_write2(substream,
116357 - (const char __force *)buf,
116358 + (const char __force_kernel *)buf,
116359 runtime->oss.period_bytes, 0);
116360 if (tmp <= 0)
116361 goto err;
116362 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
116363 struct snd_pcm_runtime *runtime = substream->runtime;
116364 snd_pcm_sframes_t frames, frames1;
116365 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
116366 - char __user *final_dst = (char __force __user *)buf;
116367 + char __user *final_dst = (char __force_user *)buf;
116368 if (runtime->oss.plugin_first) {
116369 struct snd_pcm_plugin_channel *channels;
116370 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
116371 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
116372 xfer += tmp;
116373 runtime->oss.buffer_used -= tmp;
116374 } else {
116375 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
116376 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
116377 runtime->oss.period_bytes, 0);
116378 if (tmp <= 0)
116379 goto err;
116380 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
116381 size1);
116382 size1 /= runtime->channels; /* frames */
116383 fs = snd_enter_user();
116384 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
116385 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
116386 snd_leave_user(fs);
116387 }
116388 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
116389 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
116390 index af49721..e85058e 100644
116391 --- a/sound/core/pcm_compat.c
116392 +++ b/sound/core/pcm_compat.c
116393 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
116394 int err;
116395
116396 fs = snd_enter_user();
116397 - err = snd_pcm_delay(substream, &delay);
116398 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
116399 snd_leave_user(fs);
116400 if (err < 0)
116401 return err;
116402 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
116403 index b653ab0..a4738e3 100644
116404 --- a/sound/core/pcm_native.c
116405 +++ b/sound/core/pcm_native.c
116406 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
116407 switch (substream->stream) {
116408 case SNDRV_PCM_STREAM_PLAYBACK:
116409 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
116410 - (void __user *)arg);
116411 + (void __force_user *)arg);
116412 break;
116413 case SNDRV_PCM_STREAM_CAPTURE:
116414 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
116415 - (void __user *)arg);
116416 + (void __force_user *)arg);
116417 break;
116418 default:
116419 result = -EINVAL;
116420 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
116421 index 16d4267..fe8b49b 100644
116422 --- a/sound/core/seq/oss/seq_oss.c
116423 +++ b/sound/core/seq/oss/seq_oss.c
116424 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
116425 {
116426 int rc;
116427 static struct snd_seq_dev_ops ops = {
116428 - snd_seq_oss_synth_register,
116429 - snd_seq_oss_synth_unregister,
116430 + .init_device = snd_seq_oss_synth_register,
116431 + .free_device = snd_seq_oss_synth_unregister,
116432 };
116433
116434 snd_seq_autoload_lock();
116435 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
116436 index 91a786a..4c07ed4 100644
116437 --- a/sound/core/seq/seq_device.c
116438 +++ b/sound/core/seq/seq_device.c
116439 @@ -64,7 +64,7 @@ struct ops_list {
116440 int argsize; /* argument size */
116441
116442 /* operators */
116443 - struct snd_seq_dev_ops ops;
116444 + struct snd_seq_dev_ops *ops;
116445
116446 /* registered devices */
116447 struct list_head dev_list; /* list of devices */
116448 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
116449
116450 mutex_lock(&ops->reg_mutex);
116451 /* copy driver operators */
116452 - ops->ops = *entry;
116453 + ops->ops = entry;
116454 ops->driver |= DRIVER_LOADED;
116455 ops->argsize = argsize;
116456
116457 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
116458 dev->name, ops->id, ops->argsize, dev->argsize);
116459 return -EINVAL;
116460 }
116461 - if (ops->ops.init_device(dev) >= 0) {
116462 + if (ops->ops->init_device(dev) >= 0) {
116463 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
116464 ops->num_init_devices++;
116465 } else {
116466 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
116467 dev->name, ops->id, ops->argsize, dev->argsize);
116468 return -EINVAL;
116469 }
116470 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
116471 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
116472 dev->status = SNDRV_SEQ_DEVICE_FREE;
116473 dev->driver_data = NULL;
116474 ops->num_init_devices--;
116475 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
116476 index a1fd77a..69cd659 100644
116477 --- a/sound/core/seq/seq_midi.c
116478 +++ b/sound/core/seq/seq_midi.c
116479 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
116480 static int __init alsa_seq_midi_init(void)
116481 {
116482 static struct snd_seq_dev_ops ops = {
116483 - snd_seq_midisynth_register_port,
116484 - snd_seq_midisynth_unregister_port,
116485 + .init_device = snd_seq_midisynth_register_port,
116486 + .free_device = snd_seq_midisynth_unregister_port,
116487 };
116488 memset(&synths, 0, sizeof(synths));
116489 snd_seq_autoload_lock();
116490 diff --git a/sound/core/sound.c b/sound/core/sound.c
116491 index 38ad1a0..5010a40 100644
116492 --- a/sound/core/sound.c
116493 +++ b/sound/core/sound.c
116494 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
116495 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
116496 default: return;
116497 }
116498 - request_module(str);
116499 + request_module("%s", str);
116500 }
116501
116502 #endif /* modular kernel */
116503 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
116504 index f5fd448..6ae276da 100644
116505 --- a/sound/drivers/mts64.c
116506 +++ b/sound/drivers/mts64.c
116507 @@ -29,6 +29,7 @@
116508 #include <sound/initval.h>
116509 #include <sound/rawmidi.h>
116510 #include <sound/control.h>
116511 +#include <asm/local.h>
116512
116513 #define CARD_NAME "Miditerminal 4140"
116514 #define DRIVER_NAME "MTS64"
116515 @@ -67,7 +68,7 @@ struct mts64 {
116516 struct pardevice *pardev;
116517 int pardev_claimed;
116518
116519 - int open_count;
116520 + local_t open_count;
116521 int current_midi_output_port;
116522 int current_midi_input_port;
116523 u8 mode[MTS64_NUM_INPUT_PORTS];
116524 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
116525 {
116526 struct mts64 *mts = substream->rmidi->private_data;
116527
116528 - if (mts->open_count == 0) {
116529 + if (local_read(&mts->open_count) == 0) {
116530 /* We don't need a spinlock here, because this is just called
116531 if the device has not been opened before.
116532 So there aren't any IRQs from the device */
116533 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
116534
116535 msleep(50);
116536 }
116537 - ++(mts->open_count);
116538 + local_inc(&mts->open_count);
116539
116540 return 0;
116541 }
116542 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
116543 struct mts64 *mts = substream->rmidi->private_data;
116544 unsigned long flags;
116545
116546 - --(mts->open_count);
116547 - if (mts->open_count == 0) {
116548 + if (local_dec_return(&mts->open_count) == 0) {
116549 /* We need the spinlock_irqsave here because we can still
116550 have IRQs at this point */
116551 spin_lock_irqsave(&mts->lock, flags);
116552 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
116553
116554 msleep(500);
116555
116556 - } else if (mts->open_count < 0)
116557 - mts->open_count = 0;
116558 + } else if (local_read(&mts->open_count) < 0)
116559 + local_set(&mts->open_count, 0);
116560
116561 return 0;
116562 }
116563 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
116564 index 6839953..7a0f4b9 100644
116565 --- a/sound/drivers/opl3/opl3_seq.c
116566 +++ b/sound/drivers/opl3/opl3_seq.c
116567 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
116568 {
116569 static struct snd_seq_dev_ops ops =
116570 {
116571 - snd_opl3_seq_new_device,
116572 - snd_opl3_seq_delete_device
116573 + .init_device = snd_opl3_seq_new_device,
116574 + .free_device = snd_opl3_seq_delete_device
116575 };
116576
116577 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
116578 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
116579 index b953fb4..1999c01 100644
116580 --- a/sound/drivers/opl4/opl4_lib.c
116581 +++ b/sound/drivers/opl4/opl4_lib.c
116582 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
116583 MODULE_DESCRIPTION("OPL4 driver");
116584 MODULE_LICENSE("GPL");
116585
116586 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
116587 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
116588 {
116589 int timeout = 10;
116590 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
116591 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
116592 index 9919769..d7de36c 100644
116593 --- a/sound/drivers/opl4/opl4_seq.c
116594 +++ b/sound/drivers/opl4/opl4_seq.c
116595 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
116596 static int __init alsa_opl4_synth_init(void)
116597 {
116598 static struct snd_seq_dev_ops ops = {
116599 - snd_opl4_seq_new_device,
116600 - snd_opl4_seq_delete_device
116601 + .init_device = snd_opl4_seq_new_device,
116602 + .free_device = snd_opl4_seq_delete_device
116603 };
116604
116605 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
116606 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
116607 index 78ccfa4..7a0857b 100644
116608 --- a/sound/drivers/portman2x4.c
116609 +++ b/sound/drivers/portman2x4.c
116610 @@ -48,6 +48,7 @@
116611 #include <sound/initval.h>
116612 #include <sound/rawmidi.h>
116613 #include <sound/control.h>
116614 +#include <asm/local.h>
116615
116616 #define CARD_NAME "Portman 2x4"
116617 #define DRIVER_NAME "portman"
116618 @@ -85,7 +86,7 @@ struct portman {
116619 struct pardevice *pardev;
116620 int pardev_claimed;
116621
116622 - int open_count;
116623 + local_t open_count;
116624 int mode[PORTMAN_NUM_INPUT_PORTS];
116625 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
116626 };
116627 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
116628 index f96bf4c..f3bd1e0 100644
116629 --- a/sound/firewire/amdtp.c
116630 +++ b/sound/firewire/amdtp.c
116631 @@ -512,7 +512,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
116632 ptr = s->pcm_buffer_pointer + frames;
116633 if (ptr >= pcm->runtime->buffer_size)
116634 ptr -= pcm->runtime->buffer_size;
116635 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
116636 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
116637
116638 s->pcm_period_pointer += frames;
116639 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
116640 @@ -952,7 +952,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
116641 */
116642 void amdtp_stream_update(struct amdtp_stream *s)
116643 {
116644 - ACCESS_ONCE(s->source_node_id_field) =
116645 + ACCESS_ONCE_RW(s->source_node_id_field) =
116646 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
116647 }
116648 EXPORT_SYMBOL(amdtp_stream_update);
116649 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
116650 index d8ee7b0..79dfa2a 100644
116651 --- a/sound/firewire/amdtp.h
116652 +++ b/sound/firewire/amdtp.h
116653 @@ -211,7 +211,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
116654 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
116655 struct snd_pcm_substream *pcm)
116656 {
116657 - ACCESS_ONCE(s->pcm) = pcm;
116658 + ACCESS_ONCE_RW(s->pcm) = pcm;
116659 }
116660
116661 /**
116662 @@ -229,7 +229,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
116663 struct snd_rawmidi_substream *midi)
116664 {
116665 if (port < s->midi_ports)
116666 - ACCESS_ONCE(s->midi[port]) = midi;
116667 + ACCESS_ONCE_RW(s->midi[port]) = midi;
116668 }
116669
116670 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
116671 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
116672 index 7ac9443..0ec6274 100644
116673 --- a/sound/firewire/isight.c
116674 +++ b/sound/firewire/isight.c
116675 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
116676 ptr += count;
116677 if (ptr >= runtime->buffer_size)
116678 ptr -= runtime->buffer_size;
116679 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
116680 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
116681
116682 isight->period_counter += count;
116683 if (isight->period_counter >= runtime->period_size) {
116684 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
116685 if (err < 0)
116686 return err;
116687
116688 - ACCESS_ONCE(isight->pcm_active) = true;
116689 + ACCESS_ONCE_RW(isight->pcm_active) = true;
116690
116691 return 0;
116692 }
116693 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
116694 {
116695 struct isight *isight = substream->private_data;
116696
116697 - ACCESS_ONCE(isight->pcm_active) = false;
116698 + ACCESS_ONCE_RW(isight->pcm_active) = false;
116699
116700 mutex_lock(&isight->mutex);
116701 isight_stop_streaming(isight);
116702 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
116703
116704 switch (cmd) {
116705 case SNDRV_PCM_TRIGGER_START:
116706 - ACCESS_ONCE(isight->pcm_running) = true;
116707 + ACCESS_ONCE_RW(isight->pcm_running) = true;
116708 break;
116709 case SNDRV_PCM_TRIGGER_STOP:
116710 - ACCESS_ONCE(isight->pcm_running) = false;
116711 + ACCESS_ONCE_RW(isight->pcm_running) = false;
116712 break;
116713 default:
116714 return -EINVAL;
116715 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
116716 index 2dba848..c682aef 100644
116717 --- a/sound/firewire/scs1x.c
116718 +++ b/sound/firewire/scs1x.c
116719 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
116720 {
116721 struct scs *scs = stream->rmidi->private_data;
116722
116723 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
116724 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
116725 if (up) {
116726 scs->output_idle = false;
116727 tasklet_schedule(&scs->tasklet);
116728 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
116729 {
116730 struct scs *scs = stream->rmidi->private_data;
116731
116732 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
116733 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
116734 }
116735
116736 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
116737 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
116738
116739 snd_card_disconnect(scs->card);
116740
116741 - ACCESS_ONCE(scs->output) = NULL;
116742 - ACCESS_ONCE(scs->input) = NULL;
116743 + ACCESS_ONCE_RW(scs->output) = NULL;
116744 + ACCESS_ONCE_RW(scs->input) = NULL;
116745
116746 wait_event(scs->idle_wait, scs->output_idle);
116747
116748 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
116749 index 4e3fcfb..ab45a9d 100644
116750 --- a/sound/isa/sb/emu8000_synth.c
116751 +++ b/sound/isa/sb/emu8000_synth.c
116752 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
116753 {
116754
116755 static struct snd_seq_dev_ops ops = {
116756 - snd_emu8000_new_device,
116757 - snd_emu8000_delete_device,
116758 + .init_device = snd_emu8000_new_device,
116759 + .free_device = snd_emu8000_delete_device,
116760 };
116761 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
116762 sizeof(struct snd_emu8000*));
116763 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
116764 index 048439a..3be9f6f 100644
116765 --- a/sound/oss/sb_audio.c
116766 +++ b/sound/oss/sb_audio.c
116767 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
116768 buf16 = (signed short *)(localbuf + localoffs);
116769 while (c)
116770 {
116771 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
116772 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
116773 if (copy_from_user(lbuf8,
116774 userbuf+useroffs + p,
116775 locallen))
116776 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
116777 index a33e8ce..2262303 100644
116778 --- a/sound/oss/swarm_cs4297a.c
116779 +++ b/sound/oss/swarm_cs4297a.c
116780 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
116781 {
116782 struct cs4297a_state *s;
116783 u32 pwr, id;
116784 - mm_segment_t fs;
116785 int rval;
116786 u64 cfg;
116787 int mdio_val;
116788 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
116789 if (!rval) {
116790 char *sb1250_duart_present;
116791
116792 +#if 0
116793 + mm_segment_t fs;
116794 fs = get_fs();
116795 set_fs(KERNEL_DS);
116796 -#if 0
116797 val = SOUND_MASK_LINE;
116798 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
116799 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
116800 val = initvol[i].vol;
116801 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
116802 }
116803 + set_fs(fs);
116804 // cs4297a_write_ac97(s, 0x18, 0x0808);
116805 #else
116806 // cs4297a_write_ac97(s, 0x5e, 0x180);
116807 cs4297a_write_ac97(s, 0x02, 0x0808);
116808 cs4297a_write_ac97(s, 0x18, 0x0808);
116809 #endif
116810 - set_fs(fs);
116811
116812 list_add(&s->list, &cs4297a_devs);
116813
116814 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
116815 index 4c41c90..37f3631 100644
116816 --- a/sound/pci/emu10k1/emu10k1_synth.c
116817 +++ b/sound/pci/emu10k1/emu10k1_synth.c
116818 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
116819 {
116820
116821 static struct snd_seq_dev_ops ops = {
116822 - snd_emu10k1_synth_new_device,
116823 - snd_emu10k1_synth_delete_device,
116824 + .init_device = snd_emu10k1_synth_new_device,
116825 + .free_device = snd_emu10k1_synth_delete_device,
116826 };
116827 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
116828 sizeof(struct snd_emu10k1_synth_arg));
116829 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
116830 index 4c20277..91abdce 100644
116831 --- a/sound/pci/hda/hda_codec.c
116832 +++ b/sound/pci/hda/hda_codec.c
116833 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
116834 mutex_unlock(&preset_mutex);
116835
116836 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
116837 - char name[32];
116838 if (!mod_requested)
116839 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
116840 - codec->vendor_id);
116841 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
116842 else
116843 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
116844 - (codec->vendor_id >> 16) & 0xffff);
116845 - request_module(name);
116846 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
116847 mod_requested++;
116848 goto again;
116849 }
116850 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
116851 /* FIXME: set_fs() hack for obtaining user-space TLV data */
116852 mm_segment_t fs = get_fs();
116853 set_fs(get_ds());
116854 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
116855 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
116856 tlv = _tlv;
116857 set_fs(fs);
116858 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
116859 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
116860 index 4631a23..001ae57 100644
116861 --- a/sound/pci/ymfpci/ymfpci.h
116862 +++ b/sound/pci/ymfpci/ymfpci.h
116863 @@ -358,7 +358,7 @@ struct snd_ymfpci {
116864 spinlock_t reg_lock;
116865 spinlock_t voice_lock;
116866 wait_queue_head_t interrupt_sleep;
116867 - atomic_t interrupt_sleep_count;
116868 + atomic_unchecked_t interrupt_sleep_count;
116869 struct snd_info_entry *proc_entry;
116870 const struct firmware *dsp_microcode;
116871 const struct firmware *controller_microcode;
116872 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
116873 index 81c916a..516f0bf 100644
116874 --- a/sound/pci/ymfpci/ymfpci_main.c
116875 +++ b/sound/pci/ymfpci/ymfpci_main.c
116876 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
116877 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
116878 break;
116879 }
116880 - if (atomic_read(&chip->interrupt_sleep_count)) {
116881 - atomic_set(&chip->interrupt_sleep_count, 0);
116882 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
116883 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
116884 wake_up(&chip->interrupt_sleep);
116885 }
116886 __end:
116887 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
116888 continue;
116889 init_waitqueue_entry(&wait, current);
116890 add_wait_queue(&chip->interrupt_sleep, &wait);
116891 - atomic_inc(&chip->interrupt_sleep_count);
116892 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
116893 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
116894 remove_wait_queue(&chip->interrupt_sleep, &wait);
116895 }
116896 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
116897 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
116898 spin_unlock(&chip->reg_lock);
116899
116900 - if (atomic_read(&chip->interrupt_sleep_count)) {
116901 - atomic_set(&chip->interrupt_sleep_count, 0);
116902 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
116903 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
116904 wake_up(&chip->interrupt_sleep);
116905 }
116906 }
116907 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
116908 spin_lock_init(&chip->reg_lock);
116909 spin_lock_init(&chip->voice_lock);
116910 init_waitqueue_head(&chip->interrupt_sleep);
116911 - atomic_set(&chip->interrupt_sleep_count, 0);
116912 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
116913 chip->card = card;
116914 chip->pci = pci;
116915 chip->irq = -1;
116916 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
116917 index b87d7d8..0ccaac3 100644
116918 --- a/sound/soc/soc-core.c
116919 +++ b/sound/soc/soc-core.c
116920 @@ -2279,8 +2279,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
116921 if (ret)
116922 return ret;
116923
116924 - ops->warm_reset = snd_soc_ac97_warm_reset;
116925 - ops->reset = snd_soc_ac97_reset;
116926 + pax_open_kernel();
116927 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
116928 + *(void **)&ops->reset = snd_soc_ac97_reset;
116929 + pax_close_kernel();
116930
116931 snd_ac97_rst_cfg = cfg;
116932 return 0;
116933 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
116934 index 7778b8e..3d619fc 100644
116935 --- a/sound/synth/emux/emux_seq.c
116936 +++ b/sound/synth/emux/emux_seq.c
116937 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
116938 * MIDI emulation operators
116939 */
116940 static struct snd_midi_op emux_ops = {
116941 - snd_emux_note_on,
116942 - snd_emux_note_off,
116943 - snd_emux_key_press,
116944 - snd_emux_terminate_note,
116945 - snd_emux_control,
116946 - snd_emux_nrpn,
116947 - snd_emux_sysex,
116948 + .note_on = snd_emux_note_on,
116949 + .note_off = snd_emux_note_off,
116950 + .key_press = snd_emux_key_press,
116951 + .note_terminate = snd_emux_terminate_note,
116952 + .control = snd_emux_control,
116953 + .nrpn = snd_emux_nrpn,
116954 + .sysex = snd_emux_sysex,
116955 };
116956
116957
116958 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
116959 new file mode 100644
116960 index 0000000..de92ed9
116961 --- /dev/null
116962 +++ b/tools/gcc/.gitignore
116963 @@ -0,0 +1 @@
116964 +randomize_layout_seed.h
116965 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
116966 new file mode 100644
116967 index 0000000..7b8921f
116968 --- /dev/null
116969 +++ b/tools/gcc/Makefile
116970 @@ -0,0 +1,52 @@
116971 +#CC := gcc
116972 +#PLUGIN_SOURCE_FILES := pax_plugin.c
116973 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
116974 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
116975 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
116976 +
116977 +ifeq ($(PLUGINCC),$(HOSTCC))
116978 +HOSTLIBS := hostlibs
116979 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
116980 +export HOST_EXTRACFLAGS
116981 +else
116982 +HOSTLIBS := hostcxxlibs
116983 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
116984 +export HOST_EXTRACXXFLAGS
116985 +endif
116986 +
116987 +export GCCPLUGINS_DIR HOSTLIBS
116988 +
116989 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
116990 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
116991 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
116992 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
116993 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
116994 +$(HOSTLIBS)-y += colorize_plugin.so
116995 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
116996 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
116997 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
116998 +
116999 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
117000 +subdir- += size_overflow_plugin
117001 +
117002 +always := $($(HOSTLIBS)-y)
117003 +
117004 +constify_plugin-objs := constify_plugin.o
117005 +stackleak_plugin-objs := stackleak_plugin.o
117006 +kallocstat_plugin-objs := kallocstat_plugin.o
117007 +kernexec_plugin-objs := kernexec_plugin.o
117008 +checker_plugin-objs := checker_plugin.o
117009 +colorize_plugin-objs := colorize_plugin.o
117010 +latent_entropy_plugin-objs := latent_entropy_plugin.o
117011 +structleak_plugin-objs := structleak_plugin.o
117012 +randomize_layout_plugin-objs := randomize_layout_plugin.o
117013 +
117014 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
117015 +
117016 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
117017 + cmd_create_randomize_layout_seed = \
117018 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
117019 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
117020 + $(call if_changed,create_randomize_layout_seed)
117021 +
117022 +targets += randomize_layout_seed.h randomize_layout_hash.h
117023 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
117024 new file mode 100644
117025 index 0000000..5452feea
117026 --- /dev/null
117027 +++ b/tools/gcc/checker_plugin.c
117028 @@ -0,0 +1,150 @@
117029 +/*
117030 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
117031 + * Licensed under the GPL v2
117032 + *
117033 + * Note: the choice of the license means that the compilation process is
117034 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117035 + * but for the kernel it doesn't matter since it doesn't link against
117036 + * any of the gcc libraries
117037 + *
117038 + * gcc plugin to implement various sparse (source code checker) features
117039 + *
117040 + * TODO:
117041 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
117042 + *
117043 + * BUGS:
117044 + * - none known
117045 + */
117046 +
117047 +#include "gcc-common.h"
117048 +
117049 +extern void c_register_addr_space (const char *str, addr_space_t as);
117050 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
117051 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
117052 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
117053 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
117054 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
117055 +
117056 +int plugin_is_GPL_compatible;
117057 +
117058 +static struct plugin_info checker_plugin_info = {
117059 + .version = "201304082245",
117060 + .help = NULL,
117061 +};
117062 +
117063 +#define ADDR_SPACE_KERNEL 0
117064 +#define ADDR_SPACE_FORCE_KERNEL 1
117065 +#define ADDR_SPACE_USER 2
117066 +#define ADDR_SPACE_FORCE_USER 3
117067 +#define ADDR_SPACE_IOMEM 0
117068 +#define ADDR_SPACE_FORCE_IOMEM 0
117069 +#define ADDR_SPACE_PERCPU 0
117070 +#define ADDR_SPACE_FORCE_PERCPU 0
117071 +#define ADDR_SPACE_RCU 0
117072 +#define ADDR_SPACE_FORCE_RCU 0
117073 +
117074 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
117075 +{
117076 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
117077 +}
117078 +
117079 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
117080 +{
117081 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
117082 +}
117083 +
117084 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
117085 +{
117086 + return default_addr_space_valid_pointer_mode(mode, as);
117087 +}
117088 +
117089 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
117090 +{
117091 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
117092 +}
117093 +
117094 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
117095 +{
117096 + return default_addr_space_legitimize_address(x, oldx, mode, as);
117097 +}
117098 +
117099 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
117100 +{
117101 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
117102 + return true;
117103 +
117104 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
117105 + return true;
117106 +
117107 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
117108 + return true;
117109 +
117110 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
117111 + return true;
117112 +
117113 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
117114 + return true;
117115 +
117116 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
117117 + return true;
117118 +
117119 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
117120 + return true;
117121 +
117122 + return subset == superset;
117123 +}
117124 +
117125 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
117126 +{
117127 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
117128 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
117129 +
117130 + return op;
117131 +}
117132 +
117133 +static void register_checker_address_spaces(void *event_data, void *data)
117134 +{
117135 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
117136 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
117137 + c_register_addr_space("__user", ADDR_SPACE_USER);
117138 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
117139 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
117140 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
117141 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
117142 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
117143 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
117144 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
117145 +
117146 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
117147 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
117148 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
117149 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
117150 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
117151 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
117152 + targetm.addr_space.convert = checker_addr_space_convert;
117153 +}
117154 +
117155 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117156 +{
117157 + const char * const plugin_name = plugin_info->base_name;
117158 + const int argc = plugin_info->argc;
117159 + const struct plugin_argument * const argv = plugin_info->argv;
117160 + int i;
117161 +
117162 + if (!plugin_default_version_check(version, &gcc_version)) {
117163 + error(G_("incompatible gcc/plugin versions"));
117164 + return 1;
117165 + }
117166 +
117167 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
117168 +
117169 + for (i = 0; i < argc; ++i)
117170 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117171 +
117172 + if (TARGET_64BIT == 0)
117173 + return 0;
117174 +
117175 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
117176 +
117177 + return 0;
117178 +}
117179 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
117180 new file mode 100644
117181 index 0000000..54461af
117182 --- /dev/null
117183 +++ b/tools/gcc/colorize_plugin.c
117184 @@ -0,0 +1,210 @@
117185 +/*
117186 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
117187 + * Licensed under the GPL v2
117188 + *
117189 + * Note: the choice of the license means that the compilation process is
117190 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117191 + * but for the kernel it doesn't matter since it doesn't link against
117192 + * any of the gcc libraries
117193 + *
117194 + * gcc plugin to colorize diagnostic output
117195 + *
117196 + */
117197 +
117198 +#include "gcc-common.h"
117199 +
117200 +int plugin_is_GPL_compatible;
117201 +
117202 +static struct plugin_info colorize_plugin_info = {
117203 + .version = "201404202350",
117204 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
117205 +};
117206 +
117207 +#define GREEN "\033[32m\033[K"
117208 +#define LIGHTGREEN "\033[1;32m\033[K"
117209 +#define YELLOW "\033[33m\033[K"
117210 +#define LIGHTYELLOW "\033[1;33m\033[K"
117211 +#define RED "\033[31m\033[K"
117212 +#define LIGHTRED "\033[1;31m\033[K"
117213 +#define BLUE "\033[34m\033[K"
117214 +#define LIGHTBLUE "\033[1;34m\033[K"
117215 +#define BRIGHT "\033[1;m\033[K"
117216 +#define NORMAL "\033[m\033[K"
117217 +
117218 +static diagnostic_starter_fn old_starter;
117219 +static diagnostic_finalizer_fn old_finalizer;
117220 +
117221 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
117222 +{
117223 + const char *color;
117224 + char *newprefix;
117225 +
117226 + switch (diagnostic->kind) {
117227 + case DK_NOTE:
117228 + color = LIGHTBLUE;
117229 + break;
117230 +
117231 + case DK_PEDWARN:
117232 + case DK_WARNING:
117233 + color = LIGHTYELLOW;
117234 + break;
117235 +
117236 + case DK_ERROR:
117237 + case DK_FATAL:
117238 + case DK_ICE:
117239 + case DK_PERMERROR:
117240 + case DK_SORRY:
117241 + color = LIGHTRED;
117242 + break;
117243 +
117244 + default:
117245 + color = NORMAL;
117246 + }
117247 +
117248 + old_starter(context, diagnostic);
117249 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
117250 + return;
117251 + pp_destroy_prefix(context->printer);
117252 + pp_set_prefix(context->printer, newprefix);
117253 +}
117254 +
117255 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
117256 +{
117257 + old_finalizer(context, diagnostic);
117258 +}
117259 +
117260 +static void colorize_arm(void)
117261 +{
117262 + old_starter = diagnostic_starter(global_dc);
117263 + old_finalizer = diagnostic_finalizer(global_dc);
117264 +
117265 + diagnostic_starter(global_dc) = start_colorize;
117266 + diagnostic_finalizer(global_dc) = finalize_colorize;
117267 +}
117268 +
117269 +static unsigned int execute_colorize_rearm(void)
117270 +{
117271 + if (diagnostic_starter(global_dc) == start_colorize)
117272 + return 0;
117273 +
117274 + colorize_arm();
117275 + return 0;
117276 +}
117277 +
117278 +#if BUILDING_GCC_VERSION >= 4009
117279 +static const struct pass_data colorize_rearm_pass_data = {
117280 +#else
117281 +struct simple_ipa_opt_pass colorize_rearm_pass = {
117282 + .pass = {
117283 +#endif
117284 + .type = SIMPLE_IPA_PASS,
117285 + .name = "colorize_rearm",
117286 +#if BUILDING_GCC_VERSION >= 4008
117287 + .optinfo_flags = OPTGROUP_NONE,
117288 +#endif
117289 +#if BUILDING_GCC_VERSION >= 4009
117290 + .has_gate = false,
117291 + .has_execute = true,
117292 +#else
117293 + .gate = NULL,
117294 + .execute = execute_colorize_rearm,
117295 + .sub = NULL,
117296 + .next = NULL,
117297 + .static_pass_number = 0,
117298 +#endif
117299 + .tv_id = TV_NONE,
117300 + .properties_required = 0,
117301 + .properties_provided = 0,
117302 + .properties_destroyed = 0,
117303 + .todo_flags_start = 0,
117304 + .todo_flags_finish = 0
117305 +#if BUILDING_GCC_VERSION < 4009
117306 + }
117307 +#endif
117308 +};
117309 +
117310 +#if BUILDING_GCC_VERSION >= 4009
117311 +namespace {
117312 +class colorize_rearm_pass : public simple_ipa_opt_pass {
117313 +public:
117314 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
117315 + unsigned int execute() { return execute_colorize_rearm(); }
117316 +};
117317 +}
117318 +
117319 +static opt_pass *make_colorize_rearm_pass(void)
117320 +{
117321 + return new colorize_rearm_pass();
117322 +}
117323 +#else
117324 +static struct opt_pass *make_colorize_rearm_pass(void)
117325 +{
117326 + return &colorize_rearm_pass.pass;
117327 +}
117328 +#endif
117329 +
117330 +static void colorize_start_unit(void *gcc_data, void *user_data)
117331 +{
117332 + colorize_arm();
117333 +}
117334 +
117335 +static bool should_colorize(void)
117336 +{
117337 +#if BUILDING_GCC_VERSION >= 4009
117338 + return false;
117339 +#else
117340 + char const *t = getenv("TERM");
117341 +
117342 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
117343 +#endif
117344 +}
117345 +
117346 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117347 +{
117348 + const char * const plugin_name = plugin_info->base_name;
117349 + const int argc = plugin_info->argc;
117350 + const struct plugin_argument * const argv = plugin_info->argv;
117351 + int i;
117352 + struct register_pass_info colorize_rearm_pass_info;
117353 + bool colorize;
117354 +
117355 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
117356 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
117357 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
117358 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117359 +
117360 + if (!plugin_default_version_check(version, &gcc_version)) {
117361 + error(G_("incompatible gcc/plugin versions"));
117362 + return 1;
117363 + }
117364 +
117365 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
117366 +
117367 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
117368 +
117369 + for (i = 0; i < argc; ++i) {
117370 + if (!strcmp(argv[i].key, "color")) {
117371 + if (!argv[i].value) {
117372 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117373 + continue;
117374 + }
117375 + if (!strcmp(argv[i].value, "always"))
117376 + colorize = true;
117377 + else if (!strcmp(argv[i].value, "never"))
117378 + colorize = false;
117379 + else if (!strcmp(argv[i].value, "auto"))
117380 + colorize = should_colorize();
117381 + else
117382 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117383 + continue;
117384 + }
117385 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117386 + }
117387 +
117388 + if (colorize) {
117389 + // TODO: parse GCC_COLORS as used by gcc 4.9+
117390 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
117391 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
117392 + }
117393 + return 0;
117394 +}
117395 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
117396 new file mode 100644
117397 index 0000000..82bc5a8
117398 --- /dev/null
117399 +++ b/tools/gcc/constify_plugin.c
117400 @@ -0,0 +1,557 @@
117401 +/*
117402 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
117403 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
117404 + * Licensed under the GPL v2, or (at your option) v3
117405 + *
117406 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
117407 + *
117408 + * Homepage:
117409 + * http://www.grsecurity.net/~ephox/const_plugin/
117410 + *
117411 + * Usage:
117412 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
117413 + * $ gcc -fplugin=constify_plugin.so test.c -O2
117414 + */
117415 +
117416 +#include "gcc-common.h"
117417 +
117418 +// unused C type flag in all versions 4.5-4.9
117419 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
117420 +
117421 +int plugin_is_GPL_compatible;
117422 +
117423 +static struct plugin_info const_plugin_info = {
117424 + .version = "201401270210",
117425 + .help = "no-constify\tturn off constification\n",
117426 +};
117427 +
117428 +typedef struct {
117429 + bool has_fptr_field;
117430 + bool has_writable_field;
117431 + bool has_do_const_field;
117432 + bool has_no_const_field;
117433 +} constify_info;
117434 +
117435 +static const_tree get_field_type(const_tree field)
117436 +{
117437 + return strip_array_types(TREE_TYPE(field));
117438 +}
117439 +
117440 +static bool is_fptr(const_tree field)
117441 +{
117442 + const_tree ptr = get_field_type(field);
117443 +
117444 + if (TREE_CODE(ptr) != POINTER_TYPE)
117445 + return false;
117446 +
117447 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
117448 +}
117449 +
117450 +/*
117451 + * determine whether the given structure type meets the requirements for automatic constification,
117452 + * including the constification attributes on nested structure types
117453 + */
117454 +static void constifiable(const_tree node, constify_info *cinfo)
117455 +{
117456 + const_tree field;
117457 +
117458 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
117459 +
117460 + // e.g., pointer to structure fields while still constructing the structure type
117461 + if (TYPE_FIELDS(node) == NULL_TREE)
117462 + return;
117463 +
117464 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
117465 + const_tree type = get_field_type(field);
117466 + enum tree_code code = TREE_CODE(type);
117467 +
117468 + if (node == type)
117469 + continue;
117470 +
117471 + if (is_fptr(field))
117472 + cinfo->has_fptr_field = true;
117473 + else if (!TREE_READONLY(field))
117474 + cinfo->has_writable_field = true;
117475 +
117476 + if (code == RECORD_TYPE || code == UNION_TYPE) {
117477 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
117478 + cinfo->has_do_const_field = true;
117479 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
117480 + cinfo->has_no_const_field = true;
117481 + else
117482 + constifiable(type, cinfo);
117483 + }
117484 + }
117485 +}
117486 +
117487 +static bool constified(const_tree node)
117488 +{
117489 + constify_info cinfo = {
117490 + .has_fptr_field = false,
117491 + .has_writable_field = false,
117492 + .has_do_const_field = false,
117493 + .has_no_const_field = false
117494 + };
117495 +
117496 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
117497 +
117498 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
117499 +// gcc_assert(!TYPE_READONLY(node));
117500 + return false;
117501 + }
117502 +
117503 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
117504 + gcc_assert(TYPE_READONLY(node));
117505 + return true;
117506 + }
117507 +
117508 + constifiable(node, &cinfo);
117509 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
117510 + return false;
117511 +
117512 + return TYPE_READONLY(node);
117513 +}
117514 +
117515 +static void deconstify_tree(tree node);
117516 +
117517 +static void deconstify_type(tree type)
117518 +{
117519 + tree field;
117520 +
117521 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
117522 +
117523 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
117524 + const_tree fieldtype = get_field_type(field);
117525 +
117526 + // special case handling of simple ptr-to-same-array-type members
117527 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
117528 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
117529 +
117530 + if (TREE_TYPE(TREE_TYPE(field)) == type)
117531 + continue;
117532 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
117533 + continue;
117534 + if (!constified(ptrtype))
117535 + continue;
117536 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
117537 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
117538 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
117539 + }
117540 + continue;
117541 + }
117542 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
117543 + continue;
117544 + if (!constified(fieldtype))
117545 + continue;
117546 +
117547 + deconstify_tree(field);
117548 + TREE_READONLY(field) = 0;
117549 + }
117550 + TYPE_READONLY(type) = 0;
117551 + C_TYPE_FIELDS_READONLY(type) = 0;
117552 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
117553 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
117554 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
117555 + }
117556 +}
117557 +
117558 +static void deconstify_tree(tree node)
117559 +{
117560 + tree old_type, new_type, field;
117561 +
117562 + old_type = TREE_TYPE(node);
117563 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
117564 + node = TREE_TYPE(node) = copy_node(old_type);
117565 + old_type = TREE_TYPE(old_type);
117566 + }
117567 +
117568 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
117569 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
117570 +
117571 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
117572 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
117573 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
117574 + DECL_FIELD_CONTEXT(field) = new_type;
117575 +
117576 + deconstify_type(new_type);
117577 +
117578 + TREE_TYPE(node) = new_type;
117579 +}
117580 +
117581 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117582 +{
117583 + tree type;
117584 + constify_info cinfo = {
117585 + .has_fptr_field = false,
117586 + .has_writable_field = false,
117587 + .has_do_const_field = false,
117588 + .has_no_const_field = false
117589 + };
117590 +
117591 + *no_add_attrs = true;
117592 + if (TREE_CODE(*node) == FUNCTION_DECL) {
117593 + error("%qE attribute does not apply to functions (%qF)", name, *node);
117594 + return NULL_TREE;
117595 + }
117596 +
117597 + if (TREE_CODE(*node) == PARM_DECL) {
117598 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
117599 + return NULL_TREE;
117600 + }
117601 +
117602 + if (TREE_CODE(*node) == VAR_DECL) {
117603 + error("%qE attribute does not apply to variables (%qD)", name, *node);
117604 + return NULL_TREE;
117605 + }
117606 +
117607 + if (TYPE_P(*node)) {
117608 + type = *node;
117609 + } else {
117610 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
117611 + type = TREE_TYPE(*node);
117612 + }
117613 +
117614 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
117615 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
117616 + return NULL_TREE;
117617 + }
117618 +
117619 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
117620 + error("%qE attribute is already applied to the type %qT", name, type);
117621 + return NULL_TREE;
117622 + }
117623 +
117624 + if (TYPE_P(*node)) {
117625 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
117626 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
117627 + else
117628 + *no_add_attrs = false;
117629 + return NULL_TREE;
117630 + }
117631 +
117632 + constifiable(type, &cinfo);
117633 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
117634 + deconstify_tree(*node);
117635 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
117636 + return NULL_TREE;
117637 + }
117638 +
117639 + error("%qE attribute used on type %qT that is not constified", name, type);
117640 + return NULL_TREE;
117641 +}
117642 +
117643 +static void constify_type(tree type)
117644 +{
117645 + TYPE_READONLY(type) = 1;
117646 + C_TYPE_FIELDS_READONLY(type) = 1;
117647 + TYPE_CONSTIFY_VISITED(type) = 1;
117648 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
117649 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
117650 +}
117651 +
117652 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117653 +{
117654 + *no_add_attrs = true;
117655 + if (!TYPE_P(*node)) {
117656 + error("%qE attribute applies to types only (%qD)", name, *node);
117657 + return NULL_TREE;
117658 + }
117659 +
117660 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
117661 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
117662 + return NULL_TREE;
117663 + }
117664 +
117665 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
117666 + error("%qE attribute used on %qT is already applied to the type", name, *node);
117667 + return NULL_TREE;
117668 + }
117669 +
117670 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
117671 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
117672 + return NULL_TREE;
117673 + }
117674 +
117675 + *no_add_attrs = false;
117676 + return NULL_TREE;
117677 +}
117678 +
117679 +static struct attribute_spec no_const_attr = {
117680 + .name = "no_const",
117681 + .min_length = 0,
117682 + .max_length = 0,
117683 + .decl_required = false,
117684 + .type_required = false,
117685 + .function_type_required = false,
117686 + .handler = handle_no_const_attribute,
117687 +#if BUILDING_GCC_VERSION >= 4007
117688 + .affects_type_identity = true
117689 +#endif
117690 +};
117691 +
117692 +static struct attribute_spec do_const_attr = {
117693 + .name = "do_const",
117694 + .min_length = 0,
117695 + .max_length = 0,
117696 + .decl_required = false,
117697 + .type_required = false,
117698 + .function_type_required = false,
117699 + .handler = handle_do_const_attribute,
117700 +#if BUILDING_GCC_VERSION >= 4007
117701 + .affects_type_identity = true
117702 +#endif
117703 +};
117704 +
117705 +static void register_attributes(void *event_data, void *data)
117706 +{
117707 + register_attribute(&no_const_attr);
117708 + register_attribute(&do_const_attr);
117709 +}
117710 +
117711 +static void finish_type(void *event_data, void *data)
117712 +{
117713 + tree type = (tree)event_data;
117714 + constify_info cinfo = {
117715 + .has_fptr_field = false,
117716 + .has_writable_field = false,
117717 + .has_do_const_field = false,
117718 + .has_no_const_field = false
117719 + };
117720 +
117721 + if (type == NULL_TREE || type == error_mark_node)
117722 + return;
117723 +
117724 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
117725 + return;
117726 +
117727 + constifiable(type, &cinfo);
117728 +
117729 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
117730 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
117731 + deconstify_type(type);
117732 + TYPE_CONSTIFY_VISITED(type) = 1;
117733 + } else
117734 + error("'no_const' attribute used on type %qT that is not constified", type);
117735 + return;
117736 + }
117737 +
117738 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
117739 + if (!cinfo.has_writable_field) {
117740 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
117741 + return;
117742 + }
117743 + constify_type(type);
117744 + return;
117745 + }
117746 +
117747 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
117748 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
117749 + error("'do_const' attribute used on type %qT that is constified", type);
117750 + return;
117751 + }
117752 + constify_type(type);
117753 + return;
117754 + }
117755 +
117756 + deconstify_type(type);
117757 + TYPE_CONSTIFY_VISITED(type) = 1;
117758 +}
117759 +
117760 +static void check_global_variables(void *event_data, void *data)
117761 +{
117762 +#if BUILDING_GCC_VERSION >= 4009
117763 + varpool_node *node;
117764 +#else
117765 + struct varpool_node *node;
117766 +#endif
117767 +
117768 + FOR_EACH_VARIABLE(node) {
117769 + tree var = NODE_DECL(node);
117770 + tree type = TREE_TYPE(var);
117771 +
117772 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
117773 + continue;
117774 +
117775 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
117776 + continue;
117777 +
117778 + if (!TYPE_CONSTIFY_VISITED(type))
117779 + continue;
117780 +
117781 + if (DECL_EXTERNAL(var))
117782 + continue;
117783 +
117784 + if (DECL_INITIAL(var))
117785 + continue;
117786 +
117787 + // this works around a gcc bug/feature where uninitialized globals
117788 + // are moved into the .bss section regardless of any constification
117789 + DECL_INITIAL(var) = build_constructor(type, NULL);
117790 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
117791 + }
117792 +}
117793 +
117794 +static unsigned int check_local_variables(void)
117795 +{
117796 + unsigned int ret = 0;
117797 + tree var;
117798 +
117799 + unsigned int i;
117800 +
117801 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
117802 + tree type = TREE_TYPE(var);
117803 +
117804 + gcc_assert(DECL_P(var));
117805 + if (is_global_var(var))
117806 + continue;
117807 +
117808 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
117809 + continue;
117810 +
117811 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
117812 + continue;
117813 +
117814 + if (!TYPE_CONSTIFY_VISITED(type))
117815 + continue;
117816 +
117817 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
117818 + ret = 1;
117819 + }
117820 + return ret;
117821 +}
117822 +
117823 +#if BUILDING_GCC_VERSION >= 4009
117824 +static const struct pass_data check_local_variables_pass_data = {
117825 +#else
117826 +static struct gimple_opt_pass check_local_variables_pass = {
117827 + .pass = {
117828 +#endif
117829 + .type = GIMPLE_PASS,
117830 + .name = "check_local_variables",
117831 +#if BUILDING_GCC_VERSION >= 4008
117832 + .optinfo_flags = OPTGROUP_NONE,
117833 +#endif
117834 +#if BUILDING_GCC_VERSION >= 4009
117835 + .has_gate = false,
117836 + .has_execute = true,
117837 +#else
117838 + .gate = NULL,
117839 + .execute = check_local_variables,
117840 + .sub = NULL,
117841 + .next = NULL,
117842 + .static_pass_number = 0,
117843 +#endif
117844 + .tv_id = TV_NONE,
117845 + .properties_required = 0,
117846 + .properties_provided = 0,
117847 + .properties_destroyed = 0,
117848 + .todo_flags_start = 0,
117849 + .todo_flags_finish = 0
117850 +#if BUILDING_GCC_VERSION < 4009
117851 + }
117852 +#endif
117853 +};
117854 +
117855 +#if BUILDING_GCC_VERSION >= 4009
117856 +namespace {
117857 +class check_local_variables_pass : public gimple_opt_pass {
117858 +public:
117859 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
117860 + unsigned int execute() { return check_local_variables(); }
117861 +};
117862 +}
117863 +
117864 +static opt_pass *make_check_local_variables_pass(void)
117865 +{
117866 + return new check_local_variables_pass();
117867 +}
117868 +#else
117869 +static struct opt_pass *make_check_local_variables_pass(void)
117870 +{
117871 + return &check_local_variables_pass.pass;
117872 +}
117873 +#endif
117874 +
117875 +static struct {
117876 + const char *name;
117877 + const char *asm_op;
117878 +} sections[] = {
117879 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
117880 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
117881 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
117882 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
117883 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
117884 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
117885 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
117886 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
117887 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
117888 +};
117889 +
117890 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
117891 +
117892 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
117893 +{
117894 + size_t i;
117895 +
117896 + for (i = 0; i < ARRAY_SIZE(sections); i++)
117897 + if (!strcmp(sections[i].name, name))
117898 + return 0;
117899 + return old_section_type_flags(decl, name, reloc);
117900 +}
117901 +
117902 +static void constify_start_unit(void *gcc_data, void *user_data)
117903 +{
117904 +// size_t i;
117905 +
117906 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
117907 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
117908 +// sections[i].section = get_section(sections[i].name, 0, NULL);
117909 +
117910 + old_section_type_flags = targetm.section_type_flags;
117911 + targetm.section_type_flags = constify_section_type_flags;
117912 +}
117913 +
117914 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117915 +{
117916 + const char * const plugin_name = plugin_info->base_name;
117917 + const int argc = plugin_info->argc;
117918 + const struct plugin_argument * const argv = plugin_info->argv;
117919 + int i;
117920 + bool constify = true;
117921 +
117922 + struct register_pass_info check_local_variables_pass_info;
117923 +
117924 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
117925 + check_local_variables_pass_info.reference_pass_name = "ssa";
117926 + check_local_variables_pass_info.ref_pass_instance_number = 1;
117927 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
117928 +
117929 + if (!plugin_default_version_check(version, &gcc_version)) {
117930 + error(G_("incompatible gcc/plugin versions"));
117931 + return 1;
117932 + }
117933 +
117934 + for (i = 0; i < argc; ++i) {
117935 + if (!(strcmp(argv[i].key, "no-constify"))) {
117936 + constify = false;
117937 + continue;
117938 + }
117939 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117940 + }
117941 +
117942 + if (strcmp(lang_hooks.name, "GNU C")) {
117943 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
117944 + constify = false;
117945 + }
117946 +
117947 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
117948 + if (constify) {
117949 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
117950 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
117951 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
117952 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
117953 + }
117954 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
117955 +
117956 + return 0;
117957 +}
117958 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
117959 new file mode 100644
117960 index 0000000..e90c205
117961 --- /dev/null
117962 +++ b/tools/gcc/gcc-common.h
117963 @@ -0,0 +1,295 @@
117964 +#ifndef GCC_COMMON_H_INCLUDED
117965 +#define GCC_COMMON_H_INCLUDED
117966 +
117967 +#include "plugin.h"
117968 +#include "bversion.h"
117969 +#include "plugin-version.h"
117970 +#include "config.h"
117971 +#include "system.h"
117972 +#include "coretypes.h"
117973 +#include "tm.h"
117974 +#include "line-map.h"
117975 +#include "input.h"
117976 +#include "tree.h"
117977 +
117978 +#include "tree-inline.h"
117979 +#include "version.h"
117980 +#include "rtl.h"
117981 +#include "tm_p.h"
117982 +#include "flags.h"
117983 +//#include "insn-attr.h"
117984 +//#include "insn-config.h"
117985 +//#include "insn-flags.h"
117986 +#include "hard-reg-set.h"
117987 +//#include "recog.h"
117988 +#include "output.h"
117989 +#include "except.h"
117990 +#include "function.h"
117991 +#include "toplev.h"
117992 +//#include "expr.h"
117993 +#include "basic-block.h"
117994 +#include "intl.h"
117995 +#include "ggc.h"
117996 +//#include "regs.h"
117997 +#include "timevar.h"
117998 +
117999 +#include "params.h"
118000 +#include "pointer-set.h"
118001 +#include "emit-rtl.h"
118002 +//#include "reload.h"
118003 +//#include "ira.h"
118004 +//#include "dwarf2asm.h"
118005 +#include "debug.h"
118006 +#include "target.h"
118007 +#include "langhooks.h"
118008 +#include "cfgloop.h"
118009 +//#include "hosthooks.h"
118010 +#include "cgraph.h"
118011 +#include "opts.h"
118012 +//#include "coverage.h"
118013 +//#include "value-prof.h"
118014 +
118015 +#if BUILDING_GCC_VERSION >= 4007
118016 +#include "tree-pretty-print.h"
118017 +#include "gimple-pretty-print.h"
118018 +#include "c-tree.h"
118019 +//#include "alloc-pool.h"
118020 +#endif
118021 +
118022 +#if BUILDING_GCC_VERSION <= 4008
118023 +#include "tree-flow.h"
118024 +#else
118025 +#include "tree-cfgcleanup.h"
118026 +#endif
118027 +
118028 +#include "diagnostic.h"
118029 +//#include "tree-diagnostic.h"
118030 +#include "tree-dump.h"
118031 +#include "tree-pass.h"
118032 +//#include "df.h"
118033 +#include "predict.h"
118034 +#include "ipa-utils.h"
118035 +
118036 +#if BUILDING_GCC_VERSION >= 4009
118037 +#include "varasm.h"
118038 +#include "stor-layout.h"
118039 +#include "internal-fn.h"
118040 +#include "gimple-expr.h"
118041 +//#include "diagnostic-color.h"
118042 +#include "context.h"
118043 +#include "tree-ssa-alias.h"
118044 +#include "stringpool.h"
118045 +#include "tree-ssanames.h"
118046 +#include "print-tree.h"
118047 +#include "tree-eh.h"
118048 +#include "stmt.h"
118049 +#endif
118050 +
118051 +#include "gimple.h"
118052 +
118053 +#if BUILDING_GCC_VERSION >= 4009
118054 +#include "tree-ssa-operands.h"
118055 +#include "tree-phinodes.h"
118056 +#include "tree-cfg.h"
118057 +#include "gimple-iterator.h"
118058 +#include "gimple-ssa.h"
118059 +#include "ssa-iterators.h"
118060 +#endif
118061 +
118062 +//#include "lto/lto.h"
118063 +//#include "data-streamer.h"
118064 +//#include "lto-compress.h"
118065 +
118066 +//#include "expr.h" where are you...
118067 +extern rtx emit_move_insn(rtx x, rtx y);
118068 +
118069 +// missing from basic_block.h...
118070 +extern void debug_dominance_info(enum cdi_direction dir);
118071 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
118072 +
118073 +#define __unused __attribute__((__unused__))
118074 +
118075 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
118076 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
118077 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
118078 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
118079 +
118080 +#if BUILDING_GCC_VERSION == 4005
118081 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
118082 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
118083 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
118084 +#define TODO_rebuild_cgraph_edges 0
118085 +
118086 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
118087 +{
118088 + tree fndecl;
118089 +
118090 + if (!is_gimple_call(stmt))
118091 + return false;
118092 + fndecl = gimple_call_fndecl(stmt);
118093 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
118094 + return false;
118095 +// print_node(stderr, "pax", fndecl, 4);
118096 + return DECL_FUNCTION_CODE(fndecl) == code;
118097 +}
118098 +
118099 +static inline bool is_simple_builtin(tree decl)
118100 +{
118101 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
118102 + return false;
118103 +
118104 + switch (DECL_FUNCTION_CODE(decl)) {
118105 + /* Builtins that expand to constants. */
118106 + case BUILT_IN_CONSTANT_P:
118107 + case BUILT_IN_EXPECT:
118108 + case BUILT_IN_OBJECT_SIZE:
118109 + case BUILT_IN_UNREACHABLE:
118110 + /* Simple register moves or loads from stack. */
118111 + case BUILT_IN_RETURN_ADDRESS:
118112 + case BUILT_IN_EXTRACT_RETURN_ADDR:
118113 + case BUILT_IN_FROB_RETURN_ADDR:
118114 + case BUILT_IN_RETURN:
118115 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
118116 + case BUILT_IN_FRAME_ADDRESS:
118117 + case BUILT_IN_VA_END:
118118 + case BUILT_IN_STACK_SAVE:
118119 + case BUILT_IN_STACK_RESTORE:
118120 + /* Exception state returns or moves registers around. */
118121 + case BUILT_IN_EH_FILTER:
118122 + case BUILT_IN_EH_POINTER:
118123 + case BUILT_IN_EH_COPY_VALUES:
118124 + return true;
118125 +
118126 + default:
118127 + return false;
118128 + }
118129 +}
118130 +#endif
118131 +
118132 +#if BUILDING_GCC_VERSION <= 4006
118133 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
118134 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
118135 +
118136 +// should come from c-tree.h if only it were installed for gcc 4.5...
118137 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
118138 +
118139 +#define get_random_seed(noinit) ({ \
118140 + unsigned HOST_WIDE_INT seed; \
118141 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
118142 + seed * seed; })
118143 +
118144 +static inline bool gimple_clobber_p(gimple s)
118145 +{
118146 + return false;
118147 +}
118148 +
118149 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
118150 +{
118151 + return implicit_built_in_decls[fncode];
118152 +}
118153 +
118154 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
118155 +{
118156 + struct cgraph_node *node = cgraph_get_node(decl);
118157 +
118158 + return node ? node : cgraph_node(decl);
118159 +}
118160 +
118161 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
118162 +{
118163 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
118164 +}
118165 +
118166 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
118167 +{
118168 + struct cgraph_node *node;
118169 +
118170 + for (node = cgraph_nodes; node; node = node->next)
118171 + if (cgraph_function_with_gimple_body_p(node))
118172 + return node;
118173 + return NULL;
118174 +}
118175 +
118176 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
118177 +{
118178 + for (node = node->next; node; node = node->next)
118179 + if (cgraph_function_with_gimple_body_p(node))
118180 + return node;
118181 + return NULL;
118182 +}
118183 +
118184 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
118185 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
118186 + (node) = cgraph_next_function_with_gimple_body(node))
118187 +#endif
118188 +
118189 +#if BUILDING_GCC_VERSION == 4006
118190 +extern void debug_gimple_stmt(gimple);
118191 +extern void debug_gimple_seq(gimple_seq);
118192 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
118193 +extern void print_gimple_stmt(FILE *, gimple, int, int);
118194 +extern void print_gimple_expr(FILE *, gimple, int, int);
118195 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
118196 +#endif
118197 +
118198 +#if BUILDING_GCC_VERSION <= 4007
118199 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
118200 +#define PROP_loops 0
118201 +
118202 +static inline int bb_loop_depth(const_basic_block bb)
118203 +{
118204 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
118205 +}
118206 +
118207 +static inline bool gimple_store_p(gimple gs)
118208 +{
118209 + tree lhs = gimple_get_lhs(gs);
118210 + return lhs && !is_gimple_reg(lhs);
118211 +}
118212 +#endif
118213 +
118214 +#if BUILDING_GCC_VERSION >= 4007
118215 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
118216 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
118217 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
118218 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
118219 +#endif
118220 +
118221 +#if BUILDING_GCC_VERSION <= 4008
118222 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
118223 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
118224 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
118225 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
118226 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
118227 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
118228 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
118229 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
118230 +
118231 +static inline const char *get_tree_code_name(enum tree_code code)
118232 +{
118233 + gcc_assert(code < MAX_TREE_CODES);
118234 + return tree_code_name[code];
118235 +}
118236 +
118237 +#define ipa_remove_stmt_references(cnode, stmt)
118238 +#endif
118239 +
118240 +#if BUILDING_GCC_VERSION == 4008
118241 +#define NODE_DECL(node) node->symbol.decl
118242 +#else
118243 +#define NODE_DECL(node) node->decl
118244 +#endif
118245 +
118246 +#if BUILDING_GCC_VERSION >= 4008
118247 +#define add_referenced_var(var)
118248 +#define mark_sym_for_renaming(var)
118249 +#define varpool_mark_needed_node(node)
118250 +#define TODO_dump_func 0
118251 +#define TODO_dump_cgraph 0
118252 +#endif
118253 +
118254 +#if BUILDING_GCC_VERSION >= 4009
118255 +#define TODO_ggc_collect 0
118256 +#endif
118257 +
118258 +#endif
118259 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
118260 new file mode 100644
118261 index 0000000..7514850
118262 --- /dev/null
118263 +++ b/tools/gcc/gen-random-seed.sh
118264 @@ -0,0 +1,8 @@
118265 +#!/bin/sh
118266 +
118267 +if [ ! -f "$1" ]; then
118268 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
118269 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
118270 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
118271 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
118272 +fi
118273 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
118274 new file mode 100644
118275 index 0000000..d81c094
118276 --- /dev/null
118277 +++ b/tools/gcc/kallocstat_plugin.c
118278 @@ -0,0 +1,183 @@
118279 +/*
118280 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118281 + * Licensed under the GPL v2
118282 + *
118283 + * Note: the choice of the license means that the compilation process is
118284 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118285 + * but for the kernel it doesn't matter since it doesn't link against
118286 + * any of the gcc libraries
118287 + *
118288 + * gcc plugin to find the distribution of k*alloc sizes
118289 + *
118290 + * TODO:
118291 + *
118292 + * BUGS:
118293 + * - none known
118294 + */
118295 +
118296 +#include "gcc-common.h"
118297 +
118298 +int plugin_is_GPL_compatible;
118299 +
118300 +static struct plugin_info kallocstat_plugin_info = {
118301 + .version = "201401260140",
118302 + .help = NULL
118303 +};
118304 +
118305 +static const char * const kalloc_functions[] = {
118306 + "__kmalloc",
118307 + "kmalloc",
118308 + "kmalloc_large",
118309 + "kmalloc_node",
118310 + "kmalloc_order",
118311 + "kmalloc_order_trace",
118312 + "kmalloc_slab",
118313 + "kzalloc",
118314 + "kzalloc_node",
118315 +};
118316 +
118317 +static bool is_kalloc(const char *fnname)
118318 +{
118319 + size_t i;
118320 +
118321 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
118322 + if (!strcmp(fnname, kalloc_functions[i]))
118323 + return true;
118324 + return false;
118325 +}
118326 +
118327 +static unsigned int execute_kallocstat(void)
118328 +{
118329 + basic_block bb;
118330 +
118331 + // 1. loop through BBs and GIMPLE statements
118332 + FOR_EACH_BB_FN(bb, cfun) {
118333 + gimple_stmt_iterator gsi;
118334 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118335 + // gimple match:
118336 + tree fndecl, size;
118337 + gimple stmt;
118338 + const char *fnname;
118339 +
118340 + // is it a call
118341 + stmt = gsi_stmt(gsi);
118342 + if (!is_gimple_call(stmt))
118343 + continue;
118344 + fndecl = gimple_call_fndecl(stmt);
118345 + if (fndecl == NULL_TREE)
118346 + continue;
118347 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
118348 + continue;
118349 +
118350 + // is it a call to k*alloc
118351 + fnname = DECL_NAME_POINTER(fndecl);
118352 + if (!is_kalloc(fnname))
118353 + continue;
118354 +
118355 + // is the size arg const or the result of a simple const assignment
118356 + size = gimple_call_arg(stmt, 0);
118357 + while (true) {
118358 + expanded_location xloc;
118359 + size_t size_val;
118360 +
118361 + if (TREE_CONSTANT(size)) {
118362 + xloc = expand_location(gimple_location(stmt));
118363 + if (!xloc.file)
118364 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
118365 + size_val = TREE_INT_CST_LOW(size);
118366 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
118367 + break;
118368 + }
118369 +
118370 + if (TREE_CODE(size) != SSA_NAME)
118371 + break;
118372 + stmt = SSA_NAME_DEF_STMT(size);
118373 +//debug_gimple_stmt(stmt);
118374 +//debug_tree(size);
118375 + if (!stmt || !is_gimple_assign(stmt))
118376 + break;
118377 + if (gimple_num_ops(stmt) != 2)
118378 + break;
118379 + size = gimple_assign_rhs1(stmt);
118380 + }
118381 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
118382 +//debug_tree(gimple_call_fn(call_stmt));
118383 +//print_node(stderr, "pax", fndecl, 4);
118384 + }
118385 + }
118386 +
118387 + return 0;
118388 +}
118389 +
118390 +#if BUILDING_GCC_VERSION >= 4009
118391 +static const struct pass_data kallocstat_pass_data = {
118392 +#else
118393 +static struct gimple_opt_pass kallocstat_pass = {
118394 + .pass = {
118395 +#endif
118396 + .type = GIMPLE_PASS,
118397 + .name = "kallocstat",
118398 +#if BUILDING_GCC_VERSION >= 4008
118399 + .optinfo_flags = OPTGROUP_NONE,
118400 +#endif
118401 +#if BUILDING_GCC_VERSION >= 4009
118402 + .has_gate = false,
118403 + .has_execute = true,
118404 +#else
118405 + .gate = NULL,
118406 + .execute = execute_kallocstat,
118407 + .sub = NULL,
118408 + .next = NULL,
118409 + .static_pass_number = 0,
118410 +#endif
118411 + .tv_id = TV_NONE,
118412 + .properties_required = 0,
118413 + .properties_provided = 0,
118414 + .properties_destroyed = 0,
118415 + .todo_flags_start = 0,
118416 + .todo_flags_finish = 0
118417 +#if BUILDING_GCC_VERSION < 4009
118418 + }
118419 +#endif
118420 +};
118421 +
118422 +#if BUILDING_GCC_VERSION >= 4009
118423 +namespace {
118424 +class kallocstat_pass : public gimple_opt_pass {
118425 +public:
118426 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
118427 + unsigned int execute() { return execute_kallocstat(); }
118428 +};
118429 +}
118430 +
118431 +static opt_pass *make_kallocstat_pass(void)
118432 +{
118433 + return new kallocstat_pass();
118434 +}
118435 +#else
118436 +static struct opt_pass *make_kallocstat_pass(void)
118437 +{
118438 + return &kallocstat_pass.pass;
118439 +}
118440 +#endif
118441 +
118442 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118443 +{
118444 + const char * const plugin_name = plugin_info->base_name;
118445 + struct register_pass_info kallocstat_pass_info;
118446 +
118447 + kallocstat_pass_info.pass = make_kallocstat_pass();
118448 + kallocstat_pass_info.reference_pass_name = "ssa";
118449 + kallocstat_pass_info.ref_pass_instance_number = 1;
118450 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118451 +
118452 + if (!plugin_default_version_check(version, &gcc_version)) {
118453 + error(G_("incompatible gcc/plugin versions"));
118454 + return 1;
118455 + }
118456 +
118457 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
118458 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
118459 +
118460 + return 0;
118461 +}
118462 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
118463 new file mode 100644
118464 index 0000000..89f256d
118465 --- /dev/null
118466 +++ b/tools/gcc/kernexec_plugin.c
118467 @@ -0,0 +1,522 @@
118468 +/*
118469 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118470 + * Licensed under the GPL v2
118471 + *
118472 + * Note: the choice of the license means that the compilation process is
118473 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118474 + * but for the kernel it doesn't matter since it doesn't link against
118475 + * any of the gcc libraries
118476 + *
118477 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
118478 + *
118479 + * TODO:
118480 + *
118481 + * BUGS:
118482 + * - none known
118483 + */
118484 +
118485 +#include "gcc-common.h"
118486 +
118487 +int plugin_is_GPL_compatible;
118488 +
118489 +static struct plugin_info kernexec_plugin_info = {
118490 + .version = "201401260140",
118491 + .help = "method=[bts|or]\tinstrumentation method\n"
118492 +};
118493 +
118494 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
118495 +static void (*kernexec_instrument_retaddr)(rtx);
118496 +
118497 +/*
118498 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
118499 + */
118500 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
118501 +{
118502 + gimple asm_movabs_stmt;
118503 +
118504 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
118505 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
118506 + gimple_asm_set_volatile(asm_movabs_stmt, true);
118507 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
118508 + update_stmt(asm_movabs_stmt);
118509 +}
118510 +
118511 +/*
118512 + * find all asm() stmts that clobber r12 and add a reload of r12
118513 + */
118514 +static unsigned int execute_kernexec_reload(void)
118515 +{
118516 + basic_block bb;
118517 +
118518 + // 1. loop through BBs and GIMPLE statements
118519 + FOR_EACH_BB_FN(bb, cfun) {
118520 + gimple_stmt_iterator gsi;
118521 +
118522 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118523 + // gimple match: __asm__ ("" : : : "r12");
118524 + gimple asm_stmt;
118525 + size_t nclobbers;
118526 +
118527 + // is it an asm ...
118528 + asm_stmt = gsi_stmt(gsi);
118529 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
118530 + continue;
118531 +
118532 + // ... clobbering r12
118533 + nclobbers = gimple_asm_nclobbers(asm_stmt);
118534 + while (nclobbers--) {
118535 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
118536 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
118537 + continue;
118538 + kernexec_reload_fptr_mask(&gsi);
118539 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
118540 + break;
118541 + }
118542 + }
118543 + }
118544 +
118545 + return 0;
118546 +}
118547 +
118548 +/*
118549 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
118550 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
118551 + */
118552 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
118553 +{
118554 + gimple assign_intptr, assign_new_fptr, call_stmt;
118555 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
118556 +
118557 + call_stmt = gsi_stmt(*gsi);
118558 + old_fptr = gimple_call_fn(call_stmt);
118559 +
118560 + // create temporary unsigned long variable used for bitops and cast fptr to it
118561 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
118562 + add_referenced_var(intptr);
118563 + intptr = make_ssa_name(intptr, NULL);
118564 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
118565 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
118566 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
118567 + update_stmt(assign_intptr);
118568 +
118569 + // apply logical or to temporary unsigned long and bitmask
118570 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
118571 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
118572 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
118573 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
118574 + assign_intptr = gimple_build_assign(intptr, orptr);
118575 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
118576 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
118577 + update_stmt(assign_intptr);
118578 +
118579 + // cast temporary unsigned long back to a temporary fptr variable
118580 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
118581 + add_referenced_var(new_fptr);
118582 + new_fptr = make_ssa_name(new_fptr, NULL);
118583 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
118584 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
118585 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
118586 + update_stmt(assign_new_fptr);
118587 +
118588 + // replace call stmt fn with the new fptr
118589 + gimple_call_set_fn(call_stmt, new_fptr);
118590 + update_stmt(call_stmt);
118591 +}
118592 +
118593 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
118594 +{
118595 + gimple asm_or_stmt, call_stmt;
118596 + tree old_fptr, new_fptr, input, output;
118597 +#if BUILDING_GCC_VERSION <= 4007
118598 + VEC(tree, gc) *inputs = NULL;
118599 + VEC(tree, gc) *outputs = NULL;
118600 +#else
118601 + vec<tree, va_gc> *inputs = NULL;
118602 + vec<tree, va_gc> *outputs = NULL;
118603 +#endif
118604 +
118605 + call_stmt = gsi_stmt(*gsi);
118606 + old_fptr = gimple_call_fn(call_stmt);
118607 +
118608 + // create temporary fptr variable
118609 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
118610 + add_referenced_var(new_fptr);
118611 + new_fptr = make_ssa_name(new_fptr, NULL);
118612 +
118613 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
118614 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
118615 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
118616 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
118617 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
118618 +#if BUILDING_GCC_VERSION <= 4007
118619 + VEC_safe_push(tree, gc, inputs, input);
118620 + VEC_safe_push(tree, gc, outputs, output);
118621 +#else
118622 + vec_safe_push(inputs, input);
118623 + vec_safe_push(outputs, output);
118624 +#endif
118625 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
118626 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
118627 + gimple_asm_set_volatile(asm_or_stmt, true);
118628 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
118629 + update_stmt(asm_or_stmt);
118630 +
118631 + // replace call stmt fn with the new fptr
118632 + gimple_call_set_fn(call_stmt, new_fptr);
118633 + update_stmt(call_stmt);
118634 +}
118635 +
118636 +/*
118637 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
118638 + */
118639 +static unsigned int execute_kernexec_fptr(void)
118640 +{
118641 + basic_block bb;
118642 +
118643 + // 1. loop through BBs and GIMPLE statements
118644 + FOR_EACH_BB_FN(bb, cfun) {
118645 + gimple_stmt_iterator gsi;
118646 +
118647 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118648 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
118649 + tree fn;
118650 + gimple call_stmt;
118651 +
118652 + // is it a call ...
118653 + call_stmt = gsi_stmt(gsi);
118654 + if (!is_gimple_call(call_stmt))
118655 + continue;
118656 + fn = gimple_call_fn(call_stmt);
118657 + if (TREE_CODE(fn) == ADDR_EXPR)
118658 + continue;
118659 + if (TREE_CODE(fn) != SSA_NAME)
118660 + gcc_unreachable();
118661 +
118662 + // ... through a function pointer
118663 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
118664 + fn = SSA_NAME_VAR(fn);
118665 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
118666 + debug_tree(fn);
118667 + gcc_unreachable();
118668 + }
118669 + }
118670 + fn = TREE_TYPE(fn);
118671 + if (TREE_CODE(fn) != POINTER_TYPE)
118672 + continue;
118673 + fn = TREE_TYPE(fn);
118674 + if (TREE_CODE(fn) != FUNCTION_TYPE)
118675 + continue;
118676 +
118677 + kernexec_instrument_fptr(&gsi);
118678 +
118679 +//debug_tree(gimple_call_fn(call_stmt));
118680 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
118681 + }
118682 + }
118683 +
118684 + return 0;
118685 +}
118686 +
118687 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
118688 +static void kernexec_instrument_retaddr_bts(rtx insn)
118689 +{
118690 + rtx btsq;
118691 + rtvec argvec, constraintvec, labelvec;
118692 + int line;
118693 +
118694 + // create asm volatile("btsq $63,(%%rsp)":::)
118695 + argvec = rtvec_alloc(0);
118696 + constraintvec = rtvec_alloc(0);
118697 + labelvec = rtvec_alloc(0);
118698 + line = expand_location(RTL_LOCATION(insn)).line;
118699 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
118700 + MEM_VOLATILE_P(btsq) = 1;
118701 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
118702 + emit_insn_before(btsq, insn);
118703 +}
118704 +
118705 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
118706 +static void kernexec_instrument_retaddr_or(rtx insn)
118707 +{
118708 + rtx orq;
118709 + rtvec argvec, constraintvec, labelvec;
118710 + int line;
118711 +
118712 + // create asm volatile("orq %%r12,(%%rsp)":::)
118713 + argvec = rtvec_alloc(0);
118714 + constraintvec = rtvec_alloc(0);
118715 + labelvec = rtvec_alloc(0);
118716 + line = expand_location(RTL_LOCATION(insn)).line;
118717 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
118718 + MEM_VOLATILE_P(orq) = 1;
118719 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
118720 + emit_insn_before(orq, insn);
118721 +}
118722 +
118723 +/*
118724 + * find all asm level function returns and forcibly set the highest bit of the return address
118725 + */
118726 +static unsigned int execute_kernexec_retaddr(void)
118727 +{
118728 + rtx insn;
118729 +
118730 +// if (stack_realign_drap)
118731 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
118732 +
118733 + // 1. find function returns
118734 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
118735 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
118736 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
118737 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
118738 + rtx body;
118739 +
118740 + // is it a retn
118741 + if (!JUMP_P(insn))
118742 + continue;
118743 + body = PATTERN(insn);
118744 + if (GET_CODE(body) == PARALLEL)
118745 + body = XVECEXP(body, 0, 0);
118746 + if (!ANY_RETURN_P(body))
118747 + continue;
118748 + kernexec_instrument_retaddr(insn);
118749 + }
118750 +
118751 +// print_simple_rtl(stderr, get_insns());
118752 +// print_rtl(stderr, get_insns());
118753 +
118754 + return 0;
118755 +}
118756 +
118757 +static bool kernexec_cmodel_check(void)
118758 +{
118759 + tree section;
118760 +
118761 + if (ix86_cmodel != CM_KERNEL)
118762 + return false;
118763 +
118764 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
118765 + if (!section || !TREE_VALUE(section))
118766 + return true;
118767 +
118768 + section = TREE_VALUE(TREE_VALUE(section));
118769 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
118770 + return true;
118771 +
118772 + return false;
118773 +}
118774 +
118775 +#if BUILDING_GCC_VERSION >= 4009
118776 +static const struct pass_data kernexec_reload_pass_data = {
118777 +#else
118778 +static struct gimple_opt_pass kernexec_reload_pass = {
118779 + .pass = {
118780 +#endif
118781 + .type = GIMPLE_PASS,
118782 + .name = "kernexec_reload",
118783 +#if BUILDING_GCC_VERSION >= 4008
118784 + .optinfo_flags = OPTGROUP_NONE,
118785 +#endif
118786 +#if BUILDING_GCC_VERSION >= 4009
118787 + .has_gate = true,
118788 + .has_execute = true,
118789 +#else
118790 + .gate = kernexec_cmodel_check,
118791 + .execute = execute_kernexec_reload,
118792 + .sub = NULL,
118793 + .next = NULL,
118794 + .static_pass_number = 0,
118795 +#endif
118796 + .tv_id = TV_NONE,
118797 + .properties_required = 0,
118798 + .properties_provided = 0,
118799 + .properties_destroyed = 0,
118800 + .todo_flags_start = 0,
118801 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
118802 +#if BUILDING_GCC_VERSION < 4009
118803 + }
118804 +#endif
118805 +};
118806 +
118807 +#if BUILDING_GCC_VERSION >= 4009
118808 +static const struct pass_data kernexec_fptr_pass_data = {
118809 +#else
118810 +static struct gimple_opt_pass kernexec_fptr_pass = {
118811 + .pass = {
118812 +#endif
118813 + .type = GIMPLE_PASS,
118814 + .name = "kernexec_fptr",
118815 +#if BUILDING_GCC_VERSION >= 4008
118816 + .optinfo_flags = OPTGROUP_NONE,
118817 +#endif
118818 +#if BUILDING_GCC_VERSION >= 4009
118819 + .has_gate = true,
118820 + .has_execute = true,
118821 +#else
118822 + .gate = kernexec_cmodel_check,
118823 + .execute = execute_kernexec_fptr,
118824 + .sub = NULL,
118825 + .next = NULL,
118826 + .static_pass_number = 0,
118827 +#endif
118828 + .tv_id = TV_NONE,
118829 + .properties_required = 0,
118830 + .properties_provided = 0,
118831 + .properties_destroyed = 0,
118832 + .todo_flags_start = 0,
118833 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
118834 +#if BUILDING_GCC_VERSION < 4009
118835 + }
118836 +#endif
118837 +};
118838 +
118839 +#if BUILDING_GCC_VERSION >= 4009
118840 +static const struct pass_data kernexec_retaddr_pass_data = {
118841 +#else
118842 +static struct rtl_opt_pass kernexec_retaddr_pass = {
118843 + .pass = {
118844 +#endif
118845 + .type = RTL_PASS,
118846 + .name = "kernexec_retaddr",
118847 +#if BUILDING_GCC_VERSION >= 4008
118848 + .optinfo_flags = OPTGROUP_NONE,
118849 +#endif
118850 +#if BUILDING_GCC_VERSION >= 4009
118851 + .has_gate = true,
118852 + .has_execute = true,
118853 +#else
118854 + .gate = kernexec_cmodel_check,
118855 + .execute = execute_kernexec_retaddr,
118856 + .sub = NULL,
118857 + .next = NULL,
118858 + .static_pass_number = 0,
118859 +#endif
118860 + .tv_id = TV_NONE,
118861 + .properties_required = 0,
118862 + .properties_provided = 0,
118863 + .properties_destroyed = 0,
118864 + .todo_flags_start = 0,
118865 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
118866 +#if BUILDING_GCC_VERSION < 4009
118867 + }
118868 +#endif
118869 +};
118870 +
118871 +#if BUILDING_GCC_VERSION >= 4009
118872 +namespace {
118873 +class kernexec_reload_pass : public gimple_opt_pass {
118874 +public:
118875 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
118876 + bool gate() { return kernexec_cmodel_check(); }
118877 + unsigned int execute() { return execute_kernexec_reload(); }
118878 +};
118879 +
118880 +class kernexec_fptr_pass : public gimple_opt_pass {
118881 +public:
118882 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
118883 + bool gate() { return kernexec_cmodel_check(); }
118884 + unsigned int execute() { return execute_kernexec_fptr(); }
118885 +};
118886 +
118887 +class kernexec_retaddr_pass : public rtl_opt_pass {
118888 +public:
118889 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
118890 + bool gate() { return kernexec_cmodel_check(); }
118891 + unsigned int execute() { return execute_kernexec_retaddr(); }
118892 +};
118893 +}
118894 +
118895 +static opt_pass *make_kernexec_reload_pass(void)
118896 +{
118897 + return new kernexec_reload_pass();
118898 +}
118899 +
118900 +static opt_pass *make_kernexec_fptr_pass(void)
118901 +{
118902 + return new kernexec_fptr_pass();
118903 +}
118904 +
118905 +static opt_pass *make_kernexec_retaddr_pass(void)
118906 +{
118907 + return new kernexec_retaddr_pass();
118908 +}
118909 +#else
118910 +static struct opt_pass *make_kernexec_reload_pass(void)
118911 +{
118912 + return &kernexec_reload_pass.pass;
118913 +}
118914 +
118915 +static struct opt_pass *make_kernexec_fptr_pass(void)
118916 +{
118917 + return &kernexec_fptr_pass.pass;
118918 +}
118919 +
118920 +static struct opt_pass *make_kernexec_retaddr_pass(void)
118921 +{
118922 + return &kernexec_retaddr_pass.pass;
118923 +}
118924 +#endif
118925 +
118926 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118927 +{
118928 + const char * const plugin_name = plugin_info->base_name;
118929 + const int argc = plugin_info->argc;
118930 + const struct plugin_argument * const argv = plugin_info->argv;
118931 + int i;
118932 + struct register_pass_info kernexec_reload_pass_info;
118933 + struct register_pass_info kernexec_fptr_pass_info;
118934 + struct register_pass_info kernexec_retaddr_pass_info;
118935 +
118936 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
118937 + kernexec_reload_pass_info.reference_pass_name = "ssa";
118938 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
118939 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118940 +
118941 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
118942 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
118943 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
118944 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118945 +
118946 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
118947 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
118948 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
118949 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118950 +
118951 + if (!plugin_default_version_check(version, &gcc_version)) {
118952 + error(G_("incompatible gcc/plugin versions"));
118953 + return 1;
118954 + }
118955 +
118956 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
118957 +
118958 + if (TARGET_64BIT == 0)
118959 + return 0;
118960 +
118961 + for (i = 0; i < argc; ++i) {
118962 + if (!strcmp(argv[i].key, "method")) {
118963 + if (!argv[i].value) {
118964 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118965 + continue;
118966 + }
118967 + if (!strcmp(argv[i].value, "bts")) {
118968 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
118969 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
118970 + } else if (!strcmp(argv[i].value, "or")) {
118971 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
118972 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
118973 + fix_register("r12", 1, 1);
118974 + } else
118975 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
118976 + continue;
118977 + }
118978 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118979 + }
118980 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
118981 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
118982 +
118983 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
118984 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
118985 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
118986 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
118987 +
118988 + return 0;
118989 +}
118990 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
118991 new file mode 100644
118992 index 0000000..e48b323
118993 --- /dev/null
118994 +++ b/tools/gcc/latent_entropy_plugin.c
118995 @@ -0,0 +1,466 @@
118996 +/*
118997 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
118998 + * Licensed under the GPL v2
118999 + *
119000 + * Note: the choice of the license means that the compilation process is
119001 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119002 + * but for the kernel it doesn't matter since it doesn't link against
119003 + * any of the gcc libraries
119004 + *
119005 + * gcc plugin to help generate a little bit of entropy from program state,
119006 + * used throughout the uptime of the kernel
119007 + *
119008 + * TODO:
119009 + * - add ipa pass to identify not explicitly marked candidate functions
119010 + * - mix in more program state (function arguments/return values, loop variables, etc)
119011 + * - more instrumentation control via attribute parameters
119012 + *
119013 + * BUGS:
119014 + * - LTO needs -flto-partition=none for now
119015 + */
119016 +
119017 +#include "gcc-common.h"
119018 +
119019 +int plugin_is_GPL_compatible;
119020 +
119021 +static tree latent_entropy_decl;
119022 +
119023 +static struct plugin_info latent_entropy_plugin_info = {
119024 + .version = "201409101820",
119025 + .help = NULL
119026 +};
119027 +
119028 +static unsigned HOST_WIDE_INT seed;
119029 +static unsigned HOST_WIDE_INT get_random_const(void)
119030 +{
119031 + unsigned int i;
119032 + unsigned HOST_WIDE_INT ret = 0;
119033 +
119034 + for (i = 0; i < 8 * sizeof ret; i++) {
119035 + ret = (ret << 1) | (seed & 1);
119036 + seed >>= 1;
119037 + if (ret & 1)
119038 + seed ^= 0xD800000000000000ULL;
119039 + }
119040 +
119041 + return ret;
119042 +}
119043 +
119044 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119045 +{
119046 + tree type;
119047 + unsigned long long mask;
119048 +#if BUILDING_GCC_VERSION <= 4007
119049 + VEC(constructor_elt, gc) *vals;
119050 +#else
119051 + vec<constructor_elt, va_gc> *vals;
119052 +#endif
119053 +
119054 + switch (TREE_CODE(*node)) {
119055 + default:
119056 + *no_add_attrs = true;
119057 + error("%qE attribute only applies to functions and variables", name);
119058 + break;
119059 +
119060 + case VAR_DECL:
119061 + if (DECL_INITIAL(*node)) {
119062 + *no_add_attrs = true;
119063 + error("variable %qD with %qE attribute must not be initialized", *node, name);
119064 + break;
119065 + }
119066 +
119067 + if (!TREE_STATIC(*node)) {
119068 + *no_add_attrs = true;
119069 + error("variable %qD with %qE attribute must not be local", *node, name);
119070 + break;
119071 + }
119072 +
119073 + type = TREE_TYPE(*node);
119074 + switch (TREE_CODE(type)) {
119075 + default:
119076 + *no_add_attrs = true;
119077 + 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);
119078 + break;
119079 +
119080 + case RECORD_TYPE: {
119081 + tree field;
119082 + unsigned int nelt = 0;
119083 +
119084 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
119085 + tree fieldtype;
119086 +
119087 + fieldtype = TREE_TYPE(field);
119088 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
119089 + *no_add_attrs = true;
119090 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
119091 + break;
119092 + }
119093 + }
119094 +
119095 + if (field)
119096 + break;
119097 +
119098 +#if BUILDING_GCC_VERSION <= 4007
119099 + vals = VEC_alloc(constructor_elt, gc, nelt);
119100 +#else
119101 + vec_alloc(vals, nelt);
119102 +#endif
119103 +
119104 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
119105 + tree fieldtype;
119106 +
119107 + fieldtype = TREE_TYPE(field);
119108 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
119109 + mask = 2 * (mask - 1) + 1;
119110 +
119111 + if (TYPE_UNSIGNED(fieldtype))
119112 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
119113 + else
119114 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
119115 + }
119116 +
119117 + DECL_INITIAL(*node) = build_constructor(type, vals);
119118 +//debug_tree(DECL_INITIAL(*node));
119119 + break;
119120 + }
119121 +
119122 + case INTEGER_TYPE:
119123 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
119124 + mask = 2 * (mask - 1) + 1;
119125 +
119126 + if (TYPE_UNSIGNED(type))
119127 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
119128 + else
119129 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
119130 + break;
119131 +
119132 + case ARRAY_TYPE: {
119133 + tree elt_type, array_size, elt_size;
119134 + unsigned int i, nelt;
119135 +
119136 + elt_type = TREE_TYPE(type);
119137 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
119138 + array_size = TYPE_SIZE_UNIT(type);
119139 +
119140 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
119141 + *no_add_attrs = true;
119142 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
119143 + break;
119144 + }
119145 +
119146 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
119147 +#if BUILDING_GCC_VERSION <= 4007
119148 + vals = VEC_alloc(constructor_elt, gc, nelt);
119149 +#else
119150 + vec_alloc(vals, nelt);
119151 +#endif
119152 +
119153 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
119154 + mask = 2 * (mask - 1) + 1;
119155 +
119156 + for (i = 0; i < nelt; i++)
119157 + if (TYPE_UNSIGNED(elt_type))
119158 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
119159 + else
119160 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
119161 +
119162 + DECL_INITIAL(*node) = build_constructor(type, vals);
119163 +//debug_tree(DECL_INITIAL(*node));
119164 + break;
119165 + }
119166 + }
119167 + break;
119168 +
119169 + case FUNCTION_DECL:
119170 + break;
119171 + }
119172 +
119173 + return NULL_TREE;
119174 +}
119175 +
119176 +static struct attribute_spec latent_entropy_attr = {
119177 + .name = "latent_entropy",
119178 + .min_length = 0,
119179 + .max_length = 0,
119180 + .decl_required = true,
119181 + .type_required = false,
119182 + .function_type_required = false,
119183 + .handler = handle_latent_entropy_attribute,
119184 +#if BUILDING_GCC_VERSION >= 4007
119185 + .affects_type_identity = false
119186 +#endif
119187 +};
119188 +
119189 +static void register_attributes(void *event_data, void *data)
119190 +{
119191 + register_attribute(&latent_entropy_attr);
119192 +}
119193 +
119194 +static bool gate_latent_entropy(void)
119195 +{
119196 + // don't bother with noreturn functions for now
119197 + if (TREE_THIS_VOLATILE(current_function_decl))
119198 + return false;
119199 +
119200 + // gcc-4.5 doesn't discover some trivial noreturn functions
119201 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
119202 + return false;
119203 +
119204 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
119205 +}
119206 +
119207 +static enum tree_code get_op(tree *rhs)
119208 +{
119209 + static enum tree_code op;
119210 + unsigned HOST_WIDE_INT random_const;
119211 +
119212 + random_const = get_random_const();
119213 +
119214 + switch (op) {
119215 + case BIT_XOR_EXPR:
119216 + op = PLUS_EXPR;
119217 + break;
119218 +
119219 + case PLUS_EXPR:
119220 + if (rhs) {
119221 + op = LROTATE_EXPR;
119222 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
119223 + break;
119224 + }
119225 +
119226 + case LROTATE_EXPR:
119227 + default:
119228 + op = BIT_XOR_EXPR;
119229 + break;
119230 + }
119231 + if (rhs)
119232 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
119233 + return op;
119234 +}
119235 +
119236 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
119237 +{
119238 + gimple_stmt_iterator gsi;
119239 + gimple assign;
119240 + tree addxorrol, rhs;
119241 + enum tree_code op;
119242 +
119243 + op = get_op(&rhs);
119244 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
119245 + assign = gimple_build_assign(local_entropy, addxorrol);
119246 + gsi = gsi_after_labels(bb);
119247 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
119248 + update_stmt(assign);
119249 +//debug_bb(bb);
119250 +}
119251 +
119252 +static void perturb_latent_entropy(basic_block bb, tree rhs)
119253 +{
119254 + gimple_stmt_iterator gsi;
119255 + gimple assign;
119256 + tree addxorrol, temp;
119257 +
119258 + // 1. create temporary copy of latent_entropy
119259 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
119260 + add_referenced_var(temp);
119261 +
119262 + // 2. read...
119263 + temp = make_ssa_name(temp, NULL);
119264 + assign = gimple_build_assign(temp, latent_entropy_decl);
119265 + SSA_NAME_DEF_STMT(temp) = assign;
119266 + add_referenced_var(latent_entropy_decl);
119267 + gsi = gsi_after_labels(bb);
119268 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
119269 + update_stmt(assign);
119270 +
119271 + // 3. ...modify...
119272 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
119273 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
119274 + assign = gimple_build_assign(temp, addxorrol);
119275 + SSA_NAME_DEF_STMT(temp) = assign;
119276 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
119277 + update_stmt(assign);
119278 +
119279 + // 4. ...write latent_entropy
119280 + assign = gimple_build_assign(latent_entropy_decl, temp);
119281 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
119282 + update_stmt(assign);
119283 +}
119284 +
119285 +static unsigned int execute_latent_entropy(void)
119286 +{
119287 + basic_block bb;
119288 + gimple assign;
119289 + gimple_stmt_iterator gsi;
119290 + tree local_entropy;
119291 +
119292 + if (!latent_entropy_decl) {
119293 +#if BUILDING_GCC_VERSION >= 4009
119294 + varpool_node *node;
119295 +#else
119296 + struct varpool_node *node;
119297 +#endif
119298 +
119299 + FOR_EACH_VARIABLE(node) {
119300 + tree var = NODE_DECL(node);
119301 +
119302 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
119303 + continue;
119304 + latent_entropy_decl = var;
119305 +// debug_tree(var);
119306 + break;
119307 + }
119308 + if (!latent_entropy_decl) {
119309 +// debug_tree(current_function_decl);
119310 + return 0;
119311 + }
119312 + }
119313 +
119314 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
119315 +
119316 + // 1. create local entropy variable
119317 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
119318 + add_referenced_var(local_entropy);
119319 + mark_sym_for_renaming(local_entropy);
119320 +
119321 + // 2. initialize local entropy variable
119322 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119323 + if (dom_info_available_p(CDI_DOMINATORS))
119324 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119325 + gsi = gsi_start_bb(bb);
119326 +
119327 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
119328 +// gimple_set_location(assign, loc);
119329 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
119330 + update_stmt(assign);
119331 +//debug_bb(bb);
119332 + gcc_assert(single_succ_p(bb));
119333 + bb = single_succ(bb);
119334 +
119335 + // 3. instrument each BB with an operation on the local entropy variable
119336 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
119337 + perturb_local_entropy(bb, local_entropy);
119338 +//debug_bb(bb);
119339 + bb = bb->next_bb;
119340 + };
119341 +
119342 + // 4. mix local entropy into the global entropy variable
119343 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
119344 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
119345 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
119346 + return 0;
119347 +}
119348 +
119349 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
119350 +{
119351 + tree latent_entropy_type;
119352 +
119353 + seed = get_random_seed(false);
119354 +
119355 + if (in_lto_p)
119356 + return;
119357 +
119358 + // extern volatile u64 latent_entropy
119359 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
119360 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
119361 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
119362 +
119363 + TREE_STATIC(latent_entropy_decl) = 1;
119364 + TREE_PUBLIC(latent_entropy_decl) = 1;
119365 + TREE_USED(latent_entropy_decl) = 1;
119366 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
119367 + DECL_EXTERNAL(latent_entropy_decl) = 1;
119368 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
119369 + lang_hooks.decls.pushdecl(latent_entropy_decl);
119370 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
119371 +// varpool_finalize_decl(latent_entropy_decl);
119372 +// varpool_mark_needed_node(latent_entropy_decl);
119373 +}
119374 +
119375 +#if BUILDING_GCC_VERSION >= 4009
119376 +static const struct pass_data latent_entropy_pass_data = {
119377 +#else
119378 +static struct gimple_opt_pass latent_entropy_pass = {
119379 + .pass = {
119380 +#endif
119381 + .type = GIMPLE_PASS,
119382 + .name = "latent_entropy",
119383 +#if BUILDING_GCC_VERSION >= 4008
119384 + .optinfo_flags = OPTGROUP_NONE,
119385 +#endif
119386 +#if BUILDING_GCC_VERSION >= 4009
119387 + .has_gate = true,
119388 + .has_execute = true,
119389 +#else
119390 + .gate = gate_latent_entropy,
119391 + .execute = execute_latent_entropy,
119392 + .sub = NULL,
119393 + .next = NULL,
119394 + .static_pass_number = 0,
119395 +#endif
119396 + .tv_id = TV_NONE,
119397 + .properties_required = PROP_gimple_leh | PROP_cfg,
119398 + .properties_provided = 0,
119399 + .properties_destroyed = 0,
119400 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
119401 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
119402 +#if BUILDING_GCC_VERSION < 4009
119403 + }
119404 +#endif
119405 +};
119406 +
119407 +#if BUILDING_GCC_VERSION >= 4009
119408 +namespace {
119409 +class latent_entropy_pass : public gimple_opt_pass {
119410 +public:
119411 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
119412 + bool gate() { return gate_latent_entropy(); }
119413 + unsigned int execute() { return execute_latent_entropy(); }
119414 +};
119415 +}
119416 +
119417 +static opt_pass *make_latent_entropy_pass(void)
119418 +{
119419 + return new latent_entropy_pass();
119420 +}
119421 +#else
119422 +static struct opt_pass *make_latent_entropy_pass(void)
119423 +{
119424 + return &latent_entropy_pass.pass;
119425 +}
119426 +#endif
119427 +
119428 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119429 +{
119430 + const char * const plugin_name = plugin_info->base_name;
119431 + struct register_pass_info latent_entropy_pass_info;
119432 +
119433 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
119434 + latent_entropy_pass_info.reference_pass_name = "optimized";
119435 + latent_entropy_pass_info.ref_pass_instance_number = 1;
119436 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119437 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
119438 + {
119439 + .base = &latent_entropy_decl,
119440 + .nelt = 1,
119441 + .stride = sizeof(latent_entropy_decl),
119442 + .cb = &gt_ggc_mx_tree_node,
119443 + .pchw = &gt_pch_nx_tree_node
119444 + },
119445 + LAST_GGC_ROOT_TAB
119446 + };
119447 +
119448 + if (!plugin_default_version_check(version, &gcc_version)) {
119449 + error(G_("incompatible gcc/plugin versions"));
119450 + return 1;
119451 + }
119452 +
119453 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
119454 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
119455 + if (!in_lto_p)
119456 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
119457 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
119458 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119459 +
119460 + return 0;
119461 +}
119462 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
119463 new file mode 100644
119464 index 0000000..a5cb46b
119465 --- /dev/null
119466 +++ b/tools/gcc/randomize_layout_plugin.c
119467 @@ -0,0 +1,915 @@
119468 +/*
119469 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
119470 + * and PaX Team <pageexec@freemail.hu>
119471 + * Licensed under the GPL v2
119472 + *
119473 + * Usage:
119474 + * $ # for 4.5/4.6/C based 4.7
119475 + * $ 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
119476 + * $ # for C++ based 4.7/4.8+
119477 + * $ 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
119478 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
119479 + */
119480 +
119481 +#include "gcc-common.h"
119482 +#include "randomize_layout_seed.h"
119483 +
119484 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
119485 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
119486 +#endif
119487 +
119488 +#define ORIG_TYPE_NAME(node) \
119489 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
119490 +
119491 +int plugin_is_GPL_compatible;
119492 +
119493 +static int performance_mode;
119494 +
119495 +static struct plugin_info randomize_layout_plugin_info = {
119496 + .version = "201402201816",
119497 + .help = "disable\t\t\tdo not activate plugin\n"
119498 + "performance-mode\tenable cacheline-aware layout randomization\n"
119499 +};
119500 +
119501 +/* from old Linux dcache.h */
119502 +static inline unsigned long
119503 +partial_name_hash(unsigned long c, unsigned long prevhash)
119504 +{
119505 + return (prevhash + (c << 4) + (c >> 4)) * 11;
119506 +}
119507 +static inline unsigned int
119508 +name_hash(const unsigned char *name)
119509 +{
119510 + unsigned long hash = 0;
119511 + unsigned int len = strlen((const char *)name);
119512 + while (len--)
119513 + hash = partial_name_hash(*name++, hash);
119514 + return (unsigned int)hash;
119515 +}
119516 +
119517 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119518 +{
119519 + tree type;
119520 +
119521 + *no_add_attrs = true;
119522 + if (TREE_CODE(*node) == FUNCTION_DECL) {
119523 + error("%qE attribute does not apply to functions (%qF)", name, *node);
119524 + return NULL_TREE;
119525 + }
119526 +
119527 + if (TREE_CODE(*node) == PARM_DECL) {
119528 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
119529 + return NULL_TREE;
119530 + }
119531 +
119532 + if (TREE_CODE(*node) == VAR_DECL) {
119533 + error("%qE attribute does not apply to variables (%qD)", name, *node);
119534 + return NULL_TREE;
119535 + }
119536 +
119537 + if (TYPE_P(*node)) {
119538 + type = *node;
119539 + } else {
119540 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
119541 + type = TREE_TYPE(*node);
119542 + }
119543 +
119544 + if (TREE_CODE(type) != RECORD_TYPE) {
119545 + error("%qE attribute used on %qT applies to struct types only", name, type);
119546 + return NULL_TREE;
119547 + }
119548 +
119549 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
119550 + error("%qE attribute is already applied to the type %qT", name, type);
119551 + return NULL_TREE;
119552 + }
119553 +
119554 + *no_add_attrs = false;
119555 +
119556 + return NULL_TREE;
119557 +}
119558 +
119559 +/* set on complete types that we don't need to inspect further at all */
119560 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119561 +{
119562 + *no_add_attrs = false;
119563 + return NULL_TREE;
119564 +}
119565 +
119566 +/*
119567 + * set on types that we've performed a shuffle on, to prevent re-shuffling
119568 + * this does not preclude us from inspecting its fields for potential shuffles
119569 + */
119570 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119571 +{
119572 + *no_add_attrs = false;
119573 + return NULL_TREE;
119574 +}
119575 +
119576 +/*
119577 + * 64bit variant of Bob Jenkins' public domain PRNG
119578 + * 256 bits of internal state
119579 + */
119580 +
119581 +typedef unsigned long long u64;
119582 +
119583 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
119584 +
119585 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
119586 +static u64 ranval(ranctx *x) {
119587 + u64 e = x->a - rot(x->b, 7);
119588 + x->a = x->b ^ rot(x->c, 13);
119589 + x->b = x->c + rot(x->d, 37);
119590 + x->c = x->d + e;
119591 + x->d = e + x->a;
119592 + return x->d;
119593 +}
119594 +
119595 +static void raninit(ranctx *x, u64 *seed) {
119596 + int i;
119597 +
119598 + x->a = seed[0];
119599 + x->b = seed[1];
119600 + x->c = seed[2];
119601 + x->d = seed[3];
119602 +
119603 + for (i=0; i < 30; ++i)
119604 + (void)ranval(x);
119605 +}
119606 +
119607 +static u64 shuffle_seed[4];
119608 +
119609 +struct partition_group {
119610 + tree tree_start;
119611 + unsigned long start;
119612 + unsigned long length;
119613 +};
119614 +
119615 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
119616 +{
119617 + unsigned long i;
119618 + unsigned long accum_size = 0;
119619 + unsigned long accum_length = 0;
119620 + unsigned long group_idx = 0;
119621 +
119622 + gcc_assert(length < INT_MAX);
119623 +
119624 + memset(size_groups, 0, sizeof(struct partition_group) * length);
119625 +
119626 + for (i = 0; i < length; i++) {
119627 + if (size_groups[group_idx].tree_start == NULL_TREE) {
119628 + size_groups[group_idx].tree_start = fields[i];
119629 + size_groups[group_idx].start = i;
119630 + accum_length = 0;
119631 + accum_size = 0;
119632 + }
119633 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
119634 + accum_length++;
119635 + if (accum_size >= 64) {
119636 + size_groups[group_idx].length = accum_length;
119637 + accum_length = 0;
119638 + group_idx++;
119639 + }
119640 + }
119641 +
119642 + if (size_groups[group_idx].tree_start != NULL_TREE &&
119643 + !size_groups[group_idx].length) {
119644 + size_groups[group_idx].length = accum_length;
119645 + group_idx++;
119646 + }
119647 +
119648 + *num_groups = group_idx;
119649 +}
119650 +
119651 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
119652 +{
119653 + unsigned long i, x;
119654 + struct partition_group size_group[length];
119655 + unsigned long num_groups = 0;
119656 + unsigned long randnum;
119657 +
119658 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
119659 + for (i = num_groups - 1; i > 0; i--) {
119660 + struct partition_group tmp;
119661 + randnum = ranval(prng_state) % (i + 1);
119662 + tmp = size_group[i];
119663 + size_group[i] = size_group[randnum];
119664 + size_group[randnum] = tmp;
119665 + }
119666 +
119667 + for (x = 0; x < num_groups; x++) {
119668 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
119669 + tree tmp;
119670 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
119671 + continue;
119672 + randnum = ranval(prng_state) % (i + 1);
119673 + // we could handle this case differently if desired
119674 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
119675 + continue;
119676 + tmp = newtree[i];
119677 + newtree[i] = newtree[randnum];
119678 + newtree[randnum] = tmp;
119679 + }
119680 + }
119681 +}
119682 +
119683 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
119684 +{
119685 + unsigned long i, randnum;
119686 +
119687 + for (i = length - 1; i > 0; i--) {
119688 + tree tmp;
119689 + randnum = ranval(prng_state) % (i + 1);
119690 + tmp = newtree[i];
119691 + newtree[i] = newtree[randnum];
119692 + newtree[randnum] = tmp;
119693 + }
119694 +}
119695 +
119696 +/* modern in-place Fisher-Yates shuffle */
119697 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
119698 +{
119699 + unsigned long i;
119700 + u64 seed[4];
119701 + ranctx prng_state;
119702 + const unsigned char *structname;
119703 +
119704 + if (length == 0)
119705 + return;
119706 +
119707 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
119708 +
119709 + structname = ORIG_TYPE_NAME(type);
119710 +
119711 +#ifdef __DEBUG_PLUGIN
119712 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
119713 +#ifdef __DEBUG_VERBOSE
119714 + debug_tree((tree)type);
119715 +#endif
119716 +#endif
119717 +
119718 + for (i = 0; i < 4; i++) {
119719 + seed[i] = shuffle_seed[i];
119720 + seed[i] ^= name_hash(structname);
119721 + }
119722 +
119723 + raninit(&prng_state, (u64 *)&seed);
119724 +
119725 + if (performance_mode)
119726 + performance_shuffle(newtree, length, &prng_state);
119727 + else
119728 + full_shuffle(newtree, length, &prng_state);
119729 +}
119730 +
119731 +static bool is_flexible_array(const_tree field)
119732 +{
119733 + const_tree fieldtype;
119734 + const_tree typesize;
119735 + const_tree elemtype;
119736 + const_tree elemsize;
119737 +
119738 + fieldtype = TREE_TYPE(field);
119739 + typesize = TYPE_SIZE(fieldtype);
119740 +
119741 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
119742 + return false;
119743 +
119744 + elemtype = TREE_TYPE(fieldtype);
119745 + elemsize = TYPE_SIZE(elemtype);
119746 +
119747 + /* size of type is represented in bits */
119748 +
119749 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
119750 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
119751 + return true;
119752 +
119753 + if (typesize != NULL_TREE &&
119754 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
119755 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
119756 + return true;
119757 +
119758 + return false;
119759 +}
119760 +
119761 +static int relayout_struct(tree type)
119762 +{
119763 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
119764 + unsigned long shuffle_length = num_fields;
119765 + tree field;
119766 + tree newtree[num_fields];
119767 + unsigned long i;
119768 + tree list;
119769 + tree variant;
119770 + expanded_location xloc;
119771 +
119772 + if (TYPE_FIELDS(type) == NULL_TREE)
119773 + return 0;
119774 +
119775 + if (num_fields < 2)
119776 + return 0;
119777 +
119778 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
119779 +
119780 + gcc_assert(num_fields < INT_MAX);
119781 +
119782 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
119783 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
119784 + return 0;
119785 +
119786 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
119787 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
119788 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
119789 + return 0;
119790 +
119791 + /* throw out any structs in uapi */
119792 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
119793 +
119794 + if (strstr(xloc.file, "/uapi/"))
119795 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
119796 +
119797 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
119798 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
119799 + newtree[i] = field;
119800 + }
119801 +
119802 + /*
119803 + * enforce that we don't randomize the layout of the last
119804 + * element of a struct if it's a 0 or 1-length array
119805 + * or a proper flexible array
119806 + */
119807 + if (is_flexible_array(newtree[num_fields - 1]))
119808 + shuffle_length--;
119809 +
119810 + shuffle(type, (tree *)newtree, shuffle_length);
119811 +
119812 + /*
119813 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
119814 + * as gcc provides no other way to detect such code
119815 + */
119816 + list = make_node(FIELD_DECL);
119817 + TREE_CHAIN(list) = newtree[0];
119818 + TREE_TYPE(list) = void_type_node;
119819 + DECL_SIZE(list) = bitsize_zero_node;
119820 + DECL_NONADDRESSABLE_P(list) = 1;
119821 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
119822 + DECL_SIZE_UNIT(list) = size_zero_node;
119823 + DECL_FIELD_OFFSET(list) = size_zero_node;
119824 + // to satisfy the constify plugin
119825 + TREE_READONLY(list) = 1;
119826 +
119827 + for (i = 0; i < num_fields - 1; i++)
119828 + TREE_CHAIN(newtree[i]) = newtree[i+1];
119829 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
119830 +
119831 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
119832 + TYPE_FIELDS(variant) = list;
119833 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
119834 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
119835 + // force a re-layout
119836 + TYPE_SIZE(variant) = NULL_TREE;
119837 + layout_type(variant);
119838 + }
119839 +
119840 + return 1;
119841 +}
119842 +
119843 +/* from constify plugin */
119844 +static const_tree get_field_type(const_tree field)
119845 +{
119846 + return strip_array_types(TREE_TYPE(field));
119847 +}
119848 +
119849 +/* from constify plugin */
119850 +static bool is_fptr(const_tree fieldtype)
119851 +{
119852 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
119853 + return false;
119854 +
119855 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
119856 +}
119857 +
119858 +/* derived from constify plugin */
119859 +static int is_pure_ops_struct(const_tree node)
119860 +{
119861 + const_tree field;
119862 +
119863 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
119864 +
119865 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
119866 + const_tree fieldtype = get_field_type(field);
119867 + enum tree_code code = TREE_CODE(fieldtype);
119868 +
119869 + if (node == fieldtype)
119870 + continue;
119871 +
119872 + if (!is_fptr(fieldtype))
119873 + return 0;
119874 +
119875 + if (code != RECORD_TYPE && code != UNION_TYPE)
119876 + continue;
119877 +
119878 + if (!is_pure_ops_struct(fieldtype))
119879 + return 0;
119880 + }
119881 +
119882 + return 1;
119883 +}
119884 +
119885 +static void randomize_type(tree type)
119886 +{
119887 + tree variant;
119888 +
119889 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
119890 +
119891 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
119892 + return;
119893 +
119894 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
119895 + relayout_struct(type);
119896 +
119897 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
119898 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
119899 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
119900 + }
119901 +#ifdef __DEBUG_PLUGIN
119902 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
119903 +#ifdef __DEBUG_VERBOSE
119904 + debug_tree(type);
119905 +#endif
119906 +#endif
119907 +}
119908 +
119909 +static void randomize_layout_finish_decl(void *event_data, void *data)
119910 +{
119911 + tree decl = (tree)event_data;
119912 + tree type;
119913 +
119914 + if (decl == NULL_TREE || decl == error_mark_node)
119915 + return;
119916 +
119917 + type = TREE_TYPE(decl);
119918 +
119919 + if (TREE_CODE(decl) != VAR_DECL)
119920 + return;
119921 +
119922 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
119923 + return;
119924 +
119925 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
119926 + return;
119927 +
119928 + relayout_decl(decl);
119929 +}
119930 +
119931 +static void finish_type(void *event_data, void *data)
119932 +{
119933 + tree type = (tree)event_data;
119934 +
119935 + if (type == NULL_TREE || type == error_mark_node)
119936 + return;
119937 +
119938 + if (TREE_CODE(type) != RECORD_TYPE)
119939 + return;
119940 +
119941 + if (TYPE_FIELDS(type) == NULL_TREE)
119942 + return;
119943 +
119944 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
119945 + return;
119946 +
119947 +#ifdef __DEBUG_PLUGIN
119948 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
119949 +#endif
119950 +#ifdef __DEBUG_VERBOSE
119951 + debug_tree(type);
119952 +#endif
119953 + randomize_type(type);
119954 +
119955 + return;
119956 +}
119957 +
119958 +static struct attribute_spec randomize_layout_attr = {
119959 + .name = "randomize_layout",
119960 + // related to args
119961 + .min_length = 0,
119962 + .max_length = 0,
119963 + .decl_required = false,
119964 + // need type declaration
119965 + .type_required = true,
119966 + .function_type_required = false,
119967 + .handler = handle_randomize_layout_attr,
119968 +#if BUILDING_GCC_VERSION >= 4007
119969 + .affects_type_identity = true
119970 +#endif
119971 +};
119972 +
119973 +static struct attribute_spec no_randomize_layout_attr = {
119974 + .name = "no_randomize_layout",
119975 + // related to args
119976 + .min_length = 0,
119977 + .max_length = 0,
119978 + .decl_required = false,
119979 + // need type declaration
119980 + .type_required = true,
119981 + .function_type_required = false,
119982 + .handler = handle_randomize_layout_attr,
119983 +#if BUILDING_GCC_VERSION >= 4007
119984 + .affects_type_identity = true
119985 +#endif
119986 +};
119987 +
119988 +static struct attribute_spec randomize_considered_attr = {
119989 + .name = "randomize_considered",
119990 + // related to args
119991 + .min_length = 0,
119992 + .max_length = 0,
119993 + .decl_required = false,
119994 + // need type declaration
119995 + .type_required = true,
119996 + .function_type_required = false,
119997 + .handler = handle_randomize_considered_attr,
119998 +#if BUILDING_GCC_VERSION >= 4007
119999 + .affects_type_identity = false
120000 +#endif
120001 +};
120002 +
120003 +static struct attribute_spec randomize_performed_attr = {
120004 + .name = "randomize_performed",
120005 + // related to args
120006 + .min_length = 0,
120007 + .max_length = 0,
120008 + .decl_required = false,
120009 + // need type declaration
120010 + .type_required = true,
120011 + .function_type_required = false,
120012 + .handler = handle_randomize_performed_attr,
120013 +#if BUILDING_GCC_VERSION >= 4007
120014 + .affects_type_identity = false
120015 +#endif
120016 +};
120017 +
120018 +static void register_attributes(void *event_data, void *data)
120019 +{
120020 + register_attribute(&randomize_layout_attr);
120021 + register_attribute(&no_randomize_layout_attr);
120022 + register_attribute(&randomize_considered_attr);
120023 + register_attribute(&randomize_performed_attr);
120024 +}
120025 +
120026 +static void check_bad_casts_in_constructor(tree var, tree init)
120027 +{
120028 + unsigned HOST_WIDE_INT idx;
120029 + tree field, val;
120030 + tree field_type, val_type;
120031 +
120032 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
120033 + if (TREE_CODE(val) == CONSTRUCTOR) {
120034 + check_bad_casts_in_constructor(var, val);
120035 + continue;
120036 + }
120037 +
120038 + /* pipacs' plugin creates franken-arrays that differ from those produced by
120039 + normal code which all have valid 'field' trees. work around this */
120040 + if (field == NULL_TREE)
120041 + continue;
120042 + field_type = TREE_TYPE(field);
120043 + val_type = TREE_TYPE(val);
120044 +
120045 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
120046 + continue;
120047 +
120048 + if (field_type == val_type)
120049 + continue;
120050 +
120051 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
120052 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
120053 +
120054 + if (field_type == void_type_node)
120055 + continue;
120056 + if (field_type == val_type)
120057 + continue;
120058 + if (TREE_CODE(val_type) != RECORD_TYPE)
120059 + continue;
120060 +
120061 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
120062 + continue;
120063 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
120064 + }
120065 +}
120066 +
120067 +/* derived from the constify plugin */
120068 +static void check_global_variables(void *event_data, void *data)
120069 +{
120070 + struct varpool_node *node;
120071 + tree init;
120072 +
120073 + FOR_EACH_VARIABLE(node) {
120074 + tree var = NODE_DECL(node);
120075 + init = DECL_INITIAL(var);
120076 + if (init == NULL_TREE)
120077 + continue;
120078 +
120079 + if (TREE_CODE(init) != CONSTRUCTOR)
120080 + continue;
120081 +
120082 + check_bad_casts_in_constructor(var, init);
120083 + }
120084 +}
120085 +
120086 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
120087 +{
120088 + basic_block dom;
120089 + gimple dom_stmt;
120090 + gimple call_stmt;
120091 + const_tree dom_lhs;
120092 + const_tree poss_is_err_cond;
120093 + const_tree poss_is_err_func;
120094 + const_tree is_err_arg;
120095 +
120096 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
120097 + if (!dom)
120098 + return false;
120099 +
120100 + dom_stmt = last_stmt(dom);
120101 + if (!dom_stmt)
120102 + return false;
120103 +
120104 + if (gimple_code(dom_stmt) != GIMPLE_COND)
120105 + return false;
120106 +
120107 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
120108 + return false;
120109 +
120110 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
120111 + return false;
120112 +
120113 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
120114 +
120115 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
120116 + return false;
120117 +
120118 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
120119 +
120120 + if (gimple_code(call_stmt) != GIMPLE_CALL)
120121 + return false;
120122 +
120123 + dom_lhs = gimple_get_lhs(call_stmt);
120124 + poss_is_err_func = gimple_call_fndecl(call_stmt);
120125 + if (!poss_is_err_func)
120126 + return false;
120127 + if (dom_lhs != poss_is_err_cond)
120128 + return false;
120129 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
120130 + return false;
120131 +
120132 + is_err_arg = gimple_call_arg(call_stmt, 0);
120133 + if (!is_err_arg)
120134 + return false;
120135 +
120136 + if (is_err_arg != rhs)
120137 + return false;
120138 +
120139 + return true;
120140 +}
120141 +
120142 +static void handle_local_var_initializers(void)
120143 +{
120144 + tree var;
120145 + unsigned int i;
120146 +
120147 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
120148 + tree init = DECL_INITIAL(var);
120149 + if (!init)
120150 + continue;
120151 + if (TREE_CODE(init) != CONSTRUCTOR)
120152 + continue;
120153 + check_bad_casts_in_constructor(var, init);
120154 + }
120155 +}
120156 +
120157 +/*
120158 + * iterate over all statements to find "bad" casts:
120159 + * those where the address of the start of a structure is cast
120160 + * to a pointer of a structure of a different type, or a
120161 + * structure pointer type is cast to a different structure pointer type
120162 + */
120163 +static unsigned int find_bad_casts(void)
120164 +{
120165 + basic_block bb;
120166 +
120167 + handle_local_var_initializers();
120168 +
120169 + FOR_ALL_BB_FN(bb, cfun) {
120170 + gimple_stmt_iterator gsi;
120171 +
120172 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
120173 + gimple stmt;
120174 + const_tree lhs;
120175 + const_tree lhs_type;
120176 + const_tree rhs1;
120177 + const_tree rhs_type;
120178 + const_tree ptr_lhs_type;
120179 + const_tree ptr_rhs_type;
120180 + const_tree op0;
120181 + const_tree op0_type;
120182 + enum tree_code rhs_code;
120183 +
120184 + stmt = gsi_stmt(gsi);
120185 +
120186 +#ifdef __DEBUG_PLUGIN
120187 +#ifdef __DEBUG_VERBOSE
120188 + debug_gimple_stmt(stmt);
120189 + debug_tree(gimple_get_lhs(stmt));
120190 +#endif
120191 +#endif
120192 +
120193 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
120194 + continue;
120195 +
120196 +#ifdef __DEBUG_PLUGIN
120197 +#ifdef __DEBUG_VERBOSE
120198 + debug_tree(gimple_assign_rhs1(stmt));
120199 +#endif
120200 +#endif
120201 +
120202 + rhs_code = gimple_assign_rhs_code(stmt);
120203 +
120204 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
120205 + continue;
120206 +
120207 + lhs = gimple_get_lhs(stmt);
120208 + lhs_type = TREE_TYPE(lhs);
120209 + rhs1 = gimple_assign_rhs1(stmt);
120210 + rhs_type = TREE_TYPE(rhs1);
120211 +
120212 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
120213 + TREE_CODE(lhs_type) != POINTER_TYPE)
120214 + continue;
120215 +
120216 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
120217 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
120218 +
120219 + if (ptr_rhs_type == void_type_node)
120220 + continue;
120221 +
120222 + if (ptr_lhs_type == void_type_node)
120223 + continue;
120224 +
120225 + if (dominated_by_is_err(rhs1, bb))
120226 + continue;
120227 +
120228 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
120229 +#ifndef __DEBUG_PLUGIN
120230 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
120231 +#endif
120232 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
120233 + continue;
120234 + }
120235 +
120236 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
120237 + continue;
120238 +
120239 + if (rhs_code == ADDR_EXPR) {
120240 + op0 = TREE_OPERAND(rhs1, 0);
120241 +
120242 + if (op0 == NULL_TREE)
120243 + continue;
120244 +
120245 + if (TREE_CODE(op0) != VAR_DECL)
120246 + continue;
120247 +
120248 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
120249 + if (op0_type == ptr_lhs_type)
120250 + continue;
120251 +
120252 +#ifndef __DEBUG_PLUGIN
120253 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
120254 +#endif
120255 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
120256 + } else {
120257 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
120258 + /* skip bogus type casts introduced by container_of */
120259 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
120260 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
120261 + continue;
120262 +#ifndef __DEBUG_PLUGIN
120263 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
120264 +#endif
120265 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
120266 + }
120267 +
120268 + }
120269 + }
120270 + return 0;
120271 +}
120272 +
120273 +#if BUILDING_GCC_VERSION >= 4009
120274 +static const struct pass_data randomize_layout_bad_cast_data = {
120275 +#else
120276 +static struct gimple_opt_pass randomize_layout_bad_cast = {
120277 + .pass = {
120278 +#endif
120279 + .type = GIMPLE_PASS,
120280 + .name = "randomize_layout_bad_cast",
120281 +#if BUILDING_GCC_VERSION >= 4008
120282 + .optinfo_flags = OPTGROUP_NONE,
120283 +#endif
120284 +#if BUILDING_GCC_VERSION >= 4009
120285 + .has_gate = false,
120286 + .has_execute = true,
120287 +#else
120288 + .gate = NULL,
120289 + .execute = find_bad_casts,
120290 + .sub = NULL,
120291 + .next = NULL,
120292 + .static_pass_number = 0,
120293 +#endif
120294 + .tv_id = TV_NONE,
120295 + .properties_required = PROP_cfg,
120296 + .properties_provided = 0,
120297 + .properties_destroyed = 0,
120298 + .todo_flags_start = 0,
120299 + .todo_flags_finish = TODO_dump_func
120300 +#if BUILDING_GCC_VERSION < 4009
120301 + }
120302 +#endif
120303 +};
120304 +
120305 +#if BUILDING_GCC_VERSION >= 4009
120306 +namespace {
120307 +class randomize_layout_bad_cast : public gimple_opt_pass {
120308 +public:
120309 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
120310 + unsigned int execute() { return find_bad_casts(); }
120311 +};
120312 +}
120313 +#endif
120314 +
120315 +static struct opt_pass *make_randomize_layout_bad_cast(void)
120316 +{
120317 +#if BUILDING_GCC_VERSION >= 4009
120318 + return new randomize_layout_bad_cast();
120319 +#else
120320 + return &randomize_layout_bad_cast.pass;
120321 +#endif
120322 +}
120323 +
120324 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
120325 +{
120326 + int i;
120327 + const char * const plugin_name = plugin_info->base_name;
120328 + const int argc = plugin_info->argc;
120329 + const struct plugin_argument * const argv = plugin_info->argv;
120330 + bool enable = true;
120331 + int obtained_seed = 0;
120332 + struct register_pass_info randomize_layout_bad_cast_info;
120333 +
120334 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
120335 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
120336 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
120337 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
120338 +
120339 + if (!plugin_default_version_check(version, &gcc_version)) {
120340 + error(G_("incompatible gcc/plugin versions"));
120341 + return 1;
120342 + }
120343 +
120344 + if (strcmp(lang_hooks.name, "GNU C")) {
120345 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
120346 + enable = false;
120347 + }
120348 +
120349 + for (i = 0; i < argc; ++i) {
120350 + if (!strcmp(argv[i].key, "disable")) {
120351 + enable = false;
120352 + continue;
120353 + }
120354 + if (!strcmp(argv[i].key, "performance-mode")) {
120355 + performance_mode = 1;
120356 + continue;
120357 + }
120358 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
120359 + }
120360 +
120361 + if (strlen(randstruct_seed) != 64) {
120362 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
120363 + return 1;
120364 + }
120365 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
120366 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
120367 + if (obtained_seed != 4) {
120368 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
120369 + return 1;
120370 + }
120371 +
120372 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
120373 + if (enable) {
120374 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
120375 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
120376 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
120377 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
120378 + }
120379 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
120380 +
120381 + return 0;
120382 +}
120383 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
120384 new file mode 100644
120385 index 0000000..1f0214f
120386 --- /dev/null
120387 +++ b/tools/gcc/size_overflow_plugin/.gitignore
120388 @@ -0,0 +1,3 @@
120389 +randomize_layout_seed.h
120390 +size_overflow_hash.h
120391 +size_overflow_hash_aux.h
120392 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
120393 new file mode 100644
120394 index 0000000..1ae2ed5
120395 --- /dev/null
120396 +++ b/tools/gcc/size_overflow_plugin/Makefile
120397 @@ -0,0 +1,20 @@
120398 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
120399 +always := $($(HOSTLIBS)-y)
120400 +
120401 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
120402 +
120403 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
120404 +
120405 +quiet_cmd_build_size_overflow_hash = GENHASH $@
120406 + cmd_build_size_overflow_hash = \
120407 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
120408 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
120409 + $(call if_changed,build_size_overflow_hash)
120410 +
120411 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
120412 + cmd_build_size_overflow_hash_aux = \
120413 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
120414 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
120415 + $(call if_changed,build_size_overflow_hash_aux)
120416 +
120417 +targets += size_overflow_hash.h size_overflow_hash_aux.h
120418 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
120419 new file mode 100644
120420 index 0000000..12b1e3b
120421 --- /dev/null
120422 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
120423 @@ -0,0 +1,102 @@
120424 +#!/bin/bash
120425 +
120426 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
120427 +
120428 +header1="size_overflow_hash.h"
120429 +database="size_overflow_hash.data"
120430 +n=65536
120431 +hashtable_name="size_overflow_hash"
120432 +
120433 +usage() {
120434 +cat <<EOF
120435 +usage: $0 options
120436 +OPTIONS:
120437 + -h|--help help
120438 + -o header file
120439 + -d database file
120440 + -n hash array size
120441 + -s name of the hash table
120442 +EOF
120443 + return 0
120444 +}
120445 +
120446 +while true
120447 +do
120448 + case "$1" in
120449 + -h|--help) usage && exit 0;;
120450 + -n) n=$2; shift 2;;
120451 + -o) header1="$2"; shift 2;;
120452 + -d) database="$2"; shift 2;;
120453 + -s) hashtable_name="$2"; shift 2;;
120454 + --) shift 1; break ;;
120455 + *) break ;;
120456 + esac
120457 +done
120458 +
120459 +create_defines() {
120460 + for i in `seq 0 31`
120461 + do
120462 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
120463 + done
120464 + echo >> "$header1"
120465 +}
120466 +
120467 +create_structs() {
120468 + rm -f "$header1"
120469 +
120470 + create_defines
120471 +
120472 + cat "$database" | while read data
120473 + do
120474 + data_array=($data)
120475 + struct_hash_name="${data_array[0]}"
120476 + funcn="${data_array[1]}"
120477 + params="${data_array[2]}"
120478 + next="${data_array[4]}"
120479 +
120480 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
120481 +
120482 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
120483 + echo -en "\t.param\t= " >> "$header1"
120484 + line=
120485 + for param_num in ${params//-/ };
120486 + do
120487 + line="${line}PARAM"$param_num"|"
120488 + done
120489 +
120490 + echo -e "${line%?},\n};\n" >> "$header1"
120491 + done
120492 +}
120493 +
120494 +create_headers() {
120495 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
120496 +}
120497 +
120498 +create_array_elements() {
120499 + index=0
120500 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
120501 + do
120502 + data_array=($data)
120503 + i="${data_array[3]}"
120504 + hash="${data_array[0]}"
120505 + while [[ $index -lt $i ]]
120506 + do
120507 + echo -e "\t["$index"]\t= NULL," >> "$header1"
120508 + index=$(($index + 1))
120509 + done
120510 + index=$(($index + 1))
120511 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
120512 + done
120513 + echo '};' >> $header1
120514 +}
120515 +
120516 +size_overflow_plugin_dir=`dirname $header1`
120517 +if [ "$size_overflow_plugin_dir" != '.' ]; then
120518 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
120519 +fi
120520 +
120521 +create_structs
120522 +create_headers
120523 +create_array_elements
120524 +
120525 +exit 0
120526 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
120527 new file mode 100644
120528 index 0000000..c43901f
120529 --- /dev/null
120530 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
120531 @@ -0,0 +1,748 @@
120532 +/*
120533 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120534 + * Licensed under the GPL v2, or (at your option) v3
120535 + *
120536 + * Homepage:
120537 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120538 + *
120539 + * Documentation:
120540 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120541 + *
120542 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120543 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120544 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120545 + *
120546 + * Usage:
120547 + * $ make
120548 + * $ make run
120549 + */
120550 +
120551 +#include "gcc-common.h"
120552 +#include "size_overflow.h"
120553 +
120554 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
120555 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
120556 +
120557 +// data for the size_overflow asm stmt
120558 +struct asm_data {
120559 + gimple def_stmt;
120560 + tree input;
120561 + tree output;
120562 +};
120563 +
120564 +#if BUILDING_GCC_VERSION <= 4007
120565 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
120566 +#else
120567 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
120568 +#endif
120569 +{
120570 + tree list;
120571 +#if BUILDING_GCC_VERSION <= 4007
120572 + VEC(tree, gc) *vec_list = NULL;
120573 +#else
120574 + vec<tree, va_gc> *vec_list = NULL;
120575 +#endif
120576 +
120577 + list = build_tree_list(NULL_TREE, string);
120578 + list = chainon(NULL_TREE, build_tree_list(list, io));
120579 +#if BUILDING_GCC_VERSION <= 4007
120580 + VEC_safe_push(tree, gc, vec_list, list);
120581 +#else
120582 + vec_safe_push(vec_list, list);
120583 +#endif
120584 + return vec_list;
120585 +}
120586 +
120587 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
120588 +{
120589 + gimple asm_stmt;
120590 + gimple_stmt_iterator gsi;
120591 +#if BUILDING_GCC_VERSION <= 4007
120592 + VEC(tree, gc) *input, *output = NULL;
120593 +#else
120594 + vec<tree, va_gc> *input, *output = NULL;
120595 +#endif
120596 +
120597 + input = create_asm_io_list(str_input, asm_data->input);
120598 +
120599 + if (asm_data->output)
120600 + output = create_asm_io_list(str_output, asm_data->output);
120601 +
120602 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
120603 + gsi = gsi_for_stmt(asm_data->def_stmt);
120604 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
120605 +
120606 + if (asm_data->output)
120607 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
120608 +}
120609 +
120610 +static void replace_call_lhs(const struct asm_data *asm_data)
120611 +{
120612 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
120613 + update_stmt(asm_data->def_stmt);
120614 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
120615 +}
120616 +
120617 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
120618 +{
120619 + enum mark cur_fndecl_attr;
120620 + gimple phi = get_def_stmt(result);
120621 + unsigned int i, n = gimple_phi_num_args(phi);
120622 +
120623 + pointer_set_insert(visited, phi);
120624 + for (i = 0; i < n; i++) {
120625 + tree arg = gimple_phi_arg_def(phi, i);
120626 +
120627 + cur_fndecl_attr = search_intentional(visited, arg);
120628 + if (cur_fndecl_attr != MARK_NO)
120629 + return cur_fndecl_attr;
120630 + }
120631 + return MARK_NO;
120632 +}
120633 +
120634 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
120635 +{
120636 + enum mark cur_fndecl_attr;
120637 + const_tree rhs1, rhs2;
120638 + gimple def_stmt = get_def_stmt(lhs);
120639 +
120640 + rhs1 = gimple_assign_rhs1(def_stmt);
120641 + rhs2 = gimple_assign_rhs2(def_stmt);
120642 +
120643 + cur_fndecl_attr = search_intentional(visited, rhs1);
120644 + if (cur_fndecl_attr != MARK_NO)
120645 + return cur_fndecl_attr;
120646 + return search_intentional(visited, rhs2);
120647 +}
120648 +
120649 +// Look up the intentional_overflow attribute on the caller and the callee functions.
120650 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
120651 +{
120652 + const_gimple def_stmt;
120653 +
120654 + if (TREE_CODE(lhs) != SSA_NAME)
120655 + return get_intentional_attr_type(lhs);
120656 +
120657 + def_stmt = get_def_stmt(lhs);
120658 + if (!def_stmt)
120659 + return MARK_NO;
120660 +
120661 + if (pointer_set_contains(visited, def_stmt))
120662 + return MARK_NO;
120663 +
120664 + switch (gimple_code(def_stmt)) {
120665 + case GIMPLE_NOP:
120666 + return search_intentional(visited, SSA_NAME_VAR(lhs));
120667 + case GIMPLE_ASM:
120668 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
120669 + return MARK_TURN_OFF;
120670 + return MARK_NO;
120671 + case GIMPLE_CALL:
120672 + return MARK_NO;
120673 + case GIMPLE_PHI:
120674 + return search_intentional_phi(visited, lhs);
120675 + case GIMPLE_ASSIGN:
120676 + switch (gimple_num_ops(def_stmt)) {
120677 + case 2:
120678 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
120679 + case 3:
120680 + return search_intentional_binary(visited, lhs);
120681 + }
120682 + case GIMPLE_RETURN:
120683 + return MARK_NO;
120684 + default:
120685 + debug_gimple_stmt((gimple)def_stmt);
120686 + error("%s: unknown gimple code", __func__);
120687 + gcc_unreachable();
120688 + }
120689 +}
120690 +
120691 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
120692 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
120693 +{
120694 + const_tree fndecl;
120695 + struct pointer_set_t *visited;
120696 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
120697 +
120698 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
120699 + if (is_end_intentional_intentional_attr(fndecl, argnum))
120700 + decl_attr = MARK_NOT_INTENTIONAL;
120701 + else if (is_yes_intentional_attr(fndecl, argnum))
120702 + decl_attr = MARK_YES;
120703 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
120704 + return MARK_TURN_OFF;
120705 + }
120706 +
120707 + visited = pointer_set_create();
120708 + cur_fndecl_attr = search_intentional(visited, arg);
120709 + pointer_set_destroy(visited);
120710 +
120711 + switch (cur_fndecl_attr) {
120712 + case MARK_NO:
120713 + case MARK_TURN_OFF:
120714 + return cur_fndecl_attr;
120715 + default:
120716 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
120717 + return MARK_YES;
120718 + }
120719 +}
120720 +
120721 +static void check_missing_size_overflow_attribute(tree var)
120722 +{
120723 + tree orig_fndecl;
120724 + unsigned int num;
120725 +
120726 + if (is_a_return_check(var))
120727 + orig_fndecl = DECL_ORIGIN(var);
120728 + else
120729 + orig_fndecl = DECL_ORIGIN(current_function_decl);
120730 +
120731 + num = get_function_num(var, orig_fndecl);
120732 + if (num == CANNOT_FIND_ARG)
120733 + return;
120734 +
120735 + is_missing_function(orig_fndecl, num);
120736 +}
120737 +
120738 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
120739 +{
120740 + gimple phi = get_def_stmt(result);
120741 + unsigned int i, n = gimple_phi_num_args(phi);
120742 +
120743 + pointer_set_insert(visited, phi);
120744 + for (i = 0; i < n; i++) {
120745 + tree arg = gimple_phi_arg_def(phi, i);
120746 +
120747 + search_size_overflow_attribute(visited, arg);
120748 + }
120749 +}
120750 +
120751 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
120752 +{
120753 + const_gimple def_stmt = get_def_stmt(lhs);
120754 + tree rhs1, rhs2;
120755 +
120756 + rhs1 = gimple_assign_rhs1(def_stmt);
120757 + rhs2 = gimple_assign_rhs2(def_stmt);
120758 +
120759 + search_size_overflow_attribute(visited, rhs1);
120760 + search_size_overflow_attribute(visited, rhs2);
120761 +}
120762 +
120763 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
120764 +{
120765 + const_gimple def_stmt;
120766 +
120767 + if (TREE_CODE(lhs) == PARM_DECL) {
120768 + check_missing_size_overflow_attribute(lhs);
120769 + return;
120770 + }
120771 +
120772 + def_stmt = get_def_stmt(lhs);
120773 + if (!def_stmt)
120774 + return;
120775 +
120776 + if (pointer_set_insert(visited, def_stmt))
120777 + return;
120778 +
120779 + switch (gimple_code(def_stmt)) {
120780 + case GIMPLE_NOP:
120781 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
120782 + case GIMPLE_ASM:
120783 + return;
120784 + case GIMPLE_CALL: {
120785 + tree fndecl = gimple_call_fndecl(def_stmt);
120786 +
120787 + if (fndecl == NULL_TREE)
120788 + return;
120789 + check_missing_size_overflow_attribute(fndecl);
120790 + return;
120791 + }
120792 + case GIMPLE_PHI:
120793 + return search_size_overflow_attribute_phi(visited, lhs);
120794 + case GIMPLE_ASSIGN:
120795 + switch (gimple_num_ops(def_stmt)) {
120796 + case 2:
120797 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
120798 + case 3:
120799 + return search_size_overflow_attribute_binary(visited, lhs);
120800 + }
120801 + default:
120802 + debug_gimple_stmt((gimple)def_stmt);
120803 + error("%s: unknown gimple code", __func__);
120804 + gcc_unreachable();
120805 + }
120806 +}
120807 +
120808 +// Search missing entries in the hash table (invoked from the gimple pass)
120809 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
120810 +{
120811 + tree fndecl = NULL_TREE;
120812 + tree lhs;
120813 + struct pointer_set_t *visited;
120814 +
120815 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
120816 + return;
120817 +
120818 + if (num == 0) {
120819 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
120820 + lhs = gimple_return_retval(stmt);
120821 + } else {
120822 + gcc_assert(is_gimple_call(stmt));
120823 + lhs = gimple_call_arg(stmt, num - 1);
120824 + fndecl = gimple_call_fndecl(stmt);
120825 + }
120826 +
120827 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
120828 + return;
120829 +
120830 + visited = pointer_set_create();
120831 + search_size_overflow_attribute(visited, lhs);
120832 + pointer_set_destroy(visited);
120833 +}
120834 +
120835 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
120836 +{
120837 + gimple_stmt_iterator gsi;
120838 + gimple assign;
120839 +
120840 + assign = gimple_build_assign(asm_data->input, asm_data->output);
120841 + gsi = gsi_for_stmt(stmt);
120842 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
120843 + asm_data->def_stmt = assign;
120844 +
120845 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
120846 + asm_data->output = make_ssa_name(asm_data->output, stmt);
120847 + if (gimple_code(stmt) == GIMPLE_RETURN)
120848 + gimple_return_set_retval(stmt, asm_data->output);
120849 + else
120850 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
120851 + update_stmt(stmt);
120852 +}
120853 +
120854 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
120855 +{
120856 + const char *fn_name;
120857 + char *asm_comment;
120858 + unsigned int len;
120859 +
120860 + if (argnum == 0)
120861 + fn_name = DECL_NAME_POINTER(current_function_decl);
120862 + else
120863 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
120864 +
120865 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
120866 + gcc_assert(len > 0);
120867 +
120868 + return asm_comment;
120869 +}
120870 +
120871 +static const char *convert_mark_to_str(enum mark mark)
120872 +{
120873 + switch (mark) {
120874 + case MARK_NO:
120875 + return OK_ASM_STR;
120876 + case MARK_YES:
120877 + case MARK_NOT_INTENTIONAL:
120878 + return YES_ASM_STR;
120879 + case MARK_TURN_OFF:
120880 + return TURN_OFF_ASM_STR;
120881 + }
120882 +
120883 + gcc_unreachable();
120884 +}
120885 +
120886 +/* Create the input of the size_overflow asm stmt.
120887 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
120888 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
120889 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
120890 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
120891 + */
120892 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
120893 +{
120894 + if (!asm_data->def_stmt) {
120895 + asm_data->input = NULL_TREE;
120896 + return;
120897 + }
120898 +
120899 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
120900 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
120901 +
120902 + switch (gimple_code(asm_data->def_stmt)) {
120903 + case GIMPLE_ASSIGN:
120904 + case GIMPLE_CALL:
120905 + replace_call_lhs(asm_data);
120906 + break;
120907 + case GIMPLE_PHI:
120908 + create_output_from_phi(stmt, argnum, asm_data);
120909 + break;
120910 + case GIMPLE_NOP: {
120911 + enum mark mark;
120912 + const char *mark_str;
120913 + char *asm_comment;
120914 +
120915 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
120916 +
120917 + asm_data->input = asm_data->output;
120918 + asm_data->output = NULL;
120919 + asm_data->def_stmt = stmt;
120920 +
120921 + mark_str = convert_mark_to_str(mark);
120922 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
120923 +
120924 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
120925 + free(asm_comment);
120926 + asm_data->input = NULL_TREE;
120927 + break;
120928 + }
120929 + case GIMPLE_ASM:
120930 + if (is_size_overflow_asm(asm_data->def_stmt)) {
120931 + asm_data->input = NULL_TREE;
120932 + break;
120933 + }
120934 + default:
120935 + debug_gimple_stmt(asm_data->def_stmt);
120936 + gcc_unreachable();
120937 + }
120938 +}
120939 +
120940 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
120941 + * is of the right kind create the appropriate size_overflow asm stmts:
120942 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
120943 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
120944 + */
120945 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
120946 +{
120947 + struct asm_data asm_data;
120948 + const char *mark_str;
120949 + char *asm_comment;
120950 + enum mark mark;
120951 +
120952 + if (is_gimple_constant(output_node))
120953 + return;
120954 +
120955 + asm_data.output = output_node;
120956 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
120957 + if (mark != MARK_TURN_OFF)
120958 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
120959 +
120960 + asm_data.def_stmt = get_def_stmt(asm_data.output);
120961 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
120962 + return;
120963 +
120964 + create_asm_input(stmt, argnum, &asm_data);
120965 + if (asm_data.input == NULL_TREE)
120966 + return;
120967 +
120968 + mark_str = convert_mark_to_str(mark);
120969 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
120970 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
120971 + free(asm_comment);
120972 +}
120973 +
120974 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
120975 +static bool create_mark_asm(gimple stmt, enum mark mark)
120976 +{
120977 + struct asm_data asm_data;
120978 + const char *asm_str;
120979 +
120980 + switch (mark) {
120981 + case MARK_TURN_OFF:
120982 + asm_str = TURN_OFF_ASM_STR;
120983 + break;
120984 + case MARK_NOT_INTENTIONAL:
120985 + case MARK_YES:
120986 + asm_str = YES_ASM_STR;
120987 + break;
120988 + default:
120989 + gcc_unreachable();
120990 + }
120991 +
120992 + asm_data.def_stmt = stmt;
120993 + asm_data.output = gimple_call_lhs(stmt);
120994 +
120995 + if (asm_data.output == NULL_TREE) {
120996 + asm_data.input = gimple_call_arg(stmt, 0);
120997 + if (is_gimple_constant(asm_data.input))
120998 + return false;
120999 + asm_data.output = NULL;
121000 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
121001 + return true;
121002 + }
121003 +
121004 + create_asm_input(stmt, 0, &asm_data);
121005 + gcc_assert(asm_data.input != NULL_TREE);
121006 +
121007 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
121008 + return true;
121009 +}
121010 +
121011 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
121012 +{
121013 + gimple def_stmt;
121014 +
121015 + def_stmt = get_def_stmt(lhs);
121016 + if (!def_stmt)
121017 + return;
121018 +
121019 + if (pointer_set_insert(visited, def_stmt))
121020 + return;
121021 +
121022 + switch (gimple_code(def_stmt)) {
121023 + case GIMPLE_NOP:
121024 + case GIMPLE_ASM:
121025 + case GIMPLE_CALL:
121026 + break;
121027 + case GIMPLE_PHI: {
121028 + unsigned int i, n = gimple_phi_num_args(def_stmt);
121029 +
121030 + pointer_set_insert(visited, def_stmt);
121031 +
121032 + for (i = 0; i < n; i++) {
121033 + tree arg = gimple_phi_arg_def(def_stmt, i);
121034 +
121035 + walk_use_def_ptr(visited, arg);
121036 + }
121037 + }
121038 + case GIMPLE_ASSIGN:
121039 + switch (gimple_num_ops(def_stmt)) {
121040 + case 2:
121041 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
121042 + return;
121043 + case 3:
121044 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
121045 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
121046 + return;
121047 + default:
121048 + return;
121049 + }
121050 + default:
121051 + debug_gimple_stmt((gimple)def_stmt);
121052 + error("%s: unknown gimple code", __func__);
121053 + gcc_unreachable();
121054 + }
121055 +}
121056 +
121057 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
121058 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
121059 +{
121060 + struct pointer_set_t *visited;
121061 +
121062 + visited = pointer_set_create();
121063 + walk_use_def_ptr(visited, arg);
121064 + pointer_set_destroy(visited);
121065 +}
121066 +
121067 +// Determine the return value and insert the asm stmt to mark the return stmt.
121068 +static void insert_asm_ret(gimple stmt)
121069 +{
121070 + tree ret;
121071 +
121072 + ret = gimple_return_retval(stmt);
121073 + create_size_overflow_asm(stmt, ret, 0);
121074 +}
121075 +
121076 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
121077 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
121078 +{
121079 + tree arg;
121080 + unsigned int argnum;
121081 +
121082 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
121083 + gcc_assert(argnum != 0);
121084 + if (argnum == CANNOT_FIND_ARG)
121085 + return;
121086 +
121087 + arg = gimple_call_arg(stmt, argnum - 1);
121088 + gcc_assert(arg != NULL_TREE);
121089 +
121090 + // skip all ptr - ptr expressions
121091 + insert_mark_not_intentional_asm_at_ptr(arg);
121092 +
121093 + create_size_overflow_asm(stmt, arg, argnum);
121094 +}
121095 +
121096 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
121097 +static void set_argnum_attribute(const_tree attr, bool *argnums)
121098 +{
121099 + unsigned int argnum;
121100 + tree attr_value;
121101 +
121102 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
121103 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
121104 + argnums[argnum] = true;
121105 + }
121106 +}
121107 +
121108 +// If a function arg or the return value is in the hash table then set its index in the array.
121109 +static void set_argnum_hash(tree fndecl, bool *argnums)
121110 +{
121111 + unsigned int num;
121112 + const struct size_overflow_hash *hash;
121113 +
121114 + hash = get_function_hash(DECL_ORIGIN(fndecl));
121115 + if (!hash)
121116 + return;
121117 +
121118 + for (num = 0; num <= MAX_PARAM; num++) {
121119 + if (!(hash->param & (1U << num)))
121120 + continue;
121121 +
121122 + argnums[num] = true;
121123 + }
121124 +}
121125 +
121126 +static bool is_all_the_argnums_empty(bool *argnums)
121127 +{
121128 + unsigned int i;
121129 +
121130 + for (i = 0; i <= MAX_PARAM; i++)
121131 + if (argnums[i])
121132 + return false;
121133 + return true;
121134 +}
121135 +
121136 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
121137 +static void search_interesting_args(tree fndecl, bool *argnums)
121138 +{
121139 + const_tree attr;
121140 +
121141 + set_argnum_hash(fndecl, argnums);
121142 + if (!is_all_the_argnums_empty(argnums))
121143 + return;
121144 +
121145 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
121146 + if (attr && TREE_VALUE(attr))
121147 + set_argnum_attribute(attr, argnums);
121148 +}
121149 +
121150 +/*
121151 + * Look up the intentional_overflow attribute that turns off ipa based duplication
121152 + * on the callee function.
121153 + */
121154 +static bool is_mark_turn_off_attribute(gimple stmt)
121155 +{
121156 + enum mark mark;
121157 + const_tree fndecl = gimple_call_fndecl(stmt);
121158 +
121159 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
121160 + if (mark == MARK_TURN_OFF)
121161 + return true;
121162 + return false;
121163 +}
121164 +
121165 +// 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
121166 +static void handle_interesting_function(gimple stmt)
121167 +{
121168 + unsigned int argnum;
121169 + tree fndecl;
121170 + bool orig_argnums[MAX_PARAM + 1] = {false};
121171 +
121172 + if (gimple_call_num_args(stmt) == 0)
121173 + return;
121174 + fndecl = gimple_call_fndecl(stmt);
121175 + if (fndecl == NULL_TREE)
121176 + return;
121177 + fndecl = DECL_ORIGIN(fndecl);
121178 +
121179 + if (is_mark_turn_off_attribute(stmt)) {
121180 + create_mark_asm(stmt, MARK_TURN_OFF);
121181 + return;
121182 + }
121183 +
121184 + search_interesting_args(fndecl, orig_argnums);
121185 +
121186 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
121187 + if (orig_argnums[argnum])
121188 + insert_asm_arg(stmt, argnum);
121189 +}
121190 +
121191 +// 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
121192 +static void handle_interesting_ret(gimple stmt)
121193 +{
121194 + bool orig_argnums[MAX_PARAM + 1] = {false};
121195 +
121196 + search_interesting_args(current_function_decl, orig_argnums);
121197 +
121198 + if (orig_argnums[0])
121199 + insert_asm_ret(stmt);
121200 +}
121201 +
121202 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
121203 +static unsigned int search_interesting_functions(void)
121204 +{
121205 + basic_block bb;
121206 +
121207 + FOR_ALL_BB_FN(bb, cfun) {
121208 + gimple_stmt_iterator gsi;
121209 +
121210 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121211 + gimple stmt = gsi_stmt(gsi);
121212 +
121213 + if (is_size_overflow_asm(stmt))
121214 + continue;
121215 +
121216 + if (is_gimple_call(stmt))
121217 + handle_interesting_function(stmt);
121218 + else if (gimple_code(stmt) == GIMPLE_RETURN)
121219 + handle_interesting_ret(stmt);
121220 + }
121221 + }
121222 + return 0;
121223 +}
121224 +
121225 +/*
121226 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
121227 + * this pass inserts asm stmts to mark the interesting args
121228 + * that the ipa pass will detect and insert the size overflow checks for.
121229 + */
121230 +#if BUILDING_GCC_VERSION >= 4009
121231 +static const struct pass_data insert_size_overflow_asm_pass_data = {
121232 +#else
121233 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
121234 + .pass = {
121235 +#endif
121236 + .type = GIMPLE_PASS,
121237 + .name = "insert_size_overflow_asm",
121238 +#if BUILDING_GCC_VERSION >= 4008
121239 + .optinfo_flags = OPTGROUP_NONE,
121240 +#endif
121241 +#if BUILDING_GCC_VERSION >= 4009
121242 + .has_gate = false,
121243 + .has_execute = true,
121244 +#else
121245 + .gate = NULL,
121246 + .execute = search_interesting_functions,
121247 + .sub = NULL,
121248 + .next = NULL,
121249 + .static_pass_number = 0,
121250 +#endif
121251 + .tv_id = TV_NONE,
121252 + .properties_required = PROP_cfg,
121253 + .properties_provided = 0,
121254 + .properties_destroyed = 0,
121255 + .todo_flags_start = 0,
121256 + .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
121257 +#if BUILDING_GCC_VERSION < 4009
121258 + }
121259 +#endif
121260 +};
121261 +
121262 +#if BUILDING_GCC_VERSION >= 4009
121263 +namespace {
121264 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
121265 +public:
121266 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
121267 + unsigned int execute() { return search_interesting_functions(); }
121268 +};
121269 +}
121270 +#endif
121271 +
121272 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
121273 +{
121274 +#if BUILDING_GCC_VERSION >= 4009
121275 + return new insert_size_overflow_asm_pass();
121276 +#else
121277 + return &insert_size_overflow_asm_pass.pass;
121278 +#endif
121279 +}
121280 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
121281 new file mode 100644
121282 index 0000000..73f0a12
121283 --- /dev/null
121284 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
121285 @@ -0,0 +1,943 @@
121286 +/*
121287 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
121288 + * Licensed under the GPL v2, or (at your option) v3
121289 + *
121290 + * Homepage:
121291 + * http://www.grsecurity.net/~ephox/overflow_plugin/
121292 + *
121293 + * Documentation:
121294 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
121295 + *
121296 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
121297 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
121298 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
121299 + *
121300 + * Usage:
121301 + * $ make
121302 + * $ make run
121303 + */
121304 +
121305 +#include "gcc-common.h"
121306 +#include "size_overflow.h"
121307 +
121308 +#define MIN_CHECK true
121309 +#define MAX_CHECK false
121310 +
121311 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
121312 +{
121313 + const_tree type;
121314 + tree new_type;
121315 +
121316 + gcc_assert(node != NULL_TREE);
121317 +
121318 + type = TREE_TYPE(node);
121319 +
121320 + if (pointer_set_contains(visited->my_stmts, stmt))
121321 + return TREE_TYPE(node);
121322 +
121323 + switch (TYPE_MODE(type)) {
121324 + case QImode:
121325 + new_type = size_overflow_type_HI;
121326 + break;
121327 + case HImode:
121328 + new_type = size_overflow_type_SI;
121329 + break;
121330 + case SImode:
121331 + new_type = size_overflow_type_DI;
121332 + break;
121333 + case DImode:
121334 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
121335 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
121336 + else
121337 + new_type = size_overflow_type_TI;
121338 + break;
121339 + case TImode:
121340 + gcc_assert(!TYPE_UNSIGNED(type));
121341 + new_type = size_overflow_type_TI;
121342 + break;
121343 + default:
121344 + debug_tree((tree)node);
121345 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
121346 + gcc_unreachable();
121347 + }
121348 +
121349 + if (TYPE_QUALS(type) != 0)
121350 + return build_qualified_type(new_type, TYPE_QUALS(type));
121351 + return new_type;
121352 +}
121353 +
121354 +static tree get_lhs(const_gimple stmt)
121355 +{
121356 + switch (gimple_code(stmt)) {
121357 + case GIMPLE_ASSIGN:
121358 + case GIMPLE_CALL:
121359 + return gimple_get_lhs(stmt);
121360 + case GIMPLE_PHI:
121361 + return gimple_phi_result(stmt);
121362 + default:
121363 + return NULL_TREE;
121364 + }
121365 +}
121366 +
121367 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
121368 +{
121369 + gimple_stmt_iterator gsi;
121370 + tree lhs;
121371 + gimple new_stmt;
121372 +
121373 + if (rhs == NULL_TREE)
121374 + return NULL_TREE;
121375 +
121376 + gsi = gsi_for_stmt(stmt);
121377 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
121378 + pointer_set_insert(visited->my_stmts, new_stmt);
121379 +
121380 + lhs = get_lhs(new_stmt);
121381 + gcc_assert(lhs != NULL_TREE);
121382 + return lhs;
121383 +}
121384 +
121385 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
121386 +{
121387 + tree lhs, dst_type;
121388 + gimple_stmt_iterator gsi;
121389 +
121390 + if (rhs1 == NULL_TREE) {
121391 + debug_gimple_stmt(oldstmt);
121392 + error("%s: rhs1 is NULL_TREE", __func__);
121393 + gcc_unreachable();
121394 + }
121395 +
121396 + switch (gimple_code(oldstmt)) {
121397 + case GIMPLE_ASM:
121398 + lhs = rhs1;
121399 + break;
121400 + case GIMPLE_CALL:
121401 + case GIMPLE_ASSIGN:
121402 + lhs = gimple_get_lhs(oldstmt);
121403 + break;
121404 + default:
121405 + debug_gimple_stmt(oldstmt);
121406 + gcc_unreachable();
121407 + }
121408 +
121409 + gsi = gsi_for_stmt(oldstmt);
121410 + pointer_set_insert(visited->stmts, oldstmt);
121411 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
121412 + basic_block next_bb, cur_bb;
121413 + const_edge e;
121414 +
121415 + gcc_assert(before == false);
121416 + gcc_assert(stmt_can_throw_internal(oldstmt));
121417 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
121418 + gcc_assert(!gsi_end_p(gsi));
121419 +
121420 + cur_bb = gimple_bb(oldstmt);
121421 + next_bb = cur_bb->next_bb;
121422 + e = find_edge(cur_bb, next_bb);
121423 + gcc_assert(e != NULL);
121424 + gcc_assert(e->flags & EDGE_FALLTHRU);
121425 +
121426 + gsi = gsi_after_labels(next_bb);
121427 + gcc_assert(!gsi_end_p(gsi));
121428 +
121429 + before = true;
121430 + oldstmt = gsi_stmt(gsi);
121431 + }
121432 +
121433 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
121434 +
121435 + if (is_gimple_constant(rhs1))
121436 + return cast_a_tree(dst_type, rhs1);
121437 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
121438 +}
121439 +
121440 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
121441 +{
121442 + gimple stmt;
121443 + gimple_stmt_iterator gsi;
121444 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
121445 +
121446 + if (pointer_set_contains(visited->my_stmts, oldstmt))
121447 + return lhs;
121448 +
121449 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
121450 + rhs1 = gimple_assign_rhs1(oldstmt);
121451 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
121452 + }
121453 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
121454 + rhs2 = gimple_assign_rhs2(oldstmt);
121455 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
121456 + }
121457 +
121458 + stmt = gimple_copy(oldstmt);
121459 + gimple_set_location(stmt, gimple_location(oldstmt));
121460 + pointer_set_insert(visited->my_stmts, stmt);
121461 +
121462 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
121463 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
121464 +
121465 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
121466 +
121467 + new_var = create_new_var(size_overflow_type);
121468 + new_var = make_ssa_name(new_var, stmt);
121469 + gimple_assign_set_lhs(stmt, new_var);
121470 +
121471 + if (rhs1 != NULL_TREE)
121472 + gimple_assign_set_rhs1(stmt, rhs1);
121473 +
121474 + if (rhs2 != NULL_TREE)
121475 + gimple_assign_set_rhs2(stmt, rhs2);
121476 +#if BUILDING_GCC_VERSION >= 4006
121477 + if (rhs3 != NULL_TREE)
121478 + gimple_assign_set_rhs3(stmt, rhs3);
121479 +#endif
121480 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
121481 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
121482 +
121483 + gsi = gsi_for_stmt(oldstmt);
121484 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
121485 + update_stmt(stmt);
121486 + pointer_set_insert(visited->stmts, oldstmt);
121487 + return gimple_assign_lhs(stmt);
121488 +}
121489 +
121490 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
121491 +{
121492 + gimple assign;
121493 + gimple_stmt_iterator gsi;
121494 + basic_block first_bb;
121495 +
121496 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
121497 +
121498 + if (bb->index == 0) {
121499 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121500 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
121501 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121502 + bb = first_bb;
121503 + }
121504 +
121505 + gsi = gsi_after_labels(bb);
121506 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
121507 + pointer_set_insert(visited->my_stmts, assign);
121508 +
121509 + return gimple_assign_lhs(assign);
121510 +}
121511 +
121512 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
121513 +{
121514 + gimple_stmt_iterator gsi;
121515 + gimple assign, def_stmt = get_def_stmt(new_arg);
121516 +
121517 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
121518 + gsi = gsi_after_labels(gimple_bb(def_stmt));
121519 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
121520 + } else {
121521 + gsi = gsi_for_stmt(def_stmt);
121522 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
121523 + }
121524 +
121525 + pointer_set_insert(visited->my_stmts, assign);
121526 + return gimple_assign_lhs(assign);
121527 +}
121528 +
121529 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
121530 +{
121531 + basic_block bb;
121532 + gimple_stmt_iterator gsi;
121533 + const_gimple def_stmt;
121534 + gimple assign;
121535 +
121536 + def_stmt = get_def_stmt(arg);
121537 + bb = gimple_bb(def_stmt);
121538 + gcc_assert(bb->index != 0);
121539 + gsi = gsi_after_labels(bb);
121540 +
121541 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
121542 + pointer_set_insert(visited->my_stmts, assign);
121543 + return gimple_assign_lhs(assign);
121544 +}
121545 +
121546 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
121547 +{
121548 + tree size_overflow_type;
121549 + tree arg;
121550 + const_gimple def_stmt;
121551 +
121552 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
121553 + return new_arg;
121554 +
121555 + arg = gimple_phi_arg_def(oldstmt, i);
121556 + def_stmt = get_def_stmt(arg);
121557 + gcc_assert(def_stmt != NULL);
121558 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
121559 +
121560 + switch (gimple_code(def_stmt)) {
121561 + case GIMPLE_PHI:
121562 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
121563 + case GIMPLE_NOP: {
121564 + basic_block bb;
121565 +
121566 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
121567 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
121568 + }
121569 + case GIMPLE_ASM: {
121570 + gimple_stmt_iterator gsi;
121571 + gimple assign, stmt = get_def_stmt(arg);
121572 +
121573 + gsi = gsi_for_stmt(stmt);
121574 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
121575 + pointer_set_insert(visited->my_stmts, assign);
121576 + return gimple_assign_lhs(assign);
121577 + }
121578 + default:
121579 + gcc_assert(new_arg != NULL_TREE);
121580 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
121581 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
121582 + }
121583 +}
121584 +
121585 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
121586 +{
121587 + basic_block bb;
121588 + gimple phi;
121589 + gimple_seq seq;
121590 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
121591 +
121592 + bb = gsi_bb(gsi);
121593 +
121594 + if (result == NULL_TREE) {
121595 + tree old_result = gimple_phi_result(oldstmt);
121596 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
121597 +
121598 + result = create_new_var(size_overflow_type);
121599 + }
121600 +
121601 + phi = create_phi_node(result, bb);
121602 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
121603 + seq = phi_nodes(bb);
121604 + gsi = gsi_last(seq);
121605 + gsi_remove(&gsi, false);
121606 +
121607 + gsi = gsi_for_stmt(oldstmt);
121608 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
121609 + gimple_set_bb(phi, bb);
121610 + return phi;
121611 +}
121612 +
121613 +#if BUILDING_GCC_VERSION <= 4007
121614 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
121615 +#else
121616 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
121617 +#endif
121618 +{
121619 + gimple new_phi;
121620 + unsigned int i;
121621 + tree arg, result;
121622 + location_t loc = gimple_location(oldstmt);
121623 +
121624 +#if BUILDING_GCC_VERSION <= 4007
121625 + gcc_assert(!VEC_empty(tree, *args));
121626 +#else
121627 + gcc_assert(!args->is_empty());
121628 +#endif
121629 +
121630 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
121631 + result = gimple_phi_result(new_phi);
121632 + ssa_name_var = SSA_NAME_VAR(result);
121633 +
121634 +#if BUILDING_GCC_VERSION <= 4007
121635 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
121636 +#else
121637 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
121638 +#endif
121639 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
121640 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
121641 + }
121642 +
121643 +#if BUILDING_GCC_VERSION <= 4007
121644 + VEC_free(tree, heap, *args);
121645 +#else
121646 + vec_free(args);
121647 +#endif
121648 + update_stmt(new_phi);
121649 + pointer_set_insert(visited->my_stmts, new_phi);
121650 + return result;
121651 +}
121652 +
121653 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
121654 +{
121655 + tree ssa_name_var = NULL_TREE;
121656 +#if BUILDING_GCC_VERSION <= 4007
121657 + VEC(tree, heap) *args = NULL;
121658 +#else
121659 + vec<tree, va_heap, vl_embed> *args = NULL;
121660 +#endif
121661 + gimple oldstmt = get_def_stmt(orig_result);
121662 + unsigned int i, len = gimple_phi_num_args(oldstmt);
121663 +
121664 + pointer_set_insert(visited->stmts, oldstmt);
121665 + for (i = 0; i < len; i++) {
121666 + tree arg, new_arg;
121667 +
121668 + arg = gimple_phi_arg_def(oldstmt, i);
121669 + new_arg = expand(visited, caller_node, arg);
121670 +
121671 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
121672 + ssa_name_var = SSA_NAME_VAR(new_arg);
121673 +
121674 + if (is_gimple_constant(arg)) {
121675 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
121676 +
121677 + new_arg = cast_a_tree(size_overflow_type, arg);
121678 + }
121679 +
121680 +#if BUILDING_GCC_VERSION <= 4007
121681 + VEC_safe_push(tree, heap, args, new_arg);
121682 +#else
121683 + vec_safe_push(args, new_arg);
121684 +#endif
121685 + }
121686 +
121687 +#if BUILDING_GCC_VERSION <= 4007
121688 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
121689 +#else
121690 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
121691 +#endif
121692 +}
121693 +
121694 +static tree create_cast_assign(struct visited *visited, gimple stmt)
121695 +{
121696 + tree rhs1 = gimple_assign_rhs1(stmt);
121697 + tree lhs = gimple_assign_lhs(stmt);
121698 + const_tree rhs1_type = TREE_TYPE(rhs1);
121699 + const_tree lhs_type = TREE_TYPE(lhs);
121700 +
121701 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
121702 + return create_assign(visited, stmt, lhs, AFTER_STMT);
121703 +
121704 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
121705 +}
121706 +
121707 +static bool skip_lhs_cast_check(const_gimple stmt)
121708 +{
121709 + const_tree rhs = gimple_assign_rhs1(stmt);
121710 + const_gimple def_stmt = get_def_stmt(rhs);
121711 +
121712 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
121713 + if (gimple_code(def_stmt) == GIMPLE_ASM)
121714 + return true;
121715 +
121716 + if (is_const_plus_unsigned_signed_truncation(rhs))
121717 + return true;
121718 +
121719 + return false;
121720 +}
121721 +
121722 +static tree create_string_param(tree string)
121723 +{
121724 + tree i_type, a_type;
121725 + const int length = TREE_STRING_LENGTH(string);
121726 +
121727 + gcc_assert(length > 0);
121728 +
121729 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
121730 + a_type = build_array_type(char_type_node, i_type);
121731 +
121732 + TREE_TYPE(string) = a_type;
121733 + TREE_CONSTANT(string) = 1;
121734 + TREE_READONLY(string) = 1;
121735 +
121736 + return build1(ADDR_EXPR, ptr_type_node, string);
121737 +}
121738 +
121739 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
121740 +{
121741 + gimple cond_stmt;
121742 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
121743 +
121744 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
121745 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
121746 + update_stmt(cond_stmt);
121747 +}
121748 +
121749 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
121750 +{
121751 + gimple func_stmt;
121752 + const_gimple def_stmt;
121753 + const_tree loc_line;
121754 + tree loc_file, ssa_name, current_func;
121755 + expanded_location xloc;
121756 + char *ssa_name_buf;
121757 + int len;
121758 + struct cgraph_edge *edge;
121759 + struct cgraph_node *callee_node;
121760 + int frequency;
121761 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
121762 +
121763 + def_stmt = get_def_stmt(arg);
121764 + xloc = expand_location(gimple_location(def_stmt));
121765 +
121766 + if (!gimple_has_location(def_stmt)) {
121767 + xloc = expand_location(gimple_location(stmt));
121768 + if (!gimple_has_location(stmt))
121769 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
121770 + }
121771 +
121772 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
121773 +
121774 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
121775 + loc_file = create_string_param(loc_file);
121776 +
121777 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
121778 + current_func = create_string_param(current_func);
121779 +
121780 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
121781 + call_count++;
121782 + 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);
121783 + gcc_assert(len > 0);
121784 + ssa_name = build_string(len + 1, ssa_name_buf);
121785 + free(ssa_name_buf);
121786 + ssa_name = create_string_param(ssa_name);
121787 +
121788 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
121789 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
121790 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
121791 +
121792 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
121793 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
121794 +
121795 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
121796 + gcc_assert(edge != NULL);
121797 +}
121798 +
121799 +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)
121800 +{
121801 + basic_block cond_bb, join_bb, bb_true;
121802 + edge e;
121803 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
121804 +
121805 + cond_bb = gimple_bb(stmt);
121806 + if (before)
121807 + gsi_prev(&gsi);
121808 + if (gsi_end_p(gsi))
121809 + e = split_block_after_labels(cond_bb);
121810 + else
121811 + e = split_block(cond_bb, gsi_stmt(gsi));
121812 + cond_bb = e->src;
121813 + join_bb = e->dest;
121814 + e->flags = EDGE_FALSE_VALUE;
121815 + e->probability = REG_BR_PROB_BASE;
121816 +
121817 + bb_true = create_empty_bb(cond_bb);
121818 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
121819 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
121820 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
121821 +
121822 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
121823 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
121824 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
121825 +
121826 + if (current_loops != NULL) {
121827 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
121828 + add_bb_to_loop(bb_true, cond_bb->loop_father);
121829 + }
121830 +
121831 + insert_cond(cond_bb, arg, cond_code, type_value);
121832 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
121833 +
121834 +// print_the_code_insertions(stmt);
121835 +}
121836 +
121837 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
121838 +{
121839 + const_tree rhs_type = TREE_TYPE(rhs);
121840 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
121841 +
121842 + gcc_assert(rhs_type != NULL_TREE);
121843 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
121844 + return;
121845 +
121846 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
121847 +
121848 + if (is_const_plus_unsigned_signed_truncation(rhs))
121849 + return;
121850 +
121851 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
121852 + // typemax (-1) < typemin (0)
121853 + if (TREE_OVERFLOW(type_max))
121854 + return;
121855 +
121856 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
121857 +
121858 + cast_rhs_type = TREE_TYPE(cast_rhs);
121859 + type_max_type = TREE_TYPE(type_max);
121860 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
121861 +
121862 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
121863 +
121864 + // special case: get_size_overflow_type(), 32, u64->s
121865 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
121866 + return;
121867 +
121868 + type_min_type = TREE_TYPE(type_min);
121869 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
121870 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
121871 +}
121872 +
121873 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
121874 +{
121875 + bool cast_lhs, cast_rhs;
121876 + tree lhs = gimple_assign_lhs(stmt);
121877 + tree rhs = gimple_assign_rhs1(stmt);
121878 + const_tree lhs_type = TREE_TYPE(lhs);
121879 + const_tree rhs_type = TREE_TYPE(rhs);
121880 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
121881 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
121882 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
121883 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
121884 +
121885 + static bool check_lhs[3][4] = {
121886 + // ss su us uu
121887 + { false, true, true, false }, // lhs > rhs
121888 + { false, false, false, false }, // lhs = rhs
121889 + { true, true, true, true }, // lhs < rhs
121890 + };
121891 +
121892 + static bool check_rhs[3][4] = {
121893 + // ss su us uu
121894 + { true, false, true, true }, // lhs > rhs
121895 + { true, false, true, true }, // lhs = rhs
121896 + { true, false, true, true }, // lhs < rhs
121897 + };
121898 +
121899 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
121900 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
121901 + return create_assign(visited, stmt, lhs, AFTER_STMT);
121902 +
121903 + if (lhs_size > rhs_size) {
121904 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
121905 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
121906 + } else if (lhs_size == rhs_size) {
121907 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
121908 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
121909 + } else {
121910 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
121911 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
121912 + }
121913 +
121914 + if (!cast_lhs && !cast_rhs)
121915 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
121916 +
121917 + if (cast_lhs && !skip_lhs_cast_check(stmt))
121918 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
121919 +
121920 + if (cast_rhs)
121921 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
121922 +
121923 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
121924 +}
121925 +
121926 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
121927 +{
121928 + enum tree_code rhs_code;
121929 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
121930 +
121931 + if (pointer_set_contains(visited->my_stmts, stmt))
121932 + return lhs;
121933 +
121934 + rhs1 = gimple_assign_rhs1(stmt);
121935 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
121936 + return create_assign(visited, stmt, lhs, AFTER_STMT);
121937 +
121938 + new_rhs1 = expand(visited, caller_node, rhs1);
121939 +
121940 + if (new_rhs1 == NULL_TREE)
121941 + return create_cast_assign(visited, stmt);
121942 +
121943 + if (pointer_set_contains(visited->no_cast_check, stmt))
121944 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
121945 +
121946 + rhs_code = gimple_assign_rhs_code(stmt);
121947 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
121948 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
121949 +
121950 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
121951 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
121952 + return create_assign(visited, stmt, lhs, AFTER_STMT);
121953 + }
121954 +
121955 + if (!gimple_assign_cast_p(stmt))
121956 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
121957 +
121958 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
121959 +}
121960 +
121961 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
121962 +{
121963 + tree rhs1, lhs = gimple_assign_lhs(stmt);
121964 + gimple def_stmt = get_def_stmt(lhs);
121965 +
121966 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
121967 + rhs1 = gimple_assign_rhs1(def_stmt);
121968 +
121969 + if (is_gimple_constant(rhs1))
121970 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
121971 +
121972 + switch (TREE_CODE(rhs1)) {
121973 + case SSA_NAME: {
121974 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
121975 +
121976 + if (gimple_assign_cast_p(stmt))
121977 + unsigned_signed_cast_intentional_overflow(visited, stmt);
121978 + return ret;
121979 + }
121980 + case ARRAY_REF:
121981 + case BIT_FIELD_REF:
121982 + case ADDR_EXPR:
121983 + case COMPONENT_REF:
121984 + case INDIRECT_REF:
121985 +#if BUILDING_GCC_VERSION >= 4006
121986 + case MEM_REF:
121987 +#endif
121988 + case TARGET_MEM_REF:
121989 + case VIEW_CONVERT_EXPR:
121990 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
121991 + case PARM_DECL:
121992 + case VAR_DECL:
121993 + return create_assign(visited, stmt, lhs, AFTER_STMT);
121994 +
121995 + default:
121996 + debug_gimple_stmt(def_stmt);
121997 + debug_tree(rhs1);
121998 + gcc_unreachable();
121999 + }
122000 +}
122001 +
122002 +static void __unused print_the_code_insertions(const_gimple stmt)
122003 +{
122004 + location_t loc = gimple_location(stmt);
122005 +
122006 + inform(loc, "Integer size_overflow check applied here.");
122007 +}
122008 +
122009 +static bool is_from_cast(const_tree node)
122010 +{
122011 + gimple def_stmt = get_def_stmt(node);
122012 +
122013 + if (!def_stmt)
122014 + return false;
122015 +
122016 + if (gimple_assign_cast_p(def_stmt))
122017 + return true;
122018 +
122019 + return false;
122020 +}
122021 +
122022 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
122023 +static bool is_a_ptr_minus(gimple stmt)
122024 +{
122025 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
122026 +
122027 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
122028 + return false;
122029 +
122030 + rhs1 = gimple_assign_rhs1(stmt);
122031 + if (!is_from_cast(rhs1))
122032 + return false;
122033 +
122034 + rhs2 = gimple_assign_rhs2(stmt);
122035 + if (!is_from_cast(rhs2))
122036 + return false;
122037 +
122038 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
122039 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
122040 +
122041 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
122042 + return false;
122043 +
122044 + return true;
122045 +}
122046 +
122047 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
122048 +{
122049 + enum intentional_overflow_type res;
122050 + tree rhs1, rhs2, new_lhs;
122051 + gimple def_stmt = get_def_stmt(lhs);
122052 + tree new_rhs1 = NULL_TREE;
122053 + tree new_rhs2 = NULL_TREE;
122054 +
122055 + if (is_a_ptr_minus(def_stmt))
122056 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
122057 +
122058 + rhs1 = gimple_assign_rhs1(def_stmt);
122059 + rhs2 = gimple_assign_rhs2(def_stmt);
122060 +
122061 + /* no DImode/TImode division in the 32/64 bit kernel */
122062 + switch (gimple_assign_rhs_code(def_stmt)) {
122063 + case RDIV_EXPR:
122064 + case TRUNC_DIV_EXPR:
122065 + case CEIL_DIV_EXPR:
122066 + case FLOOR_DIV_EXPR:
122067 + case ROUND_DIV_EXPR:
122068 + case TRUNC_MOD_EXPR:
122069 + case CEIL_MOD_EXPR:
122070 + case FLOOR_MOD_EXPR:
122071 + case ROUND_MOD_EXPR:
122072 + case EXACT_DIV_EXPR:
122073 + case POINTER_PLUS_EXPR:
122074 + case BIT_AND_EXPR:
122075 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
122076 + default:
122077 + break;
122078 + }
122079 +
122080 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
122081 + if (new_lhs != NULL_TREE)
122082 + return new_lhs;
122083 +
122084 + if (TREE_CODE(rhs1) == SSA_NAME)
122085 + new_rhs1 = expand(visited, caller_node, rhs1);
122086 + if (TREE_CODE(rhs2) == SSA_NAME)
122087 + new_rhs2 = expand(visited, caller_node, rhs2);
122088 +
122089 + res = add_mul_intentional_overflow(def_stmt);
122090 + if (res != NO_INTENTIONAL_OVERFLOW) {
122091 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
122092 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
122093 + return new_lhs;
122094 + }
122095 +
122096 + if (skip_expr_on_double_type(def_stmt)) {
122097 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
122098 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
122099 + return new_lhs;
122100 + }
122101 +
122102 + if (is_a_neg_overflow(def_stmt, rhs2))
122103 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
122104 + if (is_a_neg_overflow(def_stmt, rhs1))
122105 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
122106 +
122107 +
122108 + if (is_a_constant_overflow(def_stmt, rhs2))
122109 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
122110 + if (is_a_constant_overflow(def_stmt, rhs1))
122111 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
122112 +
122113 + // the const is between 0 and (signed) MAX
122114 + if (is_gimple_constant(rhs1))
122115 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
122116 + if (is_gimple_constant(rhs2))
122117 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
122118 +
122119 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
122120 +}
122121 +
122122 +#if BUILDING_GCC_VERSION >= 4006
122123 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
122124 +{
122125 + if (is_gimple_constant(rhs))
122126 + return cast_a_tree(size_overflow_type, rhs);
122127 + if (TREE_CODE(rhs) != SSA_NAME)
122128 + return NULL_TREE;
122129 + return expand(visited, caller_node, rhs);
122130 +}
122131 +
122132 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
122133 +{
122134 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
122135 + gimple def_stmt = get_def_stmt(lhs);
122136 +
122137 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
122138 +
122139 + rhs1 = gimple_assign_rhs1(def_stmt);
122140 + rhs2 = gimple_assign_rhs2(def_stmt);
122141 + rhs3 = gimple_assign_rhs3(def_stmt);
122142 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
122143 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
122144 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
122145 +
122146 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
122147 +}
122148 +#endif
122149 +
122150 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
122151 +{
122152 + gimple_stmt_iterator gsi;
122153 + gimple next_stmt = NULL;
122154 +
122155 + gsi = gsi_for_stmt(stmt);
122156 +
122157 + do {
122158 + gsi_next(&gsi);
122159 + next_stmt = gsi_stmt(gsi);
122160 +
122161 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
122162 + return NULL_TREE;
122163 +
122164 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
122165 + break;
122166 +
122167 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
122168 + } while (!gsi_end_p(gsi));
122169 +
122170 + gcc_assert(next_stmt);
122171 + return get_lhs(next_stmt);
122172 +}
122173 +
122174 +static tree expand_visited(struct visited *visited, gimple def_stmt)
122175 +{
122176 + gimple_stmt_iterator gsi;
122177 + enum gimple_code code = gimple_code(def_stmt);
122178 +
122179 + if (code == GIMPLE_ASM)
122180 + return NULL_TREE;
122181 +
122182 + gsi = gsi_for_stmt(def_stmt);
122183 + gsi_next(&gsi);
122184 +
122185 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
122186 + return NULL_TREE;
122187 + return get_my_stmt_lhs(visited, def_stmt);
122188 +}
122189 +
122190 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
122191 +{
122192 + gimple def_stmt;
122193 +
122194 + def_stmt = get_def_stmt(lhs);
122195 +
122196 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
122197 + return NULL_TREE;
122198 +
122199 + if (pointer_set_contains(visited->my_stmts, def_stmt))
122200 + return lhs;
122201 +
122202 + if (pointer_set_contains(visited->stmts, def_stmt))
122203 + return expand_visited(visited, def_stmt);
122204 +
122205 + switch (gimple_code(def_stmt)) {
122206 + case GIMPLE_PHI:
122207 + return handle_phi(visited, caller_node, lhs);
122208 + case GIMPLE_CALL:
122209 + case GIMPLE_ASM:
122210 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
122211 + case GIMPLE_ASSIGN:
122212 + switch (gimple_num_ops(def_stmt)) {
122213 + case 2:
122214 + return handle_unary_ops(visited, caller_node, def_stmt);
122215 + case 3:
122216 + return handle_binary_ops(visited, caller_node, lhs);
122217 +#if BUILDING_GCC_VERSION >= 4006
122218 + case 4:
122219 + return handle_ternary_ops(visited, caller_node, lhs);
122220 +#endif
122221 + }
122222 + default:
122223 + debug_gimple_stmt(def_stmt);
122224 + error("%s: unknown gimple code", __func__);
122225 + gcc_unreachable();
122226 + }
122227 +}
122228 +
122229 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
122230 new file mode 100644
122231 index 0000000..df50164
122232 --- /dev/null
122233 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
122234 @@ -0,0 +1,1141 @@
122235 +/*
122236 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
122237 + * Licensed under the GPL v2, or (at your option) v3
122238 + *
122239 + * Homepage:
122240 + * http://www.grsecurity.net/~ephox/overflow_plugin/
122241 + *
122242 + * Documentation:
122243 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
122244 + *
122245 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
122246 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
122247 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
122248 + *
122249 + * Usage:
122250 + * $ make
122251 + * $ make run
122252 + */
122253 +
122254 +#include "gcc-common.h"
122255 +#include "size_overflow.h"
122256 +
122257 +#define VEC_LEN 128
122258 +#define RET_CHECK NULL_TREE
122259 +#define WRONG_NODE 32
122260 +#define NOT_INTENTIONAL_ASM NULL
122261 +
122262 +unsigned int call_count;
122263 +
122264 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
122265 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
122266 +
122267 +struct visited_fns {
122268 + struct visited_fns *next;
122269 + const_tree fndecl;
122270 + unsigned int num;
122271 + const_gimple first_stmt;
122272 +};
122273 +
122274 +struct next_cgraph_node {
122275 + struct next_cgraph_node *next;
122276 + struct cgraph_node *current_function;
122277 + tree callee_fndecl;
122278 + unsigned int num;
122279 +};
122280 +
122281 +// Don't want to duplicate entries in next_cgraph_node
122282 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
122283 +{
122284 + const_tree new_callee_fndecl;
122285 + struct next_cgraph_node *cur_node;
122286 +
122287 + if (fndecl == RET_CHECK)
122288 + new_callee_fndecl = NODE_DECL(node);
122289 + else
122290 + new_callee_fndecl = fndecl;
122291 +
122292 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
122293 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
122294 + continue;
122295 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
122296 + continue;
122297 + if (num == cur_node->num)
122298 + return true;
122299 + }
122300 + return false;
122301 +}
122302 +
122303 +/* Add a next_cgraph_node into the list for handle_function().
122304 + * handle_function() iterates over all the next cgraph nodes and
122305 + * starts the overflow check insertion process.
122306 + */
122307 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
122308 +{
122309 + struct next_cgraph_node *new_node;
122310 +
122311 + if (is_in_next_cgraph_node(head, node, fndecl, num))
122312 + return head;
122313 +
122314 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
122315 + new_node->current_function = node;
122316 + new_node->next = NULL;
122317 + new_node->num = num;
122318 + if (fndecl == RET_CHECK)
122319 + new_node->callee_fndecl = NODE_DECL(node);
122320 + else
122321 + new_node->callee_fndecl = fndecl;
122322 +
122323 + if (!head)
122324 + return new_node;
122325 +
122326 + new_node->next = head;
122327 + return new_node;
122328 +}
122329 +
122330 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
122331 +{
122332 + struct cgraph_edge *e;
122333 +
122334 + if (num == 0)
122335 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
122336 +
122337 + for (e = node->callers; e; e = e->next_caller) {
122338 + tree fndecl = gimple_call_fndecl(e->call_stmt);
122339 +
122340 + gcc_assert(fndecl != NULL_TREE);
122341 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
122342 + }
122343 +
122344 + return head;
122345 +}
122346 +
122347 +struct missing_functions {
122348 + struct missing_functions *next;
122349 + const_tree node;
122350 + tree fndecl;
122351 +};
122352 +
122353 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
122354 +{
122355 + struct missing_functions *new_function;
122356 +
122357 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
122358 + new_function->node = node;
122359 + new_function->next = NULL;
122360 +
122361 + if (TREE_CODE(node) == FUNCTION_DECL)
122362 + new_function->fndecl = node;
122363 + else
122364 + new_function->fndecl = current_function_decl;
122365 + gcc_assert(new_function->fndecl);
122366 +
122367 + if (!missing_fn_head)
122368 + return new_function;
122369 +
122370 + new_function->next = missing_fn_head;
122371 + return new_function;
122372 +}
122373 +
122374 +/* If the function is missing from the hash table and it is a static function
122375 + * then create a next_cgraph_node from it for handle_function()
122376 + */
122377 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
122378 +{
122379 + unsigned int num;
122380 + const_tree orig_fndecl;
122381 + struct cgraph_node *next_node = NULL;
122382 +
122383 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
122384 +
122385 + num = get_function_num(missing_fn_head->node, orig_fndecl);
122386 + if (num == CANNOT_FIND_ARG)
122387 + return cnodes;
122388 +
122389 + if (!is_missing_function(orig_fndecl, num))
122390 + return cnodes;
122391 +
122392 + next_node = cgraph_get_node(missing_fn_head->fndecl);
122393 + if (next_node && next_node->local.local)
122394 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
122395 + return cnodes;
122396 +}
122397 +
122398 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
122399 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
122400 + */
122401 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
122402 +{
122403 + unsigned int i;
122404 + tree node;
122405 + struct missing_functions *cur, *missing_fn_head = NULL;
122406 +
122407 +#if BUILDING_GCC_VERSION <= 4007
122408 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
122409 +#else
122410 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
122411 +#endif
122412 + switch (TREE_CODE(node)) {
122413 + case PARM_DECL:
122414 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
122415 + break;
122416 + case FUNCTION_DECL:
122417 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
122418 + break;
122419 + default:
122420 + break;
122421 + }
122422 + }
122423 +
122424 + while (missing_fn_head) {
122425 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
122426 +
122427 + cur = missing_fn_head->next;
122428 + free(missing_fn_head);
122429 + missing_fn_head = cur;
122430 + }
122431 +
122432 + return cnodes;
122433 +}
122434 +
122435 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
122436 +{
122437 + gimple phi = get_def_stmt(result);
122438 + unsigned int i, n = gimple_phi_num_args(phi);
122439 +
122440 + pointer_set_insert(visited, phi);
122441 + for (i = 0; i < n; i++) {
122442 + const_tree arg = gimple_phi_arg_def(phi, i);
122443 +
122444 + set_conditions(visited, interesting_conditions, arg);
122445 + }
122446 +}
122447 +
122448 +enum conditions {
122449 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
122450 +};
122451 +
122452 +// Search for constants, cast assignments and binary/ternary assignments
122453 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
122454 +{
122455 + gimple def_stmt = get_def_stmt(lhs);
122456 +
122457 + if (is_gimple_constant(lhs)) {
122458 + interesting_conditions[FROM_CONST] = true;
122459 + return;
122460 + }
122461 +
122462 + if (!def_stmt)
122463 + return;
122464 +
122465 + if (pointer_set_contains(visited, def_stmt))
122466 + return;
122467 +
122468 + switch (gimple_code(def_stmt)) {
122469 + case GIMPLE_CALL:
122470 + if (lhs == gimple_call_lhs(def_stmt))
122471 + interesting_conditions[RET] = true;
122472 + return;
122473 + case GIMPLE_NOP:
122474 + case GIMPLE_ASM:
122475 + return;
122476 + case GIMPLE_PHI:
122477 + interesting_conditions[PHI] = true;
122478 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
122479 + case GIMPLE_ASSIGN:
122480 + if (gimple_num_ops(def_stmt) == 2) {
122481 + const_tree rhs = gimple_assign_rhs1(def_stmt);
122482 +
122483 + if (gimple_assign_cast_p(def_stmt))
122484 + interesting_conditions[CAST] = true;
122485 +
122486 + return set_conditions(visited, interesting_conditions, rhs);
122487 + } else {
122488 + interesting_conditions[NOT_UNARY] = true;
122489 + return;
122490 + }
122491 + default:
122492 + debug_gimple_stmt(def_stmt);
122493 + gcc_unreachable();
122494 + }
122495 +}
122496 +
122497 +// determine whether duplication will be necessary or not.
122498 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
122499 +{
122500 + struct pointer_set_t *visited;
122501 +
122502 + if (gimple_assign_cast_p(cur_node->first_stmt))
122503 + interesting_conditions[CAST] = true;
122504 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
122505 + interesting_conditions[NOT_UNARY] = true;
122506 +
122507 + visited = pointer_set_create();
122508 + set_conditions(visited, interesting_conditions, cur_node->node);
122509 + pointer_set_destroy(visited);
122510 +}
122511 +
122512 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
122513 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
122514 +{
122515 + gimple assign;
122516 + gimple_stmt_iterator gsi;
122517 +
122518 + // already removed
122519 + if (gimple_bb(asm_stmt) == NULL)
122520 + return;
122521 + gsi = gsi_for_stmt(asm_stmt);
122522 +
122523 + assign = gimple_build_assign(lhs, rhs);
122524 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
122525 + SSA_NAME_DEF_STMT(lhs) = assign;
122526 +
122527 + gsi_remove(&gsi, true);
122528 +}
122529 +
122530 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
122531 + * stmt is a return otherwise it is the callee function.
122532 + */
122533 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
122534 +{
122535 + const_tree fndecl;
122536 +
122537 + if (argnum == 0)
122538 + fndecl = current_function_decl;
122539 + else
122540 + fndecl = gimple_call_fndecl(stmt);
122541 +
122542 + if (fndecl == NULL_TREE)
122543 + return NULL_TREE;
122544 +
122545 + return DECL_ORIGIN(fndecl);
122546 +}
122547 +
122548 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
122549 +static bool skip_asm(const_tree arg)
122550 +{
122551 + gimple def_stmt = get_def_stmt(arg);
122552 +
122553 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
122554 + return false;
122555 +
122556 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
122557 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
122558 +}
122559 +
122560 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
122561 +{
122562 + gimple phi = get_def_stmt(result);
122563 + unsigned int i, n = gimple_phi_num_args(phi);
122564 +
122565 + pointer_set_insert(visited, phi);
122566 + for (i = 0; i < n; i++) {
122567 + tree arg = gimple_phi_arg_def(phi, i);
122568 +
122569 + walk_use_def(visited, cur_node, arg);
122570 + }
122571 +}
122572 +
122573 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
122574 +{
122575 + gimple def_stmt = get_def_stmt(lhs);
122576 + tree rhs1, rhs2;
122577 +
122578 + rhs1 = gimple_assign_rhs1(def_stmt);
122579 + rhs2 = gimple_assign_rhs2(def_stmt);
122580 +
122581 + walk_use_def(visited, cur_node, rhs1);
122582 + walk_use_def(visited, cur_node, rhs2);
122583 +}
122584 +
122585 +static void insert_last_node(struct interesting_node *cur_node, tree node)
122586 +{
122587 + unsigned int i;
122588 + tree element;
122589 + enum tree_code code;
122590 +
122591 + gcc_assert(node != NULL_TREE);
122592 +
122593 + if (is_gimple_constant(node))
122594 + return;
122595 +
122596 + code = TREE_CODE(node);
122597 + if (code == VAR_DECL) {
122598 + node = DECL_ORIGIN(node);
122599 + code = TREE_CODE(node);
122600 + }
122601 +
122602 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
122603 + return;
122604 +
122605 +#if BUILDING_GCC_VERSION <= 4007
122606 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
122607 +#else
122608 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
122609 +#endif
122610 + if (operand_equal_p(node, element, 0))
122611 + return;
122612 + }
122613 +
122614 +#if BUILDING_GCC_VERSION <= 4007
122615 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
122616 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
122617 +#else
122618 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
122619 + vec_safe_push(cur_node->last_nodes, node);
122620 +#endif
122621 +}
122622 +
122623 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
122624 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
122625 +{
122626 + if (!is_size_overflow_asm(stmt))
122627 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
122628 +}
122629 +
122630 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
122631 + * and component refs (for checking the intentional_overflow attribute).
122632 + */
122633 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
122634 +{
122635 + const_gimple def_stmt;
122636 +
122637 + if (TREE_CODE(lhs) != SSA_NAME) {
122638 + insert_last_node(cur_node, lhs);
122639 + return;
122640 + }
122641 +
122642 + def_stmt = get_def_stmt(lhs);
122643 + if (!def_stmt)
122644 + return;
122645 +
122646 + if (pointer_set_insert(visited, def_stmt))
122647 + return;
122648 +
122649 + switch (gimple_code(def_stmt)) {
122650 + case GIMPLE_NOP:
122651 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
122652 + case GIMPLE_ASM:
122653 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
122654 + case GIMPLE_CALL: {
122655 + tree fndecl = gimple_call_fndecl(def_stmt);
122656 +
122657 + if (fndecl == NULL_TREE)
122658 + return;
122659 + insert_last_node(cur_node, fndecl);
122660 + return;
122661 + }
122662 + case GIMPLE_PHI:
122663 + return walk_use_def_phi(visited, cur_node, lhs);
122664 + case GIMPLE_ASSIGN:
122665 + switch (gimple_num_ops(def_stmt)) {
122666 + case 2:
122667 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
122668 + case 3:
122669 + return walk_use_def_binary(visited, cur_node, lhs);
122670 + }
122671 + default:
122672 + debug_gimple_stmt((gimple)def_stmt);
122673 + error("%s: unknown gimple code", __func__);
122674 + gcc_unreachable();
122675 + }
122676 +}
122677 +
122678 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
122679 +static void set_last_nodes(struct interesting_node *cur_node)
122680 +{
122681 + struct pointer_set_t *visited;
122682 +
122683 + visited = pointer_set_create();
122684 + walk_use_def(visited, cur_node, cur_node->node);
122685 + pointer_set_destroy(visited);
122686 +}
122687 +
122688 +enum precond {
122689 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
122690 +};
122691 +
122692 +/* 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.
122693 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
122694 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
122695 + * It skips the possible error codes too.
122696 + */
122697 +static enum precond check_preconditions(struct interesting_node *cur_node)
122698 +{
122699 + bool interesting_conditions[5] = {false, false, false, false, false};
122700 +
122701 + set_last_nodes(cur_node);
122702 +
122703 + check_intentional_attribute_ipa(cur_node);
122704 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
122705 + return NO_ATTRIBUTE_SEARCH;
122706 +
122707 + search_interesting_conditions(cur_node, interesting_conditions);
122708 +
122709 + // error code: a phi, unary assign (not cast) and returns only
122710 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
122711 + return NO_ATTRIBUTE_SEARCH;
122712 +
122713 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
122714 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
122715 + return NO_ATTRIBUTE_SEARCH;
122716 +
122717 + // unnecessary overflow check
122718 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
122719 + return NO_CHECK_INSERT;
122720 +
122721 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
122722 + return NO_CHECK_INSERT;
122723 +
122724 + return NONE;
122725 +}
122726 +
122727 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
122728 +{
122729 + const_gimple assign;
122730 + tree orig_type = TREE_TYPE(orig_node);
122731 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
122732 +
122733 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
122734 + return gimple_assign_lhs(assign);
122735 +}
122736 +
122737 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
122738 +{
122739 + void (*set_rhs)(gimple, tree);
122740 + gimple stmt = cur_node->first_stmt;
122741 + const_tree orig_node = cur_node->node;
122742 +
122743 + switch (gimple_code(stmt)) {
122744 + case GIMPLE_RETURN:
122745 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
122746 + break;
122747 + case GIMPLE_CALL:
122748 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
122749 + break;
122750 + case GIMPLE_ASSIGN:
122751 + switch (cur_node->num) {
122752 + case 1:
122753 + set_rhs = &gimple_assign_set_rhs1;
122754 + break;
122755 + case 2:
122756 + set_rhs = &gimple_assign_set_rhs2;
122757 + break;
122758 +#if BUILDING_GCC_VERSION >= 4006
122759 + case 3:
122760 + set_rhs = &gimple_assign_set_rhs3;
122761 + break;
122762 +#endif
122763 + default:
122764 + gcc_unreachable();
122765 + }
122766 +
122767 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
122768 + break;
122769 + default:
122770 + debug_gimple_stmt(stmt);
122771 + gcc_unreachable();
122772 + }
122773 +
122774 + update_stmt(stmt);
122775 +}
122776 +
122777 +static struct visited *create_visited(void)
122778 +{
122779 + struct visited *new_node;
122780 +
122781 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
122782 + new_node->stmts = pointer_set_create();
122783 + new_node->my_stmts = pointer_set_create();
122784 + new_node->skip_expr_casts = pointer_set_create();
122785 + new_node->no_cast_check = pointer_set_create();
122786 + return new_node;
122787 +}
122788 +
122789 +static void free_visited(struct visited *visited)
122790 +{
122791 + pointer_set_destroy(visited->stmts);
122792 + pointer_set_destroy(visited->my_stmts);
122793 + pointer_set_destroy(visited->skip_expr_casts);
122794 + pointer_set_destroy(visited->no_cast_check);
122795 +
122796 + free(visited);
122797 +}
122798 +
122799 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
122800 + * 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
122801 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
122802 + */
122803 +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)
122804 +{
122805 + enum precond ret;
122806 + tree new_node, orig_node = cur_node->node;
122807 +
122808 + ret = check_preconditions(cur_node);
122809 + if (ret == NO_ATTRIBUTE_SEARCH)
122810 + return cnodes;
122811 +
122812 + cnodes = search_overflow_attribute(cnodes, cur_node);
122813 +
122814 + if (ret == NO_CHECK_INSERT)
122815 + return cnodes;
122816 +
122817 + new_node = expand(visited, caller_node, orig_node);
122818 + if (new_node == NULL_TREE)
122819 + return cnodes;
122820 +
122821 + change_orig_node(visited, cur_node, new_node);
122822 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
122823 +
122824 + return cnodes;
122825 +}
122826 +
122827 +// Check visited_fns interesting nodes.
122828 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
122829 +{
122830 + struct interesting_node *cur;
122831 +
122832 + for (cur = head; cur; cur = cur->next) {
122833 + if (!operand_equal_p(node, cur->node, 0))
122834 + continue;
122835 + if (num != cur->num)
122836 + continue;
122837 + if (first_stmt == cur->first_stmt)
122838 + return true;
122839 + }
122840 + return false;
122841 +}
122842 +
122843 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
122844 + 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
122845 + 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
122846 + the intentional_overflow attribute check. They are collected by set_last_nodes().
122847 + num: arg count of a call stmt or 0 when it is a ret
122848 + node: the recursion starts from here, it is a call arg or a return value
122849 + 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.
122850 + intentional_attr_decl: intentional_overflow attribute of the callee function
122851 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
122852 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
122853 + */
122854 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
122855 +{
122856 + struct interesting_node *new_node;
122857 + tree fndecl;
122858 + enum gimple_code code;
122859 +
122860 + gcc_assert(node != NULL_TREE);
122861 + code = gimple_code(first_stmt);
122862 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
122863 +
122864 + if (num == CANNOT_FIND_ARG)
122865 + return head;
122866 +
122867 + if (skip_types(node))
122868 + return head;
122869 +
122870 + if (skip_asm(node))
122871 + return head;
122872 +
122873 + if (is_gimple_call(first_stmt))
122874 + fndecl = gimple_call_fndecl(first_stmt);
122875 + else
122876 + fndecl = current_function_decl;
122877 +
122878 + if (fndecl == NULL_TREE)
122879 + return head;
122880 +
122881 + if (is_in_interesting_node(head, first_stmt, node, num))
122882 + return head;
122883 +
122884 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
122885 +
122886 + new_node->next = NULL;
122887 + new_node->first_stmt = first_stmt;
122888 +#if BUILDING_GCC_VERSION <= 4007
122889 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
122890 +#else
122891 + vec_alloc(new_node->last_nodes, VEC_LEN);
122892 +#endif
122893 + new_node->num = num;
122894 + new_node->node = node;
122895 + new_node->fndecl = fndecl;
122896 + new_node->intentional_attr_decl = MARK_NO;
122897 + new_node->intentional_attr_cur_fndecl = MARK_NO;
122898 + new_node->intentional_mark_from_gimple = asm_stmt;
122899 +
122900 + if (!head)
122901 + return new_node;
122902 +
122903 + new_node->next = head;
122904 + return new_node;
122905 +}
122906 +
122907 +/* 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).
122908 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
122909 + */
122910 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
122911 +{
122912 + struct next_cgraph_node *cur_node;
122913 + tree ret = gimple_return_retval(stmt);
122914 +
122915 + if (ret == NULL_TREE)
122916 + return head;
122917 +
122918 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
122919 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
122920 + continue;
122921 + if (cur_node->num == 0)
122922 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
122923 + }
122924 +
122925 + return head;
122926 +}
122927 +
122928 +/* 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).
122929 + * If the call stmt is in the next cgraph node list then it's an interesting call.
122930 + */
122931 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
122932 +{
122933 + unsigned int argnum;
122934 + tree arg;
122935 + const_tree fndecl;
122936 + struct next_cgraph_node *cur_node;
122937 +
122938 + fndecl = gimple_call_fndecl(stmt);
122939 + if (fndecl == NULL_TREE)
122940 + return head;
122941 +
122942 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
122943 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
122944 + continue;
122945 + argnum = get_correct_arg_count(cur_node->num, fndecl);
122946 + gcc_assert(argnum != CANNOT_FIND_ARG);
122947 + if (argnum == 0)
122948 + continue;
122949 +
122950 + arg = gimple_call_arg(stmt, argnum - 1);
122951 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
122952 + }
122953 +
122954 + return head;
122955 +}
122956 +
122957 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
122958 +{
122959 + if (!operand_equal_p(orig_node, node, 0))
122960 + return WRONG_NODE;
122961 + if (skip_types(node))
122962 + return WRONG_NODE;
122963 + return ret_count;
122964 +}
122965 +
122966 +// Get the index of the rhs node in an assignment
122967 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
122968 +{
122969 + const_tree rhs1, rhs2;
122970 + unsigned int ret;
122971 +
122972 + gcc_assert(stmt);
122973 + gcc_assert(is_gimple_assign(stmt));
122974 +
122975 + rhs1 = gimple_assign_rhs1(stmt);
122976 + gcc_assert(rhs1 != NULL_TREE);
122977 +
122978 + switch (gimple_num_ops(stmt)) {
122979 + case 2:
122980 + return check_ops(node, rhs1, 1);
122981 + case 3:
122982 + ret = check_ops(node, rhs1, 1);
122983 + if (ret != WRONG_NODE)
122984 + return ret;
122985 +
122986 + rhs2 = gimple_assign_rhs2(stmt);
122987 + gcc_assert(rhs2 != NULL_TREE);
122988 + return check_ops(node, rhs2, 2);
122989 + default:
122990 + gcc_unreachable();
122991 + }
122992 +}
122993 +
122994 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
122995 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
122996 +{
122997 + unsigned int i;
122998 +
122999 + if (gimple_call_fndecl(stmt) == NULL_TREE)
123000 + return CANNOT_FIND_ARG;
123001 +
123002 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
123003 + tree node;
123004 +
123005 + node = gimple_call_arg(stmt, i);
123006 + if (!operand_equal_p(arg, node, 0))
123007 + continue;
123008 + if (!skip_types(node))
123009 + return i + 1;
123010 + }
123011 +
123012 + return CANNOT_FIND_ARG;
123013 +}
123014 +
123015 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
123016 + * any of return, call or assignment stmts (because of inlining).
123017 + */
123018 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
123019 +{
123020 + use_operand_p use_p;
123021 + imm_use_iterator imm_iter;
123022 + unsigned int argnum;
123023 +
123024 + gcc_assert(TREE_CODE(node) == SSA_NAME);
123025 +
123026 + if (pointer_set_insert(visited, node))
123027 + return head;
123028 +
123029 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
123030 + gimple stmt = USE_STMT(use_p);
123031 +
123032 + if (stmt == NULL)
123033 + return head;
123034 + if (is_gimple_debug(stmt))
123035 + continue;
123036 +
123037 + switch (gimple_code(stmt)) {
123038 + case GIMPLE_CALL:
123039 + argnum = find_arg_number_gimple(node, stmt);
123040 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
123041 + break;
123042 + case GIMPLE_RETURN:
123043 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
123044 + break;
123045 + case GIMPLE_ASSIGN:
123046 + argnum = get_assign_ops_count(stmt, node);
123047 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
123048 + break;
123049 + case GIMPLE_PHI: {
123050 + tree result = gimple_phi_result(stmt);
123051 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
123052 + break;
123053 + }
123054 + case GIMPLE_ASM:
123055 + if (gimple_asm_noutputs(stmt) != 0)
123056 + break;
123057 + if (!is_size_overflow_asm(stmt))
123058 + break;
123059 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
123060 + break;
123061 + case GIMPLE_COND:
123062 + case GIMPLE_SWITCH:
123063 + break;
123064 + default:
123065 + debug_gimple_stmt(stmt);
123066 + gcc_unreachable();
123067 + break;
123068 + }
123069 + }
123070 + return head;
123071 +}
123072 +
123073 +static void remove_size_overflow_asm(gimple stmt)
123074 +{
123075 + gimple_stmt_iterator gsi;
123076 + tree input, output;
123077 +
123078 + if (!is_size_overflow_asm(stmt))
123079 + return;
123080 +
123081 + if (gimple_asm_noutputs(stmt) == 0) {
123082 + gsi = gsi_for_stmt(stmt);
123083 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
123084 + gsi_remove(&gsi, true);
123085 + return;
123086 + }
123087 +
123088 + input = gimple_asm_input_op(stmt, 0);
123089 + output = gimple_asm_output_op(stmt, 0);
123090 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
123091 +}
123092 +
123093 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
123094 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
123095 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
123096 + */
123097 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
123098 +{
123099 + const_tree output;
123100 + struct pointer_set_t *visited;
123101 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
123102 +
123103 + if (!is_size_overflow_asm(stmt))
123104 + return head;
123105 +
123106 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
123107 + intentional_asm = stmt;
123108 +
123109 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
123110 +
123111 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
123112 + return head;
123113 +
123114 + if (gimple_asm_noutputs(stmt) == 0) {
123115 + const_tree input;
123116 +
123117 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
123118 + return head;
123119 +
123120 + input = gimple_asm_input_op(stmt, 0);
123121 + remove_size_overflow_asm(stmt);
123122 + if (is_gimple_constant(TREE_VALUE(input)))
123123 + return head;
123124 + visited = pointer_set_create();
123125 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
123126 + pointer_set_destroy(visited);
123127 + return head;
123128 + }
123129 +
123130 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
123131 + remove_size_overflow_asm(stmt);
123132 +
123133 + visited = pointer_set_create();
123134 + output = gimple_asm_output_op(stmt, 0);
123135 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
123136 + pointer_set_destroy(visited);
123137 + return head;
123138 +}
123139 +
123140 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
123141 + * or a call stmt or a return stmt and store them in the interesting_node list
123142 + */
123143 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
123144 +{
123145 + basic_block bb;
123146 + struct interesting_node *head = NULL;
123147 +
123148 + FOR_ALL_BB_FN(bb, cfun) {
123149 + gimple_stmt_iterator gsi;
123150 +
123151 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
123152 + enum gimple_code code;
123153 + gimple stmt = gsi_stmt(gsi);
123154 +
123155 + code = gimple_code(stmt);
123156 +
123157 + if (code == GIMPLE_ASM)
123158 + head = handle_stmt_by_size_overflow_asm(stmt, head);
123159 +
123160 + if (!next_node)
123161 + continue;
123162 + if (code == GIMPLE_CALL)
123163 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
123164 + if (code == GIMPLE_RETURN)
123165 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
123166 + }
123167 + }
123168 + return head;
123169 +}
123170 +
123171 +static void free_interesting_node(struct interesting_node *head)
123172 +{
123173 + struct interesting_node *cur;
123174 +
123175 + while (head) {
123176 + cur = head->next;
123177 +#if BUILDING_GCC_VERSION <= 4007
123178 + VEC_free(tree, gc, head->last_nodes);
123179 +#else
123180 + vec_free(head->last_nodes);
123181 +#endif
123182 + free(head);
123183 + head = cur;
123184 + }
123185 +}
123186 +
123187 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
123188 +{
123189 + struct visited_fns *new_visited_fns;
123190 +
123191 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
123192 + new_visited_fns->fndecl = cur_node->fndecl;
123193 + new_visited_fns->num = cur_node->num;
123194 + new_visited_fns->first_stmt = cur_node->first_stmt;
123195 + new_visited_fns->next = NULL;
123196 +
123197 + if (!head)
123198 + return new_visited_fns;
123199 +
123200 + new_visited_fns->next = head;
123201 + return new_visited_fns;
123202 +}
123203 +
123204 +/* 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
123205 + * it is a visited_fns function.
123206 + */
123207 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
123208 +{
123209 + struct visited_fns *cur;
123210 +
123211 + if (!head)
123212 + return false;
123213 +
123214 + for (cur = head; cur; cur = cur->next) {
123215 + if (cur_node->first_stmt != cur->first_stmt)
123216 + continue;
123217 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
123218 + continue;
123219 + if (cur_node->num == cur->num)
123220 + return true;
123221 + }
123222 + return false;
123223 +}
123224 +
123225 +static void free_next_cgraph_node(struct next_cgraph_node *head)
123226 +{
123227 + struct next_cgraph_node *cur;
123228 +
123229 + while (head) {
123230 + cur = head->next;
123231 + free(head);
123232 + head = cur;
123233 + }
123234 +}
123235 +
123236 +static void remove_all_size_overflow_asm(void)
123237 +{
123238 + basic_block bb;
123239 +
123240 + FOR_ALL_BB_FN(bb, cfun) {
123241 + gimple_stmt_iterator si;
123242 +
123243 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
123244 + remove_size_overflow_asm(gsi_stmt(si));
123245 + }
123246 +}
123247 +
123248 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
123249 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
123250 + * the newly collected interesting functions (they are interesting if there is control flow between
123251 + * the interesting stmts and them).
123252 + */
123253 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
123254 +{
123255 + struct visited *visited;
123256 + struct interesting_node *head, *cur_node;
123257 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
123258 +
123259 + set_current_function_decl(NODE_DECL(node));
123260 + call_count = 0;
123261 +
123262 + head = collect_interesting_stmts(next_node);
123263 +
123264 + visited = create_visited();
123265 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
123266 + if (is_visited_fns_function(visited_fns, cur_node))
123267 + continue;
123268 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
123269 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
123270 + }
123271 +
123272 + free_visited(visited);
123273 + free_interesting_node(head);
123274 + remove_all_size_overflow_asm();
123275 + unset_current_function_decl();
123276 +
123277 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
123278 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
123279 +
123280 + free_next_cgraph_node(cnodes_head);
123281 + return visited_fns;
123282 +}
123283 +
123284 +static void free_visited_fns(struct visited_fns *head)
123285 +{
123286 + struct visited_fns *cur;
123287 +
123288 + while (head) {
123289 + cur = head->next;
123290 + free(head);
123291 + head = cur;
123292 + }
123293 +}
123294 +
123295 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
123296 +unsigned int search_function(void)
123297 +{
123298 + struct cgraph_node *node;
123299 + struct visited_fns *visited_fns = NULL;
123300 +
123301 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
123302 + gcc_assert(cgraph_function_flags_ready);
123303 +#if BUILDING_GCC_VERSION <= 4007
123304 + gcc_assert(node->reachable);
123305 +#endif
123306 +
123307 + visited_fns = handle_function(node, NULL, visited_fns);
123308 + }
123309 +
123310 + free_visited_fns(visited_fns);
123311 + return 0;
123312 +}
123313 +
123314 +#if BUILDING_GCC_VERSION >= 4009
123315 +static const struct pass_data insert_size_overflow_check_data = {
123316 +#else
123317 +static struct ipa_opt_pass_d insert_size_overflow_check = {
123318 + .pass = {
123319 +#endif
123320 + .type = SIMPLE_IPA_PASS,
123321 + .name = "size_overflow",
123322 +#if BUILDING_GCC_VERSION >= 4008
123323 + .optinfo_flags = OPTGROUP_NONE,
123324 +#endif
123325 +#if BUILDING_GCC_VERSION >= 4009
123326 + .has_gate = false,
123327 + .has_execute = true,
123328 +#else
123329 + .gate = NULL,
123330 + .execute = search_function,
123331 + .sub = NULL,
123332 + .next = NULL,
123333 + .static_pass_number = 0,
123334 +#endif
123335 + .tv_id = TV_NONE,
123336 + .properties_required = 0,
123337 + .properties_provided = 0,
123338 + .properties_destroyed = 0,
123339 + .todo_flags_start = 0,
123340 + .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,
123341 +#if BUILDING_GCC_VERSION < 4009
123342 + },
123343 + .generate_summary = NULL,
123344 + .write_summary = NULL,
123345 + .read_summary = NULL,
123346 +#if BUILDING_GCC_VERSION >= 4006
123347 + .write_optimization_summary = NULL,
123348 + .read_optimization_summary = NULL,
123349 +#endif
123350 + .stmt_fixup = NULL,
123351 + .function_transform_todo_flags_start = 0,
123352 + .function_transform = NULL,
123353 + .variable_transform = NULL,
123354 +#endif
123355 +};
123356 +
123357 +#if BUILDING_GCC_VERSION >= 4009
123358 +namespace {
123359 +class insert_size_overflow_check : public ipa_opt_pass_d {
123360 +public:
123361 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
123362 + unsigned int execute() { return search_function(); }
123363 +};
123364 +}
123365 +#endif
123366 +
123367 +struct opt_pass *make_insert_size_overflow_check(void)
123368 +{
123369 +#if BUILDING_GCC_VERSION >= 4009
123370 + return new insert_size_overflow_check();
123371 +#else
123372 + return &insert_size_overflow_check.pass;
123373 +#endif
123374 +}
123375 +
123376 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
123377 new file mode 100644
123378 index 0000000..d71d72a
123379 --- /dev/null
123380 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
123381 @@ -0,0 +1,736 @@
123382 +/*
123383 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123384 + * Licensed under the GPL v2, or (at your option) v3
123385 + *
123386 + * Homepage:
123387 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123388 + *
123389 + * Documentation:
123390 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123391 + *
123392 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
123393 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
123394 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
123395 + *
123396 + * Usage:
123397 + * $ make
123398 + * $ make run
123399 + */
123400 +
123401 +#include "gcc-common.h"
123402 +#include "size_overflow.h"
123403 +
123404 +/* Get the param of the intentional_overflow attribute.
123405 + * * 0: MARK_NOT_INTENTIONAL
123406 + * * 1..MAX_PARAM: MARK_YES
123407 + * * -1: MARK_TURN_OFF
123408 + */
123409 +static tree get_attribute_param(const_tree decl)
123410 +{
123411 + const_tree attr;
123412 +
123413 + if (decl == NULL_TREE)
123414 + return NULL_TREE;
123415 +
123416 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
123417 + if (!attr || !TREE_VALUE(attr))
123418 + return NULL_TREE;
123419 +
123420 + return TREE_VALUE(attr);
123421 +}
123422 +
123423 +// MARK_TURN_OFF
123424 +bool is_turn_off_intentional_attr(const_tree decl)
123425 +{
123426 + const_tree param_head;
123427 +
123428 + param_head = get_attribute_param(decl);
123429 + if (param_head == NULL_TREE)
123430 + return false;
123431 +
123432 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
123433 + return true;
123434 + return false;
123435 +}
123436 +
123437 +// MARK_NOT_INTENTIONAL
123438 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
123439 +{
123440 + const_tree param_head;
123441 +
123442 + if (argnum == 0)
123443 + return false;
123444 +
123445 + param_head = get_attribute_param(decl);
123446 + if (param_head == NULL_TREE)
123447 + return false;
123448 +
123449 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
123450 + return true;
123451 + return false;
123452 +}
123453 +
123454 +// MARK_YES
123455 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
123456 +{
123457 + tree param, param_head;
123458 +
123459 + if (argnum == 0)
123460 + return false;
123461 +
123462 + param_head = get_attribute_param(decl);
123463 + for (param = param_head; param; param = TREE_CHAIN(param))
123464 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
123465 + return true;
123466 + return false;
123467 +}
123468 +
123469 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
123470 +{
123471 + location_t loc;
123472 +
123473 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
123474 + return;
123475 +
123476 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
123477 + return;
123478 +
123479 + loc = DECL_SOURCE_LOCATION(decl);
123480 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
123481 +}
123482 +
123483 +// Get the field decl of a component ref for intentional_overflow checking
123484 +static const_tree search_field_decl(const_tree comp_ref)
123485 +{
123486 + const_tree field = NULL_TREE;
123487 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
123488 +
123489 + for (i = 0; i < len; i++) {
123490 + field = TREE_OPERAND(comp_ref, i);
123491 + if (TREE_CODE(field) == FIELD_DECL)
123492 + break;
123493 + }
123494 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
123495 + return field;
123496 +}
123497 +
123498 +/* Get the type of the intentional_overflow attribute of a node
123499 + * * MARK_TURN_OFF
123500 + * * MARK_YES
123501 + * * MARK_NO
123502 + * * MARK_NOT_INTENTIONAL
123503 + */
123504 +enum mark get_intentional_attr_type(const_tree node)
123505 +{
123506 + const_tree cur_decl;
123507 +
123508 + if (node == NULL_TREE)
123509 + return MARK_NO;
123510 +
123511 + switch (TREE_CODE(node)) {
123512 + case COMPONENT_REF:
123513 + cur_decl = search_field_decl(node);
123514 + if (is_turn_off_intentional_attr(cur_decl))
123515 + return MARK_TURN_OFF;
123516 + if (is_end_intentional_intentional_attr(cur_decl, 1))
123517 + return MARK_YES;
123518 + break;
123519 + case PARM_DECL: {
123520 + unsigned int argnum;
123521 +
123522 + cur_decl = DECL_ORIGIN(current_function_decl);
123523 + argnum = find_arg_number_tree(node, cur_decl);
123524 + if (argnum == CANNOT_FIND_ARG)
123525 + return MARK_NO;
123526 + if (is_yes_intentional_attr(cur_decl, argnum))
123527 + return MARK_YES;
123528 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
123529 + return MARK_NOT_INTENTIONAL;
123530 + break;
123531 + }
123532 + case FUNCTION_DECL:
123533 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
123534 + return MARK_TURN_OFF;
123535 + break;
123536 + default:
123537 + break;
123538 + }
123539 + return MARK_NO;
123540 +}
123541 +
123542 +// Search for the intentional_overflow attribute on the last nodes
123543 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
123544 +{
123545 + unsigned int i;
123546 + tree last_node;
123547 + enum mark mark = MARK_NO;
123548 +
123549 +#if BUILDING_GCC_VERSION <= 4007
123550 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
123551 +#else
123552 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
123553 +#endif
123554 + mark = get_intentional_attr_type(last_node);
123555 + if (mark != MARK_NO)
123556 + break;
123557 + }
123558 + return mark;
123559 +}
123560 +
123561 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
123562 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
123563 + */
123564 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
123565 +{
123566 + if (!cur_node->intentional_mark_from_gimple)
123567 + return false;
123568 +
123569 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
123570 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
123571 + else
123572 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
123573 +
123574 + // skip param decls
123575 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
123576 + return true;
123577 + return true;
123578 +}
123579 +
123580 +/* Search intentional_overflow attribute on caller and on callee too.
123581 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
123582 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
123583 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
123584 +*/
123585 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
123586 +{
123587 + const_tree fndecl;
123588 +
123589 + if (is_intentional_attribute_from_gimple(cur_node))
123590 + return;
123591 +
123592 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
123593 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
123594 + return;
123595 + }
123596 +
123597 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
123598 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
123599 + return;
123600 + }
123601 +
123602 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
123603 + return;
123604 +
123605 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
123606 + if (is_turn_off_intentional_attr(fndecl)) {
123607 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
123608 + return;
123609 + }
123610 +
123611 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
123612 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
123613 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
123614 + cur_node->intentional_attr_decl = MARK_YES;
123615 +
123616 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
123617 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
123618 +}
123619 +
123620 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
123621 +{
123622 + const_tree rhs1, lhs, rhs1_type, lhs_type;
123623 + enum machine_mode lhs_mode, rhs_mode;
123624 + gimple def_stmt = get_def_stmt(no_const_rhs);
123625 +
123626 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
123627 + return false;
123628 +
123629 + rhs1 = gimple_assign_rhs1(def_stmt);
123630 + lhs = gimple_assign_lhs(def_stmt);
123631 + rhs1_type = TREE_TYPE(rhs1);
123632 + lhs_type = TREE_TYPE(lhs);
123633 + rhs_mode = TYPE_MODE(rhs1_type);
123634 + lhs_mode = TYPE_MODE(lhs_type);
123635 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
123636 + return false;
123637 +
123638 + return true;
123639 +}
123640 +
123641 +static unsigned int uses_num(tree node)
123642 +{
123643 + imm_use_iterator imm_iter;
123644 + use_operand_p use_p;
123645 + unsigned int num = 0;
123646 +
123647 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
123648 + gimple use_stmt = USE_STMT(use_p);
123649 +
123650 + if (use_stmt == NULL)
123651 + return num;
123652 + if (is_gimple_debug(use_stmt))
123653 + continue;
123654 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
123655 + continue;
123656 + num++;
123657 + }
123658 + return num;
123659 +}
123660 +
123661 +static bool no_uses(tree node)
123662 +{
123663 + return !uses_num(node);
123664 +}
123665 +
123666 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
123667 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
123668 +{
123669 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
123670 + gimple def_stmt = get_def_stmt(lhs);
123671 +
123672 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
123673 + return false;
123674 +
123675 + rhs1 = gimple_assign_rhs1(def_stmt);
123676 + rhs_type = TREE_TYPE(rhs1);
123677 + lhs_type = TREE_TYPE(lhs);
123678 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
123679 + return false;
123680 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
123681 + return false;
123682 +
123683 + def_stmt = get_def_stmt(rhs1);
123684 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
123685 + return false;
123686 +
123687 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
123688 + return false;
123689 +
123690 + rhs1 = gimple_assign_rhs1(def_stmt);
123691 + rhs2 = gimple_assign_rhs2(def_stmt);
123692 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
123693 + return false;
123694 +
123695 + if (is_gimple_constant(rhs2))
123696 + not_const_rhs = rhs1;
123697 + else
123698 + not_const_rhs = rhs2;
123699 +
123700 + return no_uses(not_const_rhs);
123701 +}
123702 +
123703 +static bool is_lt_signed_type_max(const_tree rhs)
123704 +{
123705 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
123706 +
123707 + if (!TYPE_UNSIGNED(type))
123708 + return true;
123709 +
123710 + switch (TYPE_MODE(type)) {
123711 + case QImode:
123712 + new_type = intQI_type_node;
123713 + break;
123714 + case HImode:
123715 + new_type = intHI_type_node;
123716 + break;
123717 + case SImode:
123718 + new_type = intSI_type_node;
123719 + break;
123720 + case DImode:
123721 + new_type = intDI_type_node;
123722 + break;
123723 + default:
123724 + debug_tree((tree)type);
123725 + gcc_unreachable();
123726 + }
123727 +
123728 + type_max = TYPE_MAX_VALUE(new_type);
123729 + if (!tree_int_cst_lt(type_max, rhs))
123730 + return true;
123731 +
123732 + return false;
123733 +}
123734 +
123735 +static bool is_gt_zero(const_tree rhs)
123736 +{
123737 + const_tree type = TREE_TYPE(rhs);
123738 +
123739 + if (TYPE_UNSIGNED(type))
123740 + return true;
123741 +
123742 + if (!tree_int_cst_lt(rhs, integer_zero_node))
123743 + return true;
123744 +
123745 + return false;
123746 +}
123747 +
123748 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
123749 +{
123750 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
123751 + return false;
123752 + if (!is_gimple_constant(rhs))
123753 + return false;
123754 +
123755 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
123756 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
123757 + return false;
123758 +
123759 + return true;
123760 +}
123761 +
123762 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
123763 +{
123764 + gimple assign;
123765 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
123766 + tree origtype = TREE_TYPE(orig_rhs);
123767 +
123768 + gcc_assert(is_gimple_assign(stmt));
123769 +
123770 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
123771 + pointer_set_insert(visited->my_stmts, assign);
123772 + return gimple_assign_lhs(assign);
123773 +}
123774 +
123775 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
123776 +{
123777 + tree new_rhs, orig_rhs;
123778 + void (*gimple_assign_set_rhs)(gimple, tree);
123779 + tree rhs1 = gimple_assign_rhs1(stmt);
123780 + tree rhs2 = gimple_assign_rhs2(stmt);
123781 + tree lhs = gimple_assign_lhs(stmt);
123782 +
123783 + if (!check_overflow)
123784 + return create_assign(visited, stmt, lhs, AFTER_STMT);
123785 +
123786 + if (change_rhs == NULL_TREE)
123787 + return create_assign(visited, stmt, lhs, AFTER_STMT);
123788 +
123789 + if (new_rhs2 == NULL_TREE) {
123790 + orig_rhs = rhs1;
123791 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
123792 + } else {
123793 + orig_rhs = rhs2;
123794 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
123795 + }
123796 +
123797 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
123798 +
123799 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
123800 + gimple_assign_set_rhs(stmt, new_rhs);
123801 + update_stmt(stmt);
123802 +
123803 + return create_assign(visited, stmt, lhs, AFTER_STMT);
123804 +}
123805 +
123806 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
123807 +{
123808 + gimple rhs1_def_stmt, rhs2_def_stmt;
123809 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
123810 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
123811 + const_tree rhs1 = gimple_assign_rhs1(stmt);
123812 + const_tree rhs2 = gimple_assign_rhs2(stmt);
123813 +
123814 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
123815 + return false;
123816 +
123817 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
123818 +
123819 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
123820 + return false;
123821 +
123822 + rhs1_def_stmt = get_def_stmt(rhs1);
123823 + rhs2_def_stmt = get_def_stmt(rhs2);
123824 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
123825 + return false;
123826 +
123827 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
123828 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
123829 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
123830 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
123831 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
123832 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
123833 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
123834 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
123835 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
123836 + return false;
123837 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
123838 + return false;
123839 +
123840 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
123841 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
123842 + return true;
123843 +}
123844 +
123845 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
123846 +{
123847 + gimple assign;
123848 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
123849 + tree type = TREE_TYPE(rhs1);
123850 + tree lhs = create_new_var(type);
123851 +
123852 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
123853 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
123854 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
123855 +
123856 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
123857 + update_stmt(assign);
123858 + pointer_set_insert(visited->my_stmts, assign);
123859 + return assign;
123860 +}
123861 +
123862 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
123863 +{
123864 + gimple_stmt_iterator gsi;
123865 + gimple cast_stmt;
123866 + tree type = TREE_TYPE(node);
123867 +
123868 + if (types_compatible_p(type, intTI_type_node))
123869 + return node;
123870 +
123871 + gsi = gsi_for_stmt(stmt);
123872 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
123873 + pointer_set_insert(visited->my_stmts, cast_stmt);
123874 + return gimple_assign_lhs(cast_stmt);
123875 +}
123876 +
123877 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
123878 +{
123879 + tree rhs1, def_stmt_rhs1;
123880 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
123881 +
123882 + def_stmt = get_def_stmt(var);
123883 + if (!gimple_assign_cast_p(def_stmt))
123884 + return NULL_TREE;
123885 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
123886 +
123887 + rhs1 = gimple_assign_rhs1(def_stmt);
123888 + rhs1_def_stmt = get_def_stmt(rhs1);
123889 + if (!gimple_assign_cast_p(rhs1_def_stmt))
123890 + return rhs1;
123891 +
123892 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
123893 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
123894 +
123895 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
123896 + case GIMPLE_CALL:
123897 + case GIMPLE_NOP:
123898 + case GIMPLE_ASM:
123899 + case GIMPLE_PHI:
123900 + return def_stmt_rhs1;
123901 + case GIMPLE_ASSIGN:
123902 + return rhs1;
123903 + default:
123904 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
123905 + gcc_unreachable();
123906 + }
123907 +}
123908 +
123909 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
123910 +{
123911 + tree new_rhs1, new_rhs2;
123912 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
123913 + gimple assign, stmt = get_def_stmt(lhs);
123914 + tree rhs1 = gimple_assign_rhs1(stmt);
123915 + tree rhs2 = gimple_assign_rhs2(stmt);
123916 +
123917 + if (!is_subtraction_special(visited, stmt))
123918 + return NULL_TREE;
123919 +
123920 + new_rhs1 = expand(visited, caller_node, rhs1);
123921 + new_rhs2 = expand(visited, caller_node, rhs2);
123922 +
123923 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
123924 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
123925 +
123926 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
123927 + return NULL_TREE;
123928 +
123929 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
123930 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
123931 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
123932 + }
123933 +
123934 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
123935 + new_lhs = gimple_assign_lhs(assign);
123936 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
123937 +
123938 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
123939 +}
123940 +
123941 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
123942 +{
123943 + const_gimple def_stmt;
123944 +
123945 + if (TREE_CODE(rhs) != SSA_NAME)
123946 + return false;
123947 +
123948 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
123949 + return false;
123950 +
123951 + def_stmt = get_def_stmt(rhs);
123952 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
123953 + return false;
123954 +
123955 + return true;
123956 +}
123957 +
123958 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
123959 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
123960 + * fffffff * 16 > signed max -> truncate
123961 + */
123962 +static bool look_for_mult_and_add(const_gimple stmt)
123963 +{
123964 + const_tree res;
123965 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
123966 + const_gimple def_stmt;
123967 +
123968 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
123969 + return false;
123970 + if (!is_gimple_assign(stmt))
123971 + return false;
123972 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
123973 + return false;
123974 +
123975 + rhs1 = gimple_assign_rhs1(stmt);
123976 + rhs2 = gimple_assign_rhs2(stmt);
123977 + if (is_gimple_constant(rhs1)) {
123978 + const_rhs = rhs1;
123979 + def_stmt = get_def_stmt(rhs2);
123980 + } else if (is_gimple_constant(rhs2)) {
123981 + const_rhs = rhs2;
123982 + def_stmt = get_def_stmt(rhs1);
123983 + } else
123984 + return false;
123985 +
123986 + if (!is_gimple_assign(def_stmt))
123987 + return false;
123988 +
123989 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
123990 + return false;
123991 +
123992 + def_rhs1 = gimple_assign_rhs1(def_stmt);
123993 + def_rhs2 = gimple_assign_rhs2(def_stmt);
123994 + if (is_gimple_constant(def_rhs1))
123995 + def_const_rhs = def_rhs1;
123996 + else if (is_gimple_constant(def_rhs2))
123997 + def_const_rhs = def_rhs2;
123998 + else
123999 + return false;
124000 +
124001 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
124002 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
124003 + return false;
124004 + return true;
124005 +}
124006 +
124007 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
124008 +{
124009 + const_gimple def_stmt_1, def_stmt_2;
124010 + const_tree rhs1, rhs2;
124011 + bool add_mul_rhs1, add_mul_rhs2;
124012 +
124013 + rhs1 = gimple_assign_rhs1(stmt);
124014 + def_stmt_1 = get_def_stmt(rhs1);
124015 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
124016 +
124017 + rhs2 = gimple_assign_rhs2(stmt);
124018 + def_stmt_2 = get_def_stmt(rhs2);
124019 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
124020 +
124021 + if (add_mul_rhs1)
124022 + return RHS1_INTENTIONAL_OVERFLOW;
124023 + if (add_mul_rhs2)
124024 + return RHS2_INTENTIONAL_OVERFLOW;
124025 + return NO_INTENTIONAL_OVERFLOW;
124026 +}
124027 +
124028 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
124029 +{
124030 + gimple my_stmt;
124031 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
124032 +
124033 + gsi_next(&gsi);
124034 + my_stmt = gsi_stmt(gsi);
124035 +
124036 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
124037 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
124038 +
124039 + return my_stmt;
124040 +}
124041 +
124042 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
124043 + * unsigned type cast to signed type, unsigned type: no more uses
124044 + * e.g., lib/vsprintf.c:simple_strtol()
124045 + * _10 = (unsigned long int) _9
124046 + * _11 = -_10;
124047 + * _12 = (long int) _11; (_11_ no more uses)
124048 + */
124049 +static bool is_call_or_cast(gimple stmt)
124050 +{
124051 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
124052 +}
124053 +
124054 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
124055 +{
124056 + const_tree rhs;
124057 + gimple def_stmt;
124058 +
124059 + if (node == NULL_TREE)
124060 + return true;
124061 + if (is_gimple_constant(node))
124062 + return true;
124063 +
124064 + def_stmt = get_def_stmt(node);
124065 + if (!def_stmt)
124066 + return false;
124067 +
124068 + if (is_call_or_cast(def_stmt))
124069 + return true;
124070 +
124071 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
124072 + return false;
124073 + rhs = gimple_assign_rhs1(def_stmt);
124074 + def_stmt = get_def_stmt(rhs);
124075 + if (!def_stmt)
124076 + return false;
124077 + return is_call_or_cast(def_stmt);
124078 +}
124079 +
124080 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
124081 +{
124082 + unsigned int use_num;
124083 + gimple so_stmt;
124084 + const_gimple def_stmt;
124085 + const_tree rhs1, rhs2;
124086 + tree rhs = gimple_assign_rhs1(stmt);
124087 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
124088 + const_tree rhs_type = TREE_TYPE(rhs);
124089 +
124090 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
124091 + return;
124092 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
124093 + return;
124094 + use_num = uses_num(rhs);
124095 + if (use_num != 1)
124096 + return;
124097 +
124098 + def_stmt = get_def_stmt(rhs);
124099 + if (!def_stmt)
124100 + return;
124101 + if (!is_gimple_assign(def_stmt))
124102 + return;
124103 +
124104 + rhs1 = gimple_assign_rhs1(def_stmt);
124105 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
124106 + return;
124107 +
124108 + rhs2 = gimple_assign_rhs2(def_stmt);
124109 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
124110 + return;
124111 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
124112 + return;
124113 +
124114 + so_stmt = get_dup_stmt(visited, stmt);
124115 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
124116 +}
124117 +
124118 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
124119 new file mode 100644
124120 index 0000000..4bddad2
124121 --- /dev/null
124122 +++ b/tools/gcc/size_overflow_plugin/misc.c
124123 @@ -0,0 +1,203 @@
124124 +/*
124125 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124126 + * Licensed under the GPL v2, or (at your option) v3
124127 + *
124128 + * Homepage:
124129 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124130 + *
124131 + * Documentation:
124132 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124133 + *
124134 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124135 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124136 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124137 + *
124138 + * Usage:
124139 + * $ make
124140 + * $ make run
124141 + */
124142 +
124143 +#include "gcc-common.h"
124144 +#include "size_overflow.h"
124145 +
124146 +void set_current_function_decl(tree fndecl)
124147 +{
124148 + gcc_assert(fndecl != NULL_TREE);
124149 +
124150 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
124151 + calculate_dominance_info(CDI_DOMINATORS);
124152 + current_function_decl = fndecl;
124153 +}
124154 +
124155 +void unset_current_function_decl(void)
124156 +{
124157 + free_dominance_info(CDI_DOMINATORS);
124158 + pop_cfun();
124159 + current_function_decl = NULL_TREE;
124160 +}
124161 +
124162 +static bool is_bool(const_tree node)
124163 +{
124164 + const_tree type;
124165 +
124166 + if (node == NULL_TREE)
124167 + return false;
124168 +
124169 + type = TREE_TYPE(node);
124170 + if (!INTEGRAL_TYPE_P(type))
124171 + return false;
124172 + if (TREE_CODE(type) == BOOLEAN_TYPE)
124173 + return true;
124174 + if (TYPE_PRECISION(type) == 1)
124175 + return true;
124176 + return false;
124177 +}
124178 +
124179 +bool skip_types(const_tree var)
124180 +{
124181 + tree type;
124182 + enum tree_code code;
124183 +
124184 + if (is_gimple_constant(var))
124185 + return true;
124186 +
124187 + switch (TREE_CODE(var)) {
124188 + case ADDR_EXPR:
124189 +#if BUILDING_GCC_VERSION >= 4006
124190 + case MEM_REF:
124191 +#endif
124192 + case ARRAY_REF:
124193 + case BIT_FIELD_REF:
124194 + case INDIRECT_REF:
124195 + case TARGET_MEM_REF:
124196 + case COMPONENT_REF:
124197 + case VAR_DECL:
124198 + case VIEW_CONVERT_EXPR:
124199 + return true;
124200 + default:
124201 + break;
124202 + }
124203 +
124204 + code = TREE_CODE(var);
124205 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
124206 +
124207 + type = TREE_TYPE(var);
124208 + switch (TREE_CODE(type)) {
124209 + case INTEGER_TYPE:
124210 + case ENUMERAL_TYPE:
124211 + return false;
124212 + case BOOLEAN_TYPE:
124213 + return is_bool(var);
124214 + default:
124215 + return true;
124216 + }
124217 +}
124218 +
124219 +gimple get_def_stmt(const_tree node)
124220 +{
124221 + gcc_assert(node != NULL_TREE);
124222 +
124223 + if (skip_types(node))
124224 + return NULL;
124225 +
124226 + if (TREE_CODE(node) != SSA_NAME)
124227 + return NULL;
124228 + return SSA_NAME_DEF_STMT(node);
124229 +}
124230 +
124231 +tree create_new_var(tree type)
124232 +{
124233 + tree new_var = create_tmp_var(type, "cicus");
124234 +
124235 + add_referenced_var(new_var);
124236 + return new_var;
124237 +}
124238 +
124239 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
124240 +{
124241 + const_gimple def_stmt = get_def_stmt(rhs);
124242 +
124243 + if (force)
124244 + return false;
124245 +
124246 + if (is_gimple_constant(rhs))
124247 + return false;
124248 +
124249 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
124250 + return false;
124251 +
124252 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
124253 + return false;
124254 +
124255 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
124256 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
124257 + return false;
124258 +
124259 + return true;
124260 +}
124261 +
124262 +tree cast_a_tree(tree type, tree var)
124263 +{
124264 + gcc_assert(type != NULL_TREE);
124265 + gcc_assert(var != NULL_TREE);
124266 + gcc_assert(fold_convertible_p(type, var));
124267 +
124268 + return fold_convert(type, var);
124269 +}
124270 +
124271 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
124272 +{
124273 + gimple assign, def_stmt;
124274 +
124275 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
124276 + gcc_assert(!is_gimple_constant(rhs));
124277 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
124278 + gcc_unreachable();
124279 +
124280 + def_stmt = get_def_stmt(rhs);
124281 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
124282 + return def_stmt;
124283 +
124284 + if (lhs == CREATE_NEW_VAR)
124285 + lhs = create_new_var(dst_type);
124286 +
124287 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
124288 +
124289 + if (!gsi_end_p(*gsi)) {
124290 + location_t loc = gimple_location(gsi_stmt(*gsi));
124291 + gimple_set_location(assign, loc);
124292 + }
124293 +
124294 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
124295 +
124296 + if (before)
124297 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
124298 + else
124299 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
124300 + update_stmt(assign);
124301 + return assign;
124302 +}
124303 +
124304 +bool is_size_overflow_type(const_tree var)
124305 +{
124306 + const char *name;
124307 + const_tree type_name, type;
124308 +
124309 + if (var == NULL_TREE)
124310 + return false;
124311 +
124312 + type = TREE_TYPE(var);
124313 + type_name = TYPE_NAME(type);
124314 + if (type_name == NULL_TREE)
124315 + return false;
124316 +
124317 + if (DECL_P(type_name))
124318 + name = DECL_NAME_POINTER(type_name);
124319 + else
124320 + name = IDENTIFIER_POINTER(type_name);
124321 +
124322 + if (!strncmp(name, "size_overflow_type", 18))
124323 + return true;
124324 + return false;
124325 +}
124326 +
124327 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
124328 new file mode 100644
124329 index 0000000..7c9e6d1
124330 --- /dev/null
124331 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
124332 @@ -0,0 +1,138 @@
124333 +/*
124334 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124335 + * Licensed under the GPL v2, or (at your option) v3
124336 + *
124337 + * Homepage:
124338 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124339 + *
124340 + * Documentation:
124341 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124342 + *
124343 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124344 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124345 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124346 + *
124347 + * Usage:
124348 + * $ make
124349 + * $ make run
124350 + */
124351 +
124352 +#include "gcc-common.h"
124353 +#include "size_overflow.h"
124354 +
124355 +bool skip_expr_on_double_type(const_gimple stmt)
124356 +{
124357 + enum tree_code code = gimple_assign_rhs_code(stmt);
124358 +
124359 + switch (code) {
124360 + case RSHIFT_EXPR:
124361 + case TRUNC_DIV_EXPR:
124362 + case CEIL_DIV_EXPR:
124363 + case FLOOR_DIV_EXPR:
124364 + case ROUND_DIV_EXPR:
124365 + case EXACT_DIV_EXPR:
124366 + case RDIV_EXPR:
124367 + case TRUNC_MOD_EXPR:
124368 + case CEIL_MOD_EXPR:
124369 + case FLOOR_MOD_EXPR:
124370 + case ROUND_MOD_EXPR:
124371 + return true;
124372 + default:
124373 + return false;
124374 + }
124375 +}
124376 +
124377 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
124378 +{
124379 + const_tree orig_rhs1;
124380 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
124381 + gimple down_cast, up_cast;
124382 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
124383 +
124384 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
124385 + down_lhs = gimple_assign_lhs(down_cast);
124386 +
124387 + gsi = gsi_for_stmt(use_stmt);
124388 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
124389 + new_lhs = gimple_assign_lhs(up_cast);
124390 +
124391 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
124392 + if (operand_equal_p(orig_rhs1, rhs, 0))
124393 + gimple_assign_set_rhs1(use_stmt, new_lhs);
124394 + else
124395 + gimple_assign_set_rhs2(use_stmt, new_lhs);
124396 + update_stmt(use_stmt);
124397 +
124398 + pointer_set_insert(visited->my_stmts, up_cast);
124399 + pointer_set_insert(visited->my_stmts, down_cast);
124400 + pointer_set_insert(visited->skip_expr_casts, up_cast);
124401 + pointer_set_insert(visited->skip_expr_casts, down_cast);
124402 +}
124403 +
124404 +static tree get_proper_unsigned_half_type(const_tree node)
124405 +{
124406 + tree new_type, type;
124407 +
124408 + gcc_assert(is_size_overflow_type(node));
124409 +
124410 + type = TREE_TYPE(node);
124411 + switch (TYPE_MODE(type)) {
124412 + case HImode:
124413 + new_type = unsigned_intQI_type_node;
124414 + break;
124415 + case SImode:
124416 + new_type = unsigned_intHI_type_node;
124417 + break;
124418 + case DImode:
124419 + new_type = unsigned_intSI_type_node;
124420 + break;
124421 + case TImode:
124422 + new_type = unsigned_intDI_type_node;
124423 + break;
124424 + default:
124425 + gcc_unreachable();
124426 + }
124427 +
124428 + if (TYPE_QUALS(type) != 0)
124429 + return build_qualified_type(new_type, TYPE_QUALS(type));
124430 + return new_type;
124431 +}
124432 +
124433 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
124434 +{
124435 + tree type;
124436 +
124437 + if (rhs == NULL_TREE)
124438 + return;
124439 + if (!is_size_overflow_type(rhs))
124440 + return;
124441 +
124442 + type = get_proper_unsigned_half_type(rhs);
124443 + if (is_gimple_constant(rhs))
124444 + return;
124445 + create_up_and_down_cast(visited, stmt, type, rhs);
124446 +}
124447 +
124448 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
124449 +{
124450 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
124451 + return;
124452 + gcc_assert(is_size_overflow_type(rhs));
124453 + insert_cast_rhs(visited, stmt, rhs);
124454 +}
124455 +
124456 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
124457 +{
124458 + tree rhs1, rhs2;
124459 +
124460 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
124461 + rhs1 = gimple_assign_rhs1(stmt);
124462 + insert_cast(visited, stmt, rhs1);
124463 + }
124464 +
124465 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
124466 + rhs2 = gimple_assign_rhs2(stmt);
124467 + insert_cast(visited, stmt, rhs2);
124468 + }
124469 +}
124470 +
124471 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
124472 new file mode 100644
124473 index 0000000..e5b4e50
124474 --- /dev/null
124475 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
124476 @@ -0,0 +1,127 @@
124477 +#ifndef SIZE_OVERFLOW_H
124478 +#define SIZE_OVERFLOW_H
124479 +
124480 +#define CREATE_NEW_VAR NULL_TREE
124481 +#define CANNOT_FIND_ARG 32
124482 +#define MAX_PARAM 31
124483 +#define BEFORE_STMT true
124484 +#define AFTER_STMT false
124485 +
124486 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
124487 +#define YES_ASM_STR "# size_overflow MARK_YES "
124488 +#define OK_ASM_STR "# size_overflow "
124489 +
124490 +enum mark {
124491 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
124492 +};
124493 +
124494 +enum intentional_overflow_type {
124495 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
124496 +};
124497 +
124498 +struct visited {
124499 + struct pointer_set_t *stmts;
124500 + struct pointer_set_t *my_stmts;
124501 + struct pointer_set_t *skip_expr_casts;
124502 + struct pointer_set_t *no_cast_check;
124503 +};
124504 +
124505 +// size_overflow_plugin.c
124506 +extern tree report_size_overflow_decl;
124507 +extern tree size_overflow_type_HI;
124508 +extern tree size_overflow_type_SI;
124509 +extern tree size_overflow_type_DI;
124510 +extern tree size_overflow_type_TI;
124511 +
124512 +
124513 +// size_overflow_plugin_hash.c
124514 +struct size_overflow_hash {
124515 + const struct size_overflow_hash * const next;
124516 + const char * const name;
124517 + const unsigned int param;
124518 +};
124519 +
124520 +struct interesting_node {
124521 + struct interesting_node *next;
124522 + gimple first_stmt;
124523 + const_tree fndecl;
124524 + tree node;
124525 +#if BUILDING_GCC_VERSION <= 4007
124526 + VEC(tree, gc) *last_nodes;
124527 +#else
124528 + vec<tree, va_gc> *last_nodes;
124529 +#endif
124530 + unsigned int num;
124531 + enum mark intentional_attr_decl;
124532 + enum mark intentional_attr_cur_fndecl;
124533 + gimple intentional_mark_from_gimple;
124534 +};
124535 +
124536 +extern bool is_size_overflow_asm(const_gimple stmt);
124537 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
124538 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
124539 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
124540 +extern bool is_a_return_check(const_tree node);
124541 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
124542 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
124543 +
124544 +
124545 +// size_overflow_debug.c
124546 +extern struct opt_pass *make_dump_pass(void);
124547 +
124548 +
124549 +// intentional_overflow.c
124550 +extern enum mark get_intentional_attr_type(const_tree node);
124551 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
124552 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
124553 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
124554 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
124555 +extern bool is_turn_off_intentional_attr(const_tree decl);
124556 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
124557 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
124558 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
124559 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
124560 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
124561 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
124562 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
124563 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
124564 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
124565 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
124566 +
124567 +
124568 +// insert_size_overflow_check_ipa.c
124569 +extern unsigned int search_function(void);
124570 +extern unsigned int call_count;
124571 +extern struct opt_pass *make_insert_size_overflow_check(void);
124572 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
124573 +
124574 +
124575 +// insert_size_overflow_asm.c
124576 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
124577 +
124578 +
124579 +// misc.c
124580 +extern void set_current_function_decl(tree fndecl);
124581 +extern void unset_current_function_decl(void);
124582 +extern gimple get_def_stmt(const_tree node);
124583 +extern tree create_new_var(tree type);
124584 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
124585 +extern bool skip_types(const_tree var);
124586 +extern tree cast_a_tree(tree type, tree var);
124587 +extern bool is_size_overflow_type(const_tree var);
124588 +
124589 +
124590 +// insert_size_overflow_check_core.c
124591 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
124592 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
124593 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
124594 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
124595 +
124596 +
124597 +// remove_unnecessary_dup.c
124598 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
124599 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
124600 +extern bool skip_expr_on_double_type(const_gimple stmt);
124601 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
124602 +
124603 +#endif
124604 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
124605 new file mode 100644
124606 index 0000000..4378111
124607 --- /dev/null
124608 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
124609 @@ -0,0 +1,116 @@
124610 +/*
124611 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124612 + * Licensed under the GPL v2, or (at your option) v3
124613 + *
124614 + * Homepage:
124615 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124616 + *
124617 + * Documentation:
124618 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124619 + *
124620 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124621 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124622 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124623 + *
124624 + * Usage:
124625 + * $ make
124626 + * $ make run
124627 + */
124628 +
124629 +#include "gcc-common.h"
124630 +
124631 +static unsigned int dump_functions(void)
124632 +{
124633 + struct cgraph_node *node;
124634 +
124635 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
124636 + basic_block bb;
124637 +
124638 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
124639 + current_function_decl = NODE_DECL(node);
124640 +
124641 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
124642 +
124643 + FOR_ALL_BB_FN(bb, cfun) {
124644 + gimple_stmt_iterator si;
124645 +
124646 + fprintf(stderr, "<bb %u>:\n", bb->index);
124647 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
124648 + debug_gimple_stmt(gsi_stmt(si));
124649 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
124650 + debug_gimple_stmt(gsi_stmt(si));
124651 + fprintf(stderr, "\n");
124652 + }
124653 +
124654 + fprintf(stderr, "-------------------------------------------------------------------------\n");
124655 +
124656 + pop_cfun();
124657 + current_function_decl = NULL_TREE;
124658 + }
124659 +
124660 + fprintf(stderr, "###############################################################################\n");
124661 +
124662 + return 0;
124663 +}
124664 +
124665 +#if BUILDING_GCC_VERSION >= 4009
124666 +static const struct pass_data dump_pass_data = {
124667 +#else
124668 +static struct ipa_opt_pass_d dump_pass = {
124669 + .pass = {
124670 +#endif
124671 + .type = SIMPLE_IPA_PASS,
124672 + .name = "dump",
124673 +#if BUILDING_GCC_VERSION >= 4008
124674 + .optinfo_flags = OPTGROUP_NONE,
124675 +#endif
124676 +#if BUILDING_GCC_VERSION >= 4009
124677 + .has_gate = false,
124678 + .has_execute = true,
124679 +#else
124680 + .gate = NULL,
124681 + .execute = dump_functions,
124682 + .sub = NULL,
124683 + .next = NULL,
124684 + .static_pass_number = 0,
124685 +#endif
124686 + .tv_id = TV_NONE,
124687 + .properties_required = 0,
124688 + .properties_provided = 0,
124689 + .properties_destroyed = 0,
124690 + .todo_flags_start = 0,
124691 + .todo_flags_finish = 0,
124692 +#if BUILDING_GCC_VERSION < 4009
124693 + },
124694 + .generate_summary = NULL,
124695 + .write_summary = NULL,
124696 + .read_summary = NULL,
124697 +#if BUILDING_GCC_VERSION >= 4006
124698 + .write_optimization_summary = NULL,
124699 + .read_optimization_summary = NULL,
124700 +#endif
124701 + .stmt_fixup = NULL,
124702 + .function_transform_todo_flags_start = 0,
124703 + .function_transform = NULL,
124704 + .variable_transform = NULL,
124705 +#endif
124706 +};
124707 +
124708 +#if BUILDING_GCC_VERSION >= 4009
124709 +namespace {
124710 +class dump_pass : public ipa_opt_pass_d {
124711 +public:
124712 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
124713 + unsigned int execute() { return dump_functions(); }
124714 +};
124715 +}
124716 +#endif
124717 +
124718 +struct opt_pass *make_dump_pass(void)
124719 +{
124720 +#if BUILDING_GCC_VERSION >= 4009
124721 + return new dump_pass();
124722 +#else
124723 + return &dump_pass.pass;
124724 +#endif
124725 +}
124726 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
124727 new file mode 100644
124728 index 0000000..bf200e0
124729 --- /dev/null
124730 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
124731 @@ -0,0 +1,5671 @@
124732 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
124733 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
124734 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
124735 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
124736 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
124737 +padzero_55 padzero 1 55 &sel_read_policyvers_55
124738 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
124739 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
124740 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
124741 +load_msg_95 load_msg 2 95 NULL
124742 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
124743 +init_q_132 init_q 4 132 NULL
124744 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
124745 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
124746 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
124747 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
124748 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
124749 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
124750 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
124751 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
124752 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
124753 +br_port_info_size_268 br_port_info_size 0 268 NULL
124754 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
124755 +SYSC_connect_304 SYSC_connect 3 304 NULL
124756 +syslog_print_307 syslog_print 2 307 NULL
124757 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
124758 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
124759 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
124760 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
124761 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
124762 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
124763 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
124764 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
124765 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
124766 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
124767 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
124768 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
124769 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
124770 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
124771 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
124772 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
124773 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
124774 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
124775 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
124776 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
124777 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
124778 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
124779 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
124780 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
124781 +unlink_queued_645 unlink_queued 4 645 NULL
124782 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
124783 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
124784 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
124785 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
124786 +dvb_video_write_754 dvb_video_write 3 754 NULL
124787 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
124788 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
124789 +if_writecmd_815 if_writecmd 2 815 NULL
124790 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
124791 +error_state_read_859 error_state_read 6 859 NULL
124792 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
124793 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
124794 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
124795 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
124796 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
124797 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
124798 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
124799 +readreg_1017 readreg 0-1 1017 NULL
124800 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
124801 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
124802 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
124803 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
124804 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
124805 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
124806 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
124807 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
124808 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
124809 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
124810 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
124811 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
124812 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
124813 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
124814 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
124815 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
124816 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
124817 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
124818 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
124819 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
124820 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
124821 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
124822 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
124823 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
124824 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
124825 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
124826 +ffs_1322 ffs 0 1322 NULL
124827 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
124828 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
124829 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
124830 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
124831 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
124832 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
124833 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
124834 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
124835 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
124836 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
124837 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
124838 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
124839 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
124840 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
124841 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
124842 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
124843 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
124844 +fpregs_set_1497 fpregs_set 4 1497 NULL
124845 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
124846 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
124847 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
124848 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
124849 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
124850 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
124851 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
124852 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
124853 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
124854 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
124855 +rmap_add_1677 rmap_add 3 1677 NULL
124856 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
124857 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
124858 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
124859 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
124860 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
124861 +internal_create_group_1733 internal_create_group 0 1733 NULL
124862 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
124863 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
124864 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
124865 +cosa_write_1774 cosa_write 3 1774 NULL
124866 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
124867 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2 1815 NULL
124868 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
124869 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
124870 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
124871 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
124872 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
124873 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
124874 +bdev_erase_1933 bdev_erase 3 1933 NULL
124875 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
124876 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
124877 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
124878 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
124879 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
124880 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
124881 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
124882 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
124883 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
124884 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
124885 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
124886 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
124887 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
124888 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
124889 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
124890 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
124891 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
124892 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
124893 +audit_expand_2098 audit_expand 0 2098 NULL
124894 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
124895 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
124896 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
124897 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
124898 +enable_read_2117 enable_read 3 2117 NULL
124899 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
124900 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
124901 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
124902 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
124903 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
124904 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
124905 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
124906 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
124907 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
124908 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
124909 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
124910 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
124911 +do_update_counters_2259 do_update_counters 4 2259 NULL
124912 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
124913 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
124914 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
124915 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
124916 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
124917 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
124918 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
124919 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
124920 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
124921 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
124922 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
124923 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
124924 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
124925 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
124926 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
124927 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
124928 +raid1_size_2419 raid1_size 0-2 2419 NULL
124929 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
124930 +wiphy_new_2482 wiphy_new 2 2482 NULL
124931 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
124932 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
124933 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
124934 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
124935 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
124936 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
124937 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
124938 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
124939 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
124940 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
124941 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
124942 +slot_bytes_2609 slot_bytes 0 2609 NULL
124943 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
124944 +switch_status_2629 switch_status 5 2629 NULL
124945 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
124946 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
124947 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
124948 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
124949 +oti6858_write_2692 oti6858_write 4 2692 NULL
124950 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
124951 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
124952 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
124953 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
124954 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
124955 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
124956 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
124957 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
124958 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
124959 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
124960 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
124961 +sock_create_2838 sock_create 0 2838 NULL
124962 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
124963 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
124964 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
124965 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
124966 +nla_padlen_2883 nla_padlen 1 2883 NULL
124967 +cmm_write_2896 cmm_write 3 2896 NULL
124968 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
124969 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
124970 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
124971 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
124972 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
124973 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
124974 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
124975 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
124976 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
124977 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
124978 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
124979 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
124980 +depth_write_3021 depth_write 3 3021 NULL
124981 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
124982 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
124983 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
124984 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
124985 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
124986 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
124987 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
124988 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
124989 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
124990 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
124991 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
124992 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
124993 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
124994 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
124995 +rb_alloc_3102 rb_alloc 1 3102 NULL
124996 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
124997 +print_time_3132 print_time 0 3132 NULL
124998 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
124999 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
125000 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
125001 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
125002 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
125003 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
125004 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
125005 +alloc_context_3194 alloc_context 1 3194 NULL
125006 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
125007 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
125008 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
125009 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
125010 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
125011 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
125012 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
125013 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
125014 +key_key_read_3241 key_key_read 3 3241 NULL
125015 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
125016 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
125017 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
125018 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
125019 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
125020 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
125021 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
125022 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
125023 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
125024 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
125025 +scnprintf_3360 scnprintf 0-2 3360 NULL
125026 +sr_read_3366 sr_read 3 3366 NULL
125027 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
125028 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
125029 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
125030 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
125031 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
125032 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
125033 +softsynth_write_3455 softsynth_write 3 3455 NULL
125034 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
125035 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
125036 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
125037 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
125038 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
125039 +SyS_readv_3539 SyS_readv 3 3539 NULL
125040 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
125041 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
125042 +evtchn_read_3569 evtchn_read 3 3569 NULL
125043 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
125044 +vc_resize_3585 vc_resize 3-2 3585 NULL
125045 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
125046 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
125047 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
125048 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
125049 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
125050 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
125051 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
125052 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
125053 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
125054 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
125055 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
125056 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
125057 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
125058 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
125059 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
125060 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
125061 +get_fd_set_3866 get_fd_set 1 3866 NULL
125062 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
125063 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
125064 +nvram_write_3894 nvram_write 3 3894 NULL
125065 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
125066 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
125067 +vcs_write_3910 vcs_write 3 3910 NULL
125068 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
125069 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
125070 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
125071 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
125072 +do_add_counters_3992 do_add_counters 3 3992 NULL
125073 +userspace_status_4004 userspace_status 4 4004 NULL
125074 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
125075 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
125076 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
125077 +blk_end_request_4024 blk_end_request 3 4024 NULL
125078 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
125079 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
125080 +read_file_queues_4078 read_file_queues 3 4078 NULL
125081 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
125082 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
125083 +tm6000_read_4151 tm6000_read 3 4151 NULL
125084 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
125085 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
125086 +get_alua_req_4166 get_alua_req 3 4166 NULL
125087 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
125088 +read_file_bool_4180 read_file_bool 3 4180 NULL
125089 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
125090 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
125091 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
125092 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
125093 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
125094 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
125095 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
125096 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
125097 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
125098 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
125099 +count_strings_4315 count_strings 0 4315 NULL
125100 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
125101 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
125102 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
125103 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
125104 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
125105 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
125106 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
125107 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
125108 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
125109 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
125110 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
125111 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
125112 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
125113 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
125114 +set_link_security_4502 set_link_security 4 4502 NULL
125115 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
125116 +tty_register_device_4544 tty_register_device 2 4544 NULL
125117 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
125118 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
125119 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
125120 +bch_alloc_4593 bch_alloc 1 4593 NULL
125121 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
125122 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
125123 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
125124 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
125125 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
125126 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
125127 +kone_receive_4690 kone_receive 4 4690 NULL
125128 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
125129 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
125130 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
125131 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
125132 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
125133 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
125134 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
125135 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
125136 +create_subvol_4791 create_subvol 4 4791 NULL
125137 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
125138 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
125139 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
125140 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
125141 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
125142 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
125143 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
125144 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
125145 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
125146 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
125147 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
125148 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
125149 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
125150 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
125151 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
125152 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
125153 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
125154 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
125155 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
125156 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
125157 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
125158 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
125159 +sound_write_5102 sound_write 3 5102 NULL
125160 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
125161 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
125162 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
125163 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
125164 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
125165 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
125166 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
125167 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
125168 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
125169 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
125170 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
125171 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
125172 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
125173 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
125174 +cq_free_res_5355 cq_free_res 5 5355 NULL
125175 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
125176 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
125177 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
125178 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
125179 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
125180 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
125181 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
125182 +tty_write_5494 tty_write 3 5494 NULL
125183 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
125184 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
125185 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
125186 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
125187 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
125188 +le_readq_5557 le_readq 0 5557 NULL
125189 +inw_5558 inw 0 5558 NULL
125190 +bioset_create_5580 bioset_create 1 5580 NULL
125191 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
125192 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
125193 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
125194 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
125195 +get_arg_5694 get_arg 3 5694 NULL
125196 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
125197 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
125198 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
125199 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
125200 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
125201 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
125202 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
125203 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
125204 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
125205 +setup_req_5848 setup_req 3 5848 NULL
125206 +ria_page_count_5849 ria_page_count 0 5849 NULL
125207 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
125208 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
125209 +config_buf_5862 config_buf 0 5862 NULL
125210 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
125211 +port_show_regs_5904 port_show_regs 3 5904 NULL
125212 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
125213 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
125214 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
125215 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
125216 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
125217 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
125218 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
125219 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
125220 +SyS_semop_5980 SyS_semop 3 5980 NULL
125221 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
125222 +alloc_msg_6072 alloc_msg 1 6072 NULL
125223 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
125224 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
125225 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
125226 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
125227 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
125228 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
125229 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
125230 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
125231 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
125232 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
125233 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
125234 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
125235 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
125236 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
125237 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
125238 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
125239 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
125240 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
125241 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
125242 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
125243 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
125244 +serial_port_in_6291 serial_port_in 0 6291 NULL
125245 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
125246 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
125247 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
125248 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
125249 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
125250 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
125251 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
125252 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
125253 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
125254 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
125255 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
125256 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
125257 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
125258 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
125259 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
125260 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
125261 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
125262 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
125263 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
125264 +mei_read_6507 mei_read 3 6507 NULL
125265 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
125266 +wdm_read_6549 wdm_read 3 6549 NULL
125267 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
125268 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
125269 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
125270 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
125271 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
125272 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
125273 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
125274 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
125275 +mpeg_read_6708 mpeg_read 3 6708 NULL
125276 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
125277 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
125278 +video_proc_write_6724 video_proc_write 3 6724 NULL
125279 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
125280 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
125281 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
125282 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
125283 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
125284 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
125285 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
125286 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
125287 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
125288 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
125289 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
125290 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
125291 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
125292 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
125293 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
125294 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
125295 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
125296 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
125297 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
125298 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
125299 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
125300 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
125301 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
125302 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
125303 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
125304 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
125305 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
125306 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
125307 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
125308 +request_key_async_6990 request_key_async 4 6990 NULL
125309 +tpl_write_6998 tpl_write 3 6998 NULL
125310 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
125311 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
125312 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
125313 +wimax_msg_7030 wimax_msg 4 7030 NULL
125314 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
125315 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
125316 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
125317 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
125318 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
125319 +event_enable_read_7074 event_enable_read 3 7074 NULL
125320 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
125321 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
125322 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
125323 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
125324 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
125325 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
125326 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
125327 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
125328 +get_string_7302 get_string 0 7302 NULL
125329 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
125330 +mgmt_control_7349 mgmt_control 3 7349 NULL
125331 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
125332 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
125333 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
125334 +hweight_long_7388 hweight_long 0-1 7388 NULL
125335 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
125336 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
125337 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
125338 +readb_7401 readb 0 7401 NULL
125339 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
125340 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
125341 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
125342 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
125343 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
125344 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
125345 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
125346 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
125347 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
125348 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
125349 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
125350 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
125351 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
125352 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
125353 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
125354 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
125355 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
125356 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
125357 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
125358 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
125359 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
125360 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
125361 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
125362 +dev_write_7708 dev_write 3 7708 NULL
125363 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
125364 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
125365 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
125366 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
125367 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
125368 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
125369 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
125370 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
125371 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
125372 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
125373 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
125374 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
125375 +config_desc_7878 config_desc 0 7878 NULL
125376 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
125377 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
125378 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
125379 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
125380 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
125381 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
125382 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
125383 +vcs_read_8017 vcs_read 3 8017 NULL
125384 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
125385 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
125386 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
125387 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
125388 +venus_lookup_8121 venus_lookup 4 8121 NULL
125389 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
125390 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
125391 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
125392 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
125393 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
125394 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
125395 +play_iframe_8219 play_iframe 3 8219 NULL
125396 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
125397 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
125398 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
125399 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
125400 +init_cdev_8274 init_cdev 1 8274 NULL
125401 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
125402 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
125403 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
125404 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
125405 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
125406 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
125407 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
125408 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
125409 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
125410 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
125411 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
125412 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
125413 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
125414 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
125415 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
125416 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
125417 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
125418 +dev_config_8506 dev_config 3 8506 NULL
125419 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
125420 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
125421 +user_on_off_8552 user_on_off 2 8552 NULL
125422 +profile_remove_8556 profile_remove 3 8556 NULL
125423 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
125424 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
125425 +tower_write_8580 tower_write 3 8580 NULL
125426 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
125427 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
125428 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
125429 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
125430 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
125431 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
125432 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
125433 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
125434 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
125435 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
125436 +arcfb_write_8702 arcfb_write 3 8702 NULL
125437 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
125438 +init_header_8703 init_header 0 8703 &i_size_read_8703
125439 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
125440 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
125441 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
125442 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
125443 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
125444 +compound_order_8750 compound_order 0 8750 NULL
125445 +yurex_write_8761 yurex_write 3 8761 NULL
125446 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
125447 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
125448 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
125449 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
125450 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
125451 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
125452 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
125453 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
125454 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
125455 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
125456 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
125457 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
125458 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
125459 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
125460 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
125461 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
125462 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
125463 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
125464 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
125465 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
125466 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
125467 +write_file_ani_8918 write_file_ani 3 8918 NULL
125468 +layout_commit_8926 layout_commit 3 8926 NULL
125469 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
125470 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
125471 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
125472 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
125473 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
125474 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
125475 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
125476 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
125477 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
125478 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
125479 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
125480 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
125481 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
125482 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
125483 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
125484 +nla_put_9042 nla_put 3 9042 NULL
125485 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
125486 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
125487 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
125488 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
125489 +create_queues_9088 create_queues 2-3 9088 NULL
125490 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
125491 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
125492 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
125493 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
125494 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
125495 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
125496 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
125497 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
125498 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
125499 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
125500 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
125501 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
125502 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
125503 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
125504 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
125505 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
125506 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
125507 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
125508 +flakey_status_9274 flakey_status 5 9274 NULL
125509 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
125510 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
125511 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
125512 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
125513 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
125514 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
125515 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
125516 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
125517 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
125518 +read_9397 read 3 9397 NULL
125519 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
125520 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
125521 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
125522 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
125523 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
125524 +get_registers_9470 get_registers 4 9470 NULL nohasharray
125525 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
125526 +crypt_status_9492 crypt_status 5 9492 NULL
125527 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
125528 +lp_write_9511 lp_write 3 9511 NULL
125529 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
125530 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
125531 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
125532 +read_file_dma_9530 read_file_dma 3 9530 NULL
125533 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
125534 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
125535 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
125536 +fw_node_create_9559 fw_node_create 2 9559 NULL
125537 +kobj_map_9566 kobj_map 2-3 9566 NULL
125538 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
125539 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
125540 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
125541 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
125542 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
125543 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
125544 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
125545 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
125546 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
125547 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
125548 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
125549 +dns_query_9676 dns_query 3 9676 NULL
125550 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
125551 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
125552 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
125553 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
125554 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
125555 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
125556 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
125557 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
125558 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
125559 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
125560 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
125561 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
125562 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
125563 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
125564 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
125565 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
125566 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
125567 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
125568 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
125569 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
125570 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
125571 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
125572 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
125573 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
125574 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
125575 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
125576 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
125577 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
125578 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
125579 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
125580 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
125581 +read_file_misc_9948 read_file_misc 3 9948 NULL
125582 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
125583 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
125584 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
125585 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
125586 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
125587 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
125588 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
125589 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
125590 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
125591 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
125592 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
125593 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
125594 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
125595 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
125596 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
125597 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
125598 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
125599 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
125600 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
125601 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
125602 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
125603 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
125604 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
125605 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
125606 +read_emulate_10310 read_emulate 2-4 10310 NULL
125607 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
125608 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
125609 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
125610 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
125611 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
125612 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
125613 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
125614 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
125615 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
125616 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
125617 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
125618 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
125619 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
125620 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
125621 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
125622 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
125623 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
125624 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
125625 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
125626 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
125627 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
125628 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
125629 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
125630 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
125631 +otp_read_10594 otp_read 2-4-5 10594 NULL
125632 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
125633 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
125634 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
125635 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
125636 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
125637 +parport_write_10669 parport_write 0 10669 NULL
125638 +edge_write_10692 edge_write 4 10692 NULL
125639 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
125640 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
125641 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
125642 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
125643 +spi_sync_10731 spi_sync 0 10731 NULL
125644 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
125645 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
125646 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
125647 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
125648 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
125649 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
125650 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
125651 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
125652 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
125653 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
125654 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
125655 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
125656 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
125657 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
125658 +get_scq_10897 get_scq 2 10897 NULL
125659 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
125660 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
125661 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
125662 +kobject_add_10919 kobject_add 0 10919 NULL
125663 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
125664 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
125665 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
125666 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
125667 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
125668 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
125669 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
125670 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
125671 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
125672 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
125673 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
125674 +count_argc_11083 count_argc 0 11083 NULL
125675 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
125676 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
125677 +page_offset_11120 page_offset 0 11120 NULL
125678 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
125679 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
125680 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
125681 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
125682 +of_irq_count_11253 of_irq_count 0 11253 NULL
125683 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
125684 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
125685 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
125686 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
125687 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
125688 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
125689 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
125690 +construct_key_11329 construct_key 3 11329 NULL nohasharray
125691 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
125692 +next_segment_11330 next_segment 0-2-1 11330 NULL
125693 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
125694 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
125695 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
125696 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
125697 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
125698 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
125699 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
125700 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
125701 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
125702 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
125703 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
125704 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
125705 +str_to_user_11411 str_to_user 2 11411 NULL
125706 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
125707 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
125708 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
125709 +trace_options_read_11419 trace_options_read 3 11419 NULL
125710 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
125711 +bttv_read_11432 bttv_read 3 11432 NULL
125712 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
125713 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
125714 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
125715 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
125716 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
125717 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
125718 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
125719 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
125720 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
125721 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
125722 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
125723 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
125724 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
125725 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
125726 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
125727 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
125728 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
125729 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
125730 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
125731 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
125732 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
125733 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
125734 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
125735 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
125736 +split_11691 split 2 11691 NULL
125737 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
125738 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
125739 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
125740 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
125741 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
125742 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
125743 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
125744 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
125745 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
125746 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
125747 +umc_device_register_11824 umc_device_register 0 11824 NULL
125748 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
125749 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
125750 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
125751 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
125752 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
125753 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
125754 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
125755 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
125756 +ti_write_11916 ti_write 4 11916 NULL
125757 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
125758 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
125759 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
125760 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
125761 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
125762 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
125763 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
125764 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
125765 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
125766 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
125767 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
125768 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
125769 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
125770 +set_powered_12129 set_powered 4 12129 NULL
125771 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
125772 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
125773 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
125774 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
125775 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
125776 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
125777 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
125778 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
125779 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
125780 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
125781 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
125782 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
125783 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
125784 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
125785 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
125786 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
125787 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
125788 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
125789 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
125790 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
125791 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
125792 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
125793 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
125794 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
125795 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
125796 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
125797 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
125798 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
125799 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
125800 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
125801 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
125802 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
125803 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
125804 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
125805 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
125806 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
125807 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
125808 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
125809 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
125810 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
125811 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
125812 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
125813 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
125814 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
125815 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
125816 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
125817 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
125818 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
125819 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
125820 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
125821 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
125822 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
125823 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
125824 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
125825 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
125826 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
125827 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
125828 +ivtv_write_12721 ivtv_write 3 12721 NULL
125829 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
125830 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
125831 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
125832 +listxattr_12769 listxattr 3 12769 NULL
125833 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
125834 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
125835 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
125836 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
125837 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
125838 +spidev_sync_12842 spidev_sync 0 12842 NULL
125839 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
125840 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
125841 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
125842 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
125843 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
125844 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
125845 +bm_status_write_12964 bm_status_write 3 12964 NULL
125846 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
125847 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
125848 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
125849 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
125850 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
125851 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
125852 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
125853 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
125854 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
125855 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
125856 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
125857 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
125858 +blk_update_request_13146 blk_update_request 3 13146 NULL
125859 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
125860 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
125861 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
125862 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
125863 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
125864 +comedi_read_13199 comedi_read 3 13199 NULL
125865 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
125866 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
125867 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
125868 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
125869 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
125870 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
125871 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
125872 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
125873 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
125874 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
125875 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
125876 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
125877 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
125878 +sd_major_13294 sd_major 0-1 13294 NULL
125879 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
125880 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
125881 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
125882 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
125883 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
125884 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
125885 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
125886 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
125887 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
125888 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
125889 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
125890 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
125891 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
125892 +data_read_13494 data_read 3 13494 NULL nohasharray
125893 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
125894 +core_status_13515 core_status 4 13515 NULL
125895 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
125896 +bm_init_13529 bm_init 2 13529 NULL
125897 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
125898 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
125899 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
125900 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
125901 +cache_write_13589 cache_write 3 13589 NULL
125902 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
125903 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
125904 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
125905 +packet_snd_13634 packet_snd 3 13634 NULL
125906 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
125907 +cache_downcall_13666 cache_downcall 3 13666 NULL
125908 +usb_get_string_13693 usb_get_string 0 13693 NULL
125909 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
125910 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
125911 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
125912 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
125913 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
125914 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
125915 +random_read_13815 random_read 3 13815 NULL
125916 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
125917 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
125918 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
125919 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
125920 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
125921 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
125922 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
125923 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
125924 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
125925 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
125926 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
125927 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
125928 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
125929 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
125930 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
125931 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
125932 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
125933 +qcam_read_13977 qcam_read 3 13977 NULL
125934 +dsp_read_13980 dsp_read 2 13980 NULL
125935 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
125936 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
125937 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
125938 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
125939 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
125940 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
125941 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
125942 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
125943 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
125944 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
125945 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
125946 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
125947 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
125948 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
125949 +em_canid_change_14150 em_canid_change 3 14150 NULL
125950 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
125951 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
125952 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
125953 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
125954 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
125955 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
125956 +alloc_async_14208 alloc_async 1 14208 NULL
125957 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
125958 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
125959 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
125960 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
125961 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
125962 +rr_status_14293 rr_status 5 14293 NULL
125963 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
125964 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
125965 +oo_objects_14319 oo_objects 0 14319 NULL
125966 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
125967 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
125968 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
125969 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
125970 +lowpan_read_14369 lowpan_read 3 14369 NULL
125971 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
125972 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
125973 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
125974 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
125975 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
125976 +block_size_14443 block_size 0 14443 NULL
125977 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
125978 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
125979 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
125980 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
125981 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
125982 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
125983 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
125984 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
125985 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
125986 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
125987 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
125988 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
125989 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
125990 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
125991 +dbJoin_14644 dbJoin 0 14644 NULL
125992 +profile_replace_14652 profile_replace 3 14652 NULL
125993 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
125994 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
125995 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
125996 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
125997 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
125998 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
125999 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
126000 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
126001 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
126002 +vfd_write_14717 vfd_write 3 14717 NULL
126003 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
126004 +raid1_resize_14740 raid1_resize 2 14740 NULL
126005 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
126006 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
126007 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
126008 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
126009 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
126010 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
126011 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
126012 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
126013 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
126014 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
126015 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
126016 +lcd_write_14857 lcd_write 3 14857 NULL
126017 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
126018 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
126019 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
126020 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
126021 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
126022 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
126023 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
126024 +queue_cnt_14951 queue_cnt 0 14951 NULL
126025 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
126026 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
126027 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
126028 +setkey_14987 setkey 3 14987 NULL nohasharray
126029 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
126030 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
126031 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
126032 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
126033 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
126034 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
126035 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
126036 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
126037 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
126038 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
126039 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
126040 +start_port_15124 start_port 0 15124 NULL
126041 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
126042 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
126043 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
126044 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
126045 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
126046 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
126047 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
126048 +simple_strtol_15273 simple_strtol 0 15273 NULL
126049 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
126050 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
126051 +ioread16_15342 ioread16 0 15342 NULL
126052 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
126053 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
126054 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
126055 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
126056 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
126057 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
126058 +get_modalias_15406 get_modalias 2 15406 NULL
126059 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
126060 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
126061 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
126062 +memweight_15450 memweight 2 15450 NULL
126063 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
126064 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
126065 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
126066 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
126067 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
126068 +persistent_status_15574 persistent_status 4 15574 NULL
126069 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
126070 +vme_user_write_15587 vme_user_write 3 15587 NULL
126071 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
126072 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
126073 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
126074 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
126075 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
126076 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
126077 +fs_path_add_15648 fs_path_add 3 15648 NULL
126078 +xsd_read_15653 xsd_read 3 15653 NULL
126079 +unix_bind_15668 unix_bind 3 15668 NULL
126080 +dm_read_15674 dm_read 3 15674 NULL nohasharray
126081 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
126082 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
126083 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
126084 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
126085 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
126086 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
126087 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
126088 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
126089 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
126090 +table_size_15851 table_size 0-1-2 15851 NULL
126091 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
126092 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
126093 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
126094 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
126095 +power_read_15939 power_read 3 15939 NULL
126096 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
126097 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
126098 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
126099 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
126100 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
126101 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
126102 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
126103 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
126104 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
126105 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
126106 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
126107 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
126108 +fsm_init_16134 fsm_init 2 16134 NULL
126109 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
126110 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
126111 +mapping_level_16188 mapping_level 2-0 16188 NULL
126112 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
126113 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
126114 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
126115 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
126116 +create_table_16213 create_table 2 16213 NULL
126117 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
126118 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
126119 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
126120 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
126121 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
126122 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
126123 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
126124 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
126125 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
126126 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
126127 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
126128 +account_16283 account 0-4-2 16283 NULL nohasharray
126129 +mirror_status_16283 mirror_status 5 16283 &account_16283
126130 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
126131 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
126132 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
126133 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
126134 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
126135 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
126136 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
126137 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
126138 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
126139 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
126140 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
126141 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
126142 +cmdline_store_16442 cmdline_store 4 16442 NULL
126143 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
126144 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
126145 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
126146 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
126147 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
126148 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
126149 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
126150 +raid10_resize_16537 raid10_resize 2 16537 NULL
126151 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
126152 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
126153 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
126154 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
126155 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
126156 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
126157 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
126158 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
126159 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
126160 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
126161 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
126162 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
126163 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
126164 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
126165 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
126166 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
126167 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
126168 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
126169 +st_write_16874 st_write 3 16874 NULL
126170 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
126171 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
126172 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
126173 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
126174 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
126175 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
126176 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
126177 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
126178 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
126179 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
126180 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
126181 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
126182 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
126183 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
126184 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
126185 +entry_length_17093 entry_length 0 17093 NULL
126186 +write_mem_17114 write_mem 3 17114 NULL
126187 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
126188 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
126189 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
126190 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
126191 +sep_read_17161 sep_read 3 17161 NULL
126192 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
126193 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
126194 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
126195 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
126196 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
126197 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
126198 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
126199 +sync_request_17208 sync_request 2 17208 NULL
126200 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
126201 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
126202 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
126203 +alloc_ep_17269 alloc_ep 1 17269 NULL
126204 +pg_read_17276 pg_read 3 17276 NULL
126205 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
126206 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
126207 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
126208 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
126209 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
126210 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
126211 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
126212 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
126213 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
126214 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
126215 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
126216 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
126217 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
126218 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
126219 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
126220 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
126221 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
126222 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
126223 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
126224 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
126225 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
126226 +qp_free_res_17541 qp_free_res 5 17541 NULL
126227 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
126228 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
126229 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
126230 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
126231 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
126232 +osst_execute_17607 osst_execute 7-6 17607 NULL
126233 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
126234 +dma_map_page_17628 dma_map_page 0 17628 NULL
126235 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
126236 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
126237 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
126238 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
126239 +venus_rename_17707 venus_rename 4-5 17707 NULL
126240 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
126241 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
126242 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
126243 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
126244 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
126245 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
126246 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
126247 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
126248 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
126249 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
126250 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
126251 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
126252 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
126253 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
126254 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
126255 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
126256 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
126257 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
126258 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
126259 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
126260 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
126261 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
126262 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
126263 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
126264 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
126265 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
126266 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
126267 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
126268 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
126269 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
126270 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
126271 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
126272 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
126273 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
126274 +fpregs_get_18066 fpregs_get 4 18066 NULL
126275 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
126276 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
126277 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
126278 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
126279 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
126280 +svc_getnl_18120 svc_getnl 0 18120 NULL
126281 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
126282 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
126283 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
126284 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
126285 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
126286 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
126287 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
126288 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
126289 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
126290 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
126291 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
126292 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
126293 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
126294 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
126295 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
126296 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
126297 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
126298 +um_idi_write_18293 um_idi_write 3 18293 NULL
126299 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
126300 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
126301 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
126302 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
126303 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
126304 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
126305 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
126306 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
126307 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
126308 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
126309 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
126310 +ep_io_18367 ep_io 0 18367 NULL
126311 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
126312 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
126313 +ci_role_write_18388 ci_role_write 3 18388 NULL
126314 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
126315 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
126316 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
126317 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
126318 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
126319 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
126320 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
126321 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL
126322 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
126323 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
126324 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
126325 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
126326 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
126327 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
126328 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
126329 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
126330 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
126331 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
126332 +debug_output_18575 debug_output 3 18575 NULL
126333 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
126334 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
126335 +from_buffer_18625 from_buffer 3 18625 NULL
126336 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
126337 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
126338 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
126339 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
126340 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
126341 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
126342 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
126343 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
126344 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
126345 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
126346 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
126347 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
126348 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
126349 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
126350 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
126351 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
126352 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
126353 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
126354 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
126355 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
126356 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
126357 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
126358 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
126359 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
126360 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
126361 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
126362 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
126363 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
126364 +huge_page_size_19008 huge_page_size 0 19008 NULL
126365 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
126366 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
126367 +revalidate_19043 revalidate 2 19043 NULL
126368 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
126369 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
126370 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
126371 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
126372 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
126373 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
126374 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
126375 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
126376 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
126377 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
126378 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
126379 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
126380 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
126381 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
126382 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
126383 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
126384 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
126385 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
126386 +ucma_query_19260 ucma_query 4 19260 NULL
126387 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
126388 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
126389 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
126390 +qc_capture_19298 qc_capture 3 19298 NULL
126391 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
126392 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
126393 +debug_read_19322 debug_read 3 19322 NULL
126394 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
126395 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
126396 +closure_sub_19359 closure_sub 2 19359 NULL
126397 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
126398 +read_zero_19366 read_zero 3 19366 NULL
126399 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
126400 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
126401 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
126402 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
126403 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
126404 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
126405 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
126406 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
126407 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
126408 +sky2_read16_19475 sky2_read16 0 19475 NULL
126409 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
126410 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
126411 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
126412 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
126413 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
126414 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
126415 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
126416 +nfsd_read_19568 nfsd_read 5 19568 NULL
126417 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
126418 +bm_status_read_19583 bm_status_read 3 19583 NULL
126419 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
126420 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
126421 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
126422 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
126423 +read_reg_19723 read_reg 0 19723 NULL
126424 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
126425 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
126426 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
126427 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
126428 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
126429 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
126430 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
126431 +readhscx_19769 readhscx 0 19769 NULL
126432 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
126433 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
126434 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
126435 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
126436 +__nla_put_19857 __nla_put 3 19857 NULL
126437 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
126438 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
126439 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
126440 +mangle_name_19923 mangle_name 0 19923 NULL
126441 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
126442 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
126443 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
126444 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
126445 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
126446 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
126447 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
126448 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
126449 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
126450 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
126451 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
126452 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
126453 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
126454 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
126455 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
126456 +target_message_20072 target_message 2 20072 NULL
126457 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
126458 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
126459 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
126460 +team_options_register_20091 team_options_register 3 20091 NULL
126461 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
126462 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
126463 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
126464 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
126465 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
126466 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
126467 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
126468 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
126469 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
126470 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
126471 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
126472 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
126473 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
126474 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
126475 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
126476 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
126477 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
126478 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
126479 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
126480 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
126481 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
126482 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
126483 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
126484 +read_buf_20469 read_buf 2 20469 NULL
126485 +bio_trim_20472 bio_trim 2 20472 NULL
126486 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
126487 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
126488 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
126489 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
126490 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
126491 +venus_create_20555 venus_create 4 20555 NULL
126492 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
126493 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
126494 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
126495 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
126496 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
126497 +lirc_write_20604 lirc_write 3 20604 NULL
126498 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
126499 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
126500 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
126501 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
126502 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
126503 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
126504 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
126505 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
126506 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
126507 +cpumask_size_20683 cpumask_size 0 20683 NULL
126508 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
126509 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
126510 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
126511 +__maestro_read_20700 __maestro_read 0 20700 NULL
126512 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
126513 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
126514 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
126515 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
126516 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
126517 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
126518 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
126519 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
126520 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
126521 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
126522 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
126523 +lowpan_write_20800 lowpan_write 3 20800 NULL
126524 +strndup_user_20819 strndup_user 2 20819 NULL
126525 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
126526 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
126527 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
126528 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
126529 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
126530 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
126531 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
126532 +srq_free_res_20868 srq_free_res 5 20868 NULL
126533 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
126534 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
126535 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
126536 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
126537 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
126538 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
126539 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
126540 +htable_bits_20933 htable_bits 0 20933 NULL
126541 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
126542 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
126543 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
126544 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
126545 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
126546 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
126547 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
126548 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
126549 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
126550 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
126551 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
126552 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
126553 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
126554 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
126555 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
126556 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
126557 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
126558 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
126559 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
126560 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
126561 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
126562 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
126563 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
126564 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
126565 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
126566 +input_ff_create_21240 input_ff_create 2 21240 NULL
126567 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
126568 +fru_length_21257 fru_length 0 21257 NULL
126569 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
126570 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
126571 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
126572 +add_res_range_21310 add_res_range 4 21310 NULL
126573 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
126574 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
126575 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
126576 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
126577 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
126578 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
126579 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
126580 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
126581 +insert_ptr_21386 insert_ptr 6 21386 NULL
126582 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
126583 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
126584 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
126585 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
126586 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
126587 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
126588 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
126589 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
126590 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
126591 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
126592 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
126593 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
126594 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
126595 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
126596 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
126597 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
126598 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
126599 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
126600 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
126601 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
126602 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
126603 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
126604 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
126605 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
126606 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
126607 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
126608 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
126609 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
126610 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
126611 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
126612 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
126613 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
126614 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
126615 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
126616 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
126617 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
126618 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
126619 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
126620 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
126621 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
126622 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
126623 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
126624 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
126625 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
126626 +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
126627 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
126628 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
126629 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
126630 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
126631 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
126632 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
126633 +mem_rw_22085 mem_rw 3 22085 NULL
126634 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
126635 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
126636 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
126637 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
126638 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
126639 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
126640 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
126641 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
126642 +mem_write_22232 mem_write 3 22232 NULL
126643 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
126644 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
126645 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
126646 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
126647 +add_res_tree_22263 add_res_tree 7 22263 NULL
126648 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
126649 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
126650 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
126651 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
126652 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
126653 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
126654 +atomic_read_22342 atomic_read 0 22342 NULL
126655 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
126656 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
126657 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
126658 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
126659 +zoran_write_22404 zoran_write 3 22404 NULL
126660 +queue_reply_22416 queue_reply 3 22416 NULL
126661 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
126662 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
126663 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
126664 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
126665 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
126666 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
126667 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
126668 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
126669 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
126670 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
126671 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
126672 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
126673 +snapshot_read_22601 snapshot_read 3 22601 NULL
126674 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
126675 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
126676 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
126677 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
126678 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
126679 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
126680 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
126681 +reg_umr_22686 reg_umr 5 22686 NULL
126682 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
126683 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
126684 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
126685 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
126686 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
126687 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
126688 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
126689 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
126690 +print_frame_22769 print_frame 0 22769 NULL
126691 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
126692 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
126693 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
126694 +create_attr_set_22861 create_attr_set 1 22861 NULL
126695 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
126696 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
126697 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
126698 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
126699 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
126700 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
126701 +__set_xattr_22923 __set_xattr 0 22923 NULL
126702 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
126703 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
126704 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
126705 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
126706 +vme_get_size_22964 vme_get_size 0 22964 NULL
126707 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
126708 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
126709 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
126710 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
126711 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
126712 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
126713 +st_status_23032 st_status 5 23032 NULL
126714 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
126715 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
126716 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
126717 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
126718 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
126719 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
126720 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
126721 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
126722 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
126723 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
126724 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
126725 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
126726 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
126727 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
126728 +__clear_user_23118 __clear_user 0-2 23118 NULL
126729 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
126730 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
126731 +read_file_ani_23161 read_file_ani 3 23161 NULL
126732 +usblp_write_23178 usblp_write 3 23178 NULL
126733 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
126734 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
126735 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
126736 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
126737 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
126738 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
126739 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
126740 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
126741 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
126742 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
126743 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
126744 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
126745 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
126746 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
126747 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
126748 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
126749 +page_readlink_23346 page_readlink 3 23346 NULL
126750 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
126751 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
126752 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
126753 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
126754 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
126755 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
126756 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
126757 +linear_conf_23485 linear_conf 2 23485 NULL
126758 +event_filter_read_23494 event_filter_read 3 23494 NULL
126759 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
126760 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
126761 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
126762 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
126763 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
126764 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
126765 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
126766 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
126767 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
126768 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
126769 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
126770 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
126771 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
126772 +sInW_23663 sInW 0 23663 NULL
126773 +SyS_connect_23669 SyS_connect 3 23669 NULL
126774 +cx18_read_23699 cx18_read 3 23699 NULL
126775 +at_get_23708 at_get 0 23708 NULL
126776 +get_conn_info_23723 get_conn_info 4 23723 NULL
126777 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
126778 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
126779 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
126780 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
126781 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
126782 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
126783 +map_write_23795 map_write 3 23795 NULL
126784 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
126785 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
126786 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
126787 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
126788 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
126789 +p54_init_common_23850 p54_init_common 1 23850 NULL
126790 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
126791 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
126792 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
126793 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
126794 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
126795 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
126796 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
126797 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
126798 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
126799 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
126800 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
126801 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
126802 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
126803 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
126804 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
126805 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
126806 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
126807 +give_pages_24021 give_pages 3 24021 NULL
126808 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
126809 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
126810 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
126811 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
126812 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
126813 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
126814 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
126815 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
126816 +lov_brw_24122 lov_brw 4 24122 NULL
126817 +mpu401_read_24126 mpu401_read 3 24126 NULL
126818 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
126819 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
126820 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
126821 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
126822 +adu_read_24177 adu_read 3 24177 NULL
126823 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
126824 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
126825 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
126826 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
126827 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
126828 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
126829 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
126830 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
126831 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
126832 +thin_status_24278 thin_status 5 24278 NULL
126833 +msg_size_24288 msg_size 0 24288 NULL
126834 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
126835 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
126836 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
126837 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
126838 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
126839 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
126840 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
126841 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
126842 +igetword_24373 igetword 0 24373 NULL
126843 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
126844 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
126845 +getxattr_24398 getxattr 4 24398 NULL nohasharray
126846 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
126847 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
126848 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
126849 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
126850 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
126851 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
126852 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
126853 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
126854 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
126855 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
126856 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
126857 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
126858 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
126859 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
126860 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
126861 +pd_video_read_24510 pd_video_read 3 24510 NULL
126862 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
126863 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
126864 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
126865 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
126866 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
126867 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
126868 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
126869 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
126870 +SyS_poll_24620 SyS_poll 2 24620 NULL
126871 +context_alloc_24645 context_alloc 3 24645 NULL
126872 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
126873 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
126874 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
126875 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
126876 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
126877 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
126878 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
126879 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
126880 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
126881 +cache_read_24790 cache_read 3 24790 NULL
126882 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
126883 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
126884 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
126885 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
126886 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
126887 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
126888 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
126889 +queues_read_24877 queues_read 3 24877 NULL
126890 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
126891 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
126892 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
126893 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
126894 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
126895 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
126896 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
126897 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
126898 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
126899 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
126900 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
126901 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
126902 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
126903 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
126904 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
126905 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
126906 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
126907 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
126908 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
126909 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
126910 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
126911 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
126912 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
126913 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
126914 +stripe_status_25259 stripe_status 5 25259 NULL
126915 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
126916 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
126917 +vfs_writev_25278 vfs_writev 3 25278 NULL
126918 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
126919 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
126920 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
126921 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
126922 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
126923 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
126924 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
126925 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
126926 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
126927 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
126928 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
126929 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
126930 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
126931 +sb_permission_25523 sb_permission 0 25523 NULL
126932 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
126933 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
126934 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
126935 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
126936 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
126937 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
126938 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
126939 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
126940 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
126941 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
126942 +__direct_map_25647 __direct_map 6-5 25647 NULL
126943 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
126944 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
126945 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
126946 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
126947 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
126948 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
126949 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
126950 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
126951 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
126952 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
126953 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
126954 +sg_read_25799 sg_read 3 25799 NULL
126955 +system_enable_read_25815 system_enable_read 3 25815 NULL
126956 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
126957 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
126958 +parport_read_25855 parport_read 0 25855 NULL
126959 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
126960 +key_attr_size_25865 key_attr_size 0 25865 NULL
126961 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
126962 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
126963 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
126964 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
126965 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
126966 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
126967 +rcname_read_25919 rcname_read 3 25919 NULL
126968 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
126969 +key_flags_read_25931 key_flags_read 3 25931 NULL
126970 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
126971 +flush_25957 flush 2 25957 NULL
126972 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
126973 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
126974 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
126975 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
126976 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
126977 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
126978 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
126979 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
126980 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
126981 +read_sb_page_26119 read_sb_page 5 26119 NULL
126982 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
126983 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
126984 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
126985 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
126986 +disk_devt_26180 disk_devt 0 26180 NULL
126987 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
126988 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
126989 +mce_write_26201 mce_write 3 26201 NULL
126990 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
126991 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
126992 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
126993 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
126994 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
126995 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
126996 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
126997 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
126998 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
126999 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
127000 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
127001 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
127002 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
127003 +ntty_write_26404 ntty_write 3 26404 NULL
127004 +firmware_store_26408 firmware_store 4 26408 NULL
127005 +pagemap_read_26441 pagemap_read 3 26441 NULL
127006 +tower_read_26461 tower_read 3 26461 NULL nohasharray
127007 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
127008 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
127009 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
127010 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
127011 +read_vmcore_26501 read_vmcore 3 26501 NULL
127012 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
127013 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
127014 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
127015 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
127016 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
127017 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
127018 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
127019 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
127020 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
127021 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
127022 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
127023 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
127024 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
127025 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
127026 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
127027 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
127028 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
127029 +bos_desc_26752 bos_desc 0 26752 NULL
127030 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
127031 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
127032 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
127033 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
127034 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
127035 +smk_write_load_26829 smk_write_load 3 26829 NULL
127036 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
127037 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
127038 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
127039 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
127040 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
127041 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
127042 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
127043 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
127044 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
127045 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
127046 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
127047 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
127048 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
127049 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
127050 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
127051 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
127052 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
127053 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
127054 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
127055 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
127056 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
127057 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
127058 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
127059 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
127060 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
127061 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
127062 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
127063 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
127064 +pms_capture_27142 pms_capture 4 27142 NULL
127065 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
127066 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
127067 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
127068 +write_kmem_27225 write_kmem 3 27225 NULL
127069 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
127070 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
127071 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
127072 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
127073 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
127074 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
127075 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
127076 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
127077 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
127078 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
127079 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
127080 +seq_read_27411 seq_read 3 27411 NULL
127081 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
127082 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
127083 +cypress_write_27423 cypress_write 4 27423 NULL
127084 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
127085 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
127086 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
127087 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
127088 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
127089 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
127090 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
127091 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
127092 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
127093 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
127094 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
127095 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
127096 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
127097 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
127098 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
127099 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
127100 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
127101 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
127102 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
127103 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
127104 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
127105 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
127106 +evm_write_key_27715 evm_write_key 3 27715 NULL
127107 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
127108 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
127109 +load_scode_27738 load_scode 2 27738 NULL
127110 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
127111 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
127112 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
127113 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
127114 +SyS_readv_27804 SyS_readv 3 27804 NULL
127115 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
127116 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
127117 +init_header_complete_27833 init_header_complete 0 27833 NULL
127118 +read_profile_27859 read_profile 3 27859 NULL
127119 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
127120 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
127121 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
127122 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
127123 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
127124 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
127125 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
127126 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
127127 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
127128 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
127129 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
127130 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
127131 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
127132 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
127133 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
127134 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
127135 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
127136 +pool_status_28055 pool_status 5 28055 NULL
127137 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
127138 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
127139 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
127140 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
127141 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
127142 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
127143 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
127144 +video_read_28148 video_read 3 28148 NULL
127145 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
127146 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
127147 +vread_28173 vread 0-3 28173 NULL
127148 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
127149 +counter_free_res_28187 counter_free_res 5 28187 NULL
127150 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
127151 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
127152 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
127153 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
127154 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
127155 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
127156 +usemap_size_28281 usemap_size 0 28281 NULL
127157 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
127158 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
127159 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
127160 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
127161 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
127162 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
127163 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
127164 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
127165 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
127166 +snapshot_write_28351 snapshot_write 3 28351 NULL
127167 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
127168 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
127169 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
127170 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
127171 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
127172 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
127173 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
127174 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
127175 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
127176 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
127177 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
127178 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
127179 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
127180 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
127181 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
127182 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
127183 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
127184 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
127185 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
127186 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
127187 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
127188 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
127189 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
127190 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
127191 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
127192 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
127193 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
127194 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
127195 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
127196 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
127197 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
127198 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
127199 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
127200 +spi_execute_28736 spi_execute 5 28736 NULL
127201 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
127202 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
127203 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
127204 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
127205 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
127206 +sel_write_member_28800 sel_write_member 3 28800 NULL
127207 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
127208 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
127209 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
127210 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
127211 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
127212 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
127213 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
127214 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
127215 +push_rx_28939 push_rx 3 28939 NULL
127216 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
127217 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
127218 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
127219 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
127220 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
127221 +bin_uuid_28999 bin_uuid 3 28999 NULL
127222 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
127223 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
127224 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
127225 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
127226 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
127227 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
127228 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
127229 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
127230 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
127231 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
127232 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
127233 +snprintf_29125 snprintf 0 29125 NULL
127234 +iov_shorten_29130 iov_shorten 0 29130 NULL
127235 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
127236 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
127237 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
127238 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
127239 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
127240 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
127241 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
127242 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
127243 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
127244 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
127245 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
127246 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
127247 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
127248 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
127249 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
127250 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
127251 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
127252 +tun_put_user_29337 tun_put_user 5 29337 NULL
127253 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
127254 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
127255 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
127256 +mempool_create_29437 mempool_create 1 29437 NULL
127257 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
127258 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
127259 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
127260 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
127261 +do_register_entry_29478 do_register_entry 4 29478 NULL
127262 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
127263 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
127264 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
127265 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
127266 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
127267 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
127268 +ftrace_write_29551 ftrace_write 3 29551 NULL
127269 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
127270 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
127271 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
127272 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
127273 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
127274 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
127275 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
127276 +slots_per_page_29601 slots_per_page 0 29601 NULL
127277 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
127278 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
127279 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
127280 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
127281 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
127282 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
127283 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
127284 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
127285 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
127286 +probes_write_29711 probes_write 3 29711 NULL
127287 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
127288 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
127289 +std_nic_write_29752 std_nic_write 3 29752 NULL
127290 +static_key_count_29771 static_key_count 0 29771 NULL
127291 +dbAlloc_29794 dbAlloc 0 29794 NULL
127292 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
127293 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
127294 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
127295 +count_partial_29850 count_partial 0 29850 NULL
127296 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
127297 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
127298 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
127299 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
127300 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
127301 +write_file_queue_29922 write_file_queue 3 29922 NULL
127302 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
127303 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
127304 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
127305 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
127306 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
127307 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
127308 +drp_wmove_30043 drp_wmove 4 30043 NULL
127309 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
127310 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
127311 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
127312 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
127313 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
127314 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
127315 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
127316 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
127317 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
127318 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
127319 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
127320 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
127321 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
127322 +SyS_semop_30227 SyS_semop 3 30227 NULL
127323 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
127324 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
127325 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
127326 +compat_readv_30273 compat_readv 3 30273 NULL
127327 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
127328 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
127329 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
127330 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
127331 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
127332 +resource_from_user_30341 resource_from_user 3 30341 NULL
127333 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
127334 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
127335 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
127336 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
127337 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
127338 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
127339 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
127340 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
127341 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
127342 +enable_write_30456 enable_write 3 30456 NULL
127343 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
127344 +urandom_read_30462 urandom_read 3 30462 NULL
127345 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
127346 +adu_write_30487 adu_write 3 30487 NULL
127347 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
127348 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
127349 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
127350 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
127351 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
127352 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
127353 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
127354 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
127355 +set_le_30581 set_le 4 30581 NULL
127356 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
127357 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
127358 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
127359 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
127360 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
127361 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
127362 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
127363 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
127364 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
127365 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
127366 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
127367 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
127368 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
127369 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
127370 +snapshot_status_30744 snapshot_status 5 30744 NULL
127371 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
127372 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
127373 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
127374 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
127375 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
127376 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
127377 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
127378 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
127379 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
127380 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
127381 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
127382 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
127383 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
127384 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
127385 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
127386 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
127387 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
127388 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
127389 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
127390 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
127391 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
127392 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
127393 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
127394 +depth_read_31112 depth_read 3 31112 NULL
127395 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
127396 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
127397 +size_inside_page_31141 size_inside_page 0 31141 NULL
127398 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
127399 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
127400 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
127401 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
127402 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
127403 +__read_reg_31216 __read_reg 0 31216 NULL
127404 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
127405 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
127406 +cyy_readb_31240 cyy_readb 0 31240 NULL
127407 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
127408 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
127409 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
127410 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
127411 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
127412 +command_file_write_31318 command_file_write 3 31318 NULL
127413 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
127414 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
127415 +outlen_write_31358 outlen_write 3 31358 NULL
127416 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
127417 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
127418 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
127419 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
127420 +inb_31388 inb 0 31388 NULL
127421 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
127422 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
127423 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
127424 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
127425 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
127426 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
127427 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
127428 +alg_setkey_31485 alg_setkey 3 31485 NULL
127429 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
127430 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
127431 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
127432 +hidraw_write_31536 hidraw_write 3 31536 NULL
127433 +usbvision_read_31555 usbvision_read 3 31555 NULL
127434 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
127435 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
127436 +osst_write_31581 osst_write 3 31581 NULL
127437 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
127438 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
127439 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
127440 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
127441 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
127442 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
127443 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
127444 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
127445 +__lgread_31668 __lgread 4 31668 NULL
127446 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
127447 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
127448 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
127449 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
127450 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
127451 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
127452 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
127453 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
127454 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
127455 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
127456 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
127457 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
127458 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
127459 +get_count_order_31800 get_count_order 0 31800 NULL
127460 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
127461 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
127462 +data_write_31805 data_write 3 31805 NULL
127463 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
127464 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
127465 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
127466 +clone_bio_31854 clone_bio 4-3 31854 NULL
127467 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
127468 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
127469 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
127470 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
127471 +xattr_permission_31907 xattr_permission 0 31907 NULL
127472 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
127473 +new_dir_31919 new_dir 3 31919 NULL
127474 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
127475 +era_status_31934 era_status 5 31934 NULL
127476 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
127477 +read_mem_31942 read_mem 3 31942 NULL
127478 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
127479 +vb2_write_31948 vb2_write 3 31948 NULL
127480 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
127481 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
127482 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
127483 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
127484 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
127485 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
127486 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
127487 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
127488 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
127489 +calc_hmac_32010 calc_hmac 3 32010 NULL
127490 +aead_len_32021 aead_len 0 32021 NULL
127491 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
127492 +stk_read_32038 stk_read 3 32038 NULL
127493 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
127494 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
127495 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
127496 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
127497 +bio_alloc_32095 bio_alloc 2 32095 NULL
127498 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
127499 +disk_status_32120 disk_status 4 32120 NULL
127500 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
127501 +venus_link_32165 venus_link 5 32165 NULL
127502 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
127503 +do_writepages_32173 do_writepages 0 32173 NULL
127504 +del_ptr_32197 del_ptr 4 32197 NULL
127505 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
127506 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
127507 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
127508 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
127509 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
127510 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
127511 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
127512 +SyS_select_32319 SyS_select 1 32319 NULL
127513 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
127514 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
127515 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
127516 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
127517 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
127518 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
127519 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
127520 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
127521 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
127522 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
127523 +cache_status_32462 cache_status 5 32462 NULL
127524 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
127525 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
127526 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
127527 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
127528 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
127529 +disconnect_32521 disconnect 4 32521 NULL
127530 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
127531 +ilo_read_32531 ilo_read 3 32531 NULL
127532 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
127533 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
127534 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
127535 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
127536 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
127537 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
127538 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
127539 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
127540 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
127541 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
127542 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
127543 +kvmalloc_32646 kvmalloc 1 32646 NULL
127544 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
127545 +generic_readlink_32654 generic_readlink 3 32654 NULL
127546 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
127547 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
127548 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
127549 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
127550 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
127551 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
127552 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
127553 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
127554 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
127555 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
127556 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
127557 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
127558 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
127559 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
127560 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
127561 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
127562 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
127563 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
127564 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
127565 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
127566 +compat_filldir_32999 compat_filldir 3 32999 NULL
127567 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
127568 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
127569 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
127570 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
127571 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
127572 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
127573 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
127574 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
127575 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
127576 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
127577 +alloc_tio_33077 alloc_tio 3 33077 NULL
127578 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
127579 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
127580 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
127581 +SyS_poll_33152 SyS_poll 2 33152 NULL
127582 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
127583 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
127584 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
127585 +pp_read_33210 pp_read 3 33210 NULL
127586 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
127587 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
127588 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
127589 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
127590 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
127591 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
127592 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
127593 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
127594 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
127595 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
127596 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
127597 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
127598 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
127599 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
127600 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
127601 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
127602 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
127603 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
127604 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
127605 +message_stats_list_33440 message_stats_list 5 33440 NULL
127606 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
127607 +create_entry_33479 create_entry 2 33479 NULL
127608 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
127609 +res_counter_read_33499 res_counter_read 4 33499 NULL
127610 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
127611 +fb_read_33506 fb_read 3 33506 NULL
127612 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
127613 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
127614 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
127615 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
127616 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
127617 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
127618 +count_subheaders_33591 count_subheaders 0 33591 NULL
127619 +scsi_execute_33596 scsi_execute 5 33596 NULL
127620 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
127621 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
127622 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
127623 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
127624 +stride_page_count_33641 stride_page_count 2 33641 NULL
127625 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
127626 +inw_p_33668 inw_p 0 33668 NULL
127627 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
127628 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
127629 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
127630 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
127631 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
127632 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
127633 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
127634 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
127635 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
127636 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
127637 +hashtab_create_33769 hashtab_create 3 33769 NULL
127638 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
127639 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
127640 +filter_write_33819 filter_write 3 33819 NULL
127641 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
127642 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
127643 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
127644 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
127645 +get_user_pages_33908 get_user_pages 0 33908 NULL
127646 +sg_nents_33909 sg_nents 0 33909 NULL
127647 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
127648 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
127649 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
127650 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
127651 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
127652 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
127653 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
127654 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
127655 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
127656 +ppp_write_34034 ppp_write 3 34034 NULL
127657 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
127658 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
127659 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
127660 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
127661 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
127662 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
127663 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
127664 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
127665 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
127666 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
127667 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
127668 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
127669 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
127670 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
127671 +device_private_init_34279 device_private_init 0 34279 NULL
127672 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
127673 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
127674 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
127675 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
127676 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
127677 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
127678 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
127679 +ea_read_34378 ea_read 0 34378 NULL nohasharray
127680 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
127681 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
127682 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
127683 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
127684 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
127685 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
127686 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
127687 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
127688 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
127689 +security_socket_create_34439 security_socket_create 0 34439 NULL
127690 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
127691 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
127692 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
127693 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
127694 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
127695 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
127696 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
127697 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
127698 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
127699 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
127700 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
127701 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
127702 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
127703 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
127704 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
127705 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
127706 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
127707 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
127708 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
127709 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
127710 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
127711 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
127712 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
127713 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
127714 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
127715 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
127716 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
127717 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
127718 +port_print_34704 port_print 3 34704 NULL
127719 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
127720 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
127721 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
127722 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
127723 +bootmode_store_34762 bootmode_store 4 34762 NULL
127724 +device_add_34766 device_add 0 34766 NULL
127725 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
127726 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
127727 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
127728 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
127729 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
127730 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
127731 +file_page_index_34820 file_page_index 0-2 34820 NULL
127732 +bio_segments_34832 bio_segments 0 34832 NULL
127733 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
127734 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
127735 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
127736 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
127737 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
127738 +msg_print_text_34889 msg_print_text 0 34889 NULL
127739 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
127740 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
127741 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
127742 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
127743 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
127744 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
127745 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
127746 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
127747 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
127748 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
127749 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
127750 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
127751 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
127752 +capi_write_35104 capi_write 3 35104 NULL nohasharray
127753 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
127754 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
127755 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
127756 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
127757 +message_stats_print_35158 message_stats_print 6 35158 NULL
127758 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
127759 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
127760 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
127761 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
127762 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
127763 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
127764 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
127765 +set_fd_set_35249 set_fd_set 1 35249 NULL
127766 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
127767 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
127768 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
127769 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
127770 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
127771 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
127772 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
127773 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
127774 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
127775 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
127776 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
127777 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
127778 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
127779 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
127780 +read_kmem_35372 read_kmem 3 35372 NULL
127781 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
127782 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
127783 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
127784 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
127785 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
127786 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
127787 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
127788 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
127789 +async_setkey_35521 async_setkey 3 35521 NULL
127790 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
127791 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
127792 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
127793 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
127794 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
127795 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
127796 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
127797 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
127798 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
127799 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
127800 +kernel_readv_35617 kernel_readv 3 35617 NULL
127801 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
127802 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
127803 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
127804 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
127805 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
127806 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
127807 +md_super_write_35703 md_super_write 4 35703 NULL
127808 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
127809 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
127810 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
127811 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
127812 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
127813 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
127814 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
127815 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
127816 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
127817 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
127818 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
127819 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
127820 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
127821 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
127822 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
127823 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
127824 +acl_alloc_35979 acl_alloc 1 35979 NULL
127825 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
127826 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
127827 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
127828 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
127829 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
127830 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
127831 +account_shadowed_36048 account_shadowed 2 36048 NULL
127832 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
127833 +write_emulate_36065 write_emulate 2-4 36065 NULL
127834 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
127835 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
127836 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
127837 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
127838 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
127839 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
127840 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
127841 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
127842 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
127843 +twl_set_36154 twl_set 2 36154 NULL
127844 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
127845 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
127846 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
127847 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
127848 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
127849 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
127850 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
127851 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
127852 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
127853 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
127854 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
127855 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
127856 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
127857 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
127858 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
127859 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
127860 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
127861 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
127862 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
127863 +lc_create_36332 lc_create 4 36332 NULL
127864 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
127865 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
127866 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
127867 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
127868 +to_sector_36361 to_sector 0-1 36361 NULL
127869 +tunables_read_36385 tunables_read 3 36385 NULL
127870 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
127871 +sierra_write_36402 sierra_write 4 36402 NULL
127872 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
127873 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
127874 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
127875 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
127876 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
127877 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
127878 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
127879 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
127880 +cmd_loop_36491 cmd_loop 0 36491 NULL
127881 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
127882 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
127883 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
127884 +get_param_l_36518 get_param_l 0 36518 NULL
127885 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
127886 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
127887 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
127888 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
127889 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
127890 +__erst_read_36579 __erst_read 0 36579 NULL
127891 +put_cmsg_36589 put_cmsg 4 36589 NULL
127892 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
127893 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
127894 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
127895 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
127896 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
127897 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
127898 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
127899 +xillybus_read_36678 xillybus_read 3 36678 NULL
127900 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
127901 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
127902 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
127903 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
127904 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
127905 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
127906 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
127907 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
127908 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
127909 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
127910 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
127911 +cm_write_36858 cm_write 3 36858 NULL
127912 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
127913 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
127914 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
127915 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
127916 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
127917 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
127918 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
127919 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
127920 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
127921 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
127922 +setxattr_37006 setxattr 4 37006 NULL
127923 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
127924 +command_file_read_37038 command_file_read 3 37038 NULL
127925 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
127926 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
127927 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
127928 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
127929 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
127930 +parse_command_37079 parse_command 2 37079 NULL
127931 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
127932 +tun_get_user_37094 tun_get_user 5 37094 NULL
127933 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
127934 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
127935 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
127936 +msg_word_37164 msg_word 0 37164 NULL
127937 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
127938 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
127939 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
127940 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
127941 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
127942 +__do_replace_37227 __do_replace 5 37227 NULL
127943 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
127944 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
127945 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
127946 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
127947 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
127948 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
127949 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
127950 +tipc_send_37315 tipc_send 3 37315 NULL
127951 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
127952 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
127953 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
127954 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
127955 +seek_firmware_37372 seek_firmware 2 37372 NULL
127956 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
127957 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
127958 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
127959 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
127960 +fru_alloc_37442 fru_alloc 1 37442 NULL
127961 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
127962 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
127963 +get_est_timing_37484 get_est_timing 0 37484 NULL
127964 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
127965 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
127966 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
127967 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
127968 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
127969 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
127970 +hdr_size_37536 hdr_size 0 37536 NULL
127971 +extent_map_end_37550 extent_map_end 0 37550 NULL
127972 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
127973 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
127974 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
127975 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
127976 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
127977 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
127978 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
127979 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
127980 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
127981 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
127982 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
127983 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
127984 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
127985 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
127986 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
127987 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
127988 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
127989 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
127990 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
127991 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
127992 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
127993 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
127994 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
127995 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
127996 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
127997 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
127998 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
127999 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
128000 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
128001 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
128002 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
128003 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
128004 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
128005 +write_file_bool_37957 write_file_bool 3 37957 NULL
128006 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
128007 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
128008 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
128009 +vfs_readv_38011 vfs_readv 3 38011 NULL
128010 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
128011 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
128012 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
128013 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
128014 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
128015 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
128016 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
128017 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
128018 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
128019 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
128020 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
128021 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
128022 +ep0_read_38095 ep0_read 3 38095 NULL
128023 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
128024 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
128025 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
128026 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
128027 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
128028 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
128029 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
128030 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
128031 +cdev_add_38176 cdev_add 2-3 38176 NULL
128032 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
128033 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
128034 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
128035 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
128036 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
128037 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
128038 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
128039 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
128040 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
128041 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
128042 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
128043 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
128044 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
128045 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
128046 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
128047 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
128048 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
128049 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
128050 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
128051 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
128052 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
128053 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
128054 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
128055 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
128056 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
128057 +dev_names_read_38509 dev_names_read 3 38509 NULL
128058 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
128059 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
128060 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
128061 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
128062 +kuc_len_38557 kuc_len 0-1 38557 NULL
128063 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
128064 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
128065 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
128066 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
128067 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
128068 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
128069 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
128070 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
128071 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
128072 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
128073 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
128074 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
128075 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
128076 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
128077 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
128078 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
128079 +udf_readpages_38761 udf_readpages 4 38761 NULL
128080 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
128081 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
128082 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
128083 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
128084 +err_decode_38804 err_decode 2 38804 NULL
128085 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
128086 +direct_entry_38836 direct_entry 3 38836 NULL
128087 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
128088 +interfaces_38859 interfaces 2 38859 NULL
128089 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
128090 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
128091 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
128092 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
128093 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
128094 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
128095 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
128096 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
128097 +get_nodes_39012 get_nodes 3 39012 NULL
128098 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
128099 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
128100 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
128101 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
128102 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
128103 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
128104 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
128105 +ea_foreach_39133 ea_foreach 0 39133 NULL
128106 +generic_permission_39150 generic_permission 0 39150 NULL
128107 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
128108 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
128109 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
128110 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
128111 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
128112 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
128113 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
128114 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
128115 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
128116 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
128117 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
128118 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
128119 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
128120 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
128121 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
128122 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
128123 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
128124 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
128125 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
128126 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
128127 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
128128 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
128129 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
128130 +__send_to_port_39386 __send_to_port 3 39386 NULL
128131 +user_power_read_39414 user_power_read 3 39414 NULL
128132 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
128133 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
128134 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
128135 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
128136 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
128137 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
128138 +int_proc_write_39542 int_proc_write 3 39542 NULL
128139 +pp_write_39554 pp_write 3 39554 NULL
128140 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
128141 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
128142 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
128143 +ext_depth_39607 ext_depth 0 39607 NULL
128144 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
128145 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
128146 +sdio_readb_39618 sdio_readb 0 39618 NULL
128147 +set_dev_class_39645 set_dev_class 4 39645 NULL
128148 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
128149 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
128150 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
128151 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
128152 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
128153 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
128154 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
128155 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
128156 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
128157 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
128158 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
128159 +pkt_add_39897 pkt_add 3 39897 NULL
128160 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
128161 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
128162 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
128163 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
128164 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
128165 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
128166 +__spi_async_39932 __spi_async 0 39932 NULL
128167 +__get_order_39935 __get_order 0 39935 NULL
128168 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
128169 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
128170 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
128171 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
128172 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
128173 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
128174 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
128175 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
128176 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
128177 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
128178 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
128179 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
128180 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
128181 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
128182 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
128183 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
128184 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
128185 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
128186 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
128187 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
128188 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
128189 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
128190 +pt_write_40159 pt_write 3 40159 NULL
128191 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
128192 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
128193 +allocate_probes_40204 allocate_probes 1 40204 NULL
128194 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
128195 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
128196 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
128197 +osst_read_40237 osst_read 3 40237 NULL
128198 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
128199 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
128200 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
128201 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
128202 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
128203 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
128204 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
128205 +SyS_bind_40303 SyS_bind 3 40303 NULL
128206 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
128207 +mmio_read_40348 mmio_read 4 40348 NULL
128208 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
128209 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
128210 +get_chars_40373 get_chars 3 40373 NULL
128211 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
128212 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
128213 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
128214 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
128215 +SyS_writev_40467 SyS_writev 3 40467 NULL
128216 +SyS_select_40473 SyS_select 1 40473 NULL
128217 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
128218 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
128219 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
128220 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
128221 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
128222 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
128223 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
128224 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
128225 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
128226 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
128227 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
128228 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
128229 +fops_read_40672 fops_read 3 40672 NULL
128230 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
128231 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
128232 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
128233 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
128234 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
128235 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
128236 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
128237 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
128238 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
128239 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
128240 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
128241 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
128242 +card_send_command_40757 card_send_command 3 40757 NULL
128243 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
128244 +pg_write_40766 pg_write 3 40766 NULL
128245 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
128246 +show_list_40775 show_list 3-0 40775 NULL
128247 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
128248 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
128249 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
128250 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
128251 +add_action_40811 add_action 4 40811 NULL
128252 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
128253 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
128254 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
128255 +read_file_queue_40895 read_file_queue 3 40895 NULL
128256 +waiters_read_40902 waiters_read 3 40902 NULL
128257 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
128258 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
128259 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
128260 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
128261 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
128262 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
128263 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
128264 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
128265 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
128266 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
128267 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
128268 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
128269 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
128270 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
128271 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
128272 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
128273 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
128274 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
128275 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
128276 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
128277 +dma_attach_41094 dma_attach 5-6 41094 NULL
128278 +provide_user_output_41105 provide_user_output 3 41105 NULL
128279 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
128280 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
128281 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
128282 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
128283 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
128284 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
128285 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
128286 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
128287 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
128288 +erst_read_41260 erst_read 0 41260 NULL
128289 +alloc_context_41283 alloc_context 1 41283 NULL
128290 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
128291 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
128292 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
128293 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
128294 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
128295 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
128296 +kmp_init_41373 kmp_init 2 41373 NULL
128297 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
128298 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
128299 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
128300 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
128301 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
128302 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
128303 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
128304 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
128305 +se_io_cb_41461 se_io_cb 3 41461 NULL
128306 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
128307 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
128308 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
128309 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
128310 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
128311 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
128312 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
128313 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
128314 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
128315 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
128316 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
128317 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
128318 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
128319 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
128320 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
128321 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
128322 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
128323 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
128324 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
128325 +a2mp_send_41615 a2mp_send 4 41615 NULL
128326 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
128327 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
128328 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
128329 +get_std_timing_41654 get_std_timing 0 41654 NULL
128330 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
128331 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
128332 +fillonedir_41746 fillonedir 3 41746 NULL
128333 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
128334 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
128335 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
128336 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
128337 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
128338 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
128339 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
128340 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
128341 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
128342 +pci_map_single_41869 pci_map_single 0 41869 NULL
128343 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
128344 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
128345 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
128346 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
128347 +read_gssp_41947 read_gssp 3 41947 NULL
128348 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
128349 +portnames_read_41958 portnames_read 3 41958 NULL
128350 +dst_mtu_41969 dst_mtu 0 41969 NULL
128351 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
128352 +pool_allocate_42012 pool_allocate 3 42012 NULL
128353 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
128354 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
128355 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
128356 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
128357 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
128358 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
128359 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
128360 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
128361 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
128362 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
128363 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
128364 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
128365 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
128366 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
128367 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
128368 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
128369 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
128370 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
128371 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
128372 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
128373 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
128374 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
128375 +find_last_bit_42260 find_last_bit 0 42260 NULL
128376 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
128377 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
128378 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
128379 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
128380 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
128381 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
128382 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
128383 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
128384 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
128385 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
128386 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
128387 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
128388 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
128389 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
128390 +krng_get_random_42420 krng_get_random 3 42420 NULL
128391 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
128392 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
128393 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
128394 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
128395 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
128396 +kuc_free_42455 kuc_free 2 42455 NULL
128397 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
128398 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
128399 +bypass_write_42498 bypass_write 3 42498 NULL
128400 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
128401 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
128402 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
128403 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
128404 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
128405 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
128406 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
128407 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
128408 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
128409 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
128410 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
128411 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
128412 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
128413 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
128414 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
128415 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
128416 +vb2_read_42703 vb2_read 3 42703 NULL
128417 +read_status_42722 read_status 0 42722 NULL
128418 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
128419 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
128420 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
128421 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
128422 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
128423 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
128424 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
128425 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
128426 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
128427 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
128428 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
128429 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
128430 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
128431 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
128432 +set_arg_42824 set_arg 3 42824 NULL
128433 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
128434 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
128435 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
128436 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
128437 +hd_end_request_42904 hd_end_request 2 42904 NULL
128438 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
128439 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
128440 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
128441 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
128442 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
128443 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
128444 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
128445 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
128446 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
128447 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
128448 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
128449 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
128450 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
128451 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
128452 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
128453 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
128454 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
128455 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
128456 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
128457 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
128458 +uio_write_43202 uio_write 3 43202 NULL
128459 +iso_callback_43208 iso_callback 3 43208 NULL
128460 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
128461 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
128462 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
128463 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
128464 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
128465 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
128466 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
128467 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
128468 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
128469 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
128470 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
128471 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
128472 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
128473 +xenfb_write_43412 xenfb_write 3 43412 NULL
128474 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
128475 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
128476 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
128477 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
128478 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
128479 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
128480 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
128481 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
128482 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
128483 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
128484 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
128485 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
128486 +read_events_43534 read_events 3 43534 NULL
128487 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
128488 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
128489 +request_resource_43548 request_resource 0 43548 NULL
128490 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
128491 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
128492 +proc_read_43614 proc_read 3 43614 NULL
128493 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
128494 +random_write_43656 random_write 3 43656 NULL
128495 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
128496 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
128497 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
128498 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
128499 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
128500 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
128501 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
128502 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
128503 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
128504 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
128505 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
128506 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
128507 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
128508 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
128509 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
128510 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
128511 +read_flush_43851 read_flush 3 43851 NULL
128512 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
128513 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
128514 +SendString_43928 SendString 3 43928 NULL
128515 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
128516 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
128517 +nla_reserve_43984 nla_reserve 3 43984 NULL
128518 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
128519 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
128520 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
128521 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
128522 +emit_flags_44006 emit_flags 4-3 44006 NULL
128523 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
128524 +fru_strlen_44046 fru_strlen 0 44046 NULL
128525 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
128526 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
128527 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
128528 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
128529 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
128530 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
128531 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
128532 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
128533 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
128534 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
128535 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
128536 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
128537 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
128538 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
128539 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
128540 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
128541 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
128542 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
128543 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
128544 +device_create_file_44285 device_create_file 0 44285 NULL
128545 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
128546 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
128547 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
128548 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
128549 +rs_init_44327 rs_init 1 44327 NULL
128550 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
128551 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
128552 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
128553 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
128554 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
128555 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
128556 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
128557 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
128558 +write_file_debug_44476 write_file_debug 3 44476 NULL
128559 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
128560 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
128561 +bio_advance_44496 bio_advance 2 44496 NULL
128562 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
128563 +ac_register_board_44504 ac_register_board 3 44504 NULL
128564 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
128565 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
128566 +spidev_write_44510 spidev_write 3 44510 NULL
128567 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
128568 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
128569 +comm_write_44537 comm_write 3 44537 NULL
128570 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
128571 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
128572 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
128573 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
128574 +mpi_resize_44674 mpi_resize 2 44674 NULL
128575 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
128576 +ts_read_44687 ts_read 3 44687 NULL
128577 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
128578 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
128579 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
128580 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
128581 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
128582 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
128583 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
128584 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
128585 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
128586 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
128587 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
128588 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
128589 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
128590 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
128591 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
128592 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
128593 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
128594 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
128595 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
128596 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
128597 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
128598 +sisusb_write_44834 sisusb_write 3 44834 NULL
128599 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
128600 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
128601 +copydesc_user_44855 copydesc_user 3 44855 NULL
128602 +set_advertising_44870 set_advertising 4 44870 NULL
128603 +init_rs_44873 init_rs 1 44873 NULL
128604 +skb_availroom_44883 skb_availroom 0 44883 NULL
128605 +do_tty_write_44896 do_tty_write 5 44896 NULL
128606 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
128607 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
128608 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
128609 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
128610 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
128611 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
128612 +sel_write_user_45060 sel_write_user 3 45060 NULL
128613 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
128614 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
128615 +snd_card_new_45104 snd_card_new 5 45104 NULL
128616 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
128617 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
128618 +usbdev_read_45114 usbdev_read 3 45114 NULL
128619 +send_to_tty_45141 send_to_tty 3 45141 NULL
128620 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
128621 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
128622 +device_write_45156 device_write 3 45156 NULL nohasharray
128623 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
128624 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
128625 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
128626 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
128627 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
128628 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
128629 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
128630 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
128631 +event_enable_write_45238 event_enable_write 3 45238 NULL
128632 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
128633 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
128634 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
128635 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
128636 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
128637 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
128638 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
128639 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
128640 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
128641 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
128642 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
128643 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
128644 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
128645 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
128646 +__node_remap_45458 __node_remap 4 45458 NULL
128647 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
128648 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
128649 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
128650 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
128651 +copy_macs_45534 copy_macs 4 45534 NULL
128652 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
128653 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
128654 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
128655 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
128656 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
128657 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
128658 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
128659 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
128660 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
128661 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
128662 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
128663 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
128664 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
128665 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
128666 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
128667 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
128668 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
128669 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
128670 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
128671 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
128672 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
128673 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
128674 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
128675 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
128676 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
128677 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
128678 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
128679 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
128680 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
128681 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
128682 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
128683 +isdn_write_45863 isdn_write 3 45863 NULL
128684 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
128685 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
128686 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
128687 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
128688 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
128689 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
128690 +alloc_mr_45935 alloc_mr 1 45935 NULL
128691 +copy_to_45969 copy_to 3 45969 NULL
128692 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
128693 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
128694 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
128695 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
128696 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
128697 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
128698 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
128699 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
128700 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
128701 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
128702 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
128703 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
128704 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
128705 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
128706 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
128707 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
128708 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
128709 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
128710 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
128711 +fq_resize_46195 fq_resize 2 46195 NULL
128712 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
128713 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
128714 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
128715 +dsp_write_46218 dsp_write 2 46218 NULL
128716 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
128717 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
128718 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
128719 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
128720 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
128721 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
128722 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
128723 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
128724 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
128725 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
128726 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
128727 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
128728 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
128729 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
128730 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
128731 +filldir64_46469 filldir64 3 46469 NULL
128732 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
128733 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
128734 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
128735 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
128736 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
128737 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
128738 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
128739 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
128740 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
128741 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
128742 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
128743 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
128744 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
128745 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
128746 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
128747 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
128748 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
128749 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
128750 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
128751 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
128752 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
128753 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
128754 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
128755 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
128756 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
128757 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
128758 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
128759 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
128760 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
128761 +readreg_46845 readreg 0 46845 NULL
128762 +spi_async_46857 spi_async 0 46857 NULL
128763 +vsnprintf_46863 vsnprintf 0 46863 NULL
128764 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
128765 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
128766 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
128767 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
128768 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
128769 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
128770 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
128771 +fb_write_46924 fb_write 3 46924 NULL
128772 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
128773 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
128774 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
128775 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
128776 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
128777 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
128778 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
128779 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
128780 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
128781 +fs_path_len_47060 fs_path_len 0 47060 NULL
128782 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
128783 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
128784 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
128785 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
128786 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
128787 +mousedev_read_47123 mousedev_read 3 47123 NULL
128788 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
128789 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
128790 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
128791 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
128792 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
128793 +options_write_47243 options_write 3 47243 NULL
128794 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
128795 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
128796 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
128797 +vsnprintf_47291 vsnprintf 0 47291 NULL
128798 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
128799 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
128800 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
128801 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
128802 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
128803 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
128804 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
128805 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
128806 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
128807 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
128808 +nametbl_list_47391 nametbl_list 2 47391 NULL
128809 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
128810 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
128811 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
128812 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
128813 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
128814 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
128815 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
128816 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
128817 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
128818 +newpart_47485 newpart 6-4 47485 NULL
128819 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
128820 +core_sys_select_47494 core_sys_select 1 47494 NULL
128821 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
128822 +unlink_simple_47506 unlink_simple 3 47506 NULL
128823 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
128824 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
128825 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
128826 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
128827 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
128828 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
128829 +read_ldt_47570 read_ldt 2 47570 NULL
128830 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
128831 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
128832 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
128833 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
128834 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
128835 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
128836 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
128837 +get_size_47644 get_size 1-2 47644 NULL
128838 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
128839 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
128840 +save_microcode_47717 save_microcode 3 47717 NULL
128841 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
128842 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
128843 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
128844 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
128845 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
128846 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
128847 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
128848 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
128849 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
128850 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
128851 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
128852 +lov_packmd_47810 lov_packmd 0 47810 NULL
128853 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
128854 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
128855 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
128856 +vhci_read_47878 vhci_read 3 47878 NULL
128857 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
128858 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
128859 +comedi_write_47926 comedi_write 3 47926 NULL
128860 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
128861 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
128862 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
128863 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
128864 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
128865 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
128866 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
128867 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
128868 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
128869 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
128870 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
128871 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
128872 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
128873 +disc_write_48070 disc_write 3 48070 NULL
128874 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
128875 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
128876 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
128877 +load_firmware_48128 load_firmware 2 48128 NULL
128878 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
128879 +set_discoverable_48141 set_discoverable 4 48141 NULL
128880 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
128881 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
128882 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
128883 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
128884 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
128885 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
128886 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
128887 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
128888 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
128889 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
128890 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
128891 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
128892 +read_file_recv_48232 read_file_recv 3 48232 NULL
128893 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
128894 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
128895 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
128896 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
128897 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
128898 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
128899 +trace_options_write_48275 trace_options_write 3 48275 NULL
128900 +send_set_info_48288 send_set_info 7 48288 NULL
128901 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
128902 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
128903 +hash_setkey_48310 hash_setkey 3 48310 NULL
128904 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
128905 +skb_add_data_48363 skb_add_data 3 48363 NULL
128906 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
128907 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
128908 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
128909 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
128910 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
128911 +print_filtered_48442 print_filtered 2-0 48442 NULL
128912 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
128913 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
128914 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
128915 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
128916 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
128917 +send_control_msg_48498 send_control_msg 6 48498 NULL
128918 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
128919 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
128920 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
128921 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
128922 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
128923 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
128924 +llog_data_len_48607 llog_data_len 1 48607 NULL
128925 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
128926 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
128927 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
128928 +mtd_read_48655 mtd_read 0 48655 NULL
128929 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
128930 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
128931 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
128932 +altera_drscan_48698 altera_drscan 2 48698 NULL
128933 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
128934 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
128935 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
128936 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
128937 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
128938 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
128939 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
128940 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
128941 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
128942 +azx_get_position_48841 azx_get_position 0 48841 NULL
128943 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
128944 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
128945 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
128946 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
128947 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
128948 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
128949 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
128950 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
128951 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
128952 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
128953 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
128954 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
128955 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
128956 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
128957 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
128958 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
128959 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
128960 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
128961 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
128962 +transient_status_49027 transient_status 4 49027 NULL
128963 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
128964 +scsi_register_49094 scsi_register 2 49094 NULL
128965 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
128966 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
128967 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
128968 +pt_read_49136 pt_read 3 49136 NULL
128969 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
128970 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
128971 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
128972 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
128973 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
128974 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
128975 +print_queue_49191 print_queue 0-4 49191 NULL
128976 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
128977 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
128978 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
128979 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
128980 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
128981 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
128982 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
128983 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
128984 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
128985 +uio_read_49300 uio_read 3 49300 NULL
128986 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
128987 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
128988 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
128989 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
128990 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
128991 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
128992 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
128993 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
128994 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
128995 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
128996 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
128997 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
128998 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
128999 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
129000 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
129001 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
129002 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
129003 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
129004 +smk_write_access_49561 smk_write_access 3 49561 NULL
129005 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
129006 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
129007 +readfifo_49583 readfifo 1 49583 NULL
129008 +tap_write_49595 tap_write 3 49595 NULL
129009 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
129010 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
129011 +heap_init_49617 heap_init 2 49617 NULL
129012 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
129013 +port_fops_read_49626 port_fops_read 3 49626 NULL
129014 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
129015 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
129016 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
129017 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
129018 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
129019 +write_pool_49718 write_pool 3 49718 NULL
129020 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
129021 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
129022 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
129023 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
129024 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
129025 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
129026 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
129027 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
129028 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
129029 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
129030 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
129031 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
129032 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
129033 +add_uuid_49831 add_uuid 4 49831 NULL
129034 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
129035 +twl4030_write_49846 twl4030_write 2 49846 NULL
129036 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
129037 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
129038 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
129039 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
129040 +osc_brw_49896 osc_brw 4 49896 NULL
129041 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
129042 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
129043 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
129044 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
129045 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
129046 +isdn_read_50021 isdn_read 3 50021 NULL
129047 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
129048 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
129049 +ioread8_50049 ioread8 0 50049 NULL
129050 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
129051 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
129052 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
129053 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
129054 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
129055 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
129056 +read_file_slot_50111 read_file_slot 3 50111 NULL
129057 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
129058 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
129059 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
129060 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
129061 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
129062 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
129063 +odev_update_50169 odev_update 2 50169 NULL
129064 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
129065 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
129066 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
129067 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
129068 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
129069 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
129070 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
129071 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
129072 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
129073 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
129074 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
129075 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
129076 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
129077 +do_launder_page_50329 do_launder_page 0 50329 NULL
129078 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
129079 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
129080 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
129081 +tpm_read_50344 tpm_read 3 50344 NULL
129082 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
129083 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
129084 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
129085 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
129086 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
129087 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
129088 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
129089 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
129090 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
129091 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
129092 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
129093 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
129094 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
129095 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
129096 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
129097 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
129098 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
129099 +fat_readpages_50582 fat_readpages 4 50582 NULL
129100 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
129101 +xillybus_write_50605 xillybus_write 3 50605 NULL
129102 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
129103 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
129104 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
129105 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
129106 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
129107 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
129108 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
129109 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
129110 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
129111 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
129112 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
129113 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
129114 +tpm_write_50798 tpm_write 3 50798 NULL
129115 +tun_do_read_50800 tun_do_read 4 50800 NULL
129116 +write_flush_50803 write_flush 3 50803 NULL
129117 +dvb_play_50814 dvb_play 3 50814 NULL
129118 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
129119 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
129120 +SetArea_50835 SetArea 4 50835 NULL
129121 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
129122 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
129123 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
129124 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
129125 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
129126 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
129127 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
129128 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
129129 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
129130 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
129131 +show_device_status_50947 show_device_status 0 50947 NULL
129132 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
129133 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
129134 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
129135 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
129136 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
129137 +timeout_write_50991 timeout_write 3 50991 NULL
129138 +proc_write_51003 proc_write 3 51003 NULL
129139 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
129140 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
129141 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
129142 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
129143 +dump_midi_51040 dump_midi 3 51040 NULL
129144 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
129145 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
129146 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
129147 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
129148 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
129149 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
129150 +ti_recv_51110 ti_recv 3 51110 NULL
129151 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
129152 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
129153 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
129154 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
129155 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
129156 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
129157 +drm_property_create_51239 drm_property_create 4 51239 NULL
129158 +st_read_51251 st_read 3 51251 NULL
129159 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
129160 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
129161 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
129162 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
129163 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
129164 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
129165 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
129166 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
129167 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
129168 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
129169 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
129170 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
129171 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
129172 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
129173 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
129174 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
129175 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
129176 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
129177 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
129178 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
129179 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
129180 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
129181 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
129182 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
129183 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
129184 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
129185 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
129186 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
129187 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
129188 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
129189 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
129190 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
129191 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
129192 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
129193 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
129194 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
129195 +sel_write_access_51704 sel_write_access 3 51704 NULL
129196 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
129197 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
129198 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
129199 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
129200 +cm4040_read_51732 cm4040_read 3 51732 NULL
129201 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
129202 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
129203 +if_write_51756 if_write 3 51756 NULL
129204 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
129205 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
129206 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
129207 +ioread32_51847 ioread32 0 51847 NULL nohasharray
129208 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
129209 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
129210 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
129211 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
129212 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
129213 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
129214 +user_read_51881 user_read 3 51881 NULL
129215 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
129216 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
129217 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
129218 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
129219 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
129220 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
129221 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
129222 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
129223 +get_zone_51981 get_zone 0-1 51981 NULL
129224 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
129225 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
129226 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
129227 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
129228 +rdmalt_52022 rdmalt 0 52022 NULL
129229 +override_release_52032 override_release 2 52032 NULL
129230 +end_port_52042 end_port 0 52042 NULL
129231 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
129232 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
129233 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
129234 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
129235 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
129236 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
129237 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
129238 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
129239 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
129240 +retry_count_read_52129 retry_count_read 3 52129 NULL
129241 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
129242 +sub_alloc_52140 sub_alloc 0 52140 NULL
129243 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
129244 +htable_size_52148 htable_size 0-1 52148 NULL
129245 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
129246 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
129247 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
129248 +print_prefix_52176 print_prefix 0 52176 NULL
129249 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
129250 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
129251 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
129252 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
129253 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
129254 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
129255 +shrink_slab_52261 shrink_slab 2 52261 NULL
129256 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
129257 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
129258 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
129259 +read_file_reset_52310 read_file_reset 3 52310 NULL
129260 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
129261 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
129262 +hwflags_read_52318 hwflags_read 3 52318 NULL
129263 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
129264 +hur_len_52339 hur_len 0 52339 NULL
129265 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
129266 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
129267 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
129268 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
129269 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
129270 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
129271 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
129272 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
129273 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
129274 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
129275 +delay_status_52431 delay_status 5 52431 NULL
129276 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
129277 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
129278 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
129279 +bt_alloc_52457 bt_alloc 2 52457 NULL
129280 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
129281 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
129282 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
129283 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
129284 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
129285 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
129286 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
129287 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
129288 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
129289 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
129290 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
129291 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
129292 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
129293 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
129294 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
129295 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
129296 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
129297 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
129298 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
129299 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
129300 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
129301 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
129302 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
129303 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
129304 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
129305 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
129306 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
129307 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
129308 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
129309 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
129310 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
129311 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
129312 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
129313 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
129314 +twlreg_write_52880 twlreg_write 3 52880 NULL
129315 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
129316 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
129317 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
129318 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
129319 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
129320 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
129321 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
129322 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
129323 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
129324 +num_node_state_52989 num_node_state 0 52989 NULL
129325 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
129326 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
129327 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
129328 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
129329 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
129330 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
129331 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
129332 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
129333 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
129334 +verity_status_53120 verity_status 5 53120 NULL
129335 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
129336 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
129337 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
129338 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
129339 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
129340 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
129341 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
129342 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
129343 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
129344 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
129345 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
129346 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
129347 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
129348 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
129349 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
129350 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
129351 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
129352 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
129353 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
129354 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
129355 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
129356 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
129357 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
129358 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
129359 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
129360 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
129361 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
129362 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
129363 +check_acl_53512 check_acl 0 53512 NULL nohasharray
129364 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
129365 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
129366 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
129367 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
129368 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
129369 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
129370 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
129371 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
129372 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
129373 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
129374 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
129375 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
129376 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
129377 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
129378 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
129379 +wdm_write_53735 wdm_write 3 53735 NULL
129380 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
129381 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
129382 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
129383 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
129384 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
129385 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
129386 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
129387 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
129388 +setup_data_read_53822 setup_data_read 3 53822 NULL
129389 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
129390 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
129391 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
129392 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
129393 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
129394 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
129395 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
129396 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
129397 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
129398 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
129399 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
129400 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
129401 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
129402 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
129403 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
129404 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
129405 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
129406 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
129407 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
129408 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
129409 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
129410 +strn_len_54122 strn_len 0 54122 NULL
129411 +isku_receive_54130 isku_receive 4 54130 NULL
129412 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
129413 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
129414 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
129415 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
129416 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
129417 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
129418 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
129419 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
129420 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
129421 +reada_add_block_54247 reada_add_block 2 54247 NULL
129422 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
129423 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
129424 +audio_write_54261 audio_write 4 54261 NULL nohasharray
129425 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
129426 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
129427 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
129428 +sizeof_long_54276 sizeof_long 0 54276 NULL
129429 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
129430 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
129431 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
129432 +sprintf_54306 sprintf 0 54306 NULL
129433 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
129434 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
129435 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
129436 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
129437 +readlink_copy_54366 readlink_copy 2 54366 NULL
129438 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
129439 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
129440 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
129441 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
129442 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
129443 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
129444 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
129445 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
129446 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
129447 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
129448 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
129449 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
129450 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
129451 +viacam_read_54526 viacam_read 3 54526 NULL
129452 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
129453 +setsockopt_54539 setsockopt 5 54539 NULL
129454 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
129455 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
129456 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
129457 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
129458 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
129459 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
129460 +port_fops_write_54627 port_fops_write 3 54627 NULL
129461 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
129462 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
129463 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
129464 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
129465 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
129466 +bus_add_device_54665 bus_add_device 0 54665 NULL
129467 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
129468 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
129469 +evm_read_key_54674 evm_read_key 3 54674 NULL
129470 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
129471 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
129472 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
129473 +kzalloc_54740 kzalloc 1 54740 NULL
129474 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
129475 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
129476 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
129477 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
129478 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
129479 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
129480 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
129481 +nfsd_write_54809 nfsd_write 6 54809 NULL
129482 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
129483 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
129484 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
129485 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
129486 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
129487 +write_rio_54837 write_rio 3 54837 NULL
129488 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
129489 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
129490 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
129491 +printer_read_54851 printer_read 3 54851 NULL
129492 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
129493 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
129494 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
129495 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
129496 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
129497 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
129498 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
129499 +add_port_54941 add_port 2 54941 NULL
129500 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
129501 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
129502 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
129503 +c4_add_card_54968 c4_add_card 3 54968 NULL
129504 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
129505 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
129506 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
129507 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
129508 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
129509 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
129510 +read_dma_55086 read_dma 3 55086 NULL
129511 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
129512 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
129513 +filldir_55137 filldir 3 55137 NULL
129514 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
129515 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
129516 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
129517 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
129518 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
129519 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
129520 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
129521 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
129522 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
129523 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
129524 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
129525 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
129526 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
129527 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
129528 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
129529 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
129530 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
129531 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
129532 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
129533 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
129534 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
129535 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
129536 +vme_user_read_55338 vme_user_read 3 55338 NULL
129537 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
129538 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
129539 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
129540 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
129541 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
129542 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
129543 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
129544 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
129545 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
129546 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
129547 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
129548 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
129549 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
129550 +ea_get_55522 ea_get 3-0 55522 NULL
129551 +buffer_size_55534 buffer_size 0 55534 NULL
129552 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
129553 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
129554 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
129555 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
129556 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
129557 +add_partition_55588 add_partition 2 55588 NULL
129558 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
129559 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
129560 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
129561 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
129562 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
129563 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
129564 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
129565 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
129566 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
129567 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
129568 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
129569 +get_info_55681 get_info 3 55681 NULL
129570 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
129571 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
129572 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
129573 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
129574 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
129575 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
129576 +set_local_name_55757 set_local_name 4 55757 NULL
129577 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
129578 +strlen_55778 strlen 0 55778 NULL
129579 +set_spte_55783 set_spte 4-5 55783 NULL
129580 +conf_read_55786 conf_read 3 55786 NULL nohasharray
129581 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
129582 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
129583 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
129584 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
129585 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
129586 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
129587 +hsc_write_55875 hsc_write 3 55875 NULL
129588 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
129589 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
129590 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
129591 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
129592 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
129593 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
129594 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
129595 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2 55957 NULL
129596 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
129597 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
129598 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
129599 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
129600 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
129601 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
129602 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
129603 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
129604 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
129605 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
129606 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
129607 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
129608 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
129609 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
129610 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
129611 +fd_copyin_56247 fd_copyin 3 56247 NULL
129612 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
129613 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
129614 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
129615 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
129616 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
129617 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
129618 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
129619 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
129620 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
129621 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
129622 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
129623 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
129624 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
129625 +dev_read_56369 dev_read 3 56369 NULL
129626 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
129627 +lnet_ping_56378 lnet_ping 4 56378 NULL
129628 +write_gssp_56404 write_gssp 3 56404 NULL
129629 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
129630 +store_msg_56417 store_msg 3 56417 NULL
129631 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
129632 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
129633 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
129634 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
129635 +fl_create_56435 fl_create 5 56435 NULL
129636 +gnttab_map_56439 gnttab_map 2 56439 NULL
129637 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
129638 +set_connectable_56458 set_connectable 4 56458 NULL
129639 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
129640 +putused_user_56467 putused_user 3 56467 NULL
129641 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
129642 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
129643 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
129644 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
129645 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
129646 +init_map_ip_56508 init_map_ip 5 56508 NULL
129647 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
129648 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
129649 +ip_options_get_56538 ip_options_get 4 56538 NULL
129650 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
129651 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
129652 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
129653 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
129654 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
129655 +event_filter_write_56609 event_filter_write 3 56609 NULL
129656 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
129657 +gather_array_56641 gather_array 3 56641 NULL
129658 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
129659 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
129660 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
129661 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
129662 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
129663 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
129664 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
129665 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
129666 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
129667 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
129668 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
129669 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
129670 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
129671 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
129672 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
129673 +do_syslog_56807 do_syslog 3 56807 NULL
129674 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
129675 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
129676 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
129677 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
129678 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
129679 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
129680 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
129681 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
129682 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
129683 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
129684 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
129685 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
129686 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
129687 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
129688 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
129689 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
129690 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
129691 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
129692 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
129693 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
129694 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
129695 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
129696 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
129697 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
129698 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
129699 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
129700 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
129701 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
129702 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
129703 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
129704 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
129705 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
129706 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
129707 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
129708 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
129709 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
129710 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
129711 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
129712 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
129713 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
129714 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
129715 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
129716 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
129717 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
129718 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
129719 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
129720 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
129721 +write_file_regval_57313 write_file_regval 3 57313 NULL
129722 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
129723 +usblp_read_57342 usblp_read 3 57342 NULL
129724 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
129725 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
129726 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
129727 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
129728 +read_file_blob_57406 read_file_blob 3 57406 NULL
129729 +enclosure_register_57412 enclosure_register 3 57412 NULL
129730 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
129731 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
129732 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
129733 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
129734 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
129735 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
129736 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
129737 +skb_headlen_57501 skb_headlen 0 57501 NULL
129738 +copy_in_user_57502 copy_in_user 3 57502 NULL
129739 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
129740 +init_tag_map_57515 init_tag_map 3 57515 NULL
129741 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
129742 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
129743 +cmm_read_57520 cmm_read 3 57520 NULL
129744 +inode_permission_57531 inode_permission 0 57531 NULL
129745 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
129746 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
129747 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
129748 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
129749 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
129750 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
129751 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
129752 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
129753 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
129754 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
129755 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
129756 +mem_read_57631 mem_read 3 57631 NULL
129757 +r3964_write_57662 r3964_write 4 57662 NULL
129758 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
129759 +__lgwrite_57669 __lgwrite 4 57669 NULL
129760 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
129761 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
129762 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
129763 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
129764 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
129765 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
129766 +ld2_57794 ld2 0 57794 NULL
129767 +ivtv_read_57796 ivtv_read 3 57796 NULL
129768 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
129769 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
129770 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
129771 +flash_read_57843 flash_read 3 57843 NULL
129772 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
129773 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
129774 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
129775 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
129776 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
129777 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
129778 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
129779 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
129780 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
129781 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
129782 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
129783 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
129784 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
129785 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
129786 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
129787 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
129788 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
129789 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
129790 +mce_async_out_58056 mce_async_out 3 58056 NULL
129791 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
129792 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
129793 +cm4040_write_58079 cm4040_write 3 58079 NULL
129794 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
129795 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
129796 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
129797 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
129798 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
129799 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
129800 +read_file_debug_58256 read_file_debug 3 58256 NULL
129801 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
129802 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
129803 +profile_load_58267 profile_load 3 58267 NULL
129804 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
129805 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
129806 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
129807 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
129808 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
129809 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
129810 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
129811 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
129812 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
129813 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
129814 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
129815 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
129816 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
129817 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
129818 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
129819 +capabilities_read_58457 capabilities_read 3 58457 NULL
129820 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
129821 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
129822 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
129823 +nv_rd08_58472 nv_rd08 0 58472 NULL
129824 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
129825 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
129826 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
129827 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
129828 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
129829 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
129830 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
129831 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
129832 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
129833 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
129834 +xip_file_read_58592 xip_file_read 3 58592 NULL
129835 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
129836 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
129837 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
129838 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
129839 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
129840 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
129841 +find_zero_58685 find_zero 0-1 58685 NULL
129842 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
129843 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
129844 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
129845 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
129846 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
129847 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
129848 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
129849 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
129850 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
129851 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
129852 +ep_read_58813 ep_read 3 58813 NULL
129853 +command_write_58841 command_write 3 58841 NULL
129854 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
129855 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
129856 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
129857 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
129858 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
129859 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
129860 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
129861 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
129862 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
129863 +init_list_set_59005 init_list_set 3 59005 NULL
129864 +ep_write_59008 ep_write 3 59008 NULL
129865 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
129866 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
129867 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
129868 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
129869 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
129870 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
129871 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
129872 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
129873 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
129874 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
129875 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
129876 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
129877 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
129878 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
129879 +ksize_59176 ksize 0 59176 NULL
129880 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
129881 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
129882 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
129883 +dt3155_read_59226 dt3155_read 3 59226 NULL
129884 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
129885 +nla_len_59258 nla_len 0 59258 NULL
129886 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
129887 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
129888 +fd_copyout_59323 fd_copyout 3 59323 NULL
129889 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
129890 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
129891 +__map_request_59350 __map_request 0 59350 NULL
129892 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
129893 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
129894 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
129895 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
129896 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
129897 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
129898 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
129899 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
129900 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
129901 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
129902 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
129903 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
129904 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
129905 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
129906 +tunables_write_59563 tunables_write 3 59563 NULL
129907 +bio_split_59564 bio_split 2 59564 NULL
129908 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
129909 +write_pbl_59583 write_pbl 4 59583 NULL
129910 +memdup_user_59590 memdup_user 2 59590 NULL
129911 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
129912 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
129913 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
129914 +mtrr_write_59622 mtrr_write 3 59622 NULL
129915 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
129916 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
129917 +hidraw_read_59650 hidraw_read 3 59650 NULL
129918 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
129919 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
129920 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
129921 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
129922 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
129923 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
129924 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
129925 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
129926 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
129927 +strnlen_59746 strnlen 0 59746 NULL
129928 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
129929 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
129930 +venus_remove_59781 venus_remove 4 59781 NULL
129931 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
129932 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
129933 +ipw_write_59807 ipw_write 3 59807 NULL
129934 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
129935 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
129936 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
129937 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
129938 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
129939 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
129940 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
129941 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
129942 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
129943 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
129944 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
129945 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
129946 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
129947 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
129948 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
129949 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
129950 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
129951 +copy_items_60009 copy_items 7 60009 NULL
129952 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
129953 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
129954 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
129955 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
129956 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
129957 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
129958 +vcs_size_60050 vcs_size 0 60050 NULL
129959 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
129960 +compat_writev_60063 compat_writev 3 60063 NULL
129961 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
129962 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
129963 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
129964 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
129965 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
129966 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
129967 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
129968 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
129969 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
129970 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
129971 +init_state_60165 init_state 2 60165 NULL
129972 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
129973 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
129974 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
129975 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
129976 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
129977 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
129978 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
129979 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
129980 +printer_write_60276 printer_write 3 60276 NULL
129981 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
129982 +getDataLength_60301 getDataLength 0 60301 NULL
129983 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
129984 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
129985 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
129986 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
129987 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
129988 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
129989 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
129990 +driver_names_read_60399 driver_names_read 3 60399 NULL
129991 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
129992 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
129993 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
129994 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
129995 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
129996 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
129997 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
129998 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
129999 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
130000 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
130001 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
130002 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
130003 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
130004 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
130005 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
130006 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
130007 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
130008 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
130009 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
130010 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
130011 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
130012 +raid_status_60755 raid_status 5 60755 NULL
130013 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
130014 +opticon_write_60775 opticon_write 4 60775 NULL
130015 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
130016 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
130017 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
130018 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
130019 +generic_writepages_60871 generic_writepages 0 60871 NULL
130020 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
130021 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
130022 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
130023 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
130024 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
130025 +pti_char_write_60960 pti_char_write 3 60960 NULL
130026 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
130027 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
130028 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
130029 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
130030 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
130031 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
130032 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
130033 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
130034 +symtab_init_61050 symtab_init 2 61050 NULL
130035 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
130036 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
130037 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
130038 +get_derived_key_61100 get_derived_key 4 61100 NULL
130039 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
130040 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
130041 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
130042 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
130043 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
130044 +pair_device_61175 pair_device 4 61175 NULL nohasharray
130045 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
130046 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
130047 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
130048 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
130049 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
130050 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
130051 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
130052 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270
130053 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
130054 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
130055 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
130056 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
130057 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
130058 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
130059 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
130060 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
130061 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
130062 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
130063 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
130064 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
130065 +system_enable_write_61396 system_enable_write 3 61396 NULL
130066 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
130067 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
130068 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
130069 +erst_errno_61526 erst_errno 0 61526 NULL
130070 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
130071 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
130072 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
130073 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
130074 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
130075 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
130076 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
130077 +seq_open_private_61589 seq_open_private 3 61589 NULL
130078 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
130079 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
130080 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
130081 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
130082 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
130083 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
130084 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
130085 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
130086 +resize_stripes_61650 resize_stripes 2 61650 NULL
130087 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
130088 +insert_one_name_61668 insert_one_name 7 61668 NULL
130089 +lock_loop_61681 lock_loop 1 61681 NULL
130090 +filter_read_61692 filter_read 3 61692 NULL
130091 +iov_length_61716 iov_length 0 61716 NULL
130092 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
130093 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
130094 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
130095 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
130096 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
130097 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
130098 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
130099 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
130100 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
130101 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
130102 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
130103 +get_fw_name_61874 get_fw_name 3 61874 NULL
130104 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
130105 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
130106 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
130107 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
130108 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
130109 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
130110 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
130111 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
130112 +fix_read_error_61965 fix_read_error 4 61965 NULL
130113 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
130114 +cow_file_range_61979 cow_file_range 3 61979 NULL
130115 +dequeue_event_62000 dequeue_event 3 62000 NULL
130116 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
130117 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
130118 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
130119 +SYSC_select_62024 SYSC_select 1 62024 NULL
130120 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
130121 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
130122 +do_pselect_62061 do_pselect 1 62061 NULL
130123 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
130124 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
130125 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
130126 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
130127 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
130128 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
130129 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
130130 +ql_status_62135 ql_status 5 62135 NULL nohasharray
130131 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
130132 +video_usercopy_62151 video_usercopy 2 62151 NULL
130133 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
130134 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
130135 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
130136 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
130137 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
130138 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
130139 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
130140 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
130141 +get_random_int_62279 get_random_int 0 62279 NULL
130142 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
130143 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
130144 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
130145 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
130146 +subseq_list_62332 subseq_list 3-0 62332 NULL
130147 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
130148 +flash_write_62354 flash_write 3 62354 NULL
130149 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
130150 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
130151 +altera_irscan_62396 altera_irscan 2 62396 NULL
130152 +set_ssp_62411 set_ssp 4 62411 NULL
130153 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
130154 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
130155 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
130156 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
130157 +debugfs_read_62535 debugfs_read 3 62535 NULL
130158 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
130159 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
130160 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
130161 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
130162 +get_subdir_62581 get_subdir 3 62581 NULL
130163 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
130164 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
130165 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
130166 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
130167 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
130168 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
130169 +rdm_62719 rdm 0 62719 NULL
130170 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
130171 +key_replays_read_62746 key_replays_read 3 62746 NULL
130172 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
130173 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
130174 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
130175 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
130176 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
130177 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
130178 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
130179 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
130180 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
130181 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
130182 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
130183 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
130184 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
130185 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
130186 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
130187 +aoechr_write_62883 aoechr_write 3 62883 NULL
130188 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
130189 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
130190 +getdqbuf_62908 getdqbuf 1 62908 NULL
130191 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
130192 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
130193 +hwdep_read_62992 hwdep_read 3 62992 NULL
130194 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
130195 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
130196 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
130197 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
130198 +unlink1_63059 unlink1 3 63059 NULL
130199 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
130200 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
130201 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
130202 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
130203 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
130204 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
130205 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
130206 +vme_master_read_63221 vme_master_read 0 63221 NULL
130207 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
130208 +ptp_read_63251 ptp_read 4 63251 NULL
130209 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
130210 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
130211 +raid5_resize_63306 raid5_resize 2 63306 NULL
130212 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
130213 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
130214 +proc_info_read_63344 proc_info_read 3 63344 NULL
130215 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
130216 +idmouse_read_63374 idmouse_read 3 63374 NULL
130217 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
130218 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
130219 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
130220 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
130221 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
130222 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
130223 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
130224 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
130225 +read_kcore_63488 read_kcore 3 63488 NULL
130226 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
130227 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
130228 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
130229 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
130230 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
130231 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
130232 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
130233 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
130234 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
130235 +write_debug_level_63613 write_debug_level 3 63613 NULL
130236 +__spi_validate_63618 __spi_validate 0 63618 NULL
130237 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
130238 +hid_report_len_63637 hid_report_len 0 63637 NULL
130239 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
130240 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
130241 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
130242 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
130243 +vbi_read_63673 vbi_read 3 63673 NULL
130244 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
130245 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
130246 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
130247 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
130248 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
130249 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
130250 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
130251 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
130252 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
130253 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
130254 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
130255 +sel_write_load_63830 sel_write_load 3 63830 NULL
130256 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
130257 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
130258 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
130259 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
130260 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
130261 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
130262 +__team_options_register_63941 __team_options_register 3 63941 NULL
130263 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
130264 +set_bredr_63975 set_bredr 4 63975 NULL
130265 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
130266 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
130267 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
130268 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
130269 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
130270 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
130271 +__sock_create_64069 __sock_create 0 64069 NULL
130272 +get_u8_64076 get_u8 0 64076 NULL
130273 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
130274 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
130275 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
130276 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
130277 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
130278 +to_bytes_64103 to_bytes 0-1 64103 NULL
130279 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
130280 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
130281 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
130282 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
130283 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
130284 +init_bch_64130 init_bch 1-2 64130 NULL
130285 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
130286 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
130287 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
130288 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
130289 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
130290 +read_pulse_64227 read_pulse 0-3 64227 NULL
130291 +ea_len_64229 ea_len 0 64229 NULL
130292 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
130293 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
130294 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
130295 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
130296 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
130297 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
130298 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
130299 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
130300 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
130301 +ts_write_64336 ts_write 3 64336 NULL
130302 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
130303 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
130304 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
130305 +reg_create_64372 reg_create 5 64372 NULL
130306 +ilo_write_64378 ilo_write 3 64378 NULL
130307 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
130308 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
130309 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
130310 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
130311 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
130312 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
130313 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
130314 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
130315 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
130316 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
130317 +single_open_size_64483 single_open_size 4 64483 NULL
130318 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
130319 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
130320 +remove_uuid_64505 remove_uuid 4 64505 NULL
130321 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
130322 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
130323 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
130324 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
130325 +SyS_bind_64544 SyS_bind 3 64544 NULL
130326 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
130327 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
130328 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
130329 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
130330 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
130331 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
130332 +do_erase_64574 do_erase 4 64574 NULL
130333 +fanotify_write_64623 fanotify_write 3 64623 NULL
130334 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
130335 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
130336 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
130337 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
130338 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
130339 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
130340 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
130341 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
130342 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
130343 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
130344 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
130345 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
130346 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
130347 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
130348 +hwdep_write_64776 hwdep_write 3 64776 NULL
130349 +message_for_md_64777 message_for_md 5 64777 NULL
130350 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
130351 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
130352 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
130353 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
130354 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
130355 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
130356 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
130357 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
130358 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
130359 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
130360 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
130361 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
130362 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
130363 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
130364 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
130365 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
130366 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
130367 +insert_dent_65034 insert_dent 7 65034 NULL
130368 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
130369 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
130370 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
130371 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
130372 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
130373 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
130374 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
130375 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
130376 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
130377 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
130378 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
130379 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
130380 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
130381 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
130382 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
130383 +get_var_len_65304 get_var_len 0 65304 NULL
130384 +unpack_array_65318 unpack_array 0 65318 NULL
130385 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
130386 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
130387 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
130388 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
130389 +SyS_writev_65372 SyS_writev 3 65372 NULL
130390 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
130391 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
130392 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
130393 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
130394 +device_add_groups_65423 device_add_groups 0 65423 NULL
130395 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
130396 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
130397 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
130398 +clear_user_65470 clear_user 2 65470 NULL
130399 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
130400 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
130401 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
130402 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
130403 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
130404 new file mode 100644
130405 index 0000000..560cd7b
130406 --- /dev/null
130407 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
130408 @@ -0,0 +1,92 @@
130409 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
130410 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
130411 +mappedread_2627 mappedread 2 2627 NULL
130412 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
130413 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
130414 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
130415 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
130416 +dmu_write_6048 dmu_write 4-3 6048 NULL
130417 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
130418 +update_pages_6225 update_pages 2-3 6225 NULL
130419 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
130420 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
130421 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
130422 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
130423 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
130424 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
130425 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
130426 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
130427 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
130428 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
130429 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
130430 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
130431 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
130432 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
130433 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
130434 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
130435 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
130436 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
130437 +uiocopy_18680 uiocopy 2 18680 NULL
130438 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
130439 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
130440 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
130441 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
130442 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
130443 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
130444 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
130445 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
130446 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
130447 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
130448 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
130449 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
130450 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
130451 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
130452 +splat_write_30943 splat_write 3 30943 NULL
130453 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
130454 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
130455 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
130456 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
130457 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
130458 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
130459 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
130460 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
130461 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
130462 +copyinstr_36980 copyinstr 3 36980 NULL
130463 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
130464 +splat_read_38116 splat_read 3 38116 NULL
130465 +sa_setup_38756 sa_setup 4 38756 NULL
130466 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
130467 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
130468 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
130469 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
130470 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
130471 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
130472 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
130473 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
130474 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
130475 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
130476 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
130477 +kcopy_write_43683 kcopy_write 3 43683 NULL
130478 +uiomove_44355 uiomove 2 44355 NULL
130479 +dmu_read_44418 dmu_read 4-3 44418 NULL
130480 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
130481 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
130482 +copyin_45945 copyin 3 45945 NULL
130483 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
130484 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
130485 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
130486 +spa_history_write_49650 spa_history_write 3 49650 NULL
130487 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
130488 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
130489 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
130490 +copyout_51409 copyout 3 51409 NULL
130491 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
130492 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
130493 +get_nvlist_56685 get_nvlist 2 56685 NULL
130494 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
130495 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
130496 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
130497 +zpios_write_61823 zpios_write 3 61823 NULL
130498 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
130499 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
130500 +zpios_read_64734 zpios_read 3 64734 NULL
130501 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
130502 new file mode 100644
130503 index 0000000..95f7abd
130504 --- /dev/null
130505 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
130506 @@ -0,0 +1,259 @@
130507 +/*
130508 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
130509 + * Licensed under the GPL v2, or (at your option) v3
130510 + *
130511 + * Homepage:
130512 + * http://www.grsecurity.net/~ephox/overflow_plugin/
130513 + *
130514 + * Documentation:
130515 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
130516 + *
130517 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
130518 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
130519 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
130520 + *
130521 + * Usage:
130522 + * $ make
130523 + * $ make run
130524 + */
130525 +
130526 +#include "gcc-common.h"
130527 +#include "size_overflow.h"
130528 +
130529 +int plugin_is_GPL_compatible;
130530 +
130531 +tree report_size_overflow_decl;
130532 +
130533 +tree size_overflow_type_HI;
130534 +tree size_overflow_type_SI;
130535 +tree size_overflow_type_DI;
130536 +tree size_overflow_type_TI;
130537 +
130538 +static struct plugin_info size_overflow_plugin_info = {
130539 + .version = "20140725",
130540 + .help = "no-size-overflow\tturn off size overflow checking\n",
130541 +};
130542 +
130543 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
130544 +{
130545 + unsigned int arg_count;
130546 + enum tree_code code = TREE_CODE(*node);
130547 +
130548 + switch (code) {
130549 + case FUNCTION_DECL:
130550 + arg_count = type_num_arguments(TREE_TYPE(*node));
130551 + break;
130552 + case FUNCTION_TYPE:
130553 + case METHOD_TYPE:
130554 + arg_count = type_num_arguments(*node);
130555 + break;
130556 + default:
130557 + *no_add_attrs = true;
130558 + error("%s: %qE attribute only applies to functions", __func__, name);
130559 + return NULL_TREE;
130560 + }
130561 +
130562 + for (; args; args = TREE_CHAIN(args)) {
130563 + tree position = TREE_VALUE(args);
130564 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
130565 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
130566 + *no_add_attrs = true;
130567 + }
130568 + }
130569 + return NULL_TREE;
130570 +}
130571 +
130572 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
130573 +{
130574 + unsigned int arg_count;
130575 + enum tree_code code = TREE_CODE(*node);
130576 +
130577 + switch (code) {
130578 + case FUNCTION_DECL:
130579 + arg_count = type_num_arguments(TREE_TYPE(*node));
130580 + break;
130581 + case FUNCTION_TYPE:
130582 + case METHOD_TYPE:
130583 + arg_count = type_num_arguments(*node);
130584 + break;
130585 + case FIELD_DECL:
130586 + return NULL_TREE;
130587 + default:
130588 + *no_add_attrs = true;
130589 + error("%qE attribute only applies to functions", name);
130590 + return NULL_TREE;
130591 + }
130592 +
130593 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
130594 + return NULL_TREE;
130595 +
130596 + for (; args; args = TREE_CHAIN(args)) {
130597 + tree position = TREE_VALUE(args);
130598 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
130599 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
130600 + *no_add_attrs = true;
130601 + }
130602 + }
130603 + return NULL_TREE;
130604 +}
130605 +
130606 +static struct attribute_spec size_overflow_attr = {
130607 + .name = "size_overflow",
130608 + .min_length = 1,
130609 + .max_length = -1,
130610 + .decl_required = true,
130611 + .type_required = false,
130612 + .function_type_required = false,
130613 + .handler = handle_size_overflow_attribute,
130614 +#if BUILDING_GCC_VERSION >= 4007
130615 + .affects_type_identity = false
130616 +#endif
130617 +};
130618 +
130619 +static struct attribute_spec intentional_overflow_attr = {
130620 + .name = "intentional_overflow",
130621 + .min_length = 1,
130622 + .max_length = -1,
130623 + .decl_required = true,
130624 + .type_required = false,
130625 + .function_type_required = false,
130626 + .handler = handle_intentional_overflow_attribute,
130627 +#if BUILDING_GCC_VERSION >= 4007
130628 + .affects_type_identity = false
130629 +#endif
130630 +};
130631 +
130632 +static void register_attributes(void __unused *event_data, void __unused *data)
130633 +{
130634 + register_attribute(&size_overflow_attr);
130635 + register_attribute(&intentional_overflow_attr);
130636 +}
130637 +
130638 +static tree create_typedef(tree type, const char* ident)
130639 +{
130640 + tree new_type, decl;
130641 +
130642 + new_type = build_variant_type_copy(type);
130643 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
130644 + DECL_ORIGINAL_TYPE(decl) = type;
130645 + TYPE_NAME(new_type) = decl;
130646 + return new_type;
130647 +}
130648 +
130649 +// Create the noreturn report_size_overflow() function decl.
130650 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
130651 +{
130652 + tree const_char_ptr_type_node;
130653 + tree fntype;
130654 +
130655 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
130656 +
130657 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
130658 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
130659 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
130660 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
130661 +
130662 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
130663 + fntype = build_function_type_list(void_type_node,
130664 + const_char_ptr_type_node,
130665 + unsigned_type_node,
130666 + const_char_ptr_type_node,
130667 + const_char_ptr_type_node,
130668 + NULL_TREE);
130669 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
130670 +
130671 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
130672 + TREE_PUBLIC(report_size_overflow_decl) = 1;
130673 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
130674 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
130675 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
130676 +}
130677 +
130678 +
130679 +extern struct gimple_opt_pass pass_dce;
130680 +
130681 +static struct opt_pass *make_dce_pass(void)
130682 +{
130683 +#if BUILDING_GCC_VERSION >= 4009
130684 + return make_pass_dce(g);
130685 +#else
130686 + return &pass_dce.pass;
130687 +#endif
130688 +}
130689 +
130690 +
130691 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
130692 +{
130693 + int i;
130694 + const char * const plugin_name = plugin_info->base_name;
130695 + const int argc = plugin_info->argc;
130696 + const struct plugin_argument * const argv = plugin_info->argv;
130697 + bool enable = true;
130698 + struct register_pass_info insert_size_overflow_asm_pass_info;
130699 + struct register_pass_info __unused dump_before_pass_info;
130700 + struct register_pass_info __unused dump_after_pass_info;
130701 + struct register_pass_info insert_size_overflow_check_info;
130702 + struct register_pass_info dce_pass_info;
130703 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
130704 + {
130705 + .base = &report_size_overflow_decl,
130706 + .nelt = 1,
130707 + .stride = sizeof(report_size_overflow_decl),
130708 + .cb = &gt_ggc_mx_tree_node,
130709 + .pchw = &gt_pch_nx_tree_node
130710 + },
130711 + LAST_GGC_ROOT_TAB
130712 + };
130713 +
130714 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
130715 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
130716 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
130717 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
130718 +
130719 + dump_before_pass_info.pass = make_dump_pass();
130720 + dump_before_pass_info.reference_pass_name = "increase_alignment";
130721 + dump_before_pass_info.ref_pass_instance_number = 1;
130722 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
130723 +
130724 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
130725 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
130726 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
130727 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
130728 +
130729 + dump_after_pass_info.pass = make_dump_pass();
130730 + dump_after_pass_info.reference_pass_name = "increase_alignment";
130731 + dump_after_pass_info.ref_pass_instance_number = 1;
130732 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
130733 +
130734 + dce_pass_info.pass = make_dce_pass();
130735 + dce_pass_info.reference_pass_name = "vrp";
130736 + dce_pass_info.ref_pass_instance_number = 1;
130737 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
130738 +
130739 + if (!plugin_default_version_check(version, &gcc_version)) {
130740 + error(G_("incompatible gcc/plugin versions"));
130741 + return 1;
130742 + }
130743 +
130744 + for (i = 0; i < argc; ++i) {
130745 + if (!strcmp(argv[i].key, "no-size-overflow")) {
130746 + enable = false;
130747 + continue;
130748 + }
130749 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
130750 + }
130751 +
130752 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
130753 + if (enable) {
130754 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
130755 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
130756 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
130757 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
130758 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
130759 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
130760 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
130761 + }
130762 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
130763 +
130764 + return 0;
130765 +}
130766 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
130767 new file mode 100644
130768 index 0000000..0888f6c
130769 --- /dev/null
130770 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
130771 @@ -0,0 +1,364 @@
130772 +/*
130773 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
130774 + * Licensed under the GPL v2, or (at your option) v3
130775 + *
130776 + * Homepage:
130777 + * http://www.grsecurity.net/~ephox/overflow_plugin/
130778 + *
130779 + * Documentation:
130780 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
130781 + *
130782 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
130783 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
130784 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
130785 + *
130786 + * Usage:
130787 + * $ make
130788 + * $ make run
130789 + */
130790 +
130791 +#include "gcc-common.h"
130792 +#include "size_overflow.h"
130793 +
130794 +#include "size_overflow_hash.h"
130795 +#include "size_overflow_hash_aux.h"
130796 +
130797 +#define CODES_LIMIT 32
130798 +
130799 +static unsigned char get_tree_code(const_tree type)
130800 +{
130801 + switch (TREE_CODE(type)) {
130802 + case ARRAY_TYPE:
130803 + return 0;
130804 + case BOOLEAN_TYPE:
130805 + return 1;
130806 + case ENUMERAL_TYPE:
130807 + return 2;
130808 + case FUNCTION_TYPE:
130809 + return 3;
130810 + case INTEGER_TYPE:
130811 + return 4;
130812 + case POINTER_TYPE:
130813 + return 5;
130814 + case RECORD_TYPE:
130815 + return 6;
130816 + case UNION_TYPE:
130817 + return 7;
130818 + case VOID_TYPE:
130819 + return 8;
130820 + case REAL_TYPE:
130821 + return 9;
130822 + case VECTOR_TYPE:
130823 + return 10;
130824 + case REFERENCE_TYPE:
130825 + return 11;
130826 + case OFFSET_TYPE:
130827 + return 12;
130828 + case COMPLEX_TYPE:
130829 + return 13;
130830 + default:
130831 + debug_tree((tree)type);
130832 + gcc_unreachable();
130833 + }
130834 +}
130835 +
130836 +struct function_hash {
130837 + size_t tree_codes_len;
130838 + unsigned char tree_codes[CODES_LIMIT];
130839 + const_tree fndecl;
130840 + unsigned int hash;
130841 +};
130842 +
130843 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
130844 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
130845 +{
130846 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
130847 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
130848 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
130849 +
130850 + unsigned int m = 0x57559429;
130851 + unsigned int n = 0x5052acdb;
130852 + const unsigned int *key4 = (const unsigned int *)key;
130853 + unsigned int h = len;
130854 + unsigned int k = len + seed + n;
130855 + unsigned long long p;
130856 +
130857 + while (len >= 8) {
130858 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
130859 + len -= 8;
130860 + }
130861 + if (len >= 4) {
130862 + cwmixb(key4[0]) key4 += 1;
130863 + len -= 4;
130864 + }
130865 + if (len)
130866 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
130867 + cwmixb(h ^ (k + n));
130868 + return k ^ h;
130869 +
130870 +#undef cwfold
130871 +#undef cwmixa
130872 +#undef cwmixb
130873 +}
130874 +
130875 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
130876 +{
130877 + unsigned int fn, codes, seed = 0;
130878 +
130879 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
130880 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
130881 +
130882 + fn_hash_data->hash = fn ^ codes;
130883 +}
130884 +
130885 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
130886 +{
130887 + gcc_assert(type != NULL_TREE);
130888 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
130889 +
130890 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
130891 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
130892 + fn_hash_data->tree_codes_len++;
130893 + type = TREE_TYPE(type);
130894 + }
130895 +}
130896 +
130897 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
130898 +{
130899 + const_tree result;
130900 +
130901 + gcc_assert(node != NULL_TREE);
130902 +
130903 + if (DECL_P(node)) {
130904 + result = DECL_RESULT(node);
130905 + if (result != NULL_TREE)
130906 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
130907 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
130908 + }
130909 +
130910 + gcc_assert(TYPE_P(node));
130911 +
130912 + if (TREE_CODE(node) == FUNCTION_TYPE)
130913 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
130914 +
130915 + return set_node_codes(node, fn_hash_data);
130916 +}
130917 +
130918 +static void set_function_codes(struct function_hash *fn_hash_data)
130919 +{
130920 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
130921 + enum tree_code code = TREE_CODE(type);
130922 +
130923 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
130924 +
130925 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
130926 +
130927 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
130928 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
130929 +}
130930 +
130931 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
130932 +{
130933 + while (entry) {
130934 + if (!strcmp(entry->name, func_name))
130935 + return entry;
130936 + entry = entry->next;
130937 + }
130938 + return NULL;
130939 +}
130940 +
130941 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
130942 +{
130943 + const struct size_overflow_hash *entry;
130944 + struct function_hash fn_hash_data;
130945 + const char *func_name;
130946 +
130947 + // skip builtins __builtin_constant_p
130948 + if (DECL_BUILT_IN(fndecl))
130949 + return NULL;
130950 +
130951 + fn_hash_data.fndecl = fndecl;
130952 + fn_hash_data.tree_codes_len = 0;
130953 +
130954 + set_function_codes(&fn_hash_data);
130955 + gcc_assert(fn_hash_data.tree_codes_len != 0);
130956 +
130957 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
130958 + set_hash(func_name, &fn_hash_data);
130959 +
130960 + entry = size_overflow_hash[fn_hash_data.hash];
130961 + entry = get_proper_hash_chain(entry, func_name);
130962 + if (entry)
130963 + return entry;
130964 + entry = size_overflow_hash_aux[fn_hash_data.hash];
130965 + return get_proper_hash_chain(entry, func_name);
130966 +}
130967 +
130968 +static void print_missing_msg(const_tree func, unsigned int argnum)
130969 +{
130970 + location_t loc;
130971 + const char *curfunc;
130972 + struct function_hash fn_hash_data;
130973 +
130974 + fn_hash_data.fndecl = DECL_ORIGIN(func);
130975 + fn_hash_data.tree_codes_len = 0;
130976 +
130977 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
130978 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
130979 +
130980 + set_function_codes(&fn_hash_data);
130981 + set_hash(curfunc, &fn_hash_data);
130982 +
130983 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
130984 +}
130985 +
130986 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
130987 +{
130988 + tree var;
130989 + unsigned int argnum = 1;
130990 +
130991 + if (TREE_CODE(arg) == SSA_NAME)
130992 + arg = SSA_NAME_VAR(arg);
130993 +
130994 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
130995 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
130996 + continue;
130997 + if (!skip_types(var))
130998 + return argnum;
130999 + }
131000 +
131001 + return CANNOT_FIND_ARG;
131002 +}
131003 +
131004 +static const char *get_asm_string(const_gimple stmt)
131005 +{
131006 + if (!stmt)
131007 + return NULL;
131008 + if (gimple_code(stmt) != GIMPLE_ASM)
131009 + return NULL;
131010 +
131011 + return gimple_asm_string(stmt);
131012 +}
131013 +
131014 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
131015 +{
131016 + const char *str;
131017 +
131018 + str = get_asm_string(stmt);
131019 + if (!str)
131020 + return false;
131021 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
131022 +}
131023 +
131024 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
131025 +{
131026 + const char *str;
131027 +
131028 + str = get_asm_string(stmt);
131029 + if (!str)
131030 + return false;
131031 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
131032 +}
131033 +
131034 +bool is_size_overflow_asm(const_gimple stmt)
131035 +{
131036 + const char *str;
131037 +
131038 + str = get_asm_string(stmt);
131039 + if (!str)
131040 + return false;
131041 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
131042 +}
131043 +
131044 +bool is_a_return_check(const_tree node)
131045 +{
131046 + if (TREE_CODE(node) == FUNCTION_DECL)
131047 + return true;
131048 +
131049 + gcc_assert(TREE_CODE(node) == PARM_DECL);
131050 + return false;
131051 +}
131052 +
131053 +// Get the argnum of a function decl, if node is a return then the argnum is 0
131054 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
131055 +{
131056 + if (is_a_return_check(node))
131057 + return 0;
131058 + else
131059 + return find_arg_number_tree(node, orig_fndecl);
131060 +}
131061 +
131062 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
131063 +{
131064 + const struct size_overflow_hash *hash;
131065 + unsigned int new_argnum;
131066 + tree arg;
131067 + const_tree origarg;
131068 +
131069 + if (argnum == 0)
131070 + return argnum;
131071 +
131072 + hash = get_function_hash(fndecl);
131073 + if (hash && hash->param & (1U << argnum))
131074 + return argnum;
131075 +
131076 + if (DECL_EXTERNAL(fndecl))
131077 + return argnum;
131078 +
131079 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
131080 + argnum--;
131081 + while (origarg && argnum) {
131082 + origarg = TREE_CHAIN(origarg);
131083 + argnum--;
131084 + }
131085 + gcc_assert(argnum == 0);
131086 + gcc_assert(origarg != NULL_TREE);
131087 +
131088 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
131089 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
131090 + return new_argnum;
131091 +
131092 + return CANNOT_FIND_ARG;
131093 +}
131094 +
131095 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
131096 +{
131097 + const struct size_overflow_hash *hash;
131098 +
131099 + hash = get_function_hash(fndecl);
131100 + if (hash && (hash->param & (1U << num)))
131101 + return true;
131102 + return false;
131103 +}
131104 +
131105 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
131106 + * If the function is missing everywhere then print the missing message into stderr.
131107 + */
131108 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
131109 +{
131110 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
131111 +#if BUILDING_GCC_VERSION >= 4008
131112 + case BUILT_IN_BSWAP16:
131113 +#endif
131114 + case BUILT_IN_BSWAP32:
131115 + case BUILT_IN_BSWAP64:
131116 + case BUILT_IN_EXPECT:
131117 + case BUILT_IN_MEMCMP:
131118 + return false;
131119 + default:
131120 + break;
131121 + }
131122 +
131123 + // skip test.c
131124 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
131125 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
131126 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
131127 + }
131128 +
131129 + if (is_in_hash_table(orig_fndecl, num))
131130 + return false;
131131 +
131132 + print_missing_msg(orig_fndecl, num);
131133 + return true;
131134 +}
131135 +
131136 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
131137 new file mode 100644
131138 index 0000000..924652b
131139 --- /dev/null
131140 +++ b/tools/gcc/stackleak_plugin.c
131141 @@ -0,0 +1,395 @@
131142 +/*
131143 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
131144 + * Licensed under the GPL v2
131145 + *
131146 + * Note: the choice of the license means that the compilation process is
131147 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
131148 + * but for the kernel it doesn't matter since it doesn't link against
131149 + * any of the gcc libraries
131150 + *
131151 + * gcc plugin to help implement various PaX features
131152 + *
131153 + * - track lowest stack pointer
131154 + *
131155 + * TODO:
131156 + * - initialize all local variables
131157 + *
131158 + * BUGS:
131159 + * - none known
131160 + */
131161 +
131162 +#include "gcc-common.h"
131163 +
131164 +int plugin_is_GPL_compatible;
131165 +
131166 +static int track_frame_size = -1;
131167 +static const char track_function[] = "pax_track_stack";
131168 +static const char check_function[] = "pax_check_alloca";
131169 +static tree track_function_decl, check_function_decl;
131170 +static bool init_locals;
131171 +
131172 +static struct plugin_info stackleak_plugin_info = {
131173 + .version = "201408011900",
131174 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
131175 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
131176 +};
131177 +
131178 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
131179 +{
131180 + gimple check_alloca;
131181 + tree alloca_size;
131182 +
131183 + // insert call to void pax_check_alloca(unsigned long size)
131184 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
131185 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
131186 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
131187 +}
131188 +
131189 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
131190 +{
131191 + gimple track_stack;
131192 +
131193 + // insert call to void pax_track_stack(void)
131194 + track_stack = gimple_build_call(track_function_decl, 0);
131195 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
131196 +}
131197 +
131198 +static bool is_alloca(gimple stmt)
131199 +{
131200 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
131201 + return true;
131202 +
131203 +#if BUILDING_GCC_VERSION >= 4007
131204 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
131205 + return true;
131206 +#endif
131207 +
131208 + return false;
131209 +}
131210 +
131211 +static unsigned int execute_stackleak_tree_instrument(void)
131212 +{
131213 + basic_block bb, entry_bb;
131214 + bool prologue_instrumented = false, is_leaf = true;
131215 +
131216 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
131217 +
131218 + // 1. loop through BBs and GIMPLE statements
131219 + FOR_EACH_BB_FN(bb, cfun) {
131220 + gimple_stmt_iterator gsi;
131221 +
131222 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
131223 + gimple stmt;
131224 +
131225 + stmt = gsi_stmt(gsi);
131226 +
131227 + if (is_gimple_call(stmt))
131228 + is_leaf = false;
131229 +
131230 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
131231 + if (!is_alloca(stmt))
131232 + continue;
131233 +
131234 + // 2. insert stack overflow check before each __builtin_alloca call
131235 + stackleak_check_alloca(&gsi);
131236 +
131237 + // 3. insert track call after each __builtin_alloca call
131238 + stackleak_add_instrumentation(&gsi);
131239 + if (bb == entry_bb)
131240 + prologue_instrumented = true;
131241 + }
131242 + }
131243 +
131244 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
131245 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
131246 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
131247 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
131248 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
131249 + return 0;
131250 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
131251 + return 0;
131252 +
131253 + // 4. insert track call at the beginning
131254 + if (!prologue_instrumented) {
131255 + gimple_stmt_iterator gsi;
131256 +
131257 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
131258 + if (dom_info_available_p(CDI_DOMINATORS))
131259 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
131260 + gsi = gsi_start_bb(bb);
131261 + stackleak_add_instrumentation(&gsi);
131262 + }
131263 +
131264 + return 0;
131265 +}
131266 +
131267 +static unsigned int execute_stackleak_final(void)
131268 +{
131269 + rtx insn, next;
131270 +
131271 + if (cfun->calls_alloca)
131272 + return 0;
131273 +
131274 + // keep calls only if function frame is big enough
131275 + if (get_frame_size() >= track_frame_size)
131276 + return 0;
131277 +
131278 + // 1. find pax_track_stack calls
131279 + for (insn = get_insns(); insn; insn = next) {
131280 + // 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))
131281 + rtx body;
131282 +
131283 + next = NEXT_INSN(insn);
131284 + if (!CALL_P(insn))
131285 + continue;
131286 + body = PATTERN(insn);
131287 + if (GET_CODE(body) != CALL)
131288 + continue;
131289 + body = XEXP(body, 0);
131290 + if (GET_CODE(body) != MEM)
131291 + continue;
131292 + body = XEXP(body, 0);
131293 + if (GET_CODE(body) != SYMBOL_REF)
131294 + continue;
131295 +// if (strcmp(XSTR(body, 0), track_function))
131296 + if (SYMBOL_REF_DECL(body) != track_function_decl)
131297 + continue;
131298 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
131299 + // 2. delete call
131300 + delete_insn_and_edges(insn);
131301 +#if BUILDING_GCC_VERSION >= 4007
131302 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
131303 + insn = next;
131304 + next = NEXT_INSN(insn);
131305 + delete_insn_and_edges(insn);
131306 + }
131307 +#endif
131308 + }
131309 +
131310 +// print_simple_rtl(stderr, get_insns());
131311 +// print_rtl(stderr, get_insns());
131312 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
131313 +
131314 + return 0;
131315 +}
131316 +
131317 +static bool gate_stackleak_track_stack(void)
131318 +{
131319 + tree section;
131320 +
131321 + if (ix86_cmodel != CM_KERNEL)
131322 + return false;
131323 +
131324 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
131325 + if (section && TREE_VALUE(section)) {
131326 + section = TREE_VALUE(TREE_VALUE(section));
131327 +
131328 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
131329 + return false;
131330 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
131331 + return false;
131332 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
131333 + return false;
131334 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
131335 + return false;
131336 + }
131337 +
131338 + return track_frame_size >= 0;
131339 +}
131340 +
131341 +static void stackleak_start_unit(void *gcc_data, void *user_data)
131342 +{
131343 + tree fntype;
131344 +
131345 + // void pax_track_stack(void)
131346 + fntype = build_function_type_list(void_type_node, NULL_TREE);
131347 + track_function_decl = build_fn_decl(track_function, fntype);
131348 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
131349 + TREE_PUBLIC(track_function_decl) = 1;
131350 + DECL_EXTERNAL(track_function_decl) = 1;
131351 + DECL_ARTIFICIAL(track_function_decl) = 1;
131352 +
131353 + // void pax_check_alloca(unsigned long)
131354 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
131355 + check_function_decl = build_fn_decl(check_function, fntype);
131356 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
131357 + TREE_PUBLIC(check_function_decl) = 1;
131358 + DECL_EXTERNAL(check_function_decl) = 1;
131359 + DECL_ARTIFICIAL(check_function_decl) = 1;
131360 +}
131361 +
131362 +#if BUILDING_GCC_VERSION >= 4009
131363 +static const struct pass_data stackleak_tree_instrument_pass_data = {
131364 +#else
131365 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
131366 + .pass = {
131367 +#endif
131368 + .type = GIMPLE_PASS,
131369 + .name = "stackleak_tree_instrument",
131370 +#if BUILDING_GCC_VERSION >= 4008
131371 + .optinfo_flags = OPTGROUP_NONE,
131372 +#endif
131373 +#if BUILDING_GCC_VERSION >= 4009
131374 + .has_gate = true,
131375 + .has_execute = true,
131376 +#else
131377 + .gate = gate_stackleak_track_stack,
131378 + .execute = execute_stackleak_tree_instrument,
131379 + .sub = NULL,
131380 + .next = NULL,
131381 + .static_pass_number = 0,
131382 +#endif
131383 + .tv_id = TV_NONE,
131384 + .properties_required = PROP_gimple_leh | PROP_cfg,
131385 + .properties_provided = 0,
131386 + .properties_destroyed = 0,
131387 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
131388 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
131389 +#if BUILDING_GCC_VERSION < 4009
131390 + }
131391 +#endif
131392 +};
131393 +
131394 +#if BUILDING_GCC_VERSION >= 4009
131395 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
131396 +#else
131397 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
131398 + .pass = {
131399 +#endif
131400 + .type = RTL_PASS,
131401 + .name = "stackleak_final",
131402 +#if BUILDING_GCC_VERSION >= 4008
131403 + .optinfo_flags = OPTGROUP_NONE,
131404 +#endif
131405 +#if BUILDING_GCC_VERSION >= 4009
131406 + .has_gate = true,
131407 + .has_execute = true,
131408 +#else
131409 + .gate = gate_stackleak_track_stack,
131410 + .execute = execute_stackleak_final,
131411 + .sub = NULL,
131412 + .next = NULL,
131413 + .static_pass_number = 0,
131414 +#endif
131415 + .tv_id = TV_NONE,
131416 + .properties_required = 0,
131417 + .properties_provided = 0,
131418 + .properties_destroyed = 0,
131419 + .todo_flags_start = 0,
131420 + .todo_flags_finish = TODO_dump_func
131421 +#if BUILDING_GCC_VERSION < 4009
131422 + }
131423 +#endif
131424 +};
131425 +
131426 +#if BUILDING_GCC_VERSION >= 4009
131427 +namespace {
131428 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
131429 +public:
131430 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
131431 + bool gate() { return gate_stackleak_track_stack(); }
131432 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
131433 +};
131434 +
131435 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
131436 +public:
131437 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
131438 + bool gate() { return gate_stackleak_track_stack(); }
131439 + unsigned int execute() { return execute_stackleak_final(); }
131440 +};
131441 +}
131442 +
131443 +static opt_pass *make_stackleak_tree_instrument_pass(void)
131444 +{
131445 + return new stackleak_tree_instrument_pass();
131446 +}
131447 +
131448 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
131449 +{
131450 + return new stackleak_final_rtl_opt_pass();
131451 +}
131452 +#else
131453 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
131454 +{
131455 + return &stackleak_tree_instrument_pass.pass;
131456 +}
131457 +
131458 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
131459 +{
131460 + return &stackleak_final_rtl_opt_pass.pass;
131461 +}
131462 +#endif
131463 +
131464 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
131465 +{
131466 + const char * const plugin_name = plugin_info->base_name;
131467 + const int argc = plugin_info->argc;
131468 + const struct plugin_argument * const argv = plugin_info->argv;
131469 + int i;
131470 + struct register_pass_info stackleak_tree_instrument_pass_info;
131471 + struct register_pass_info stackleak_final_pass_info;
131472 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
131473 + {
131474 + .base = &track_function_decl,
131475 + .nelt = 1,
131476 + .stride = sizeof(track_function_decl),
131477 + .cb = &gt_ggc_mx_tree_node,
131478 + .pchw = &gt_pch_nx_tree_node
131479 + },
131480 + {
131481 + .base = &check_function_decl,
131482 + .nelt = 1,
131483 + .stride = sizeof(check_function_decl),
131484 + .cb = &gt_ggc_mx_tree_node,
131485 + .pchw = &gt_pch_nx_tree_node
131486 + },
131487 + LAST_GGC_ROOT_TAB
131488 + };
131489 +
131490 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
131491 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
131492 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
131493 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
131494 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
131495 +
131496 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
131497 + stackleak_final_pass_info.reference_pass_name = "final";
131498 + stackleak_final_pass_info.ref_pass_instance_number = 1;
131499 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
131500 +
131501 + if (!plugin_default_version_check(version, &gcc_version)) {
131502 + error(G_("incompatible gcc/plugin versions"));
131503 + return 1;
131504 + }
131505 +
131506 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
131507 +
131508 + for (i = 0; i < argc; ++i) {
131509 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
131510 + if (!argv[i].value) {
131511 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
131512 + continue;
131513 + }
131514 + track_frame_size = atoi(argv[i].value);
131515 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
131516 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
131517 + continue;
131518 + }
131519 + if (!strcmp(argv[i].key, "initialize-locals")) {
131520 + if (argv[i].value) {
131521 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
131522 + continue;
131523 + }
131524 + init_locals = true;
131525 + continue;
131526 + }
131527 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
131528 + }
131529 +
131530 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
131531 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
131532 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
131533 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
131534 +
131535 + return 0;
131536 +}
131537 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
131538 new file mode 100644
131539 index 0000000..4ee2231
131540 --- /dev/null
131541 +++ b/tools/gcc/structleak_plugin.c
131542 @@ -0,0 +1,274 @@
131543 +/*
131544 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
131545 + * Licensed under the GPL v2
131546 + *
131547 + * Note: the choice of the license means that the compilation process is
131548 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
131549 + * but for the kernel it doesn't matter since it doesn't link against
131550 + * any of the gcc libraries
131551 + *
131552 + * gcc plugin to forcibly initialize certain local variables that could
131553 + * otherwise leak kernel stack to userland if they aren't properly initialized
131554 + * by later code
131555 + *
131556 + * Homepage: http://pax.grsecurity.net/
131557 + *
131558 + * Usage:
131559 + * $ # for 4.5/4.6/C based 4.7
131560 + * $ 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
131561 + * $ # for C++ based 4.7/4.8+
131562 + * $ 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
131563 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
131564 + *
131565 + * TODO: eliminate redundant initializers
131566 + * increase type coverage
131567 + */
131568 +
131569 +#include "gcc-common.h"
131570 +
131571 +// unused C type flag in all versions 4.5-4.9
131572 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
131573 +
131574 +int plugin_is_GPL_compatible;
131575 +
131576 +static struct plugin_info structleak_plugin_info = {
131577 + .version = "201401260140",
131578 + .help = "disable\tdo not activate plugin\n",
131579 +};
131580 +
131581 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
131582 +{
131583 + *no_add_attrs = true;
131584 +
131585 + // check for types? for now accept everything linux has to offer
131586 + if (TREE_CODE(*node) != FIELD_DECL)
131587 + return NULL_TREE;
131588 +
131589 + *no_add_attrs = false;
131590 + return NULL_TREE;
131591 +}
131592 +
131593 +static struct attribute_spec user_attr = {
131594 + .name = "user",
131595 + .min_length = 0,
131596 + .max_length = 0,
131597 + .decl_required = false,
131598 + .type_required = false,
131599 + .function_type_required = false,
131600 + .handler = handle_user_attribute,
131601 +#if BUILDING_GCC_VERSION >= 4007
131602 + .affects_type_identity = true
131603 +#endif
131604 +};
131605 +
131606 +static void register_attributes(void *event_data, void *data)
131607 +{
131608 + register_attribute(&user_attr);
131609 +// register_attribute(&force_attr);
131610 +}
131611 +
131612 +static tree get_field_type(tree field)
131613 +{
131614 + return strip_array_types(TREE_TYPE(field));
131615 +}
131616 +
131617 +static bool is_userspace_type(tree type)
131618 +{
131619 + tree field;
131620 +
131621 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
131622 + tree fieldtype = get_field_type(field);
131623 + enum tree_code code = TREE_CODE(fieldtype);
131624 +
131625 + if (code == RECORD_TYPE || code == UNION_TYPE)
131626 + if (is_userspace_type(fieldtype))
131627 + return true;
131628 +
131629 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
131630 + return true;
131631 + }
131632 + return false;
131633 +}
131634 +
131635 +static void finish_type(void *event_data, void *data)
131636 +{
131637 + tree type = (tree)event_data;
131638 +
131639 + if (TYPE_USERSPACE(type))
131640 + return;
131641 +
131642 + if (is_userspace_type(type))
131643 + TYPE_USERSPACE(type) = 1;
131644 +}
131645 +
131646 +static void initialize(tree var)
131647 +{
131648 + basic_block bb;
131649 + gimple_stmt_iterator gsi;
131650 + tree initializer;
131651 + gimple init_stmt;
131652 +
131653 + // this is the original entry bb before the forced split
131654 + // TODO: check further BBs in case more splits occured before us
131655 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
131656 +
131657 + // first check if the variable is already initialized, warn otherwise
131658 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
131659 + gimple stmt = gsi_stmt(gsi);
131660 + tree rhs1;
131661 +
131662 + // we're looking for an assignment of a single rhs...
131663 + if (!gimple_assign_single_p(stmt))
131664 + continue;
131665 + rhs1 = gimple_assign_rhs1(stmt);
131666 +#if BUILDING_GCC_VERSION >= 4007
131667 + // ... of a non-clobbering expression...
131668 + if (TREE_CLOBBER_P(rhs1))
131669 + continue;
131670 +#endif
131671 + // ... to our variable...
131672 + if (gimple_get_lhs(stmt) != var)
131673 + continue;
131674 + // if it's an initializer then we're good
131675 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
131676 + return;
131677 + }
131678 +
131679 + // these aren't the 0days you're looking for
131680 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
131681 +
131682 + // build the initializer expression
131683 + initializer = build_constructor(TREE_TYPE(var), NULL);
131684 +
131685 + // build the initializer stmt
131686 + init_stmt = gimple_build_assign(var, initializer);
131687 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
131688 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
131689 + update_stmt(init_stmt);
131690 +}
131691 +
131692 +static unsigned int handle_function(void)
131693 +{
131694 + basic_block bb;
131695 + unsigned int ret = 0;
131696 + tree var;
131697 + unsigned int i;
131698 +
131699 + // split the first bb where we can put the forced initializers
131700 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
131701 + if (dom_info_available_p(CDI_DOMINATORS))
131702 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
131703 +
131704 + // enumarate all local variables and forcibly initialize our targets
131705 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
131706 + tree type = TREE_TYPE(var);
131707 +
131708 + gcc_assert(DECL_P(var));
131709 + if (!auto_var_in_fn_p(var, current_function_decl))
131710 + continue;
131711 +
131712 + // only care about structure types
131713 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
131714 + continue;
131715 +
131716 + // if the type is of interest, examine the variable
131717 + if (TYPE_USERSPACE(type))
131718 + initialize(var);
131719 + }
131720 +
131721 + return ret;
131722 +}
131723 +
131724 +#if BUILDING_GCC_VERSION >= 4009
131725 +static const struct pass_data structleak_pass_data = {
131726 +#else
131727 +static struct gimple_opt_pass structleak_pass = {
131728 + .pass = {
131729 +#endif
131730 + .type = GIMPLE_PASS,
131731 + .name = "structleak",
131732 +#if BUILDING_GCC_VERSION >= 4008
131733 + .optinfo_flags = OPTGROUP_NONE,
131734 +#endif
131735 +#if BUILDING_GCC_VERSION >= 4009
131736 + .has_gate = false,
131737 + .has_execute = true,
131738 +#else
131739 + .gate = NULL,
131740 + .execute = handle_function,
131741 + .sub = NULL,
131742 + .next = NULL,
131743 + .static_pass_number = 0,
131744 +#endif
131745 + .tv_id = TV_NONE,
131746 + .properties_required = PROP_cfg,
131747 + .properties_provided = 0,
131748 + .properties_destroyed = 0,
131749 + .todo_flags_start = 0,
131750 + .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
131751 +#if BUILDING_GCC_VERSION < 4009
131752 + }
131753 +#endif
131754 +};
131755 +
131756 +#if BUILDING_GCC_VERSION >= 4009
131757 +namespace {
131758 +class structleak_pass : public gimple_opt_pass {
131759 +public:
131760 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
131761 + unsigned int execute() { return handle_function(); }
131762 +};
131763 +}
131764 +
131765 +static opt_pass *make_structleak_pass(void)
131766 +{
131767 + return new structleak_pass();
131768 +}
131769 +#else
131770 +static struct opt_pass *make_structleak_pass(void)
131771 +{
131772 + return &structleak_pass.pass;
131773 +}
131774 +#endif
131775 +
131776 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
131777 +{
131778 + int i;
131779 + const char * const plugin_name = plugin_info->base_name;
131780 + const int argc = plugin_info->argc;
131781 + const struct plugin_argument * const argv = plugin_info->argv;
131782 + bool enable = true;
131783 + struct register_pass_info structleak_pass_info;
131784 +
131785 + structleak_pass_info.pass = make_structleak_pass();
131786 + structleak_pass_info.reference_pass_name = "ssa";
131787 + structleak_pass_info.ref_pass_instance_number = 1;
131788 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
131789 +
131790 + if (!plugin_default_version_check(version, &gcc_version)) {
131791 + error(G_("incompatible gcc/plugin versions"));
131792 + return 1;
131793 + }
131794 +
131795 + if (strcmp(lang_hooks.name, "GNU C")) {
131796 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
131797 + enable = false;
131798 + }
131799 +
131800 + for (i = 0; i < argc; ++i) {
131801 + if (!strcmp(argv[i].key, "disable")) {
131802 + enable = false;
131803 + continue;
131804 + }
131805 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
131806 + }
131807 +
131808 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
131809 + if (enable) {
131810 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
131811 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
131812 + }
131813 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
131814 +
131815 + return 0;
131816 +}
131817 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
131818 index 88461f0..6fb70a0 100644
131819 --- a/tools/include/linux/compiler.h
131820 +++ b/tools/include/linux/compiler.h
131821 @@ -35,6 +35,14 @@
131822 # define unlikely(x) __builtin_expect(!!(x), 0)
131823 #endif
131824
131825 +#ifndef __size_overflow
131826 +# define __size_overflow(...)
131827 +#endif
131828 +
131829 +#ifndef __intentional_overflow
131830 +# define __intentional_overflow(...)
131831 +#endif
131832 +
131833 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
131834
131835 #endif /* _TOOLS_LINUX_COMPILER_H */
131836 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
131837 index ce00f7e..0aca5e4 100644
131838 --- a/tools/lib/api/Makefile
131839 +++ b/tools/lib/api/Makefile
131840 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
131841
131842 LIBFILE = libapikfs.a
131843
131844 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
131845 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
131846 EXTLIBS = -lelf -lpthread -lrt -lm
131847 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
131848 ALL_LDFLAGS = $(LDFLAGS)
131849 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
131850 index 6789d788..4afd019e 100644
131851 --- a/tools/perf/util/include/asm/alternative-asm.h
131852 +++ b/tools/perf/util/include/asm/alternative-asm.h
131853 @@ -5,4 +5,7 @@
131854
131855 #define altinstruction_entry #
131856
131857 + .macro pax_force_retaddr rip=0, reload=0
131858 + .endm
131859 +
131860 #endif
131861 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
131862 index 0a578fe..b81f62d 100644
131863 --- a/tools/virtio/linux/uaccess.h
131864 +++ b/tools/virtio/linux/uaccess.h
131865 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
131866 ({ \
131867 typeof(ptr) __pu_ptr = (ptr); \
131868 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
131869 - ACCESS_ONCE(*(__pu_ptr)) = x; \
131870 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
131871 0; \
131872 })
131873
131874 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
131875 index 4b6c01b..16eb755 100644
131876 --- a/virt/kvm/kvm_main.c
131877 +++ b/virt/kvm/kvm_main.c
131878 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
131879
131880 static cpumask_var_t cpus_hardware_enabled;
131881 static int kvm_usage_count = 0;
131882 -static atomic_t hardware_enable_failed;
131883 +static atomic_unchecked_t hardware_enable_failed;
131884
131885 struct kmem_cache *kvm_vcpu_cache;
131886 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
131887
131888 -static __read_mostly struct preempt_ops kvm_preempt_ops;
131889 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
131890 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
131891 +static struct preempt_ops kvm_preempt_ops = {
131892 + .sched_in = kvm_sched_in,
131893 + .sched_out = kvm_sched_out,
131894 +};
131895
131896 struct dentry *kvm_debugfs_dir;
131897
131898 @@ -761,7 +766,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
131899 /* We can read the guest memory with __xxx_user() later on. */
131900 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
131901 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
131902 - !access_ok(VERIFY_WRITE,
131903 + !access_ok_noprefault(VERIFY_WRITE,
131904 (void __user *)(unsigned long)mem->userspace_addr,
131905 mem->memory_size)))
131906 goto out;
131907 @@ -1618,9 +1623,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
131908
131909 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
131910 {
131911 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
131912 + int r;
131913 + unsigned long addr;
131914
131915 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
131916 + addr = gfn_to_hva(kvm, gfn);
131917 + if (kvm_is_error_hva(addr))
131918 + return -EFAULT;
131919 + r = __clear_user((void __user *)addr + offset, len);
131920 + if (r)
131921 + return -EFAULT;
131922 + mark_page_dirty(kvm, gfn);
131923 + return 0;
131924 }
131925 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
131926
131927 @@ -1870,7 +1883,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
131928 return 0;
131929 }
131930
131931 -static struct file_operations kvm_vcpu_fops = {
131932 +static file_operations_no_const kvm_vcpu_fops __read_only = {
131933 .release = kvm_vcpu_release,
131934 .unlocked_ioctl = kvm_vcpu_ioctl,
131935 #ifdef CONFIG_COMPAT
131936 @@ -2540,7 +2553,7 @@ out:
131937 }
131938 #endif
131939
131940 -static struct file_operations kvm_vm_fops = {
131941 +static file_operations_no_const kvm_vm_fops __read_only = {
131942 .release = kvm_vm_release,
131943 .unlocked_ioctl = kvm_vm_ioctl,
131944 #ifdef CONFIG_COMPAT
131945 @@ -2640,7 +2653,7 @@ out:
131946 return r;
131947 }
131948
131949 -static struct file_operations kvm_chardev_ops = {
131950 +static file_operations_no_const kvm_chardev_ops __read_only = {
131951 .unlocked_ioctl = kvm_dev_ioctl,
131952 .compat_ioctl = kvm_dev_ioctl,
131953 .llseek = noop_llseek,
131954 @@ -2666,7 +2679,7 @@ static void hardware_enable_nolock(void *junk)
131955
131956 if (r) {
131957 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
131958 - atomic_inc(&hardware_enable_failed);
131959 + atomic_inc_unchecked(&hardware_enable_failed);
131960 printk(KERN_INFO "kvm: enabling virtualization on "
131961 "CPU%d failed\n", cpu);
131962 }
131963 @@ -2722,10 +2735,10 @@ static int hardware_enable_all(void)
131964
131965 kvm_usage_count++;
131966 if (kvm_usage_count == 1) {
131967 - atomic_set(&hardware_enable_failed, 0);
131968 + atomic_set_unchecked(&hardware_enable_failed, 0);
131969 on_each_cpu(hardware_enable_nolock, NULL, 1);
131970
131971 - if (atomic_read(&hardware_enable_failed)) {
131972 + if (atomic_read_unchecked(&hardware_enable_failed)) {
131973 hardware_disable_all_nolock();
131974 r = -EBUSY;
131975 }
131976 @@ -3130,7 +3143,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
131977 kvm_arch_vcpu_put(vcpu);
131978 }
131979
131980 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
131981 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
131982 struct module *module)
131983 {
131984 int r;
131985 @@ -3177,7 +3190,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
131986 if (!vcpu_align)
131987 vcpu_align = __alignof__(struct kvm_vcpu);
131988 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
131989 - 0, NULL);
131990 + SLAB_USERCOPY, NULL);
131991 if (!kvm_vcpu_cache) {
131992 r = -ENOMEM;
131993 goto out_free_3;
131994 @@ -3187,9 +3200,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
131995 if (r)
131996 goto out_free;
131997
131998 + pax_open_kernel();
131999 kvm_chardev_ops.owner = module;
132000 kvm_vm_fops.owner = module;
132001 kvm_vcpu_fops.owner = module;
132002 + pax_close_kernel();
132003
132004 r = misc_register(&kvm_dev);
132005 if (r) {
132006 @@ -3199,9 +3214,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
132007
132008 register_syscore_ops(&kvm_syscore_ops);
132009
132010 - kvm_preempt_ops.sched_in = kvm_sched_in;
132011 - kvm_preempt_ops.sched_out = kvm_sched_out;
132012 -
132013 r = kvm_init_debug();
132014 if (r) {
132015 printk(KERN_ERR "kvm: create debugfs files failed\n");